index.vue 9.95 KB
<!-- 商品管理-门店 -->
<template>
  <div class="marketing pro-group p-t-20">
    <div class="m-b-20">
      <GLButton :size="size" type="primary" class="el-icon-plus" @click="addActivity()" fn="新增秒杀活动" mode="el-button">新增秒杀活动</GLButton>
      <!-- <el-button :size="size" type="primary" class="el-icon-plus" @click="addActivity()">新增秒杀活动</el-button> -->
    </div>
    <div class="container">
      <div>
        <glsx-combi-form ref="showSearch" :formObj="searchForm" :formData="searchFormData">
          <span slot="footer" class="footer-btns">
            <el-button :size="size" @click="handleReset">重置</el-button>
            <el-button :size="size" type="primary" @click="handleSearch">查询</el-button>
          </span>
        </glsx-combi-form>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="activity" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <template slot="activityImg" slot-scope="scope">
          <img class="img-60" :src="scope.scope.activityImg" />
        </template>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <el-button v-if="scope.scope.activityStatus == '1'" type="text" @click="start(scope.scope)">开始</el-button>
          <el-button v-if="scope.scope.activityStatus == '2'" type="text" @click="end(scope.scope)">结束</el-button>
          <GLButton v-if="scope.scope.activityStatus == '1'" type="text" @click="handleEdit(2, scope.scope)" fn="编辑秒杀活动" mode="el-button">编辑</GLButton>
          <!-- <el-button v-if="scope.scope.activityStatus == '1'" type="text" @click="handleEdit(2, scope.scope)">编辑</el-button> -->
           <GLButton  v-if="scope.scope.activityStatus == '2' || scope.scope.activityStatus == '3'" type="text" @click="handleEdit(3, scope.scope)"  fn="编辑秒杀活动" mode="el-button">查看</GLButton>
          <!-- <el-button v-if="scope.scope.activityStatus == '2' || scope.scope.activityStatus == '3'" type="text" @click="handleEdit(3, scope.scope)">查看</el-button> -->
          <el-button v-if="scope.scope.activityStatus == '3'" type="text" @click="del(scope.scope)">删除</el-button>
          <el-button type="text" @click="topping(scope.scope)">置顶</el-button>
          <el-button v-if="scope.scope.activityStatus == '1' || scope.scope.activityStatus == '2'" type="text" @click="handleShare(scope.scope)">分享</el-button>
        </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'
        }
      ],
      // 表格
      getListApi: this.$apis.seckillActivity.getActivityPageApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '活动名称',
            prop: 'activityName'
          },
          {
            label: '缩略图',
            prop: 'activityImg',
            addHtml: 'activityImg'
          },
          {
            label: '浏览量(次)',
            prop: 'viewAmount'
          },
          {
            label: '销量',
            prop: 'saleAmount'
          },
          {
            label: '秒杀价(元)',
            name: 'activityPrice',
            formatter: cellValue => {
              if (cellValue.activityPrice) {
                return (cellValue.activityPrice / 100).toFixed(2)
              }
              return ''
            }
          },
          {
            label: '剩余库存',
            prop: 'goodsStock'
          },
          {
            label: '创建日期',
            name: 'createdDate',
            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>