index.vue 6.56 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>
    <whiteList :linkDetailObj.sync="whiteListObj">
    </whiteList>
  </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,
      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
        },
      ],
      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: '红包链接总数',
            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',
          },
          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.whiteListObj = {
        show: true,
        id: e.id
      }
    },
    showEditFun(e) {
      this.editObj = {
        show: true,
        title: e.id ? '编辑' : '新建',
        id: e.id || ''
      }
    },
    handleExport(row) {
      this.$apis.redenvelope.exportActivityRedEnvelope(this.getParams()).then(res => {
        exportFn(res)
      })
    },
  }
}
</script>

<style scoped lang='scss'>
.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>