

<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="hospitalLevel">
          <el-select class="w100" v-model="formData.hospitalLevel" placeholder="请选择">
            <el-option v-for="item in hospitalLevel" :key="item.id" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品进入形式：" prop="entryForm">
          <el-input v-model="formData.entryForm" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="预期治疗量/疗程数：" prop="expectedSales">
          <el-input v-model="formData.expectedSales" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="负责人：" prop="leader">
          <el-input v-model="formData.leader" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="中标通知书：" prop="noticeUrl">
          <uploadCom  @updateInfo='(list) => updateInfo(list, "noticeUrl")' :info="formData.noticeUrl" key="noticeUrl" />
        </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="contractsAmount">
          <el-input v-model="formData.contractsAmount" @input="(v) => (formData.contractsAmount = v.replace(/[^\d.]/g, ''))" />
        </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,  saveTaskHospital } 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: "doTaskHospital",
  components: { ElImageViewer, uploadCom },
  data() {
    return {
      taskTypeId: 66,
      formData: {
        packageId: '',
        productName: '',
        hospitalLevel: '',
        entryForm: '',
        leader: '',
        expectedSales: '',
        noticeUrl: [],
        contractsUrl: [],
        invoiceUrl: [],
        contractsAmount: '',
        invoiceUrl: [],
        summary: ''
      },
      formRules: {
        packageId: [{ required: true, message: '请选择关联积分包', trigger: 'blur' }],
        productName: [{ required: true, message: '请输入推广名称', trigger: 'blur' }],
        hospitalLevel: [{ required: true, message: '请选择准入医院等级', trigger: 'blur' }],
        entryForm: [{ required: true, message: '请输入产品进入形式', trigger: 'blur' }],
        expectedSales: [{ required: true, message: '请输入预期治疗量/疗程数', trigger: 'blur' }],
        leader: [{ required: true, message: '请输入负责人' }],
        noticeUrl:  [{ required: true, message: '请上传付款证明' }],
        contractsUrl:  [{ required: true, message: '请上传购销合同' }],
        contractsAmount: [{ required: true, message: '请输入合同金额', trigger: 'blur' }],
        invoiceUrl: [{ required: true, message: '请上发票' }],
      },
      relatedEntPackList: [], // 关联企业包 // 所有上传文件
      hospitalLevel: []
    }
  },
  methods: {
    async  getDeptTask() {
      const res = await getDeptTaskApi(66)
      console.log(
        'res', res
      );
      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, 66)
      if (res.data.code === 0) {
        this.$message.success('保存成功')
        this.backFn()
      }
    },
    submitFn() {
      this.$refs.formRef.validate(async val => {
        if(val) {
          const res = await saveTaskHospital(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>
