index.vue 10.8 KB
<!-- 秒杀活动 -->
<template>
  <div class="marketing">
    <div class="m-b-20">
      <GLButton :size="size" class="el-icon-plus" type="primary" @click="addActivity()" fn="新增秒杀活动" mode="el-button">新增秒杀活动</GLButton>
    </div>
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>

      <!-- 表格区域 开始 -->
      <GLTable ref="activity" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div slot="activityImg" 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.activityImg" />
            <img class="img-60 pointer" slot="reference" :src="scope.scope.activityImg" />
          </el-popover>
        </div>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
    <!-- 分享 -->
    <share-dialog :isShareVisible="isShareVisible" :shareForm="shareForm" @handleShareClose="handleShareClose"></share-dialog>
  </div>
</template>

<script>
import shareDialog from '../productGroup/components/shareDialog'
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
export default {
  name: 'activity',
  data() {
    return {
      size: 'small',
      url: url,
      downForm: {
        id: '',
        offReason: '',
        goodsStatus: 0
      },
      // 分享
      isShareVisible: false,
      shareForm: {},
      searchForm: {
        activityName: '',
        activityStatus: ''
      },
      tableSearchForm: {},
      // 搜索
      searchFormData: [
        {
          label: '活动名称',
          name: 'activityName',
          type: 'input',
          width: '215px',
          maxlength: 20
        },
        {
          label: '状态',
          name: 'activityStatus',
          type: 'select',
          width: '215px',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'statusList'
        }
      ],
      // 表格按钮
      tableButtonList: [
        {
          type: 'el-button',
          name: '开始',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.activityStatus == '1'
          },
          listeners: {
            click: this.start
          }
        },
        {
          type: 'el-button',
          name: '结束',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.activityStatus == '2'
          },
          listeners: {
            click: this.end
          }
        },
        {
          type: 'GLButton',
          name: row => {
            return row.activityStatus == '1' ? '编辑' : '查看'
          },
          attrs: {
            type: 'text',
            fn: '编辑秒杀活动'
          },
          condition: row => {
            return row.activityStatus == '1' || row.activityStatus == '2' || row.activityStatus == '3'
          },
          listeners: {
            click: row => {
              var editOrDetail = {
                1: 2,
                2: 3,
                3: 3
              }[row.activityStatus]
              return this.handleEdit(editOrDetail, row)
            }
          }
        },
        {
          type: 'el-button',
          name: '删除',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.activityStatus == '3'
          },
          listeners: {
            click: this.del
          }
        },
        {
          type: 'el-button',
          name: '置顶',
          attrs: {
            type: 'text'
          },
          listeners: {
            click: this.topping
          }
        },
        {
          type: 'el-button',
          name: '分享',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.activityStatus == '1' || row.activityStatus == '2'
          },
          listeners: {
            click: this.handleShare
          }
        },
      ],
      // 表格
      getListApi: this.$apis.seckillActivity.getActivityPageApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '活动名称',
            prop: 'activityName',
            width: 220
          },
          {
            label: '缩略图',
            prop: 'activityImg',
            addHtml: 'activityImg'
          },
          {
            label: '浏览量(次)',
            prop: 'viewAmount',
            width: 140
          },
          {
            label: '销量',
            prop: 'saleAmount'
          },
          {
            label: '秒杀价(元)',
            name: 'activityPrice',
            width: 140,
            formatter: cellValue => {
              // if (cellValue.activityPrice) {
              return (cellValue.activityPrice / 100).toFixed(2)
              // }
              // return ''
            }
          },
          {
            label: '剩余库存',
            prop: 'goodsStock'
          },
          {
            label: '创建日期',
            name: 'createdDate',
            width: 200,
            formatter: cellValue => {
              return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
            }
          },
          {
            label: '活动状态',
            name: 'activityStatus',
            formatter: cellValue => {
              return this.baseData.statusList.find(item => item.confId == cellValue.activityStatus).confName
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      baseData: {
        statusList: [
          {
            confId: '1',
            confName: '未开始 '
          },
          {
            confId: '2',
            confName: '进行中'
          },
          {
            confId: '3',
            confName: '已结束'
          }
        ]
      }
    }
  },

  components: {
    shareDialog
  },

  mounted() {
    this.getOptionsList('searchFormData')
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        // delete this.tableSearchForm.createDate
        resolve()
      })
    },

    secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis[apiModule][apiName](apiParams).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                fn && fn()
                this.handleSearch()
              }
            })
          }
        }
      })
    },

    //开始
    start(item) {
      this.startOrEndConfirm('开始', item)
    },

    //结束
    end(item) {
      this.startOrEndConfirm('结束', item)
    },

    startOrEndConfirm(txt, row) {
      var title = txt
      var params = {}
      params.id = row.id
      if (txt == '开始') {
        params.activityStatus = '2' //活动状态(1:未开始,2:开始,3:结束)
      } else if (txt == '结束') {
        params.activityStatus = '3' //活动状态(1:未开始,2:开始,3:结束)
      }
      this.secondConfirm(title, '确定要' + txt + '此活动?', 'seckillActivity', 'toggleStatusApi', params)
    },

    //置顶
    topping(row) {
      var params = {}
      params.id = row.id
      this.secondConfirm('删除', '确定置顶此活动?', 'seckillActivity', 'topActivityApi', params)
    },

    //删除
    del(row) {
      var params = {}
      params.id = row.id
      this.secondConfirm('删除', '确定删除此活动?', 'seckillActivity', 'deleteActivityApi', params)
    },

    //新增活动
    addActivity() {
      this.$router.push('/seckillActivity/editActivity/1')
    },

    // addOrEdit:1-新增;2-编辑;3-查看
    handleEdit(addOrEdit, row) {
      this.$router.push('/seckillActivity/editActivity/' + addOrEdit + '/' + row.id)
    },

    handleShare(row) {
      this.$apis.seckillActivity.getSharedApi({ id: row.id }).then(res => {
        this.shareForm = res
        this.handleShareClose()
      })
    },

    handleShareClose() {
      this.isShareVisible = !this.isShareVisible
    },

    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },

    handleSearch() {
      this.$refs.activity.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        activityName: '',
        activityStatus: ''
      }
      this.handleSearch()
    },

    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.activity.data.length ? (this.$refs.activity.tableHeightValues = '') : this.$refs.activity.setTableHeightFun()
    }
  }
}
</script>

<style scoped></style>