<!--
 * @Description: 补充说明组件
 * @Author: gmy
 * @Date: 2020-08-4 19:59:15
-->
<template>
  <div class="mb16">
    <table class="from_table">
      <!--  是否使用工具制作采购文件 projectFileType 00是 01 否 默认01  -->
      <!-- <tr class="singleRow">
        <td>
          <el-form-item label="使用工具制作采购文件" prop="projectFileType" />
        </td>
        <td colspan="3">
          <el-radio-group v-model="updataFilesData.makeWay">
            <el-radio
              v-for="(item, index) in procurementFileList"
              :key="index"
              :label="item.typecode"
            >{{ item.typename }}</el-radio>
          </el-radio-group>
        </td>
      </tr> -->
      <!--  projectFileType 00显示使用工具制作 01 否显示文件上传 默认01   -->
      <tr class="singleRow">
        <td>
          <el-form-item label="采购文件" :rules="rules.principalFile" prop="principalFile" />
        </td>
        <!-- <td v-if="updataFilesData.makeWay=== '00'" colspan="3">
          <el-button type="primary">使用工具制作采购文件</el-button>
        </td> -->
        <td v-if="updataFilesData.makeWay=== '01'" colspan="3">
          <upload
            ref="principalFileUpload"
            :title="''"
            :data="procurementFile"
            :auto-delete="true"
            :auto-upload="true"
            :success="successdata"
            :file-size="200"
            tip-text="上传附件格式（*.doc;*.docx;*.pdf;*.png;*.jpg;*.zip;*.jpeg;*.txt;*.xlsx;*.xls;*.ppt;*.pptx;*.rar）单个文件不得超过200M"
            accept=".doc,.docx,.pdf,.png,.jpg,.zip,.jpeg,.txt,.xlsx,.xls,.ppt,.pptx,.rar"
            file-ref="fileRef"
            but-text="点击上传"
          />
        </td>
      </tr>
      <!--公开附件-->
      <tr class="singleRow">
        <td>
          <el-form-item label="公开附件" />
        </td>
        <td>
          <upload
            ref="upload"
            title=""
            :data="openTenderProjectFileType"
            :auto-delete="true"
            :auto-upload="true"
            :file-size="200"
            tip-text="上传附件格式（*.doc;*.docx;*.pdf;*.png;*.jpg;*.zip;*.jpeg;*.txt;*.xlsx;*.xls;*.ppt;*.pptx;*.rar）单个文件不得超过200M"
            accept=".doc,.docx,.pdf,.png,.jpg,.zip,.jpeg,.txt,.xlsx,.xls,.ppt,.pptx,.rar"
            file-ref="fileRef"
            but-text="点击上传"
          />
        </td>
      </tr>
      <!--  文字补充说明  -->
      <tr class="singleRow">
        <td>
          <el-form-item label="公告备注">
            <el-popover
              placement="top-start"
              popper-class="hint"
              width="260"
              offset="5"
              trigger="hover"
              content="发布公告时,给予供应商的提示信息"
            >
              <el-button slot="reference" type="info" class="prompt">
                <i class="iconfont icon-qm" />
              </el-button>
            </el-popover>
          </el-form-item>
        </td>
        <td colspan="3">
          <el-input
            v-model="saveNoticeData.mattersNeedingAttention"
            :autosize="{ minRows: 3, maxRows: 3 }"
            type="textarea"
            maxlength="800"
            show-word-limit
            style="width: 96%"
            placeholder="允许输入800个汉字，1600个字符"
          />
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
import { procurementProcfileTakeEffect, getProcurementProcfileByPackId } from '@/api/procurement/procurementProtdoc'
/* 公共方法 */
import { randomData } from '@assets/js/utils' // 随机生成uid
/* 混合开发-参数字段*/
import { procurementProjectMixins } from '../mixins/procurementProjectMixins'
import { procurementProjectGroupMixin } from '../mixins/procurementProjectGroupMixin'
/* 公共组件 */
import upload from '@comp/common/updownload/upload' // 文件上传组件

export default {
  name: 'ProcurementProjectSupplementAdd',
  components: {
    upload
  },
  mixins: [procurementProjectMixins, procurementProjectGroupMixin],
  props: {
    // 采购公告数据
    saveNoticeData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 上传附件数据
    updataFilesData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      // 校验输入内容
      rules: {
        principalFile: [{ required: true, message: '请上传', trigger: 'change' }]// 法人/负责人身份证号或护照号
      }
    }
  },
  watch: {
    'saveNoticeData.id'(val) {
      if (val) {
        this.giveFileData.bizId = this.saveNoticeData.id
      }
    }
  },
  created() {
    // 查看上传文件
    const packId = this.$route.query.packId
    this.getProcurementProcfileData(packId)
    this.giveFileData.bizId = this.saveNoticeData.id
    this.openTenderProjectFileType.bizId = this.$route.query.tenderId
  },
  methods: {
    // 封装获取采购文件方法
    getProcurementProcfileData(packId) {
      getProcurementProcfileByPackId(packId)
        .then(res => {
          // 判断是是否回显业务主键id
          if (res.data.procfileId) {
            // 保存后二次进入页面时获取业务id
            this.procurementFile.bizId = res.data.procfileId
            this.updataFilesData.id = res.data.procfileId
          } else {
            // 首次加载业务id为前端自动生成
            this.procurementFile.bizId = randomData()
            this.updataFilesData.id = this.procurementFile.bizId
          }
          // 获取采购工具字段 00 使用工具 01 上传文件
          this.updataFilesData.makeWay = res.data.makeWay ? res.data.makeWay : '01'
          // 获取单一来源附件主键id
          this.giveFileData.bizId = this.saveNoticeData.id
        })
        .catch(() => {})
    },
    // 文件生效
    setfileTakeEffect(updataFilesData) {
      // 保存生效文件方法
      procurementProcfileTakeEffect(updataFilesData).then(res => {
      }).catch(() => {})
    },
    // 采购文件附件上传
    principalFile() { // 判断是否有文件上传
      const fileList = this.$refs.principalFileUpload.fileList
      if (fileList.length > 0) { // 上传了
        this.$emit('fileListType', 'true')
      } else { // 未上传
        this.$emit('fileListType', '')
      }
    },
    // 采购文件上传成功的回调
    successdata(file) {
      // 调用文件生效方法
      this.setfileTakeEffect(this.updataFilesData)
    }
  }
}
</script>

<style scoped lang="less">
@import url("~@/assets/style/common/public.less");
.give{
  color: @font
}
</style>
