ai-tabel.vue 8.04 KB
<template>
  <div class="help-main">
    <div class="help-tabel scrm-box-f">
      <GLTable v-show="taskNum" @setTableFinishFun="setTableFinishFun" :noDataImg="url" ref="taskForm" :getListApi="getListApi" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
        <div class="table-btns" slot="optionBtns" slot-scope="scope">
          <el-button type="text" @click="handleDel(scope.scope)" :disabled="scope.scope.taskStatus == 2 || scope.scope.taskStatus == 3">删除</el-button>
          <el-button type="text" @click="goDetail(scope.scope)" v-if="activeIndex == 2">数据详情</el-button>
           <el-button type="text" @click="goEdit(scope.scope)">编辑</el-button>
        </div>
        <template slot="taskStatus" slot-scope="scope">
          <div :class="['task_icon', `task_icon${scope.scope.taskStatus}`]">{{ taskStatus(scope.scope.taskStatus) }}</div>
        </template>
        <template slot="phoneCount" slot-scope="scope">
          <div class="process-box" v-if="activeIndex == 1">
            <div class="process-bar">
              <div class="process-bar-item" :style="{ width: calcNum(scope.scope) }"></div>
            </div>
            <div class="process-val">{{ calcNum(scope.scope) }}</div>
          </div>
          <div class="process-box" v-if="activeIndex == 2">
            <div class="process-bar">
              <div class="process-bar-item" :style="{ width: '100%' }"></div>
            </div>
            <div class="process-val">{{ scope.scope.executedCount ? scope.scope.executedCount : 0 }}</div>
          </div>
        </template>
      </GLTable>
      <div class="tabel-null" v-show="taskNum == 0">
        <div class="tabel-null-panel">
          <div class="null-image"><img src="@/assets/img/empty.png" /></div>
          <div class="null-desc">
            暂无数据,
            <label @click="$parent.handleAdd">添加数据</label>
          </div>
        </div>
      </div>
    </div>
    <GLDialog title="提示" @onOk="handleDelSure" @onCancel="dialogVisibleDel = false" type="error" content="是否删除?" :visible.sync="dialogVisibleDel" mode="small"></GLDialog>
  </div>
</template>

