<!--
  @description:风险控制部提交异议
  @Modifier: haofengxian
  @routerPath: /objection/riskDepartObjectionAdd
  @date: 2020-6-6-15:04
-->
<template>
  <div>
    <!--工作流进入不显示-->
    <div v-if="!flowStatus" class="title p0-16 clearfix">
      <div class="title-back pointer" @click="back">
        <i class="iconfont icon-fanhui mr10" />新增异议投诉
      </div>
    </div>
    <div :class="flowStatus?'':'p0-16'">
      <el-form
        ref="formBidderData"
        :rules="rules"
        :model="formData"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td>
              <el-form-item ref="tenderName" label="项目名称" prop="tenderName" />
            </td>
            <td>
              <gx-input
                v-model="formData.tenderName"
                placeholder="请选择项目名称"
                gx-maxlength="varchar500"
                style="width: calc(100% - 160px)"
                disabled
              />
              <el-button type="primary" class="ml10" @click="selectProject()">
                选择
              </el-button>
              <el-button @click="empty()">
                清空
              </el-button>
            </td>
            <td>
              <el-form-item ref="tenderNo" label="项目编号" prop="tenderNo" />
            </td>
            <td colspan="3">
              <gx-input
                v-model.trim="formData.tenderNo"
                gx-maxlength="varchar200"
                type="text"
                placeholder="项目编号"
                disabled
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="packName" label="标段（包）名称" prop="packName" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.packName"
                gx-maxlength="varchar300"
                type="text"
                placeholder="标段（包）名称"
                disabled
              />
            </td>
            <td>
              <el-form-item ref="packNo" label="标段（包）编号" prop="packNo" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.packNo"
                gx-maxlength="varchar200"
                type="text"
                placeholder="标段（包）编号"
                disabled
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="问题类型" prop="objectionMode" />
            </td>
            <td>
              <el-radio-group v-model="formData.objectionMode">
                <el-radio
                  v-for="(item,index) in objectionModeList"
                  :key="index"
                  :label="item.typecode"
                >
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
            <td>
              <el-form-item label="异议类型" prop="objectionType" />
            </td>
            <td>
              <el-select v-model="formData.objectionType" style="width: 100%;" placeholder="请选择">
                <el-option
                  v-for="(item,index) in objectionTypeList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item :label="objectionNoName" />
            </td>
            <td>
              <gx-input
                v-model="formData.objectionNo"
                disabled
                type="text"
                placeholder="系统自动生成"
              />
            </td>
            <td />
            <td />
          </tr>
          <tr>
            <td>
              <el-form-item label="异议人" prop="supplierName" />
            </td>
            <td>
              <gx-input v-model.trim="formData.supplierName" gx-maxlength="varchar100" type="text" placeholder="异议人" />
            </td>
            <td>
              <el-form-item label="地址" prop="address" />
            </td>
            <td>
              <gx-input v-model.trim="formData.address" gx-maxlength="varchar100" type="text" placeholder="地址" />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="法定代表人" prop="legalPerson" />
            </td>
            <td>
              <gx-input v-model.trim="formData.legalPerson" gx-maxlength="varchar100" type="text" placeholder="法定代表人" />
            </td>
            <td>
              <el-form-item label="法定代表人电话" prop="legalPersonPhone" />
            </td>
            <td>
              <gx-input v-model.trim="formData.legalPersonPhone" gx-maxlength="varchar100" type="text" placeholder="法定代表人电话" />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="法定代表邮箱" prop="legalPersonEmail" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.legalPersonEmail"
                gx-maxlength="varchar100"
                type="text"
                placeholder="法定代表邮箱"
              />
            </td>
            <td>
              <el-form-item label="授权委托人" prop="grantauthPerson" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.grantauthPerson"
                gx-maxlength="varchar100"
                type="text"
                placeholder="授权委托人"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="授权委托人电话" prop="grantauthPersonPhone" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.grantauthPersonPhone"
                gx-maxlength="varchar100"
                type="text"
                placeholder="授权委托人电话"
              />
            </td>
            <td>
              <el-form-item label="授权委托邮箱" prop="grantauthPersonEmail" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.grantauthPersonEmail"
                gx-maxlength="varchar100"
                type="text"
                placeholder="授权委托邮箱"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="投诉方式" />
            </td>
            <td colspan="3">
              <el-select v-model="formData.complaintType" style="width: 200px;" placeholder="请选择">
                <el-option
                  v-for="(item,index) in clarificationObjectionTypeList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="提出异议事项的基本事实" prop="objectionbasicfactsContent" />
            </td>
            <td colspan="3">
              <gx-input
                v-model="formData.objectionbasicfactsContent"
                :autosize="{ minRows: 4, maxRows: 4 }"
                type="textarea"
                style="width: 96%"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="相关证明材料" prop="name" />
            </td>
            <td colspan="3">
              <upload
                ref="upload"
                :data="upLoadData"
                :auto-delete="true"
                :auto-upload="true"
                title=""
                file-ref="fileRef"
                :tip-text="'注：请上传盖章的《异议申请函》和其它证明材料'"
              />
            </td>
          </tr>
        </table>
      </el-form>
      <!--保存按钮-->
      <div class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <el-button :loading="confirmLoading" @click="saveObjection('formBidderData')">
              保存
            </el-button>
            <el-button :loading="confirmLoading" type="primary" @click="submitObjection('formBidderData')">
              提交
            </el-button>
          </div>
        </div>
      </div>
    </div>
    <!--选择项目标段弹框-->
    <bid-project-dialog ref="bidProject" @projectInfo="projectInfo" />
    <!--选择投诉/异议公司弹框-->
    <selectBidderListDialog ref="selectBidder" title-name="公司" @dialogDataInfo="dialogDataInfo" />
    <!--工作流选择节点组件-->
    <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>
