<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">

        <span slot="action" slot-scope="text, record">
          <a @click="showEdit(record)">完善</a>
          <a-divider type="vertical"/>
          <a @click="showUpload(record)">上传</a>
          <a-divider type="vertical"/>

          <template v-if="record.checkState == 1 || record.checkState == 4">
            <a @click="handSubmit(record)">提交</a>
            <a-divider type="vertical"/>
          </template>
          <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="() => dataDelete(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 {postAction, deleteAction} 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'}
        },
        {
          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",
        dataDelete: "/smsCheck/customerData/clear",
      },
      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]
    }
  },
  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: '/sms/check/data/edit' ,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;
    },
    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>