index.vue 9.53 KB
<template>
  <div class="task-contentbox">
    <div>
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="业务场景:">
          <el-select v-model="searchForm.businessScene" size="small">
            <el-option
              v-for="(item, index) in sceneOption"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商户:">
          <el-input
            v-model="searchForm.merchantName"
            size="small"
            placeholder="请输入商户名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="活动/产品:">
          <el-input
            v-model="searchForm.activityName"
            size="small"
            placeholder="请输入活动/产品名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态:">
          <el-select v-model="searchForm.activityStatus" size="small">
            <el-option
              v-for="(item, index) in taskStatus"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="handleSearch"
            >查询
          </el-button>
          <el-button plain size="small" @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-top">
      <div class="table-title">订单列表</div>
      <el-button type="primary" size="small" @click="handleEdit()"
        >添加任务</el-button
      >
    </div>
    <div>
      <d2-table
        ref="taskTable"
        :searchForm="searchForm"
        :getListApi="getListApi"
        :tableParams="tableParams"
        :pageConf="pageConf"
      >
        <div slot="businessScene" slot-scope="scope">
          <span v-if="scope.scope.businessScene == 0">1.0新车权益销售</span>
          <span v-if="scope.scope.businessScene == 1">1.1次新车精品升级</span>
          <span v-if="scope.scope.businessScene == 2">1.2次新车线上转化</span>
          <span v-if="scope.scope.businessScene == 3">1.3存量用户众筹</span>
        </div>
        <div slot="activityStatus" slot-scope="scope">
          <span v-if="scope.scope.activityStatus == statusNum.UNPUBLISH"
            >未发布</span
          >
          <span v-if="scope.scope.activityStatus == statusNum.PUBLISHED"
            >已发布</span
          >
          <span v-if="scope.scope.activityStatus == statusNum.FINISHIED"
            >已结束</span
          >
        </div>
        <template slot="auth-button" slot-scope="scope">
          <el-button
            type="text"
            v-if="scope.scope.activityStatus == statusNum.UNPUBLISH"
            @click="handleEdit(scope.scope, 1)"
            >编辑</el-button
          >
          <el-button
            type="text"
            v-if="scope.scope.activityStatus != statusNum.UNPUBLISH"
            @click="handleAnalyze(scope.scope)"
            >任务分析</el-button
          >
          <el-button
            type="text"
            v-if="scope.scope.activityStatus == statusNum.UNPUBLISH"
            @click="handleDelete(scope.scope)"
            style="color: red"
            >删除</el-button
          >
          <el-button
            type="text"
            v-if="scope.scope.activityStatus == statusNum.UNPUBLISH"
            @click="handleActive(scope.scope)"
            >发布</el-button
          >
          <el-button
            type="text"
            v-if="scope.scope.activityStatus == statusNum.PUBLISHED"
            @click="handleInactive(scope.scope)"
            >结束</el-button
          >
          <el-button type="text" @click="handleClone(scope.scope)"
            >复制</el-button
          >
          <el-button
            type="text"
            v-if="scope.scope.activityStatus != statusNum.UNPUBLISH"
            @click="handleViewDetail(scope.scope)"
            >查看</el-button
          >
        </template>
      </d2-table>
    </div>
  </div>
</template>
<script>
const sceneOption = [
  {
    label: '全部',
    value: '',
  },
  {
    label: '1.0新车权益销售',
    value: '0',
  },
  {
    label: '1.1次新车精品升级',
    value: '1',
  },
  {
    label: '1.2次新车线上转化',
    value: '2',
  },
  {
    label: '1.3存量用户众筹',
    value: '3',
  },
]
const statusNum = {
  UNPUBLISH: '1',
  PUBLISHED: '2',
  FINISHIED: '3',
}
const taskStatus = [
  {
    label: '全部',
    value: '',
  },
  {
    label: '未发布',
    value: statusNum.UNPUBLISH,
  },
  {
    label: '已发布',
    value: statusNum.PUBLISHED,
  },
  {
    label: '已结束',
    value: statusNum.FINISHIED,
  },
]
import { taskApi } from '../../../api/task'

