
 <!-- 新增设备维修弹窗 -->
<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="85px" 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="rprId">
            <el-input v-model="formData.rprId" :disabled="true"></el-input>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="8">
          <el-form-item label="制造厂商" prop="manufacturer" style="white-space:nowrap">
            <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="specModel" style="white-space:nowrap">
            <el-input v-model="formData.specModel"></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="rprPay" style="white-space:nowrap">
            <el-input v-model="formData.rprPay"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="故障编号" prop="prbNo" style="white-space:nowrap">
            <el-input v-model="formData.prbNo"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="维修人" prop="rprOpr">
            <el-input v-model="formData.rprOpr"></el-input>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row>
        <el-col :span="8">
            <el-form-item label="维修结果" prop="rprResult">
                <el-input v-model="formData.rprResult"></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="8">
            <el-form-item label="维修内容" prop="rprNotes">
                <el-input v-model="formData.rprNotes"></el-input>
                </el-form-item>
        </el-col>
        <el-col :span="8">
           <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: ['showFlag5', 'Params', 'Params5'],
  data () {
    return {
        dialogTableVisible: false,
        formTypeDsc: '修改仪器维修设备',
        formType: 0,
        formData : {
          eqpNo: '',
          eqpName: '',
          eqpTypeName: '',
          rprId: '',
          manufacturer: '',
          specModel: '',
          strTime: '',
          endTime: '',
          rprPay: '',
          prbNo: '',
          rprOpr: '',
          rprResult: '',
          rprNotes: '',
          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: '',
          rprId: '',
          manufacturer: '',
          specModel: '',
          strTime: '',
          endTime: '',
          rprPay: '',
          prbNo: '',
          rprOpr: '',
          rprResult: '',
          rprNotes: '',
          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/limslrceqprprs/', 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/limslrceqprprs/', 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: '',
          rprId: '',
          manufacturer: '',
          specModel: '',
          strTime: '',
          endTime: '',
          rprPay: '',
          prbNo: '',
          rprOpr: '',
          rprResult: '',
          rprNotes: '',
          memo: ''
        };
     },
  },
   watch: {
   showFlag5 (arg) {
        this.dialogTableVisible = true;
        if (this.Params5 !== null) {
          this.formData = Object.assign({},this.Params5)
          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.rprId = this.Params.rprId;
          this.formTypeDsc = '新增仪器维修设备';
        }
      }
        }
}
</script>
<style lang="less">
.tb-row {
    margin-bottom: 2px !important;
}
</style>
