<template>
  <div>
    <a-page-header
      style="background-color: #FFFFFF;"
      title="稽核统计详情"
      sub-title=""
      @back="goBack"
    >
      <a-descriptions :title="'任务名称:  '+task.taskName" :column="3" :bordered="false">
        <a-descriptions-item label="稽核状态">
          <a-tag :color="taskStateColor">{{ checkState }}</a-tag>
        </a-descriptions-item>
        <a-descriptions-item label="开始时间">{{ taskStartTime }}</a-descriptions-item>
        <a-descriptions-item label="结束时间">{{ taskEndTime }}</a-descriptions-item>
        <!--        <a-descriptions-item label="描述"><span v-html="task.description"></span></a-descriptions-item>-->
      </a-descriptions>
      <a-divider style="margin: 6px;"/>
    </a-page-header>

    <a-card :bordered="false" style="margin-top: -20px;">
      <a-tabs :active-key="currentTab" default-active-key="all" @change="tabChange">
        <a-tab-pane key="all" :tab="tabAll"></a-tab-pane>
        <a-tab-pane key="Line" :tab="tabLine"></a-tab-pane>
        <a-tab-pane key="Business" :tab="tabBusiness"></a-tab-pane>
        <a-tab-pane key="Reopening" :tab="tabReopening"></a-tab-pane>
        <a-tab-pane key="TrunkLineAudit" :tab="tabTrunkLineAudit"></a-tab-pane>
      </a-tabs>
      <!-- 查询区域 -->
      <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-input placeholder="请输入客户名称" v-model="queryParam.customerName"></j-input>
              </a-form-item>
            </a-col>
            <template v-if="toggleSearchStatus">

            </template>
            <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 @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button 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" v-has="'task:check:list:delete'">
              <a-icon type="delete"/>
              删除
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作
            <a-icon type="down"/>
          </a-button>
        </a-dropdown>
      </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="action" slot-scope="text, record">

            <span v-has="'special:task:check:list:upload:improve'" v-if="record.checkState == 0 || record.checkState == 1 || record.checkState == 4">
              <a @click="showImproveAndUpload(record)">上传资料</a>
              <a-divider type="vertical"/>
            </span>

            <span v-has="'special:task:check:list:submit'" v-if="record.checkState == 1 || record.checkState == 4">
              <a @click="handSubmit(record)">提交</a>
              <a-divider type="vertical"/>
            </span>

            <span v-has="'special:task:check:list:audit'" v-if="record.checkState === 2 || record.checkState === 3">
              <a @click="showCheckCheck(record)">稽核</a>
              <a-divider type="vertical"/>
            </span>

            <span v-has="'special:task:check:list:history'" v-if="record.checkState >= 4">
              <a @click="showCheckLog(record)">历史</a>
              <a-divider type="vertical"/>
            </span>

            <span v-has="'special:task:check:list:notice'"
                  v-if="record.checkState != 2 && record.checkState != 3 && record.checkState != 5">
              <a @click="noticeDeal(record)">催办</a>
              <a-divider type="vertical"/>
            </span>

            <a-dropdown>
              <a class="ant-dropdown-link">更多
                <a-icon type="down"/>
              </a>
              <a-menu slot="overlay">

                <a-menu-item v-has="'task:check:list:delete'">
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </a-menu-item>
                <a-menu-item v-has="'task:check:list:clear'">
                  <a-popconfirm title="确定清空吗?" @confirm="() => dataDelete(record.id)">
                    <a>清空</a>
                  </a-popconfirm>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </template>

          <template v-slot:customerName="text, record">
            <a @click="showCheckDetail(record)">{{ text }}</a>
          </template>
          <template v-slot:checkState="status">
            <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
          </template>
          <template v-slot:rowIndex="text,records,index">
            {{ (ipagination.current - 1) * ipagination.pageSize + Number(index) + 1 }}
          </template>

        </a-table>

      </div>
      <!-- table区域 end -->
    </a-card>

  </div>

</template>

<script>

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

