<template>
  <div class="app-container">
    <div class="title-container">
      <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
    </div>
    <y-page-list-layout :page-list="pageData" :page-para="listQuery" :get-page-list="getPage">
      <template slot="left">
        <el-input v-model="listQuery.keyword" placeholder="关键字搜索..." clearable
          style="margin-left: 20px;width: 500px;float: left;">
        </el-input>
        <el-select v-model="listQuery.nodeName" placeholder="当前节点" style="margin-left: 20px;width: 200px;float: left;" clearable
            filterable>
          <el-option
            v-for="item in majorNodes"
            :key="item.code"
            :label="item.name"
            :value="item.name">
          </el-option>
        </el-select>
        <el-date-picker
          style="margin-left: 20px;float: left;"
          v-model="orderDate"
          type="daterange"
          align="center"
          unlink-panels
          range-separator="至"
          start-placeholder="下单日期（开始）"
          end-placeholder="下单日期（结束）"
          :picker-options="pickerOptions" value-format="yyyy-MM-dd">
        </el-date-picker>
        <el-button class="filter-item" style="margin-left: 10px;float: left;" type="primary" @click="searchList" round>搜索
        </el-button>
        <el-button class="filter-item" style="float: left;" round type="success" @click="resetSearch()">重置
        </el-button>
      </template>
      <parentTable  :data="pageData.records" slot="table" style="width: 100%;" @sortTable="sortTable">
        <el-table-column label="项目名称" align="center" width="300" >
          <template slot-scope="{row}">
            <span class="enableClick" @click="toDetail(row)">{{ row.productionName==null?row.orderName: row.productionName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单号" align="center" width="150">
          <template slot-scope="{row}">
            <span class="enableClick" @click="toDetail(row)">{{ row.orderId }}</span>
          </template>
        </el-table-column>
        <el-table-column label="价值意见书号" align="center" width="280" prop="statementNo" sortable>
          <template slot-scope="{row}">
            <span>{{ row.statementNo==null?'-': row.statementNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="报告号/复评函号" align="center" width="280" prop="reportNo" sortable>
          <template slot-scope="{row}">
            <span>{{ row.reportNo==null?'-': row.reportNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="评估对象类型" align="center" width="120">
          <template slot-scope="{row}">
            <span>{{ row.businessObjectType}}</span>
          </template>
        </el-table-column>
        <el-table-column label="待办人" align="center">
          <template slot-scope="{row}">
            <span>{{ row.handler }}</span>
          </template>
        </el-table-column>
        <el-table-column label="当前节点" align="center" width="140">
          <template slot-scope="{row}">
            <span>{{ row.nodeName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户经理" align="center">
          <template slot-scope="{row}">
            <span>{{ row.clientManager }}</span>
          </template>
        </el-table-column>
        <el-table-column label="负责人" align="center">
          <template slot-scope="{row}">
            <span>{{ row.principal==null?'-': row.principal }}</span>
          </template>
        </el-table-column>
        <el-table-column label="评估对象类型" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.businessObjectType }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.cclienteleName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="业务来源" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.cclienteleSubName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户联系人" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.cclienteleContactName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户联系人电话" align="center" width="130">
          <template slot-scope="{row}">
            {{ row.cmobile }}
          </template>
        </el-table-column>
        <el-table-column label="下单时间" align="center" width="160">
          <template slot-scope="{row}">
            <span>{{ row.created }}</span>
          </template>
        </el-table-column>
        <el-table-column label="任务创建时间" align="center" width="160" prop="taskCreated" sortable>
          <template slot-scope="{row}">
            <span>{{ row.taskCreated }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100" fixed="right">
          <template slot-scope="{row}">
            <el-button type="text"  @click="toDetail(row)">办理</el-button>
            <el-button  type="text" @click="transfer(row.taskId)">转交</el-button>
          </template>
        </el-table-column>
      </parentTable>
    </y-page-list-layout>
    <TransferDialog :transferDialogVisible="visible" @parentFalse="parentFalse()" @getPage="getPage()" :recordId="recordId"></TransferDialog>
  </div>
</template>
<script>
import YPageListLayout from '@/components/YPageListLayout'
import Breadcrumb from '@/components/Breadcrumb'
import TransferDialog from '@/components/TaskTransferDialog'

export default {
  name: 'MajorTaskTodoList',
  components: {
    Breadcrumb,
    YPageListLayout,
    TransferDialog
  },

  data() {
    return {
      pageData: { records: [] },
      listQuery: {
        page: 1,
        size: 10,
        keyword:null,
        descs: null,
        ascs:null
      },
      majorNodes:[],
      orderDate:'',
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
      },
      visible:false,
      recordId:null
    }
  },
  created() {
    this.getPage();
    this.getMajorNodes();
  },
  methods: {
  
    resetSearch() {
      this.$router.push({ query: {} });
      this.orderDate = '';
      this.listQuery = {
        current: 1,
        size: 10,
        descs: 'taskCreated',
      }
      this.getPage()
    },
   
    removeHandle(row) {
      // console.log(data)
      this.$confirm('确认删除当前记录吗?', '警告', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(async () => {
          this.$api.term.delete(row.id).then((res) => {
            if (res.code === 200) {
              this.$message({
                type: 'success',
                message: '删除成功',
              })
              this.getPage()
            }
          })
        })
        .catch((err) => {
          console.error(err)
        })
    },
    searchList() {
      // 重置分页
      this.listQuery.page = 1
      this.listQuery.size = 10
      if (this.orderDate){
        this.listQuery.startDate = this.orderDate[0]+' 00:00:00';
        this.listQuery.endDate = this.orderDate[1]+ ' 23:59:59';
      }
      this.getPage()
    },
    getPage() {

      this.$api.workNodeTaskRecord.majorTaskTodoList(this.listQuery).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
        }
      })
    },
    deleteInfo(id) {
      const that = this
      that.$confirm('请确认是否删除该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        that.$api.item.delete(id).then(data => {
          that.loading = false
          if (data.code === 200) {
            that.getPage()
          } else {
            this.$message({
              type: 'error',
              message: data.msg
            })
          }
        })
      }).catch(() => {
      })
    },
    getMajorNodes(){
        this.$api.workNode.nodesByBusiness('MAJOR_BUSINESS').then(res=>{
          if (res.code === 200){
              this.majorNodes = res.data
          }
        })
    },
    parentFalse(){
      this.visible = false;
    },
    transfer(recordId){
      this.visible = true;
      this.recordId = recordId;
    },
    toDetail(row){
      let reportNo = row.reportNo;
      let statementNo = row.statementNo;
      if (row.nodeCode === 'REPORT_OUT_APPLY' || row.nodeCode === 'LETTER_OUT_APPLY'){
         this.$router.push(`/major/my/order?todoBusinessId=${row.businessId}&sNo=${statementNo}&rNo=${reportNo}&tId=${row.taskId}&cId=${row.currentNodeId}`)
         return;
      }
      if (row.nodeCode === 'REPORT_OUT_FINANCE_CHECK' || row.nodeCode === 'REPORT_OUT_DEPARTMENT_CHECK' || row.nodeCode === 'LETTER_OUT_FINANCE_CHECK' || row.nodeCode === 'LETTER_OUT_DEPARTMENT_CHECK'){
         this.$router.push(`/out/warehouse/check?todoBusinessId=${row.businessId}&sNo=${statementNo}&rNo=${reportNo}&tId=${row.taskId}&cId=${row.currentNodeId}&nCode=${row.nodeCode}&businessType=MAJOR_BUSINESS`)
         return;
      }
      if (row.nodeCode === 'BUSINESS_ARCHIVING'){
          this.$router.push(`/major/saveFile/waiting`)
         return;
      }
      if (row.nodeCode === 'STATEMENT_DELIVERY'){
          this.$router.push(`/major/my/order?todoBusinessId=${row.businessId}&sNo=${statementNo}&tId=${row.taskId}&cId=${row.currentNodeId}`)
         return;
      }
      if (row.nodeCode==='STATEMENT_IN' || row.nodeCode==='STATEMENT_OUT' ||
          row.nodeCode==='REPORT_IN'|| row.nodeCode==='REPORT_OUT' ||
          row.nodeCode==='LETTER_IN' || row.nodeCode==='LETTER_OUT'){
          this.$router.push(`/major/production/in?openDialog=${true}`)
          return;
      }
      if (reportNo && statementNo){
        this.$router.push(`/major/todo/detail?id=${row.businessId}&reportNo=${reportNo}&statementNo=${row.statementNo}&doWorkflow=${true}&currentNodeId=${row.currentNodeId}&currentNodeCode=${row.nodeCode}&back=${'/major/todo'}`)
      }else if (!reportNo && statementNo){
        this.$router.push(`/major/todo/detail?id=${row.businessId}&statementNo=${row.statementNo}&doWorkflow=${true}&currentNodeId=${row.currentNodeId}&currentNodeCode=${row.nodeCode}&back=${'/major/todo'}`)
      }else if (reportNo && !statementNo){
        this.$router.push(`/major/todo/detail?id=${row.businessId}&reportNo=${reportNo}&doWorkflow=${true}&currentNodeId=${row.currentNodeId}&currentNodeCode=${row.nodeCode}&back=${'/major/todo'}`)
      }else{
        this.$router.push(`/major/todo/detail?id=${row.businessId}&doWorkflow=${true}&currentNodeId=${row.currentNodeId}&currentNodeCode=${row.nodeCode}&back=${'/major/todo'}`)
      }
    },

    sortTable(sortParams){
       this.listQuery.ascs = sortParams.ascs;
       this.listQuery.descs = sortParams.descs;
       this.$api.workNodeTaskRecord.majorTaskTodoList(this.listQuery).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
        }
      })
    }
  },
  
}



</script>
<style lang="scss" scoped>
 .enableClick:hover{
    color:#1890ff;
    cursor: pointer;
 }
</style>
