<!--
  @description: 变更公告内容预览-提交公告
  @Modifier: haoFx
  @routerPath: /bidding/projectDrive/changeBulletin/submitChangeBulletin
  @date: 2020/1/7-16:18
-->
<template>
  <div>
    <!--公告内容预览-->
    <makeChangeBulletinPdfDetail ref="bulletinPdf" />
    <!--工作流选择节点组件-->
    <processNode-com
      ref="processNode"
      :process-definition-key="processDefinitionKey"
      @processNodeData="processNodeData"
    />
    <!--工作流流程节点/获取审核用户-->
    <depart-dialog
      ref="departDialog"
      :process-node="processNode"
      @isSingleUser="isSingleUser"
      @processInitData="processInitData"
      @submit="submit"
    />
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="editBulletin">
          编辑
        </el-button>
        <el-button :loading="confirmLoading" type="primary" @click="submitBulletin">
          提交公告
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api*/
import { addChangeBulletin } from '@/api/bidding/changeBulletin'
/* 组件*/
import makeChangeBulletinPdfDetail from './makeChangeBulletinPdf-detail'
import processNodeCom from '@views/work/processNodeCom'
import departDialog from '@views/work/depart-dialog'
/* 混入公共方法 */
import { changeBulletinCommon } from './mixins/changeBulletinCommon'
import { workCommonMixins } from '@views/work/mixins/workCommonMixins'
/* 公共方法*/
import workconstant from '@/assets/js/workutils/workconstant'
export default {
  name: 'BidBulletinContentPreview',
  components: {
    makeChangeBulletinPdfDetail,
    'processNode-com': processNodeCom,
    'depart-dialog': departDialog
  },
  mixins: [changeBulletinCommon, workCommonMixins],
  data() {
    return {
      changeBulletinConfigType: this.$store.getters.systemConfigVo.configType, // true启动工作流 false普通审核
      processDefinitionKey: '', // 工作流流程id
      // 保存公告内容参数
      isSubmit: '01' // 是否提交 00否 01是
    }
  },
  mounted() {
    this.processDefinitionKey = workconstant.changeBulletin
  },
  methods: {
    getBulletinPdf() {
      this.$refs.bulletinPdf.getBulletinContentPdf() // 调用子组件获取pdf方法
    },
    // 编辑
    editBulletin() {
      this.$router.push({
        path: this.changeBulletinPath.changeBulletinAddPath, // 路径动态变更
        query: {
          ...this.$route.query
        }
      })
    },
    // 提交公告
    submitBulletin() {
      this.$confirm('确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        /* changeBulletinConfigType true启动工作流 false普通审核*/
        if (this.changeBulletinConfigType) {
          // 启动工作流
          if (JSON.stringify(this.processNode) !== '{}' && this.processNode.nodeId) {
            this.$refs.departDialog.getUserDepart(this.processNode)
          }
        } else {
          // 直接提交
          this.submit()
        }
      }).catch(() => {
      })
    },
    // 变更公告保存提交
    submit() {
      /* changeBulletinConfigType true启动工作流 添加工作流参数*/
      if (this.changeBulletinConfigType) {
        this.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
        this.formData.processInitDto = this.processInitDto // 审核人信息传回得信息
      }
      const data = this.assemblyData()// 保存组装数据
      this.confirmLoading = true
      addChangeBulletin(data).then(response => {
        this.submitJumpPage()
        this.confirmLoading = false
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 设置提交跳转页面
    submitJumpPage() {
      // 审批流进入flowStatus true 跳转回待办列表
      if (this.flowStatus) {
        this.$router.push({
          path: this.changeBulletinPath.submitListPath // 路径动态变更
        })
      } else {
        this.$router.push({
          path: this.changeBulletinPath.submitListPath, // 路径动态变更
          query: {
            ...this.$route.query
          }
        })
      }
      this.$message({
        message: '提交成功',
        type: 'success'
      })
    }
  }
}
</script>

<style scoped>

</style>