/* 接口*/
import { riskDepartSaveObjection, getRaiseObjectionInfoByObjectionId } from '@api/bidding/tenderObjection'
/* 公共方法 */
import workconstant from '@/assets/js/workutils/workconstant'
import upload from '@comp/common/updownload/upload'
/* 组件*/
import bidProjectDialog from './bidProject-dialog'
import processNodeCom from '@views/work/processNodeCom'
import departDialog from '@views/work/depart-dialog'
import selectBidderListDialog from '@views/bidding/bidProject/bidProjectDepart/bidProjectDepart-dialog'

/* 常用方法*/
import { randomData } from '@/assets/js/utils/index'
import { characters1_auto, checkLinktel, email } from '@/assets/js/validate'// 校验输入内容
/* 混入公共方法*/
import { workCommonMixins } from '@views/work/mixins/workCommonMixins'
import { objectionConfigMixin } from '../mixins/objectionConfigMixin'

export default {
  name: 'RiskDepartObjectionAdd',
  components: {
    upload, // 文件上传
    'bid-project-dialog': bidProjectDialog, // 选择项目标段弹框
    'processNode-com': processNodeCom, // 工作流节点信息组件
    'depart-dialog': departDialog, // 工作流审批人组件
    selectBidderListDialog // 选择投标人弹框
  },
  mixins: [workCommonMixins, objectionConfigMixin],
  data() {
    return {
      /* 字典信息-start */
      objectionTypeList: [], // 异议类型
      clarificationObjectionTypeList: [], // 投诉方式
      /* 字典信息-end */
      flowStatus: this.$route.query.flowStatus, // 01 工作流进入
      processDefinitionKey: '', // 工作流流程id
      confirmLoading: false,
      upLoadData: {
        bizId: '', // 业务主键Id
        fileType: 'clarification_objection_attachment'// 文件类型
      },
      formData: {
        address: '', // 地址
        grantauthPerson: '', // 授权人
        grantauthPersonEmail: '', // 授权人邮箱
        grantauthPersonPhone: '', // 授权人电话
        legalPerson: '', // 法定代表人
        legalPersonEmail: '', // 法定代表人邮箱
        legalPersonPhone: '', // 法定代表人电话
        objectionId: '', // 异议id
        objectionMode: '00', // 问题类型 00异议 01投诉
        objectionType: '01', // 异议类型字典
        complaintType: '00', // 投诉方式
        objectionbasicfactsContent: '', // 事项基本内容
        stageIds: '', // 阶段Id（多个用,”隔开。为空获取全部）
        supplierName: '', // 供应商名称
        tenderId: '', // 项目id
        tenderName: '', // 项目名称
        tenderNo: '', // 项目编号
        packName: '', // 标段名称
        packNo: '', // 标段编号
        title: '', // 异议投诉标题
        useStatus: '', // 有效状态 00:保存 01:提交
        buk: '', // 投标人机构代码
        objectionNo: '' //  投诉申请单据号
      },
      rules: {
        tenderName: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 项目名称
        tenderNo: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 项目编号
        packName: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 标段名称
        packNo: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 标段编号
        objectionMode: [{ required: true, message: '请选择', trigger: 'change' }], // 问题类型
        objectionType: [{ required: true, message: '请选择', trigger: 'change' }], // 异议类型
        supplierName: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 异议人
        address: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 地址
        legalPerson: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 法定代表人
        legalPersonPhone: [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 法定代表人电话
        legalPersonEmail: [{ required: true, validator: email, trigger: 'blur' }], // 法定代表人邮箱
        grantauthPerson: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 授权委托人
        grantauthPersonPhone: [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 授权委托人电话
        grantauthPersonEmail: [{ required: true, validator: email, trigger: 'blur' }], // 授权委托人邮箱
        objectionbasicfactsContent: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 提出异议事项的基本事实
        buk: [{ required: true, message: '请选择', trigger: 'change' }] // 问题类型
      },
      objectionNoName: '异议申请单据号'
    }
  },
  watch: {
    // 00异议 01投诉
    'formData.objectionMode'(val) {
      if (val === '01') {
        this.objectionNoName = '投诉申请单据号'
      } else {
        this.objectionNoName = '异议申请单据号'
      }
    }
  },
  created() {
    // 审批流进入flowStatus true 取异议objectionId 方式不同
    if (this.flowStatus) {
      this.objectionId = this.$route.query.bizId
    } else {
      this.objectionId = this.$route.params.objectionId
    }
  },
  mounted() {
    this.initData() // 获取异议内容编辑信息
    this.initGroup() // 获取字典方法
    this.processDefinitionKey = workconstant.raiseObjectionWeb // 工作流流程key
  },
  methods: {
    // 获取字典方法
    initGroup() {
      const data = [
        'objectionType', // 异议类型
        'clarificationObjectionType'// 异议投诉方式
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 获取异议内容编辑信息
    initData() {
      // 判断是否有异议Id
      if (this.objectionId) {
        const data = {
          objectionId: this.objectionId // 异议Id
        }
        this.upLoadData.bizId = this.objectionId
        getRaiseObjectionInfoByObjectionId(data).then(res => {
          const { data } = res
          this.formData = data
          if (this.formData.packInfoList.length > 0) {
            this.formData.packName = this.formData.packInfoList[0].packName
            this.formData.packNo = this.formData.packInfoList[0].packNo
            this.formData.stageIds = this.formData.packInfoList[0].stageId
          }
        })
      } else {
        this.formData.objectionId = randomData()// 随机生成ID
        this.upLoadData.bizId = this.formData.objectionId
      }
    },
    // 选择项目（打开弹框）
    selectProject() {
      this.$refs.bidProject.openDialogVisible()
    },
    // 已选项目信息
    projectInfo(data) {
      this.formData.tenderName = data.tenderName
      this.formData.tenderId = data.tenderId
      this.formData.tenderNo = data.tenderNo
      this.formData.packName = data.packName
      this.formData.packNo = data.packNo
      this.formData.stageIds = data.stageId
    },
    // 清空
    empty() {
      this.formData.tenderName = ''
      this.formData.tenderNo = ''
      this.formData.packName = ''
      this.formData.packNo = ''
      this.formData.stageIds = ''
    },
    // 提交调用接口方法（子组件审批流选择审核人员后调用）
    submit(type) {
      this.formData.useStatus = type || '01' // 有效状态 00:保存 01:提交
      // 提交时添加工作流信息
      if (this.formData.useStatus === '01' && this.clarificationObjectSourceType) {
        this.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
        this.formData.processInitDto = this.processInitDto // 审核人信息传回得信息
      }
      this.confirmLoading = true
      riskDepartSaveObjection(this.formData).then(res => {
        this.confirmLoading = false
        // 提交成功则返回列表
        if (this.formData.useStatus === '01') {
          this.submitJumpPage()
        } else {
          this.$message({
            type: 'success',
            message: res.header.msg
          })
        }
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 保存
    saveObjection() {
      this.submit('00')
    },
    // 提交
    submitObjection(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          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(() => {
          })
        }
      })
    },
    // 设置提交跳转页面
    submitJumpPage() {
      // 审批流进入flowStatus true 跳转回待办列表
      if (this.flowStatus) {
        this.$router.push({ path: '/work/todo' })
      } else {
        this.$message({
          message: '提交成功',
          type: 'success'
        })
        this.back()
      }
    },
    back() {
      this.$router.push({
        path: '/objection/riskDepartObjectionList'
      })
    },
    // 选择投诉/异议公司
    selectBidder() {
      this.$refs.selectBidder.openOrganizationDialog('10')
    },
    // 已选投诉/异议信息
    dialogDataInfo(data) {
      // 10 招标人 11代理机构
      this.formData.buk = data.orgCode// 投诉/异议公司代码
    },
    // 清空按钮
    clearAgency() {
      this.formData.buk = ''// 投诉/异议公司代码
    }
  }
}
</script>

<style scoped>

</style>
