<!--
  @description: 提交澄清函
  @Modifier: haoFx
  @routerPath:/bidding/projectDrive/clarification/submitClarification
  @date: 2020/3/13-15:46
-->
<template>
  <div>
    <!--澄清函pdf预览-->
    <clarificationLetterPdfDetail />
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="editorClarify">
          编辑
        </el-button>
        <el-button type="primary" @click="submitClarificationLetter">
          提交
        </el-button>
      </div>
    </div>
    <!--工作流选择节点组件-->
    <processNode-com
      ref="processNode"
      :process-definition-key="processDefinitionKey"
      @processNodeData="processNodeData"
    />
    <!--工作流流程节点/获取审核用户-->
    <depart-dialog
      ref="departDialog"
      :process-node="processNode"
      @isSingleUser="isSingleUser"
      @processInitData="processInitData"
      @submit="submit"
    />
  </div>
</template>

<script>
/* api*/
import { submitClarificationInfo } from '@/api/bidding/bidClarification'// 澄清
/* 组件*/
import clarificationLetterPdfDetail from './clarificationLetterPdf-detail'
import processNodeCom from '@views/work/processNodeCom'
import departDialog from '@views/work/depart-dialog'
/* 公共方法*/
import workconstant from '@/assets/js/workutils/workconstant'
/* 混入公共方法*/
import { workCommonMixins } from '@views/work/mixins/workCommonMixins'
import { clarificationMixin } from '../../mixins/clarificationMixin'
export default {
  name: 'SubmitClarification',
  components: {
    clarificationLetterPdfDetail,
    'processNode-com': processNodeCom,
    'depart-dialog': departDialog
  },
  mixins: [workCommonMixins, clarificationMixin],
  data() {
    return {
      clarificationConfigType: this.$store.getters.systemConfigVo.configType, // true启动工作流 false普通审核
      processDefinitionKey: '' // 工作流流程id
    }
  },
  mounted() {
    this.processDefinitionKey = workconstant.clarification
  },
  methods: {
    submitClarificationLetter() {
      this.$confirm('是否确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        /* clarificationConfigType true启动工作流 false普通审核*/
        if (this.clarificationConfigType) {
          // 启动工作流
          if (JSON.stringify(this.processNode) !== '{}' && this.processNode.nodeId) {
            this.$refs.departDialog.getUserDepart(this.processNode)
          }
        } else {
          // 直接提交
          this.submit()
        }
      }).catch(() => {
      })
    },
    // 提交
    submit() {
      const data = {
        clarificationId: this.clarificationId // 澄清Id
      }
      /* clarificationConfigType true启动工作流 添加工作流参数*/
      if (this.clarificationConfigType) {
        this.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
        data.processInitDto = this.processInitDto // 审核人信息传回得信息
      }
      submitClarificationInfo(data).then(res => {
        this.confirmLoading = false
        this.submitJumpPage()
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 设置提交跳转页面
    submitJumpPage() {
      // 审批流进入flowStatus '01' 跳转回待办列表
      if (this.flowStatus === '01') {
        this.$router.push({
          path: this.clarificationPath.submitListPath // 路径动态变更
        })
      } else {
        this.$router.push({
          path: this.clarificationPath.submitListPath, // 路径动态变更
          query: {
            ...this.$route.query
          }
        })
      }
      this.$message({
        message: '提交成功',
        type: 'success'
      })
    },
    // 编辑澄清
    editorClarify() {
      this.$router.push({
        path: this.clarificationPath.clarificationAddPath, // 编辑路由
        query: {
          ...this.$route.query
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
