<!--
  @description:采购立项-项目管理-采购文件-有效最低价
  @Modifier:qk
  @routerPath:/procurement/procurementSupplier
  @date:2020/3/27-13:27
-->
<template>
  <div style="padding: 0 15px;">
    <el-form
      ref="form"
      :model="formData"
      :rules="rules"
      :inline-message="true"
    >
      <table class="from_table" style="margin-top:30px;">
        <tr>
          <td>
            <el-form-item label="采购文件" prop="principalData" />
          </td>
          <td>
            <upload
              ref="upload"
              :on-change="principalFile"
              :data="principalData"
              :file-list="principalList"
              :auto-delete="true"
              :auto-upload="true"
              :limit="1"
              :action="importFileUrl"
              tip-text=""
              file-ref="fileRef"
              but-text="点击上传"
              title=""
            />
          </td>
          <td />
          <td />
        </tr>
      </table>
    </el-form>
    <!--保存按钮-->
    <div v-if="status === '00' || status === '04'" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 下一步 -->
          <el-button :loading="confirmLoading" type="primary" @click="nextStep('form')">
            生效
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* 接口*/
import { queryProcurementProjectBuysersInfo, queryBaseProcurementProjectInfo } from '@/api/procurement/procurementProject' // 暂存获取
/* 公用方法*/
import { linkerName, checkLinktel, email } from '@/assets/js/validate'// 校验输入内容
import upload from '@comp/common/updownload/upload'// 文件上传组件
import { upLoadFileUrl } from '@/api/common/uploadCenter'
// vuex
import { mapGetters } from 'vuex'
export default {
  name: 'ProcurementProjectAdd',
  components: {
    upload
  },
  data() {
    return {
      status: '00', // 00 未报名 01 已报名 02 待审核 03 审核不通过 04 审核通过
      importFileUrl: upLoadFileUrl, // 文件上传地址
      confirmLoading: false,
      principalData: {
        bizId: this.$route.query.id, // 业务主键Id
        fileType: 'pro_procurement_project_material_requirements_base'// 文件类型
      },
      formData: {
        projectBuyersName: '', // 联系人
        buyersLinkerTel: '', // 联系电话
        buyersLinkerEmail: '' // 邮箱
      },
      errorMsg: '',
      // 校验输入内容
      rules: {
        buyersLinkerName: [{ required: true, validator: linkerName, trigger: 'blur' }], // 联系人
        buyersLinkerTel: [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 联系电话
        buyersLinkerEmail: [{ required: true, validator: email, trigger: 'blur' }] // 邮箱
      }
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  watch: {
  },
  created() {
    this.initUser() // 获取采购人信息
    const tenderId = this.$route.query.id// 采购项目信息Id
    if (tenderId) {
      // 编辑时
      // 查询采购项目信息
      this.initData(tenderId)
    }
  },
  methods: {
    // 获取采购人信息
    initUser() {
      queryProcurementProjectBuysersInfo().then(res => {
        this.formData.projectBuyersName = res.data.projectBuyersName // 采购人
      })
    },
    // 编辑获取采购项目信息
    initData(tenderId) {
      queryBaseProcurementProjectInfo({ tenderId: tenderId }).then((response) => {
        this.formData = response.data
      })
    }
  },
  // 保存组装数据
  assemblyData() {
    const data = {
      ...this.formData
    }
    return data
  },
  // 附件上传
  principalFile(file, fileList) {
    this.principalList = fileList
  },
  // 暂存，进行下一步
  nextStep(formName) {
    // 校验输入内容
    this.$refs[formName].validate((valid, field) => {
      if (valid) { // 校验通过
        this.saveData('next')// 下一步
      } else { // 校验不通过
        this.$confirm('基本信息未完善, 是否进入下一步?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.saveData()
        }).catch(() => {
        })
      }
    })
  }
}
</script>

<style lang="less" scoped>

  /deep/.show-word-limit-padding{
    .el-input__inner{
      padding-right: 70px;
    }
  }
  .title{
    font-weight: 600;
  }
</style>
