<!--
  @description: 供应商入库申请表
  @Modifier:qrf
  @routerPath:
  @date: 2020/9/18-13:41
-->
<template>
  <div>
    <el-dialog
      :visible.sync="dialog"
      :close-on-click-modal="false"
      title="供应商入库申请表"
      width="50%"
      min-width="700px"
      custom-class="el-dialog_table"
    >
      <el-form
        ref="form"
        :rules="rules"
        :model="batchAuditSupplierDto"
        :inline-message="true"
        class="main mb10"
      >
        <table class="from_table">
          <tr>
            <td>
              <el-form-item label="申报供应范围" prop="supplyScope" />
            </td>
            <td>
              <el-input v-model="batchAuditSupplierDto.supplyScope" disabled style="width: calc(100% - 156px );" />
              <!-- 请选择 -->
              <el-button type="primary" @click="dialogData.dialog=true">
                选择
              </el-button>
              <el-button type="primary" plain @click="categoryTreeInfo('clear')">
                清空
              </el-button>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="调查方式" prop="nvestigationMethod" />
            </td>
            <td>
              <el-select v-model="batchAuditSupplierDto.nvestigationMethod" placeholder="请选择调查方式">
                <el-option label="实地调查" value="00" />
                <el-option label="样品检验、试用 " value="01" />
                <el-option label="实地考察" value="02" />
                <el-option label="其他" value="03" />
              </el-select>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="是否新供应商" prop="isNewSupplier" />
            </td>
            <td>
              <el-radio-group v-model="batchAuditSupplierDto.isNewSupplier">
                <el-radio label="是" />
                <el-radio label="否" />
              </el-radio-group>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="推荐理由" prop="auditOpinion" />
            </td>
            <td>
              <el-input v-model="batchAuditSupplierDto.reason" type="textarea" />
            </td>
          </tr>
          <tr>
            <td>
              <!-- prop="siteAssessmenteportList" -->
              <el-form-item ref="siteAssessmenteportList" label="调查报告" />
            </td>
            <td>
              <upload
                ref="upload"
                :on-change="fileChange"
                :data="siteAssessmenteportData"
                :auto-delete="true"
                :auto-upload="true"
                :limit="1"
                file-ref="fileRef"
                but-text="上传文件"
                title=""
                accept=".doc, .docx, .pdf, .png, .jpg"
                tip-text="上传报告格式（*.doc;*.docx;*.pdf;*.png;*.jpg;）"
              />
            </td>
          </tr>
        </table>
      </el-form>
      <!--底部操作按钮-->
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ensure('form')">提交</el-button>
        <el-button @click="dialog = false">取消</el-button>
      </span>
    </el-dialog>
    <!-- 供货范围 -->
    <category-tree-dialog :dialog-data="dialogData" @categoryTreeInfo="categoryTreeInfo" />
  </div>
</template>

<script>
/* api */
import { updateAuditDeclarationInfo } from '@/api/supplier/declaraTionrecord.js'
/* 公共方法*/
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin'
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins.js'
/* 校验方法*/
import { characters1_auto } from '@/assets/js/validate'
/* 组件*/
import categoryTreeDialog from '@/views/common/tools/categoryTree-dialog'// 供货范围-弹框
import upload from '@comp/common/updownload/upload' // 文件上传

export default {
  name: 'EditorDeclarationPassed',
  components: {
    'category-tree-dialog': categoryTreeDialog, // 供货范围选择弹框
    upload
  },
  mixins: [supplierGroupMixin, declareHegSupperMixins],
  props: {
    // 供应商入库申请表数据
    applyData: {
      type: Object,
      default: () => {
        return {
          ids: '', // 调查报告
          isNewSupplier: null, // 是否是新供应商
          nvestigationMethod: '', // 调查方式
          reason: null, // 推荐理由
          supplyScopeId: '' // 申报供应范围
        }
      }
    }
  },
  data() {
    return {
      dialog: false, // 弹窗状态 false 关闭 true 打开
      isFieldTrips: false,
      batchAuditSupplierDto: {
        auditOpinion: '', // 审核意见
        auditStatus: '01', // 审核状态
        auditUser: '', // 审核人
        // batchStatus: '', // 批量审核 提交00 审核01
        createUser: '', // 创建人id
        departId: '', // 供应商id
        ids: this.$route.params.bizId, // 主键id
        isNewSupplier: '是', // 是否新供应商 [00否] [01是]
        nvestigationMethod: '', // 调查方式 [实地考察:00],[问卷调查:01],[综合:02],[其他:03]
        reason: '', // 推荐理由
        supplyScope: '', // 申报供应范围
        supplyScopeId: '', // 申报供应范围id
        useStatus: '01', // 状态 01提交 00保存
        siteAssessmenteportList: ''
      },
      rules: {
        supplyScope: [{ required: true, message: '请选择', trigger: 'blur' }], // 申报供应范围
        nvestigationMethod: [{ required: true, message: '请选择', trigger: 'blur' }], // 调查方式
        reason: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 推荐理由
        siteAssessmenteportList: [{ required: true, message: '请选择', trigger: 'blur' }]
      },
      // 弹窗-展示/隐藏状态 true 展示/false 隐藏
      dialogData: {
        title: '供货范围',
        dialog: false,
        selectCodes: [] // 当前选中的供货范围Code
      }
    }
  },
  watch: {
    'batchAuditSupplierDto.nvestigationMethod'(val) {
      if (val === '00') {
        this.isFieldTrips = true
      } else {
        this.isFieldTrips = false
      }
    },
    // 供应商入库申请数据
    applyData: {
      handler(val) {
        this.batchAuditSupplierDto = val
        this.batchAuditSupplierDto.ids = val.id // 供应商入库审核申报表提交的传的ids
        this.siteAssessmenteportData.bizId = val.id // 调查报告
      },
      deep: true
    }
  },
  created() {
    this.siteAssessmenteportData.bizId = this.$route.params.bizId
  },
  methods: {
    openDialog() {
      this.dialog = true
      // this.aveDeclarationInfoDto.list[0] = storageFormParan
      // this.aveDeclarationInfoDto.supplierId = this.$route.params.supplierId
      // this.bizId = this.$route.params.bizId
      // this.siteAssessmenteportData.bizId = this.bizId
    },
    // 范围选择/清空
    categoryTreeInfo(data) {
      if (data === 'clear') { // 清空
        this.batchAuditSupplierDto.supplyScope = ''// 供货范围范围
        this.batchAuditSupplierDto.supplyScopeId = ''// 供货范围id
      } else { // 选择
        this.batchAuditSupplierDto.supplyScope = data.labels// 名称
        this.batchAuditSupplierDto.supplyScopeId = data.keys// 代码
      }
    },
    // 现场评审报告上传监听
    fileChange(file, fileList) {
      if (fileList.length > 0) {
        this.batchAuditSupplierDto.siteAssessmenteportList = 'true'// 上传了
      } else {
        this.batchAuditSupplierDto.siteAssessmenteportList = '' // 未上传
      }
    },
    // 提交
    ensure(formName) {
      // 校验输入内容
      this.$refs[formName].validate((valid, field) => {
        if (valid) { // 校验通过
          this.batchAuditSupplierDto.auditStatus = '01'
          updateAuditDeclarationInfo(this.batchAuditSupplierDto).then(res => {
            this.$message({
              message: '审核提交成功',
              type: 'success'
            })
            this.dialog = false
            this.$emit('call-back') // 提交成功触发父组件重新获取列表
            // this.$router.push({
            //   path: '/supperManagement/supplierAuditList'
            // })
          })
        }
      })
    }
  }
}
</script>

<style></style>