export default {
  name: 'TaskCheckList',
  mixins: [JeecgListMixin],
  inject: ['closeCurrent'],
  data() {
    let _self = this;
    return {
      description: '稽核详情页面',
      currentTab: 'all',
      currentChecktype: null,
      customerNo:'',
      taskType:'',
      task: {
        id: '',
        taskName: '',
        customerNo:'',
        description: '',
        taskState: 0,
        taskStateText: '',
        taskStateColor: '',
        checkState:''
      },
      taskStartTime: '',
      taskEndTime: '',
      checkState:'',
      taskStateColor:'',
      tabAll: '全部（0）',
      tabLine: '行短稽核（0）',
      tabBusiness: '物联网业务稽核（0）',
      tabReopening: '复开审批（0）',
      tabTrunkLineAudit: '中继线稽核（0）',
      count: 0,
      Line: 0,
      Business: 0,
      Reopening: 0,
      TrunkLineAudit: 0,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          scopedSlots: {customRender: 'rowIndex'}
        },
        {
          title: '客户名称',
          align: "left",
          sorter: true,
          dataIndex: 'customerName',
          scopedSlots: {customRender: 'customerName'}
        },
        {
          title: '客户编号',
          align: "center",
          sorter: true,
          dataIndex: 'customerNo'
        },
        {
          title: '服务号码（全）',
          align: "center",
          dataIndex: 'smsNumber'
        },
        {
          title: '用户编号',
          align: "center",
          dataIndex: 'userNo'
        },
        {
          title: '入网时间',
          align: "center",
          sorter: true,
          dataIndex: 'networkAccessTime'
        },
        {
          title: '用户状态',
          align: "center",
          dataIndex: 'userState',
          customRender: function (text, record, index) {
            if (text === '1') {
              return '在用';
            } else if (text === '2') {
              return '拆机';
            }
            return text;
          }
        },
        {
          title: '员工姓名',
          align: "center",
          dataIndex: 'staffName'
        },
        {
          title: '员工工号',
          align: "center",
          sorter: true,
          dataIndex: 'staffNo'
        },
        {
          title: '稽核进度',
          align: "center",
          sorter: true,
          dataIndex: 'checkState',
          scopedSlots: {customRender: 'checkState'}
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'}
        }
      ],
      isorter: {
        column: 'checkState',
        order: 'asc',
      },
      url: {
        queryTask: "/smsCheck/statistics/queryById",
        list: "/smsCheck/statistics/list",
        count: "/smsCheck/statistics/count",
        delete: "/smsCheck/customerInfo/delete",
        edit: "/smsCheck/customerInfo/edit",
        notice: "/smsCheck/customerInfo/notice",
        editCheck: "/smsCheck/customerInfo/edit/check/state",
        dataDelete: "/smsCheck/customerData/clear",
        exportXlsUrl: "smsCheck/customerInfo/exportXls",
      },
      autoSearch: false,
    }
  },
  created() {
    this.task.id = this.$route.query.id;
    this.customerNo = this.$route.query.customerNo;
    this.queryTaskById(this.task.id,this.customerNo);
    this.queryParam.taskId = this.task.id;
    this.loadData();
    this.loadTabNumber(this.task.id,this.customerNo);
  },
  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: {
    // 返回上一级
    goBack() {
      this.$router.go(-1);
      //关闭当前页面
      this.closeCurrent();
    },
    // 上传客户资料
    showImproveAndUpload(record){
      this.$router.push({path: '/specialApply/data/upload', query: {id: record.id}});
    },
    // 显示完善页面
    showImprove(record) {
      this.$router.push({path: '/sms/check/data/edit', query: {id: record.id}});
    },
    // 显示上传页面
    showUpload(record) {
      this.$router.push({path: '/sms/check/data/upload', query: {id: record.id}});
    },
    // 显示上传页面
    handSubmit(record) {
      let that = this;
      let model = {
        id: record.id,
      }
      postAction(this.url.editCheck, model)
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.loadData(that.ipagination.current);
          } else {
            that.$message.warning(res.message)
          }
        }).finally(() => {

      })
    },
    dataDelete(id) {
      var that = this;
      deleteAction(that.url.dataDelete, {infoId: id}).then((res) => {
        if (res.success) {
          that.$message.success('附件资料清空完成！');
        } else {
          that.$message.warning('附件资料清空失败！');
        }
      });
    },
    // 稽核点击事件
    showCheckCheck(record) {
      this.$router.push({path: '/specialApply/modules/TaskCheckAudit', query: {id: record.id}});
    },
    // 显示稽核详情页面
    showCheckDetail(record) {
      this.$router.push({path: '/specialApply/modules/TaskCheckDetails', query: {id: record.id}});
    },
    // 显示稽核历史页面
    showCheckLog(record) {
      this.$router.push({path: '/sms/check/task/check/log', query: {id: record.id}});
    },
    // 构建任务信息
    buildTaskInfo(record) {
      let taskInfo = Object.assign({}, this.task);
      taskInfo.count = this.count;
      taskInfo.undoCount = this.undoCount;
      taskInfo.uncheckCount = this.uncheckCount;
      taskInfo.checkedCount = this.checkedCount;
      taskInfo.passedCount = this.passedCount;
      return {
        task: this.task,
        info: record
      }
    },
    handleCancel() {
      this.visible = false;
    },
    detail(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    searchQuery() {
      this.loadData(1);
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.loadTabNumber(this.task.id);
    },
    searchReset() {
      this.queryParam = {};
      this.queryParam.taskId = this.task.id;
      this.queryParam.checkState_MultiString = this.currentChecktype;
      this.tabChange('all');
      this.loadTabNumber(this.queryParam.taskId);
    },
    tabChange(key) {
      // 稽核状态（0：未处理；1：未完善；2：待稽核；3：待整改；4：已整改；5：稽核通过；）
      if (key === 'all') {
        this.taskType = '';
        this.currentTab = 'all';
      } else if (key === 'Line') {
        this.taskType = '1';
        this.currentTab = 'Line';
      } else if (key === 'Business') {
        this.taskType = '2';
        this.currentTab = 'Business';
      } else if (key === 'Reopening') {
        this.taskType = '3';
        this.currentTab = 'Reopening';
      } else if (key === 'TrunkLineAudit') {
        this.taskType = '4';
        this.currentTab = 'TrunkLineAudit';
      }
      let queryParam = {
        "customerName":this.customerName,
        "startDate": this.startDate,
        "endDate":  this.endDate,
        "infoId":this.taskId,
        "taskName":this.taskName,
        "customerNo":this.customerNo,
        "taskType":this.taskType,
        "taskState":this.taskState
      }

      this.loadData(null,queryParam);
    },
    loadTabNumber(taskId,  customerNo) {
      let url = this.url.count;
      let params = {
        id: taskId,
        customerNo:customerNo
      }
      let that = this;
      getAction(url, params).then(res => {
        let {result} = res;
        if (result) {
          that.count = result.totalNum;
          that.Line = result.lineNum;
          that.Business = result.businessNum;
          that.Reopening = result.reopeningNum;
          that.TrunkLineAudit = result.trunkLineAuditNum;
          that.tabAll = '全部（' + result.totalNum + '）';
          that.tabLine = '行短稽核（' + result.lineNum + '）';
          that.tabBusiness = '物联网业务稽核（' + result.businessNum + '）';
          that.tabReopening = '复开审批（' + result.reopeningNum + '）';
          that.tabTrunkLineAudit = '中继线稽核（' + result.trunkLineAuditNum + '）';
        }
      }).finally(() => {

      })
    },
    noticeDeal(record) {
      let url = this.url.notice;
      let params = {
        customerName: record.customerName,
        smsNumber: record.smsNumber,
        staffNo: record.staffNo,
        userNo: record.userNo,
      }
      let that = this;
      postAction(url, params).then(res => {
        let {result} = res;
        if (res.success) {
          that.$message.info('已通知客户经理，进行材料补充！');
        }
      }).finally(() => {

      })

    },
    queryTaskById(id,customerNo) {

      let url = this.url.queryTask;
      let params = {
        id: id
      }
      let that = this;
      getAction(url, params).then(res => {
        if (res.success) {
          that.task = res.result[0].checkState;
          this.checkState = that.task;
          that.getTaskState(that.task);
          this.taskStartTime=res.result[0].taskStartTime;
          this.taskEndTime=res.result[0].taskEndTime;

        }
      }).finally(() => {

      })
    },
    getTaskState(checkState ) {
      if (checkState === 0) {
        this.taskStateColor= '#fadb14';
        this.checkState = '未处理';
      } else if (checkState === 1) {
        this.taskStateColor = '#1890ff';
        this.checkState = '未完善';
      } else if (checkState === 2) {
        this.taskStateColor = '#52c41a';
        this.checkState = '待稽核';
      }else if (checkState === 3) {
        this.taskStateColor = '#fadb14';
        this.checkState = '已整改';
      }else if (checkState === 4) {
        this.taskStateColor = '#52c41a';
        this.checkState = '待整改';
      }else if (checkState === 5) {
        this.taskStateColor = '#1890ff';
        this.checkState = '稽核通过';
      }
    }
  }
}
</script>

<style scoped>

</style>