<!--
  @description: 提交异议回复函
  @Modifier: haofengxian
  @routerPath: /objection/objectionTabs/submitObjectionAcceptance
  @date: 2020-5-11-10:54
-->
<template>
  <div>
    <pdf :pdf-url="pdfUrl" />
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button :loading="confirmLoading" @click="editBulletin">
          编辑
        </el-button>
        <el-button :loading="confirmLoading" type="primary" @click="submitObjection">
          提交
        </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 { submitObjectionByObjectionId } from '@api/bidding/tenderObjection'
import { getFileDetail } from '@/api/common/uploadCenter'
import { readImageRoot } from '@api/common/uploadCenter'
/* 工作流常用方法*/
import workconstant from '@/assets/js/workutils/workconstant'
/* 混入公共方法*/
import { objectionAcceptanceMixin } from '../mixins/objectionAcceptanceMixin'
import { objectionConfigMixin } from '../mixins/objectionConfigMixin'

import { workCommonMixins } from '@views/work/mixins/workCommonMixins'
/* 组件*/
import pdf from '@comp/common/pdf/pdf'
import processNodeCom from '@views/work/processNodeCom'
import departDialog from '@views/work/depart-dialog'
export default {
  name: 'SubmitObjectionAcceptance',
  components: {
    pdf,
    'processNode-com': processNodeCom, // 工作流节点信息组件
    'depart-dialog': departDialog // 工作流审批人组件
  },
  mixins: [objectionAcceptanceMixin, workCommonMixins, objectionConfigMixin],
  data() {
    return {
      confirmLoading: false,
      processDefinitionKey: '', // 工作流流程id
      readImageUrl: readImageRoot, // 预览图片
      pdfUrl: ''
    }
  },
  watch: {
    'objectionReceiptContentData.bizId'(val) {
      if (val) {
        // 获取内容pdf
        this.getObjectionReceiptContentPdf()
      }
    }
  },
  created() {
    // 获取内容pdf
    this.getObjectionReceiptContentPdf()
  },
  mounted() {
    this.handleReceiptStatusProcessDefinitionKey()
  },
  methods: {
    // 项目经理发送异议回复函状态01:受理 02:不受理--（受理or 不受理）走不同的工作流 配置不同key
    handleReceiptStatusProcessDefinitionKey() {
      if (this.receiptStatus === '01') {
        this.processDefinitionKey = workconstant.clarificationRaiseObjection // 投诉异议-项目经理-受理工作流流程key
      } else {
        this.processDefinitionKey = workconstant.objectionNotAcceptance // 投诉异议-项目经理-不受理工作流流程key
      }
      this.$refs.processNode.getProcessDefinitionKey(this.processDefinitionKey)
    },
    // 获取内容
    getObjectionReceiptContentPdf() {
      getFileDetail(this.objectionReceiptContentData).then(response => {
        const url = this.readImageUrl + response.data[0].path
        this.pdfUrl = encodeURIComponent(url)
      }).catch(() => {
      })
    },
    // 编辑
    editBulletin() {
      // 工作流进入
      if (this.flowStatus) {
        this.$router.push({
          path: this.objectionPath.makeObjectionPath,
          query: {
            ...this.$route.query
          }
        })
      } else {
        this.$router.push({
          name: 'MakeReplyLetterAdd',
          params: {
            ...this.$route.params
          }
        })
      }
    },
    // 提交调用接口方法（子组件审批流选择审核人员后调用）
    submit() {
      const params = {
        objectionId: this.objectionReceiptContentData.bizId // 异议id
      }
      /* clarificationObjectSourceType true启动工作流 添加工作流参数*/
      if (this.clarificationObjectSourceType) {
        this.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
        params.processInitDto = this.processInitDto // 审核人信息传回得信息
      }

      this.confirmLoading = true
      submitObjectionByObjectionId(params).then(() => {
        this.$message({
          message: '提交成功',
          type: 'success'
        })
        this.$router.push({
          path: this.objectionPath.submitListPath,
          params: {
            ...this.$route.params
          }
        })
        sessionStorage.clear()
        this.confirmLoading = false
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 提交
    submitObjection() {
      this.$confirm('确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        /* clarificationObjectSourceType true启动工作流 false普通审核*/
        if (this.clarificationObjectSourceType) {
          // 启动工作流
          if (JSON.stringify(this.processNode) !== '{}' && this.processNode.nodeId) {
            this.$refs.departDialog.getUserDepart(this.processNode)
          }
        } else {
          // 直接提交
          this.submit()
        }
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped>

</style>
