<template>

  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户名称/使用人名称">
              <j-input placeholder="请输入客户名称/使用人名称" v-model="queryParam.customerName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="资料状态">
              <j-dict-select-tag placeholder="请选择资料状态" v-model="queryParam.status"
                                 dictCode="special_examination_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
               <a-button style="margin-left: 8px  " type="primary" icon="download"
                         @click="handleExportXls('资料文件')">导出</a-button>
               <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>

        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
            </span>
          </a-col>




        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"

        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">

          <template v-if="record.status == 0">
            <a @click="adoptSubmit(record)">通过</a>
            <a-divider type="vertical"/>
             <a @click="refuseSubmit(record)">驳回</a>
             <a-divider type="vertical"/>
          </template>


         <a @click="showEdit(record)">详情</a>
          <a-divider type="vertical"/>



           <template v-if="record.status == 0 || record.status == 2">
            <a @click="removeSubmit(record)">删除</a>
            <a-divider type="vertical"/>
          </template>

        </span>

        <template v-slot:shutdownLabel="status">
          <a-badge :status="status | shutdownTypeFilter" :text="status | shutdownFilter"/>
        </template>

        <template v-slot:status="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
      </a-table>
    </div>
    <!-- 任务添加 -->
    <task-add ref="modalForm" @ok="modalFormOk"></task-add>
  </a-card>


</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {postAction, deleteAction, httpAction} from "@api/manage";
import {getAction} from "@/api/manage";

export default {
  name: 'TaskList',
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      description: '稽核任务管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '用户标签',
          align: "center",
          dataIndex: 'userLable',
          customRender: function (text, record, index) {
            if (text === 0) {
              return '个人户';
            }
            if (text === 1) {
              return '单位户';
            }
            return "未识别";
          }
        },
        {
          title: '申请用户',
          align: "center",
          dataIndex: 'createUser'
        },
        {
          title: '客户名称/使用人名称',
          align: "center",
          dataIndex: 'customerName'
        },
        {
          title: '单位名称',
          align: "center",
          dataIndex: 'unitName',
          customRender: function (text, record, index) {
            if (text === null) {
              return '无';
            }
            return text;
          }
        },
        {
          title: '关停时间',
          align: "center",
          dataIndex: 'shutdownTime',
        },
        {
          title: '关停标签',
          align: "center",
          dataIndex: 'shutdownLabel',
          scopedSlots: {customRender: 'shutdownLabel'}

        },
        {
          title: '材料标签',
          align: "center",
          dataIndex: 'materialLabel',
          customRender: function (text, record, index) {
            if (text === 0) {
              return '材料不全，有特审';
            }
            if (text === 1) {
              return '材料齐全，无特审';
            }
            return "未识别";
          }
        },
        {
          title: '审核状态',
          align: "center",
          sorter: true,
          dataIndex: 'status',
          scopedSlots: {customRender: 'status'}
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        editCheck: "/smsCheck/customerInfo/edit/check/state",
        list: "/special/examination/all/list/page",
        delete: "/special/examination/remove",
        refuse: "/special/examination/status/refuse",
        adopt: "/special/examination/status/adopt",
        deleteBatch: "/smsCheck/customerInfo/deleteBatch",
        exportXlsUrl: "/smsCheck/customerInfo/exportXls",
        dataDelete: "/smsCheck/customerData/clear",
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  filters: {
    shutdownTypeFilter(type) {
      const statusTypeMap = {
        '0': 'error',
        '1': 'warning',
        '2': 'processing',
        '3': 'success',
        '4': 'error',
        '5': 'warning',
        '6': 'processing',
        '7': 'success',
        '8': 'error'
      }
      return statusTypeMap[type]
    },

    statusTypeFilter(type){
      const statusTypeMap = {
        '0': 'warning',
        '1': 'success',
        '2': 'error',
      }
      return statusTypeMap[type]
    },

    statusFilter(status) {
      console.log("123")
      const statusMap = {
        '0': '审核中',
        '1': '审核通过',
        '2': '驳回',
      }
      return statusMap[status]
    },


    shutdownFilter(status) {
      const statusMap = {
        '0': '安防停机（高危漫游地）',
        '1': '安防关停（紫名单）',
        '2': '安防停机（专班研判）',
        '3': '安防停机（可复开）',
        '4': '沉默移动卡保护性单停',
        '5': '集团一点停复机（单停）',
        '6': '大数据保护停机单停（单停）',
        '7': '工信部断卡单停',
        '8': '实人核验未通过关停（单停）',
      }
      return statusMap[status]
    }
  },
  methods: {
    // 显示添加页面
    showAdd() {
      this.$emit('goAdd', true);
    },
    // 显示附件上传页面
    showUpload(record) {
      let infoId = record.id;
      if (infoId == undefined || infoId == null) {
        this.$message.warning('用户编号不能为空！');
        return;
      }
      this.$router.push({path: '/sms/check/data/upload', query: {id: record.id}});
    },
    // 显示添加页面
    showEdit(record) {

      this.$router.push({path: '/specialApply/modules/AdminDetails', query: {id: record.id}});
    },
    handSubmit(record) {
      let nowIpagination = this.ipagination;
      let model = {
        "id": record.id,
        //value1:fileUrl
      }
      postAction(this.url.editCheck, model)
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData(nowIpagination.current);

          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {

      })
      //this.ipagination.current = 2;
    },

    removeSubmit(record) {
      //console.log(record)
      let self = this;
      let model = {
        "id": record.id,
      }
      postAction(this.url.delete, model)
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            self.loadData();
          } else {
            this.$message.error(res.message);
          }
        }).finally(() => {
        this.$message.error(res.message);
      })
    },

    adoptSubmit(record) {
      //console.log(record)
      let self = this;
      let model = {
        "id": record.id,
      }
      postAction(this.url.adopt, model)
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            self.loadData();
          } else {
            this.$message.error(res.message);
          }
        }).finally(() => {
        this.$message.error(res.message);
      })
    },

    refuseSubmit(record) {
      //console.log(record)
      let self = this;
      let model = {
        "id": record.id,
      }
      postAction(this.url.refuse, model)
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            self.loadData();
          } else {
            this.$message.error(res.message);
          }
        }).finally(() => {
        this.$message.error(res.message);
      })
    },

    initDictConfig() {

    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'customerNo', text: '任务名称', dictCode: ''})
      fieldList.push({type: 'string', value: 'checkState', text: '任务状态', dictCode: 'sms_check_task_state'})
      fieldList.push({type: 'datetime', value: 'taskStartTime', text: '任务开始时间'})
      fieldList.push({type: 'datetime', value: 'taskEndTime', text: '任务结束时间'})
      this.superFieldList = fieldList
    },
    dataDelete(id) {


      var that = this;
      deleteAction(that.url.dataDelete, {infoId: id}).then((res) => {
        if (res.success) {
          that.$message.success('附件资料清空完成！');
        } else {
          that.$message.warning('附件资料清空失败！');
        }
      });
    },
  }
}
</script>

<style scoped>

</style>