<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.customerNo"></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.checkState"
                                 dictCode="sms_check_check_state"/>
            </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">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
           <a v-if="loadSubData(record)" @click="handSubmit(record)">提交稽核</a>
          <a-divider type="vertical"/>
           <a @click="handUpload(record)">资料上传</a>
           <a-divider type="vertical"/>
          <a @click="handleEdit(record)">信息编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <template v-slot:checkState="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 SmsCheckTaskModal from './SmsCheckTaskModal'
import TaskAdd from './TaskAdd'
import {httpAction} from "@api/manage";

export default {
  name: 'TaskList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    SmsCheckTaskModal,
    TaskAdd
  },
  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: 'customerNo'
        },
        {
          title: '用户编号',
          align: "center",
          dataIndex: 'userNo'
        },
        {
          title: '客户名称',
          align: "center",
          dataIndex: 'customerName'
        },
        {
          title: '用户发展员工',
          align: "center",
          dataIndex: 'staffName'
        },
        {
          title: '入网时间',
          align: "center",
          dataIndex: 'networkAccessTime'
        },
        {
          title: '服务号码',
          align: "center",
          dataIndex: 'smsNumber'
        },
        {
          title: '资料状态',
          align: "center",
          sorter: true,
          dataIndex: 'checkState',
          scopedSlots: {customRender: 'checkState'}
          /* customRender: function (t, r, index) {
             let checkState = "无状态";
             switch (t) {
               case 0:
                 checkState = "未处理";
                 break;
               case 1:
                 checkState = "未完善";
                 break;
               case 2:
                 checkState = "待稽核";
                 break;
               case 3:
                 checkState = "已整改";
                 break;
               case 4:
                 checkState = "待整改";
                 break;
               case 5:
                 checkState = "稽核通过";
                 break;
             }
             return checkState;
             //return <span><Badge status=success ></span>;

           }*/
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        editCheck: "/smsCheck/customerInfo/edit/check/state",
        list: "/smsCheck/customerInfo/staff/list",
        delete: "/smsCheck/customerInfo/delete",
        deleteBatch: "/smsCheck/customerInfo/deleteBatch",
        exportXlsUrl: "/smsCheck/customerInfo/exportXls",
        importExcelUrl: "/smsCheck/customerInfo/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  filters: {
    statusTypeFilter(type) {
      const statusTypeMap = {
        '0': 'error',
        '1': 'error',
        '2': 'warning',
        '3': 'warning',
        '4': 'processing',
        '5': 'success'
      }
      return statusTypeMap[type]
    },
    statusFilter(status) {
      const statusMap = {
        '0': '未完善',
        '1': '未完善',
        '2': '待稽核',
        '3': '待稽核',
        '4': '待整改',
        '5': '通过'
      }
      return statusMap[status]
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
    ,
  }
  ,
  methods: {

    loadSubData(record) {
      let checkState = record.checkState;
      let state = true;
      switch (checkState) {
        case 0:
          state = true;
          break;
        case 1:
          state = true;
          break;
        case 2:
          state = true;
          break;
        case 3:
          state = false;
          break;
        case 4:
          state = true;
          break;
        case 5:
          state = false;
          break;
      }
      return state;

    }
    ,

    // 显示添加页面
    showAdd() {
      this.$emit('goAdd', true);
    }
    ,
    // 显示导入页面
    showImport() {
      this.$emit('goImport', true);
    }
    ,
    handUpload(record) {
      let infoId = record.id;
      if (infoId == undefined || infoId == null) {
        this.$message.warning('用户编号不能为空！');
        return;
      }
      //console.log(record)
      this.$emit('goImport', infoId);
    }
    ,

    handSubmit(record) {
      let nowIpagination = this.ipagination;
      let model = {
        "id": record.id,
        //value1:fileUrl
      }
      httpAction(this.url.editCheck, model, "post")
        .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;
    }
    ,
    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
    }
    ,
    // handleAdd: function () {
    //   this.$refs.modalForm.add();
    //   this.$refs.modalForm.title = "新增";
    //   this.$refs.modalForm.disableSubmit = false;
    // },
    // handleEdit: function (record) {
    //   this.$refs.modalForm.edit(record);
    //   this.$refs.modalForm.title = "编辑";
    //   this.$refs.modalForm.disableSubmit = false;
    // },
  }
}
</script>

<style scoped>

</style>