
 <!-- 新增仪器故障弹窗 -->
<template>
  <div class="resource">
      <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible"  width='60%'>
     <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="75px" 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"></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" :disabled="true" ></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="prbId">
            <el-input v-model="formData.prbId" :disabled="true"></el-input>
          </el-form-item>
        </el-col> -->
            <el-col :span="8">
          <el-form-item label="故障日期" prop="prbTime" style="white-space:nowrap">
             <el-date-picker v-model="formData.prbTime" style="width:100%" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
         <el-col :span="8">
          <el-form-item label="故障分类" prop="prbSort" style="white-space:nowrap">
            <el-input v-model="formData.prbSort"></el-input>
          </el-form-item>
        </el-col>
         </el-row>
        <el-row>
        <el-col :span="8">
            <el-form-item label="故障描述" prop="prbDesc">
                <el-input size="mini" v-model="formData.prbDesc"></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="故障原因分析" prop="prbCause" style="white-space:nowrap">
            <el-input size="mini" v-model="formData.prbCause"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="8">
          <el-form-item label="故障发现人" prop="prbRptOpr" style="white-space:nowrap">
            <el-input v-model="formData.prbRptOpr"></el-input>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row>
        <!-- <el-col :span="8">
          <el-form-item label="仪器处置结果" prop="treatRst" style="white-space:nowrap">
            <el-input v-model="formData.treatRst"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="处理记录号" prop="treatId" style="white-space:nowrap">
            <el-input v-model="formData.treatId"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="16">
           <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: ['showFlag4', 'Params', 'Params4'],
  data () {
    return {
        dialogTableVisible: false,
        formTypeDsc: '修改仪器检定记录',
        formType: 0,
        formData : {
          eqpNo: '',
          eqpName: '',
          eqpTypeName: '',
          prbId: '',
          prbTime: '',
          prbSort: '',
          prbDesc: '',
          prbCause: '',
          prbRptOpr: '',
          treatRst: '',
          treatId: '',
          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: '',
          prbId: '',
          prbTime: '',
          prbSort: '',
          prbDesc: '',
          prbCause: '',
          prbRptOpr: '',
          treatRst: '',
          treatId: '',
          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/limslrceqpprbs/', 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/limslrceqpprbs/', 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: '',
          prbId: '',
          prbTime: '',
          prbSort: '',
          prbDesc: '',
          prbCause: '',
          prbRptOpr: '',
          treatRst: '',
          treatId: '',
          memo: ''
        }
      },
     },
   watch: {
   showFlag4 (arg) {
        this.dialogTableVisible = true;
        if (this.Params4 !== null) {
        this.formData = Object.assign({},this.Params4)
        this.formType = 1;
        this.formTypeDsc = '修改仪器故障';
        } else {
        this.formType = 0;
        this.formData.eqpNo = this.Params.eqpNo;
        this.formData.eqpName = this.Params.eqpName;
        this.formData.prbId = this.Params.prbId;
        this.formTypeDsc = '新增仪器故障';
        }
      }
    }
}
</script>
<style lang="less">
.tb-row {
    margin-bottom: 2px !important;
}
</style>
