<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="getList">
      <template slot="left">
        <el-input v-model="listQuery.keyword" placeholder="关键字搜索..." clearable
          style="margin-left: 20px;width: 500px;float: left;">
        </el-input>
        <el-select style="margin-left: 20px;width: 170px;float: left;" v-model="listQuery.production" clearable placeholder="业务类型">
          <el-option value="MAJOR_BUSINESS" label="大中型业务">大中型业务</el-option>
          <!-- <el-option value="REPORT" label="个贷业务">个贷业务</el-option>
          <el-option value="LETTER" label="资产业务">资产业务</el-option> -->
        </el-select>
        <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%;">
        <el-table-column label="业务类型" align="center" width='120'>
          <template slot-scope="{row}">
            <span>{{ businessTypeAlias(row.businessType) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="报告号" align="center" width='300' >
          <template slot-scope="{row}">
            <span>{{ row.reportNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="当前实收款(￥)" align="center" width='150'>
          <template slot-scope="{row}">
            <span>{{ row.xrealAmount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="收费标准(￥)" align="center" width='120'>
          <template slot-scope="{row}">
            <span>{{ row.standardAmount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="申请原因" align="center" width='300' show-overflow-tooltip>
          <template slot-scope="{row}">
            <span>{{ row.remark==null?'-':row.remark}}</span>
          </template>
        </el-table-column>
        <el-table-column label="申请人" align="center">
          <template slot-scope="{row}">
            <span>{{ row.applyName}}</span>
          </template>
        </el-table-column>
        <el-table-column label="部门审核状态" align="center" >
          <template slot-scope="{row}">
            <span>{{ row.departmentCheckState}}</span>
          </template>
        </el-table-column>
        <el-table-column label="部门审核人" align="center" >
          <template slot-scope="{row}">
            <span>{{ row.departmentChecker}}</span>
          </template>
        </el-table-column>
        <el-table-column label="部门审核时间" align="center" width="160">
          <template slot-scope="{row}">
            <span>{{ row.departmentCheckTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="部门审核意见" align="center" width='150' show-overflow-tooltip>
          <template slot-scope="{row}">
            <span>{{ row.departmentReply==null?'-':row.departmentReply}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="财务审核状态" align="center" width='150'>
          <template slot-scope="{row}">
            <span>{{ row.financeCheckState}}</span>
          </template>
        </el-table-column>
        <el-table-column label="财务审核人" align="center" width='150'>
          <template slot-scope="{row}">
            <span>{{ row.financeChecker}}</span>
          </template>
        </el-table-column>
        <el-table-column label="财务审核时间" align="center" width="160">
          <template slot-scope="{row}">
            <span>{{ row.financeCheckTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="财务审核意见" align="center" width='150' show-overflow-tooltip>
          <template slot-scope="{row}">
            <span>{{ row.financeReply==null?'-':row.departmentReply}}</span>
          </template>
        </el-table-column> -->
        <el-table-column v-if="taskId"
        align = "center" fixed="right"  width='120'
          label="操作">
          <template slot-scope="{row}">
            <PermissionButton menu-code="_views_do_out_warehouse_check" class-name="filter-item" type="success"
              :page-jump="false" round size="mini" @click="doCheck(row.id)" :disabled="row.departmentCheckState" />
          </template>
        </el-table-column>
      </parentTable>
    </y-page-list-layout>
    <el-dialog :visible.sync="checkDialog" width="35%" center top="35vh" custom-class="doWarehouseClass">
      <el-form ref="checkDTO" :model="checkDTO" style="margin-left:40px">
          <el-row>
            <el-col :xs="24" :sm="12" :lg="24" :span="12">
              <el-form-item label="审核结果：" prop="state"   label-width="160px" class="postInfo-container-item"
              :rules="{required: true, message: '审核结果不能为空', trigger: 'blur'}">
                    <el-select v-model="checkDTO.state" placeholder="请选择" style="width:300px">
                      <el-option label="审核通过" value="审核通过" />
                      <el-option label="审核拒绝" value="审核拒绝" />
                    </el-select>
              </el-form-item >
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :lg="24" :span="12">
                <el-form-item label="审核意见：" prop="reply"  label-width="160px" class="postInfo-container-item">
                    <el-input style="width:300px" type="textarea" v-model="checkDTO.reply"></el-input>
                </el-form-item>
            </el-col>
          </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="checkDialog = false">取 消</el-button>
        <el-button type="primary" @click="saveCheck()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import YPageListLayout from '@/components/YPageListLayout'
import Breadcrumb from '@/components/Breadcrumb'

export default {
  name: 'outWarehouseCheck',
  components: {
    Breadcrumb,
    YPageListLayout,
  },
  filters: {
    
  },
  data() {
    return {
      pageData: { records: [] },
      listQuery: {
        page: 1,
        size: 10,
        descs: 'id',
        keyword:null,
      },
      checkDialog:false,
      checkDTO:{
        id:null,
        state:null,
        reply:null,
        checkType:0
      },
      todoBusinessId:null,
      taskId:null,
      nodeCode:null
      
    }
  },
  created() {
    this.todoBusinessId = this.$route.query.todoBusinessId;
    this.statementNo = this.$route.query.sNo;
    this.reportNo = this.$route.query.rNo;
    this.taskId = this.$route.query.tId;
    this.currentNodeId = this.$route.query.cId;
    this.nodeCode = this.$route.query.nCode;
    this.businessType = this.$route.query.businessType;
    this.getList();
  },
  methods: {
  
    resetSearch() {
      this.$router.push({ query: {} });
      this.listQuery = {
        current: 1,
        size: 10,
        descs: 'id',
        
      }
      this.getList()
    },
   
    searchList() {
      // 重置分页
      this.listQuery.page = 1
      this.listQuery.size = 10
      this.getList()
    },
    getList() {
      this.listQuery.keyword = this.$route.query.sNo;
      if (this.$route.query.businessType === 'ASSET_BUSINESS') {
        this.listQuery.keyword = this.$route.query.rNo;
      }
      this.$api.productionOutWarehouse.list(Object.assign({businessType:this.businessType}, this.listQuery)).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
        }
      })
    },
    businessTypeAlias(code){
      if (code === 'MAJOR_BUSINESS'){
        return '大中型业务'
      }
      if (code === 'PERSONAL_BUSINESS'){
        return '个贷业务'
      }
      if (code === 'ASSET_BUSINESS') {
        return '资产业务'
      }
    },
    doCheck(id){
        this.checkDialog = true;
        this.checkDTO.id= id;
    },
    saveCheck(){
      if (this.checkDTO.id){
        this.$refs.checkDTO.validate(valid=>{
          if (valid){
            let taskRecordDTO = new Object();
            if (!this.taskId){
              this.$notify({
                    title: '警告',
                    message: '节点任务未找到，暂时无法审核。请查看“我的待办”列表。',
                    type: 'warning',
                    duration: 3000
                  });
                  return ;
            }
            if (this.nodeCode.indexOf("FINANCE")!=-1){
                this.checkDTO.checkType = 1;
            }
            taskRecordDTO.recordId = this.taskId;
            taskRecordDTO.taskData = this.checkDTO;
              this.$api.productionOutWarehouse.edit(taskRecordDTO).then(res=>{
                if (res.code === 200 && res.data){
                    this.$notify({
                      title: '成功',
                      message: '申请处理成功',
                      type: 'success',
                      duration: 2000
                    });
                    this.commitNode();
                    this.getList();
                    this.checkDialog = false;
                }else {
                  this.$notify({
                    title: '失败',
                    message: '申请处理失败',
                    type: 'error',
                    duration: 2000
                  });
                }
              })
          }
        })
      }
    },
    commitNode(){
      let commit = new Object;
      commit.instanceNodeId = this.currentNodeId;
      if (this.checkDTO.state==='审核通过'){
        commit.state = 'PASS';
      }
      else{
        commit.state = 'REVERSE';
      }
      commit.comments = this.checkDTO.reply;
      commit.businessMinId = this.reportNo;
      commit.businessSubId = this.statementNo;
      this.$api.workflow.commit(commit).then(res=>{
        if (res.code === 200 && res.data){
          this.$notify({
              title: '成功',
              message: '工作流节点提交成功。',
              type: 'success',
              duration: 2000
            });
        }else{
          this.$notify({
              title: '失败',
              message: '工作流节点提交失败，请联系管理员。',
              type: 'error',
              duration: 2000
            });
        }
      })
    }
  },
  
}
</script>
<style lang="scss" scoped>
    /deep/.doWarehouseClass {
     border-radius: 10px;
    }
</style>
