index.vue 5.18 KB
<template>
  <div class="channel-wrap">
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="tableSearchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <GLTable ref="channelRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :beforeSearchFn="beforeSearchFn" :tableParams="tableParams" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun">
        <div slot="publicityImg" class="table-image" slot-scope="scope">
          <el-popover placement="top" width="160" trigger="hover" popper-class="table-popover-block">
            <img class="table-popover-img" :src="scope.scope.publicityImg" />
            <img class="img-36 pointer" slot="reference" :src="scope.scope.publicityImg" />
          </el-popover>
        </div>
        <template slot="activityLink" slot-scope="scope">
          <span class="relink">{{ scope.scope.activityName }}</span>
        </template>
        <template slot="moveCarCodeCount" slot-scope="scope">
          <span class="moveCarCodeCount" @click="opneMoveMessage(scope.scope)">{{ scope.scope.moveCarCodeCount }}</span>
        </template>
        <template slot="switch" slot-scope="scope">
          <el-switch v-model="scope.scope.isOpen" @change="updateState(scope.scope)"></el-switch>
        </template>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <el-button type="text" @click="handleEdit(scope.scope)">编辑</el-button>
        </div>
      </GLTable>
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
import * as dayjs from 'dayjs'
export default {
  name: 'App',
  data() {
    return {
      tableSearchForm: {
        channelName: '',
        createDate: []
      },
      searchForm: {},
      url: url,
      searchFormData: [
        {
          label: '频道名称',
          name: 'channelName',
          type: 'input'
        },
        {
          label: '创建时间',
          name: 'createDate',
          type: 'datePicker',
          isClear: true,
          customPickerOptions: {
            disabledDate(date) {
              const yesterday = new Date(new Date().setDate(new Date().getDate()))
              if (date > yesterday) {
                return true
              }
              return false
            }
          }
        }
      ],
      getListApi: this.$apis.channel.getChannelListApi,
      tableParams: {
        listName: 'list',
        // tableOption: true,
        tableColumns: [
          {
            label: '频道名称',
            prop: 'channelName',
            formatter: cellValue => {
              return cellValue.channelName || '--'
            }
          },
          {
            label: '频道子名称',
            width: 180,
            prop: 'channelChildName'
          },
          {
            label: '频道宣传语',
            prop: 'promotion',
            width: 300,
            line: 1,
            formatter: cellValue => {
              return cellValue.promotion || '--'
            }
          },
          {
            label: '宣传图',
            prop: 'publicityImg',
            addHtml: 'publicityImg'
          },
          {
            label: '关联门店',
            width: 100,
            prop: 'linkMerchantCnt',
            formatter: cellValue => {
              return cellValue.linkMerchantCnt || '--'
            }
          },
          {
            label: '创建日期',
            width: 220,
            prop: 'createdDate',
            formatter: cellValue => {
              return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
            }
          },
          {
            label: '操作',
            addHtml: 'auth-button',
            fixed: 'right',
            width: 100
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' }
    }
  },
  created() {},
  mounted() {},
  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.tableSearchForm))
      if (this.tableSearchForm.createDate.length) {
        params.createdDateStrat = new Date(this.tableSearchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.createdDateEnd = new Date(this.tableSearchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }

      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchForm = this.getParams()
        delete this.searchForm.createDate
        resolve()
      })
    },
    handleSearch() {
      this.$refs.channelRef.refreshTable()
    },
    handleReset() {
      this.tableSearchForm = {
        channelName: '',
        createDate: []
      }
      this.searchForm = {}
      this.handleSearch()
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.channelRef.data.length ? (this.$refs.channelRef.tableHeightValues = '') : this.$refs.channelRef.setTableHeightFun()
    },
    handleEdit(val) {
      this.$router.push({
        path: `/channel/add?id=${val.id}&channelType=${val.channelType}&$title=频道设置`
      })
    }
  }
}
</script>

<style scoped lang="scss">
.channel-wrap {
}
</style>