
 <!-- 新增仪器检定记录 -->
<template>
  <div class="resource">
      <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible"  width='70%'>
     <div slot="title" class="titleBox">
       <i :class="formType === 0? 'el-icon-document':'el-icon-edit-outline'" style="font-size: 20px"></i>
        <!-- <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/more.png' /> -->
        <span style="margin-left:10px;font-size:18px">{{formTypeDsc}}</span>
        </div>
        <!-- 表单 -->
      <el-form ref="formData" label-width="80px" size="mini" :model="formData">
        <el-row>
        <!-- <el-col :span="8">
          <el-form-item label="仪器编号" prop="eqpNo" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
            <el-input v-model="formData.eqpNo" :disabled="true"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="仪器名称" prop="eqpName" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
            <el-input v-model="formData.eqpName" style="width: 100%;" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
            <el-form-item label="检定单位" prop="vrfOrg">
                <el-input v-model="formData.vrfOrg" style="width: 100%;"></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检定人" prop="vrfOpr">
            <el-input v-model="formData.vrfOpr" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
         <!-- <el-col :span="8">
            <el-form-item label="仪器类型" prop="eqpTypeNo" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
                <el-select v-model="formData.eqpTypeNo" clearable placeholder="请选择">
                    <el-option
                    v-for="(item,index) in eqpTypeNameList"
                    :key="index"
                    :label="item.baseName"
                    :value="item.baseCode">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-col> -->
        <!-- <el-col :span="8">
          <el-form-item label="制造厂商" prop="manufacturer">
            <el-input v-model="formData.manufacturer"></el-input>
          </el-form-item>
        </el-col> -->
         </el-row>
        <el-row>
        <!-- <el-col :span="8">
          <el-form-item label="记录编号" prop="vrfId">
            <el-input v-model="formData.vrfId" :disabled="true"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="确认人" prop="cfmOpr">
            <el-input v-model="formData.cfmOpr" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检定开始时间" prop="strTime" style="white-space:nowrap" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
            <el-date-picker v-model="formData.strTime" style="width:100%" type="datetime" placeholder="选择时间"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检定结束时间" prop="endTime" style="white-space:nowrap" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
            <el-date-picker v-model="formData.endTime" style="width:100%" type="datetime" placeholder="选择时间"></el-date-picker>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row>
        <el-col :span="8">
          <el-form-item label="检定费用（元）" prop="vrfPay" style="white-space:nowrap">
            <el-input v-model="formData.vrfPay" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检定内容" prop="vrfNotes">
            <el-input v-model="formData.vrfNotes" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检定结果" prop="vrfResults">
             <el-select v-model="formData.vrfResults" clearable placeholder="请选择" style="width: 100%;">
                    <el-option
                    v-for="(item,index) in vrfResultsList"
                    :key="index"
                    :label="item.vrfResults"
                    :value="item.id">
                    </el-option>
              </el-select>
          </el-form-item>
        </el-col>
         </el-row>
        <el-row>
        <el-col :span="8">
            <el-form-item label="检定周期值" prop="vrfCycValue" style="white-space:nowrap">
                <el-input v-model="formData.vrfCycValue" style="width: 100%;"></el-input>
             </el-form-item>
        </el-col>
        <el-col :span="8">
            <el-form-item label="检定周期单位" prop="vrfCycUnit" style="white-space:nowrap">
                <el-select v-model="formData.vrfCycUnit" clearable placeholder="请选择" style="width: 100%;">
                    <el-option
                    v-for="(item,index) in vrfCycUnitList"
                    :key="index"
                    :label="item.vrfCycUnit"
                    :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-col>
        <el-col :span="8">
            <el-form-item label="下次检定日期" prop="nextVrfDate" style="white-space:nowrap">
               <el-date-picker v-model="formData.nextVrfDate" style="width:100%" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
            </el-form-item>
        </el-col>
        </el-row>
        <el-row>
        <el-col :span="24">
           <el-form-item label="备注" prop="memo" style="width: 100%;">
                <el-input size="mini" v-model="formData.memo"></el-input>
            </el-form-item>
        </el-col>
        </el-row>
      </el-form>
          <span slot="footer" class="dialog-footer">
        <el-button type="primary" icon="el-icon-check" size="mini" @click="formType === 0 ? addData():modifyData()">确定</el-button>
        <el-button size="mini" type="primary" icon="el-icon-remove-outline" @click="cancel">取消</el-button>
      </span>
 </el-dialog>
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
   props: ['showFlag3', 'Params', 'Params3'],
  data () {
    return {
        dialogTableVisible: false,
        formTypeDsc: '修改设备检定记录',
        formType: 0,
        seen: true,
        seenNo: true,
        beInvalid: false,
        vrfCycUnitList: [
           { id: '1',  vrfCycUnit: '天'},
           { id: '2',  vrfCycUnit: '周'},
           { id: '3',  vrfCycUnit: '月'},
           { id: '4',  vrfCycUnit: '季'},
           { id: '5',  vrfCycUnit: '年'},
        ],//核查周期单位
         vrfResultsList: [
           { id: '0',  vrfResults: '不合格'},
           { id: '1',  vrfResults: '合格'},
         ],
        formData : {
          eqpNo: '',
          eqpName: '',
          eqpTypeName: '',
          manufacturer: '',
          vrfId: '',
          strTime: '',
          endTime: '',
          vrfOrg: '',
          vrfOpr: '',
          cfmOpr: '',
          vrfPay: '',
          vrfResults: '',
          vrfNotes: '',
          vrfCycValue: '',
          vrfCycUnit: '',
          nextVrfDate: '',
          memo: ''
        },
        // eqpTypeNameList: []
    }
  },
  mounted () {
    // this.getEqpTypeNameList ()
  },
  methods: {
    //  getCode (code, arr, codeKey, nameKey) {
    //     if (!code) {
    //       return '';
    //     }
    //     let targetRow = arr.find(item => {
    //       return item[codeKey] === code;
    //     });
    //     // console.log(targetRow, 'targetRow');
    //     return targetRow ? targetRow[nameKey] : '';
    // },
    // getEqpTypeNameList () {
    //   this.axios.post('pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode',{validFlag:1,baseCode:4808}, {individualType: 'json'})
    //         .then(res => {
    //           this.eqpTypeNameList= res.data;
    //    })
    // },
    cancel () {
        this.formData = {
          eqpNo: '',
          eqpName: '',
          eqpTypeName: '',
          manufacturer: '',
          vrfId: '',
          strTime: '',
          endTime: '',
          vrfOrg: '',
          vrfOpr: '',
          cfmOpr: '',
          vrfPay: '',
          vrfResults: '',
          vrfNotes: '',
          vrfCycValue: '',
          vrfCycUnit: '',
          nextVrfDate: '',
          memo: ''
        };
        this.dialogTableVisible = false;
      },
     addData () {
        this.$refs['formData'].validate((valid) => {
        if (valid) {
             this.formData.createMan = userName;
             this.formData.createNo = userId;
            //  this.formData.eqpTypeName = this.getCode(this.formData.eqpTypeNo,this.eqpTypeNameList,'baseCode','baseName')
             this.axios.post('pass/baseManagement/v1/limslrceqpvrfs/', this.formData, {individualType: 'json'}).then(res => {
                     if (res.succeed) {
                      this.dialogTableVisible = false;
                      this.$message.success('添加成功')
                      this.$emit('refresh')
                     } else {
                      this.$message.error(res.message)
                     }
                     }).catch(e => {
                      this.$message.error(e.message)
               })
             }
          })
      },
      modifyData () {
        this.$refs['formData'].validate((valid) => {
        if (valid) {
            this.formData.updateMan = userName;
            this.formData.updateNo = userId;
            // this.formData.eqpTypeName = this.getCode(this.formData.eqpTypeNo,this.eqpTypeNameList,'baseCode','baseName')                            
            this.axios.put('pass/baseManagement/v1/limslrceqpvrfs/', this.formData, {individualType: 'json'}).then(res => {
               if (res.succeed) {
                this.dialogTableVisible = false;
                this.$message.success('修改成功')
                this.$emit('refresh')
               } else {
                this.$message.error(res.message)
               }
               }).catch(e => {
                this.$message.error(e.message)
              })
            }
        })
      },
       closeDialog () {
        this.formData = {
          eqpNo: '',
          eqpName: '',
          eqpTypeName: '',
          manufacturer: '',
          vrfId: '',
          strTime: '',
          endTime: '',
          vrfOrg: '',
          vrfOpr: '',
          cfmOpr: '',
          vrfPay: '',
          vrfResults: '',
          vrfNotes: '',
          vrfCycValue: '',
          vrfCycUnit: '',
          nextVrfDate: '',
          memo: ''
        };
      //  this.seen = true;
      //  this.seenNo = true;
      //  this.beInvalid = false;
       },
     },
   watch: {
   showFlag3 (arg) {
        this.dialogTableVisible = true;
        if (this.Params3 !== null) {
          this.formData = Object.assign({},this.Params3)
          this.formType = 1;
          this.formTypeDsc = '修改设备检定记录';
          // this.beInvalid = true;
          //  this.seen = false;
        } else {
          this.formType = 0;
          this.seenNo = false;
          this.formData.eqpNo = this.Params.eqpNo;
          this.formData.eqpName = this.Params.eqpName;
          this.formData.vrfId = this.Params.vrfId;
          this.formTypeDsc = '新增设备检定记录';
        }
      }
        }
}
</script>
<style lang="less">
.tb-row {
    margin-bottom: 2px !important;
}
</style>