export default {
  data() {
    return {
      // 业务场景选项
      sceneOption,
      // 状态选项
      taskStatus,
      statusNum,
      searchForm: {
        businessScene: '',
        merchantName: '',
        activityName: '',
        activityStatus: '',
      },
      // 表格参数
      tableParams: {
        // btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'data.data',
        tableOption: true,
        tableColumns: [
          {
            label: '业务场景',
            prop: 'businessScene',
            addHtml: 'businessScene',
            width: 150,
          },
          {
            label: '商户',
            prop: 'merchantName',
            width: 150,
          },
          {
            label: '活动/产品',
            prop: 'activityName',
            width: 200,
          },
          {
            label: '任务数',
            prop: 'missionCount',
          },
          {
            label: '创建人',
            prop: 'createdBy',
          },
          {
            label: '创建时间',
            prop: 'createdTime',
            width: 150,
          },
          {
            label: '状态',
            prop: 'activityStatus',
            addHtml: 'activityStatus',
          },
        ],
      },
      pageConf: {
        pageSize: 'pageSize',
        pageNum: 'pageNum',
        totalCount: 'data.count',
      },
      // 活动开始/结束时间
      startTime: '',
      endTime: '',
      // 获取订单列表
      getListApi: taskApi.findMissionList,
      status: false,
    }
  },
  methods: {
    // 搜索框搜索
    handleSearch() {
      this.$refs.taskTable.refreshTable()
    },
    // 重置搜索框搜索
    handleReset() {
      this.searchForm = {
        businessScene: '',
        merchantName: '',
        activityName: '',
        activityStatus: '',
      }
      this.$nextTick(() => {
        this.$refs.taskTable.refreshTable()
      })
    },
    // 编辑
    handleEdit(item, type) {
      this.status = true
      const para = {
        task: item,
        type,
      }
      this.$root.to(
        ['任务中心', '任务平台', '任务管理', '任务模板管理', '*添加任务模板'],
        para
      )
      this.$root.close('任务管理列表')
    },
    // 删除
    handleDelete(scope) {
      this.secondConfirm(
        '提示',
        '任务计划删除后,无法恢复。是否确定删除?',
        4,
        scope.id
      )
    },
    // 发布
    handleActive(scope) {
      this.secondConfirm(
        '提示',
        '任务计划发布后,任务会自动下发给对应的员工。是否确定发布?',
        2,
        scope.id
      )
    },
    // 结束
    handleInactive(scope) {
      this.secondConfirm(
        '提示',
        '任务计划结束后,整个任务计划将无法再使用。是否确定结束?',
        3,
        scope.id
      )
    },
    // 克隆
    handleClone(scope) {
      this.$root.to(
        ['任务中心', '任务平台', '任务管理', '任务模板管理', '*添加任务模板'],
        scope
      )
      this.$root.close('任务管理列表')
    },
    // 跳转查看详情
    handleViewDetail(scope) {
      this.$root.to(
        ['任务中心', '任务平台', '任务管理', '任务模板管理', '*查看任务'],
        { taskId: scope.id }
      )
    },
    // 任务分析
    handleAnalyze(scope) {
      this.$root.to(
        ['任务中心', '任务平台', '任务管理', '任务模板管理', '*任务分析'],
        { taskId: scope.id }
      )
    },
    // 二次确认
    secondConfirm(title, txt, apiParams, apiId, fn) {
      var params = { id: apiId, activityStatus: apiParams }
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: (action) => {
          if (action == 'confirm') {
            taskApi.updateStatusMission(params).then((res) => {
              this.$message({
                message: res.code == '0' ? '操作成功' : '操作失败',
                type: res.code == '0' ? 'success' : 'error',
              })
              if (res.code == '0') {
                this.$nextTick(() => {
                  this.$refs.taskTable.refreshTable()
                })
              }
            })
          }
        },
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.task-contentbox {
  padding: 20px;
}
.table-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.table-title {
  font-size: 16px;
  font-weight: 600;
  color: rgb(51, 51, 51);
  line-height: 16px;
}
/deep/ .el-table .cell {
  line-height: 20px;
}
</style>