<template>
  <div>
    <BackBar title="待办处理-大中型" lefttext="返回" />
    <van-form>
      <van-cell-group inset>
        <van-field label="项目编号" v-model="major.orderId" name="orderId" readonly />
        <van-field label="订单名称" v-model="major.projectName" name="projectName" type="textarea" readonly />
        <van-field label="意见书号" v-model="major.statementNo" name="statementNo" readonly />
        <van-field label="报告/函号" v-model="major.reportNo" name="reportNo" readonly />
        <van-field label="当前节点" v-model="currentNode.nodeName" name="nodeName" readonly :error="true" />
        <van-field label="客户经理" v-model="major.clientManager" name="clientManager" readonly />
        <van-field label="项目负责人" v-model="major.principal" name="principal" readonly />
        <van-field label="对象类型" v-model="major.businessObjectType" name="businessObjectType" readonly />
        <van-field label="客户名称" v-model="major.cclienteleName" name="clientName" readonly />
        <van-field label="业务来源" v-model="major.cclienteleSubName" name="clientSubName" readonly />
        <van-field label="客户联系人" v-model="major.cclienteleContactName" name="cclienteleContactName" readonly />
        <van-field label="联系电话" v-model="major.cmobile" name="cmobile" readonly />
        <van-field label="下单时间" v-model="major.created" name="created" readonly />
        <van-field label="任务创建时间" v-model="currentNode.taskCreated" name="taskCreated" readonly />
        <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 { showNotify } from 'vant';
import { getMajorTodoDetail } from '@/api/major';
import { currentNode } from '@/api/workFlowNodeInstance';
import { commit } from '@/api/workflow';

export default {
  data() {
    return {
      // 大中型详情
      major: {},
      currentNode: {},
      // 节点提交信息
      commitInfo: {},
    };
  },
  created() {
    this.major.id = this.$route.query.id;
    this.currentNode.nodeCode = this.$route.query.currentNodeCode;
    this.getTodoDetail();
  },
  methods: {
    // 获取待办详情
    getTodoDetail() {
      if (this.major.id) {
        getMajorTodoDetail(this.major.id).then((res) => {
          if (res.code === 200) {
            this.major = res.data;
            this.major.principal = this.$route.query.principal;
            this.major.projectName = this.$route.query.projectName;
            this.major.reportNo = this.$route.query.reportNo;
            this.major.statementNo = this.$route.query.statementNo;
            this.getCurrentNode();
          }
        });
      }
    },
    // 获取当前节点实例
    getCurrentNode() {
      if (this.major.id) {
        currentNode({ mainBusiness: 'MAJOR_BUSINESS', businessId: this.major.id, businessSubId: this.major.statementNo, businessMinId: this.major.reportNo }).then((res) => {
          if (res.code === 200) {
            this.currentNode = res.data;
            this.currentNode.taskCreated = this.$route.query.taskCreated;
          }
        });
      }
    },
    // 提交节点
    commitNode(state) {
      this.commitInfo.instanceNodeId = this.currentNode.instanceId;
      this.commitInfo.state = state;
      this.commitInfo.businessSubId = this.major.statementNo;
      this.commitInfo.businessMinId = this.major.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>