index.vue 7.53 KB
<template>
  <div class="container">
    <div class="sticky">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <div class="sticky-btns">
        <div class="btns">
          <el-button type="default" plain @click="showEditFun">新建</el-button>
          <el-button type="default" @click="handleExport">导出</el-button>
        </div>
      </div>
    </div>
    <div class="tabelList">
      <div class="table-title">红包配置列表</div>
      <GLTable ref="listRef" :getListApi="getListApi" :searchForm="tableSearchForm" :noDataImg="url" :tableParams="tableParams" :pageConf="pageConf">
        <span slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </span>
      </GLTable>
    </div>
    <link-detail :linkDetailObj.sync="linkDetailObj"></link-detail>
    <edit :editObj.sync="editObj"></edit>
    <transition name="fade">
      <whiteList v-if="whiteListObj.show" :whiteListObj.sync="whiteListObj" :key="whiteListKey"></whiteList>
    </transition>
  </div>
</template>

<script type='text/ecmascript-6'>
import url from '@/assets/empty.png'
import * as dayjs from 'dayjs'
import linkDetail from './linkDetail.vue'
import edit from './edit.vue'
import whiteList from './whiteList'
import { exportFn, activityStatusList } from '@/common/constant'

export default {
  components: { linkDetail, edit, whiteList },
  name: 'RedEnvelopeConfig',
  data() {
    return {
      url,
      whiteListKey: 0,
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      searchForm: {
        activityName: '',
        merchantId: '',
        activityStatus: '',
        activityTime: ''
      },
      searchFormData: [
        {
          label: '活动名称',
          name: 'activityName',
          type: 'input',
          maxlength: 40
        },
        {
          label: '所属渠道',
          name: 'merchantName',
          type: 'input',
          maxlength: 40
        },
        {
          label: '状态',
          name: 'activityStatus',
          type: 'select',
          optionList: activityStatusList,
          optionId: 'id',
          optionLabel: 'text'
        },
        {
          label: '活动时间',
          name: 'activityTime',
          type: 'datePicker',
          isClear: true
        },
        {
          label: '创建类型',
          name: 'createdSource',
          type: 'select',
          optionList: [
            { text: '全部', id: '' },
            { text: '外采', id: '1' },
            { text: '自研', id: '0' }
          ],
          optionId: 'id',
          optionLabel: 'text'
        }
      ],
      getListApi: this.$apis.redenvelope.getRedEnvelopeConfigList,
      tableParams: {
        listName: 'data',
        tableOption: true,
        tableColumns: [
          {
            label: '活动名称',
            prop: 'activityName',
            minWidth: 100
          },
          {
            label: '所属渠道',
            prop: 'merchantName',
            minWidth: 100
          },
          {
            label: '活动时间',
            prop: 'questionCount',
            minWidth: 100,
            formatter: cell => {
              return cell.activityStartTime ? `${dayjs(cell.activityStartTime).format('YYYY/MM/DD')}-${dayjs(cell.activityEndTime).format('YYYY/MM/DD')} ` : ''
            }
          },
          {
            label: '活动形式',
            prop: 'activityTypeStr',
            minWidth: 100
          },
          {
            label: '创建类型',
            minWidth: 100,
            formatter: cell => {
              return { 0: '自研', 1: '外采' }[cell.sourceType]
            }
          },
          {
            label: '红包链接总数',
            prop: 'amount',
            minWidth: 150
          },
          {
            label: '已用总数',
            prop: 'usedAmount',
            minWidth: 100
          },
          {
            label: '可用总数',
            prop: 'usableAmount',
            minWidth: 100
          },
          {
            label: '状态',
            prop: 'activityStatusStr',
            minWidth: 100
          }
        ]
      },
      // 表格按钮
      tableButtonList: [
        {
          type: 'el-button',
          name: '编辑',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.sourceType == 1
          },
          listeners: {
            click: row => this.showEditFun(row)
          }
        },
        {
          type: 'el-button',
          name: '链接详情',
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.jumpDetail(row)
          }
        },
        {
          type: 'el-button',
          name: '白名单',
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.whiteList(row)
          }
        }
      ],
      editObj: {},
      linkDetailObj: {},
      whiteListObj: {},
      tableSearchForm: {}
    }
  },
  mounted() {},
  methods: {
    getParams() {
      const searchForm = JSON.parse(JSON.stringify(this.searchForm))
      if (searchForm.activityTime) {
        searchForm.activityStartTime = dayjs(this.searchForm.activityTime[0]).format('YYYY-MM-DD')
        searchForm.activityEndTime = dayjs(this.searchForm.activityTime[1]).format('YYYY-MM-DD')
      }
      delete searchForm.activityTime
      return searchForm
    },
    handleSearch() {
      this.tableSearchForm = this.getParams()
      this.$refs.listRef.refreshTable()
    },
    handleReset() {
      this.searchForm = this.$options.data.call(this).searchForm
      this.handleSearch()
    },
    jumpDetail(e) {
      this.linkDetailObj = {
        show: true,
        id: e.id
      }
    },
    whiteList(e) {
      this.whiteListKey++ // 更改key值,强制Vue重新渲染whiteList组件
      setTimeout(() => {
        this.whiteListObj = {
          show: true,
          id: e.id
        }
      }) // 延迟100毫秒,您可以根据需要调整这个值
    },
    showEditFun(e) {
      // this.editObj = {
      //   show: true,
      //   title: e.id ? '编辑' : '新建',
      //   id: e.id || ''
      // }
      this.$router.push({
        path: `/redEnvelope/components/RedEnvelopeConfig/add`,
        query:{
          id:e.id,
          sourceType:e.sourceType
        }
      })
    },
    handleExport() {
      this.$apis.redenvelope
        .exportActivityRedEnvelope({
          ...this.getParams(),
          ...this.$refs.listRef.page
        })
        .then(res => {
          exportFn(res)
        })
    }
  }
}
</script>

<style scoped lang='scss'>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.1s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */ {
  opacity: 0;
}

.container {
  height: 100%;
  background-color: #fff;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  padding: 20px;
  .table-title {
    font-weight: 700;
    font-size: 16px;
    color: #333333;
    padding-bottom: 18px;
  }
  .sticky {
    position: relative;
    z-index: 2;
    &-btns {
      position: absolute;
      right: 0;
      bottom: -23px;
      overflow: hidden;
      .el-button + .el-button {
        margin-left: 8px;
      }
      .btns {
        transition: all 0.25s;
        .el-button {
          padding: 8px 15px;
          min-width: 60px;
        }
      }
    }
  }
}
</style>