
<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="projectName">
          <el-input v-model="formData.projectName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="甲方名称：" prop="partAName">
          <el-input v-model="formData.partAName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="乙方名称：" prop="partBName">
          <el-input v-model="formData.partBName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="项目简介：" prop="introduction">
          <el-input v-model="formData.introduction" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="合同金额（元）：" prop="contractsAmount">
          <el-input v-model="formData.contractsAmount" @input="(v) => (formData.contractsAmount = v.replace(/[^\d.]/g, ''))" />
        </el-form-item>
        <el-form-item label="合同上传：" prop="contractsUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "contractsUrl")' :info="formData.contractsUrl"
            key="contractsUrl" />
        </el-form-item>
        <el-form-item label="发票上传：" prop="invoiceUrl">
          <uploadCom @updateInfo='(list) => updateInfo(list, "invoiceUrl")' :info="formData.invoiceUrl"
            key="invoiceUrl" />
        </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, saveTaskSpecialContracts } 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: "doTaskSpecialContracts",
  components: { ElImageViewer, uploadCom },
  data() {
    return {
      taskTypeId: 70,
      formData: {
        packageId: '',
        projectName: '',
        partAName: '',
        partBName: '',
        introduction: '',
        contractsAmount: '',
        contractsUrl: [],
        invoiceUrl: [],


      },
      formRules: {
        packageId: [{ required: true, message: '请选择关联积分包', trigger: 'blur' }],
        projectName: [{ required: true, message: '请输入推广名称', trigger: 'blur' }],
        partAName: [{ required: true, message: '请输入甲方名称', trigger: 'blur' }],
        partBName: [{ required: true, message: '请输入乙方名称', trigger: 'blur' }],
        introduction: [{ required: true, message: '请输入项目简介', trigger: 'blur' }],
        contractsAmount: [{ required: true, message: '请输入合同金额', trigger: 'blur' }],
        contractsUrl: [{ required: true, message: '请上传合同' }],
        invoiceUrl: [{ required: true, message: '请上传发票' }],


      },
      relatedEntPackList: [], // 关联企业包
      hospitalLevel: []
    }
  },
  methods: {
    async getDeptTask() {
      const res = await getDeptTaskApi(70)
      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, 70)
      if (res.data.code === 0) {
        this.$message.success('保存成功')
        this.backFn()
      }
    },
    submitFn() {
      this.$refs.formRef.validate(async val => {
        if (val) {
          const res = await saveTaskSpecialContracts(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>
