
<template>
  <div class="do-task">
    <div class="mb12">
      <el-button @click="backFn">后退</el-button>
    </div>
    <div>
      <span class="f18 fwb clr_333">提交任务</span> - <span>招投标服务</span>
    </div>
    <div class="form-wrapper">
      <el-form ref="formRef" :model="formData" :rules="formRules" label-width="160px">
        <el-form-item label="关联企业包：" prop="packageId">
          <el-select class="w100" v-model="formData.packageId" placeholder="请选择">
            <el-option v-for="item in relatedEntPackList" :key="item.id" :label="item.scorePackageName" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推广产品名称：" prop="productName">
          <el-input v-model="formData.productName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="招标计划书：" prop="tenderProposalUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "tenderProposalUrl")' :info="formData.tenderProposalUrl" key="tenderProposalUrl" />
        </el-form-item>
        <el-form-item label="目录：" prop="tendersCatalogueUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "tendersCatalogueUrl")' :info="formData.tendersCatalogueUrl" key="tendersCatalogueUrl" />
        </el-form-item>
        <el-form-item label="标书：" prop="tenderUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "tenderUrl")' :info="formData.tenderUrl" key="tenderUrl" />
        </el-form-item>
        <el-form-item label="投标资料清单：" prop="informationListUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "informationListUrl")' :info="formData.informationListUrl" key="informationListUrl" />
        </el-form-item>
        <el-form-item label="产品投标及报价：" prop="quoteUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "quoteUrl")' :info="formData.quoteUrl" key="quoteUrl" />
        </el-form-item>
        <el-form-item label="招标活动总结表：" prop="summaryTableUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "summaryTableUrl")' :info="formData.summaryTableUrl" key="summaryTableUrl" />
        </el-form-item>
        <el-form-item label="会议总结:" prop="summary">
          <el-input type="textarea" v-model="formData.summary" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="saveFn">保 存</el-button>
        <el-button type="primary" size="small" @click="submitFn">提 交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getRelatedEntPackList, saveTemp, getDeptTaskApi, saveTaskTender } from "@/api/enterpriseTask"
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
import { getDictType } from "@/api/common";
import uploadCom from "./uploadCom.vue";

export default {
  name: "doTaskTender",
  components: { ElImageViewer, uploadCom },
  data() {
    return {
      taskTypeId: 67,
      formData: {
        packageId: '',
        productName: '',
        tenderProposalUrl: [],
        tendersCatalogueUrl: [],
        tenderUrl: [],
        informationListUrl: [],
        quoteUrl: [],
        summaryTableUrl: [],
        summary: ''

      },
      formRules: {
        packageId: [{ required: true, message: '请选择关联积分包', trigger: 'blur' }],
        productName: [{ required: true, message: '请输入推广名称', trigger: 'blur' }],
        tenderProposalUrl: [{ required: true, message: '请上传招标计划书' }],
        tendersCatalogueUrl: [{ required: true, message: '请上传招标目录' }],
        tenderUrl: [{ required: true, message: '请上传标书' }],
        informationListUrl: [{ required: true, message: '请上传投标资料清单' }],
        quoteUrl: [{ required: true, message: '请上传产品投标及报价' }],
        summaryTableUrl: [{ required: true, message: '请上传招标活动总结表' }],

      },
      relatedEntPackList: [], // 关联企业包
      hospitalLevel: []
    }
  },
  methods: {
    async getDeptTask() {
      const res = await getDeptTaskApi(67)
      if (res.data.code === 0 && res.data.data) {
        this.formData = res.data.data
      }
    },

    // 返回
    backFn() {
      this.$emit('back')
    },
    getDict() {
      getRelatedEntPackList().then(res => this.relatedEntPackList = res.data.data)
      getDictType({ type: 'tasktype66_hospital_level' }).then(res => this.hospitalLevel = res.data.data)
    },
    async saveFn() {
      const res = await saveTemp(this.formData, 67)
      if (res.data.code === 0) {
        this.$message.success('保存成功')
        this.backFn()
      }
    },
    submitFn() {
      this.$refs.formRef.validate(async val => {
        if (val) {
          const res = await saveTaskTender(this.formData)
          if (res.data.code === 0) {
            this.$message.success('提交成功')
            this.backFn()
          }
        }
      })

    },
    updateInfo(list, type) {
      this.formData[type] = list
      this.$refs.formRef.validateField(type)
    },

  },

  mounted() {
    this.getDict()
    this.getDeptTask()
  }
}
</script>

<style lang="scss" scoped>
.do-task {
  position: relative;

  .form-wrapper {
    margin-top: 36px;

    .input-num-box {
      ::v-deep .el-input__inner {
        text-align: left;
      }
    }
  }
}</style>
