<template>
  <div>
    <BackBar title="待办处理-资产" lefttext="返回" />
    <van-form>
      <van-cell-group inset>
        <van-field label="项目编号" v-model="assets.orderId" name="orderId" readonly placeholder="-" />
        <van-field label="订单名称" v-model="assets.projectName" name="projectName" type="textarea" readonly placeholder="-" />
        <van-field label="意见书号" v-model="assets.statementNo" name="statementNo" readonly placeholder="-" />
        <van-field label="报告号" v-model="assets.reportNo" name="reportNo" readonly placeholder="-" />
        <van-field label="业务类型" v-model="assets.assetsBusinessGener" name="assetsBusinessGener" readonly placeholder="-" />
        <van-field label="客户名称" v-model="assets.customerName" name="customerName" readonly placeholder="-" />
        <van-field label="业务来源" v-model="assets.customerSubName" name="customerSubName" readonly placeholder="-" />
        <van-field label="委托人" v-model="assets.bailor" name="bailor" readonly placeholder="-" />
        <van-field label="委托人电话" v-model="assets.bailorContactTel" name="bailorContactTel" readonly placeholder="-" />
        <van-field label="当前节点" v-model="currentNode.nodeName" name="nodeName" readonly :error="true" placeholder="-" />
        <van-field label="节点处理人" v-model="currentNode.handlerName" name="handlerName" readonly placeholder="-" />
        <van-field label="项目负责人" v-model="assets.principalName" name="principalName" readonly placeholder="-" />
        <van-field label="客户经理" v-model="assets.clientManagerName" name="clientManagerName" readonly placeholder="-" />
        <van-field label="最新备注" v-model="commitInfo.comments" name="comments" type="textarea" />
      </van-cell-group>
    </van-form>
    <div class="button-style" style="float: left" v-if="currentNode.reversible">
      <van-button type="warning" style="width: 100%" @click="commitNode('REVERSE')">退回</van-button>
    </div>
    <div class="button-style" style="float: right">
      <van-button type="success" style="width: 100%" @click="commitNode('PASS')">提交</van-button>
    </div>
  </div>
</template>

<script>
import { showConfirmDialog } from 'vant';
import { showNotify } from 'vant';
import { getAssetsTodoDetail } from '@/api/assets';
import { currentNode } from '@/api/workFlowNodeInstance';
import { commit } from '@/api/workflow';

export default {
  data() {
    return {
      // 资产详情
      assets: {},
      currentNode: {},
      // 节点提交信息
      commitInfo: {},
    };
  },
  created() {
    this.assets.id = this.$route.query.assetsId;
    this.getTodoDetail();
    this.getCurrentNode();
  },
  methods: {
    // 获取待办详情
    getTodoDetail() {
      if (this.assets.id) {
        getAssetsTodoDetail(this.assets.id).then((res) => {
          if (res.code === 200) {
            this.assets = res.data;
            this.assets.statementNo = this.$route.query.statementNo;
            this.assets.reportNo = this.$route.query.reportNo;
            this.assets.projectName = this.$route.query.projectName;
          }
        });
      }
    },
    // 获取当前节点实例
    getCurrentNode() {
      if (this.assets.id) {
        currentNode({ mainBusiness: 'ASSET_BUSINESS', businessId: this.assets.id, businessSubId: this.$route.query.statementNo, businessMinId: this.$route.query.reportNo }).then((res) => {
          if (res.code === 200) {
            this.currentNode = res.data;
            this.currentNode.currentNodeCode = this.$route.query.currentNodeCode;
            this.currentNode.handlerName = this.$route.query.handlerName;
          }
        });
      }
    },
    // 提交节点
    commitNode(state) {
      showConfirmDialog({
        title: '提交节点',
        message: '确认提交流程节点?',
      }).then(() => {
        this.commitInfo.instanceNodeId = this.currentNode.instanceId;
        this.commitInfo.state = state;
        this.commitInfo.businessSubId = this.assets.statementNo;
        this.commitInfo.businessMinId = this.assets.reportNo;
        commit(this.commitInfo).then((res) => {
          if (res.code === 200 && res.data) {
            showNotify({ type: 'success', message: '节点提交成功' });
            history.back();
          }
        });
      });
    },
  },
};
</script>

<style scoped>
.button-style {
  display: inline-block;
  margin: 20px;
  width: 100px;
}
</style>