<script>
const TASK_STATUS = [
  {
    label: '待执行',
    value: 1
  },
  {
    label: '执行中',
    value: 2
  },
  {
    label: '执行中',
    value: 3
  },
  {
    label: '已完成',
    value: 4
  }
]
export default {
  name: 'resultStatistics',
  data() {
    return {
      isFirstEnter: false,
      taskNum: 0,
      dialogVisibleDel: false,
      taskId: '',
      tableSearchForm: {},
      createTime: '',
      dialogVisible: true,
      getListApi: this.$apis.aiCard.taskPage,
      tableParams: {
        tableOption: false,
        checkSelectKey: 'id',
        checkSelectVal: [],
        hasNum: false,
        listName: 'data',
        tableColumns: []
      },
      tableColumns1: [
        {
          label: '任务名称',
          prop: 'taskName',
          minWidth: 140,
          line: 1
        },
        {
          label: '状态',
          prop: 'taskStatus',
          minWidth: 140,
          addHtml: 'taskStatus'
        },
        {
          label: '进度',
          prop: 'phoneCount',
          minWidth: 200,
          addHtml: 'phoneCount'
        },
        {
          label: '创建时间',
          prop: 'createdTime',
          minWidth: 180
        },
        {
          label: '操作',
          prop: 'optionBtns',
          width: '120px',
          addHtml: 'optionBtns',
          fixed: 'right'
        }
      ],
      tableColumns2: [
        {
          label: '任务名称',
          prop: 'taskName',
          minWidth: 140,
          line: 1
        },
        {
          label: '状态',
          prop: 'taskStatus',
          addHtml: 'taskStatus'
        },
        {
          label: '执行总数',
          prop: 'phoneCount',
          width: 200,
          addHtml: 'phoneCount'
        },
        {
          label: '已通过申请',
          prop: 'passCount',
          width: 200,
          line: 1
        },
        {
          label: '不存在的手机号用户',
          prop: 'unExistCount',
          width: 200,
          line: 1
        },
        {
          label: '提交时间',
          prop: 'submitTime',
          width: 180
        },
        {
          label: '操作',
          prop: 'optionBtns',
          width: '200px',
          addHtml: 'optionBtns',
          fixed: 'right'
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      baseData: {
        allMerchantList: [],
        roleList: [],
        staffStatusList: []
      }
    }
  },
  props: {
    activeIndex: Number
  },
  activated() {
    if (!this.isFirstEnter) {
      this.handleSeach()
    }
    this.isFirstEnter = false
  },
  watch: {
    activeIndex(val) {
      if (val == 2) {
        this.tableParams.tableColumns = this.tableColumns2
      } else {
        this.tableParams.tableColumns = this.tableColumns1
      }
      this.handleSeach()
    }
  },
  created() {
    this.isFirstEnter = true
    this.tableParams.tableColumns = this.tableColumns1
  },
  methods: {
    calcNum(val) {
      let count = '0%'
      if (val.phoneCount) {
        count = (100 * val.executedCount) / val.phoneCount
        count = (count > 100 ? 100 : Number.isInteger(count) ? count : count.toFixed(2)) + '%'
      }
      return count
    },
    taskStatus(status) {
      return TASK_STATUS.find(item => item.value == status).label
    },
    //删除
    handleDel(scope) {
      this.taskId = scope.id
      this.dialogVisibleDel = true
    },
    handleDelSure() {
      const { taskId, activeIndex } = this
      this.$apis.aiCard.taskDelete({ taskId, deleteType: activeIndex }).then(res => {
        this.dialogVisibleDel = false
        this.handleSeach()
      })
    },
    handleSeach() {
      this.$refs.taskForm.refreshTable()
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm.taskStatus = this.activeIndex == 1 ? 1 : 4
        resolve()
      })
    },
    setTableFinishFun(val) {
      this.taskNum = val.length
      this.$refs.taskForm.data.length ? (this.$refs.taskForm.tableHeightValues = '') : this.$refs.taskForm.setTableHeightFun()
    },
    goDetail(scope) {
      this.$router.push('/home/taskDetail?id=' + scope.id)
    },
    goEdit(data){
      this.$emit('update',data)
    }
  }
}
</script>

<style lang="scss" scoped>
.scrm-box-f {
  padding: 20px;
}
.tabel-null {
  min-height: calc(100vh - 480px);
  display: flex;
  justify-content: center;
  align-items: center;
  &-panel {
    .null-image {
      margin: 5px auto;
      width: 64px;
    }
    .null-desc {
      font-size: 14px;
      font-weight: 400;
      color: #666666;
      line-height: 22px;
      label {
        color: #5850ff;
        cursor: pointer;
      }
    }
  }
}
.process-box {
  display: flex;
  align-items: center;
  width: 200px;
  .process-bar {
    margin-right: 6px;
  }
  .process-val {
    width: 80px;
  }
}
.process-bar {
  width: 100%;
  height: 6px;
  background: #e7e7e7;
  position: relative;
  border-radius: 6px;
  .process-bar-item {
    position: absolute;
    top: 0px;
    border-radius: 6px;
    left: 0px;
    height: 6px;
    background: #5850ff;
  }
}
.task_icon {
  position: relative;
  &::after {
    content: '';
    position: absolute;
    top: 4px;
    left: -10px;
    width: 6px;
    height: 6px;
    border-radius: 4px;
  }
  &.task_icon1 {
    &::after {
      background: #fdb757;
    }
  }
  &.task_icon2 {
    &::after {
      background: #5850ff;
    }
  }
  &.task_icon3 {
    &::after {
      background: #5850ff;
    }
  }
  &.task_icon4 {
    &::after {
      background: #2cca74;
    }
  }
}
.select-panel {
  display: flex;
  margin-bottom: 10px;
  justify-content: space-between;
  align-items: center;
  .help-tabel-name {
    font-size: 16px;
    color: #333333;
    text-align: left;
    line-height: 16px;
    font-weight: 500;
  }
  .help-select-date {
    display: flex;
    align-items: center;
    .select-date-input {
      margin-right: 10px;
    }
  }
}
</style>