<template>
  <div class="app-container pageTopForm">
    <el-form :model="queryParams" ref="queryRef" v-show="showSearch" size="small" label-width="68px" class="demo-ruleForm" @submit.native.prevent>
      <el-col :span="6">
        <el-form-item label="任务名称" prop="taskName">
          <el-input
            v-model="queryParams.taskName"
            placeholder="请输入任务名称"
            clearable
            @keyup.enter.native="handleQuery"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item class="lastBtnSty">
          <el-button type="primary" size="mini" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-col>
    </el-form>
    <TableList :columns="columns" :config="config" :queryParams="queryParams" :modelIdent="this.$options.name" :tableList="roleList" @fnClick="callback" @fnRenderList="getList" @value-change="handleValueChange">
      <template #tempStatus="{ row, column }">
        <dict-tag :options="dict.type.eps_business_review_status" :value="row.reviewStatus"/>
      </template>
    </TableList>
  </div>
</template>

<script setup>
  import TableList from "@/components/table/index.vue"
  import {listBusDeploy, delBusDeploy, updateBusDeploy} from "@/api/disRevenue/earnManage"
  export default {
    name: 'BusinessIssued',
    components: {TableList},
    dicts: ['eps_business_review_status'],
    data() {
      return {
        editStatus: false,
        loading: false,
        showSearch: true,
        roleList: [],
        queryParams: {
          total: 0,
          pageNum: 1,
          pageSize: 10
        },
        // 列显隐信息
        columns: {
          id: {label: 'ID', width: '50'},
          taskName: { label: `任务名称`, minWidth: '120', visible: true},
          businessName: { label: `业务名称`, minWidth: '120', visible: true},
          scriptName: { label: `脚本名称`, minWidth: '120', visible: true},
          scriptParams: { label: `脚本参数`, minWidth: '120',},
          deployDevice: { label: `部署设备`, minWidth: '120', customTooltip: true},
          submitBy: { label: `提交人`, minWidth: '120',},
          reviewStatus: { label: `审核状态`, minWidth: '100', slotName: 'tempStatus', visible: true},
          reviewTime: { label: `审核时间`, minWidth: '120'},
          reviewComment: { label: `审核意见`, minWidth: '160'},
          createTime: { label: `创建时间`, minWidth: '160'},
          updateTime: { label: `修改时间`, minWidth: '160'},
        },
        config: {
          tableButton: {
            top: [
              {content: '新增', fnCode: 'add', type: 'primary', icon: 'el-icon-plus', hasPermi: 'earnManage:businessIssued:add'},
              {content: '导出', fnCode: 'export', type: 'warning', icon: 'el-icon-download', hasPermi: 'earnManage:businessIssued:export'},
            ],
            line: [
              {content: '修改', fnCode: 'edit', type: 'primary', icon: 'el-icon-edit', showName: 'reviewStatus', showVal: ['0', '3'], hasPermi: 'earnManage:businessIssued:edit'},
              {content: '详情', fnCode: 'details', type: 'primary', icon: 'el-icon-view', hasPermi: 'earnManage:businessIssued:details'},
              {content: '删除', fnCode: 'delete', type: 'danger', icon: 'el-icon-delete', showName: 'reviewStatus', showVal: ['0', '3'], hasPermi: 'earnManage:businessIssued:delete'},
              {content: '审核', fnCode: 'audit', type: 'primary', showName: 'reviewStatus', showVal: '1', icon: 'el-icon-document-add', hasPermi: 'earnManage:businessIssued:audit'},
              {content: '提交审核', fnCode: 'upAudit', type: 'primary', showName: 'reviewStatus', showVal: ['0', '3'], icon: 'el-icon-document-checked', hasPermi: 'earnManage:businessIssued:upAudit'},
            ]
          }
        }
      }
    },
    created() {
      this.getList();
    },
    activated() {
      this.$nextTick(() => {
        this.getList();
      });
    },
    methods: {
      rowDataChange(row) {
        this.$set(row, 'editStatus', true);
      },
      // 处理子组件传递的新值
      handleValueChange(newValue) {
        // 父组件更新自身数据，实现同步
        this.showSearch = newValue;
        // console.log('父组件拿到新值:', newValue);
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        listBusDeploy(this.queryParams).then(response => {
          this.roleList = response.rows;
          this.queryParams.total = response.total;
          this.loading = false;
        })
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryRef");
        this.handleQuery();
      },

      callback(result, rowData, selectChange) {
        if (result && result.fnCode) {
          switch (result.fnCode) {
            case 'add':
              this.$router.push({
                path:'/earnManage/businessIssued/details'});
              break;
            case 'edit':
              this.$router.push({
                path:'/earnManage/businessIssued/details',
                query: {
                  id: rowData.id
                }
              });
              break;
            case 'details':
              this.$router.push({
                path:'/earnManage/businessIssued/details',
                query:{
                  id: rowData.id,
                  readonly: true
                }
              });
              break;
            case 'audit':
              this.$router.push({
                path:'/earnManage/businessIssued/details',
                query:{
                  id: rowData.id,
                  reviewStatus: rowData.reviewStatus
                }
              });
                break;
            case 'upAudit':
              let content = '<p style="font-size: 1rem;font-weight: 600;">提交审核</p>' +
                '<p style="height: 0px;margin:10px 0 50px;">提交审核后，相关的任务内容将不能修改</p>';
              this.$modal.confirm(content, {submitTitle: '继续提交'}).then(() => {
                let params = {
                  id: rowData.id,
                  reviewStatus: '1'
                };
                updateBusDeploy(params).then(res => {
                  this.$modal.msgSuccess("提交审核成功！");
                  this.getList();
                });
              }).catch(() => {});
              break;
            case 'delete':
              this.$modal.confirm('是否确认删除数据项？').then(function() {
                return delBusDeploy(rowData.id)
              }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功")
              }).catch(() => {});
              break;
            case 'export':
              // let dataList = [];
              // Object.keys(this.columns).forEach(item => {
              //   if (item.visible) {
              //     dataList.push(item.prop);
              //   }
              // });
              // this.download("/system/Business/export", {properties: dataList,}, `业务管理_${new Date().getTime()}.xlsx`);
              let paramsList = Object.assign({}, this.queryParams,rowData);
              this.download("system/businessDeploy/export", paramsList, `业务下发管理_${new Date().getTime()}.xlsx`, null, 'json');
              break;
            default:

          }
        }
      }
    }
  }
</script>
<style scoped>
  ::v-deep .lastBtnSty .el-form-item__content{
    margin-left: 10px!important;
  }
  ::v-deep .el-message-box__status {
    top: 35%!important;
  }
</style>
