sopList.vue 8.52 KB
<!-- sop管理 -->
<template>
  <div class="marketing sop-list">
    <div class="m-b-20 p-relative">
      <el-button :size="size" type="primary" class="el-icon-plus" @click="handleEdit('add')">新建SOP</el-button>
      <el-button class="sop-back-btn" :size="size" type="primary" @click="handleBack">返回</el-button>
    </div>
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>

      <!-- 表格区域 开始 -->
      <GLTable ref="sopListRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
export default {
  name: 'sopList',
  data() {
    return {
      size: 'small',
      url: url,
      searchForm: {
        sopName: '',
        sopStatus: ''
      },
      // 搜索
      searchFormData: [
        {
          label: 'SOP名称',
          name: 'sopName',
          type: 'input',
          isClear: true,
          maxlength: 20
        },
        {
          label: '营销状态',
          name: 'sopStatus',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'sopStatusList'
        }
      ],
      // 表格按钮
      tableButtonList: [
        {
          type: 'el-button',
          name: 'SOP分析',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.sopStatus != 1
          },
          listeners: {
            click: row => this.handleJump('sopAnalysisList', row)
          }
        },
        {
          type: 'el-button',
          name: '结束',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.sopStatus == 2
          },
          listeners: {
            click: this.handleEnd
          }
        },
        {
          type: 'el-button',
          name: '编辑',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.sopStatus != 3
          },
          listeners: {
            click: row => this.handleEdit('edit', row)
          }
        },
        {
          type: 'el-button',
          name: '删除',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.sopStatus == 1
          },
          listeners: {
            click: this.handleDelete
          }
        }
      ],
      // 表格
      getListApi: this.$apis.sop.getSopInfoListApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: 'SOP名称',
            prop: 'sopName',
            width: 260,
            line: 1
          },
          {
            label: '营销时间',
            prop: 'startDate',
            width: '220',
            formatter: cellValue => {
              return dayjs(cellValue.startDate).format('YYYY-MM-DD') + (cellValue.endDate ? '-' + dayjs(cellValue.endDate).format('YYYY-MM-DD') : '')
            }
          },
          {
            label: '营销状态',
            prop: 'sopStatus',
            formatter: cellValue => {
              return this.baseData.sopStatusList.map(item => item.confId).includes(cellValue.sopStatus) ? this.baseData.sopStatusList.find(item => item.confId == cellValue.sopStatus).confName : '-'
            }
          },
          {
            label: '完成度',
            prop: 'sopStatistics',
            formatter: cellValue => {
              return cellValue.sopStatistics ? Math.round((cellValue.sopStatistics.finishEventCount / cellValue.sopStatistics.eventCount) * 100).toFixed(0) + '%' : '-'
            }
          },
          {
            label: '创建人',
            prop: 'createdBy'
          },
          {
            label: '创建时间',
            prop: 'createdDate',
            width: '180',
            formatter: cellValue => {
              return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      baseData: {
        sopStatusList: [
          {
            confId: 1,
            confName: '未开始'
          },
          {
            confId: 2,
            confName: '进行中'
          },
          {
            confId: 3,
            confName: '已结束'
          }
        ]
      }
    }
  },

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

  methods: {
    handleJump(path, row = {}) {
      this.$router.push({
        path: '/sop/' + path,
        query: row ? { id: row.id, fromPage: '/marketing/sop/sopList' } : ''
      })
    },

    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()
              }
            })
          }
        }
      })
    },
    // 1-新增;2-编辑
    handleEdit(addOrEdit, row) {
      var params = {
        addOrEdit: addOrEdit,
        fromPage: '/marketing/sop/sopList',
        $title: encodeURI(addOrEdit == 'add' ? '新建SOP' : '编辑SOP')
      }
      addOrEdit != 'add' && (params.id = row.id)
      this.$router.push({
        path: '/sop/editSop',
        query: params
      })
    },

    // 结束
    handleEnd(row) {
      this.secondConfirm('结束', '结束SOP后,将不再进行营销任务自动推送,且不可恢复。是否确定结束?', 'sop', 'endSopEventApi', { sopId: row.id })
    },

    handleDelete(row) {
      this.secondConfirm('删除', 'SOP删除后,不可恢复。是否确定删除?', 'sop', 'deleteSopEventApi', { sopId: row.id })
    },

    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)
            }
          }
        })
      }
    },

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

    handleBack() {
      this.$router.push({
        path: '/sop/index'
      })
    },

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

    handleReset() {
      this.searchForm = {
        sopName: '',
        sopStatus: ''
      }
      this.handleSearch()
    }
  }
}
</script>

<style scoped>
.sop-list .sop-back-btn {
  position: absolute;
  right: 0;
  top: 0;
}
</style>