<!-- 新增维修保养信息 -->
<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">
            <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" :disabled="true" 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="mtnOpr">
            <el-input v-model="formData.mtnOpr" clearable style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="8">
          <el-form-item label="档案文件" prop="mtnSort" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
            <el-input v-model="formData.mtnSort" clearable style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row>
        <!-- <el-col :span="8">
          <el-form-item label="记录编号" prop="mtnId">
            <el-input v-model="formData.mtnId" :disabled="true"></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"  clearable style="width:100%" type="datetime" placeholder="选择时间"></el-date-picker>
          </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" clearable></el-input>
            </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"  clearable style="width:100%" type="datetime" placeholder="选择时间"></el-date-picker>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="8">
          <el-form-item label="保养内容" prop="mtnNotes">
            <el-input v-model="formData.mtnNotes"  clearable style="width: 100%;"></el-input>
          </el-form-item>
        </el-col> -->
         </el-row>
        <!-- <el-row>
        <el-col :span="8">
          <el-form-item label="保养费用（元）" prop="mtnPay" style="white-space:nowrap">
            <el-input v-model="formData.mtnPay" clearable style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="保养地点" prop="mtnPlace">
            <el-input v-model="formData.mtnPlace" clearable style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="8">
          <el-form-item label="仪器处置结果" prop="treatRst" style="white-space:nowrap">
             <el-select v-model="formData.treatRst" clearable style="width: 100%;" placeholder="请选择">
                    <el-option
                    v-for="(item,index) in treatRstList"
                    :key="index"
                    :label="item.treatRst"
                    :value="item.id">
                    </el-option>
            </el-select>
          </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" clearable></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: ['showFlag2', 'Params', 'Params2'],
  data () {
    return {
        dialogTableVisible: false,
        formTypeDsc: '修改仪器信息',
        formType: 0,
        seen: true,
        seenNo: true,
        beInvalid: false,
        formData : {
          eqpNo: '',
          eqpName: '',
          eqpTypeName: '',
          eqpDesc: '',
          manufacturer: '',
          mtnId: '',
          specModel: '',
          strTime: '',
          endTime: '',
          mtnSort: '',
          mtnNotes: '',
          mtnPay: '',
          mtnPlace: '',
          mtnOpr: '',
          treatRst: '',
          memo: ''
       },
       treatRstList: [
          {id: '1', treatRst: '在用'},
          {id: '2', treatRst: '故障'},
          {id: '3', treatRst: '维修'},
          {id: '4', treatRst: '检定'},
          {id: '5', treatRst: '封存'},
          {id: '6', treatRst: '降级'},
          {id: '7', treatRst: '停用'},
          {id: '0', treatRst: '报废'},
        ]
      //  eqpTypeNatreatRst }
    }
  },
  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: '',
          eqpDesc: '',
          manufacturer: '',
           mtnId: '',
          specModel: '',
          strTime: '',
          endTime: '',
          mtnSort: '',
          mtnNotes: '',
          mtnPay: '',
          mtnPlace: '',
          mtnOpr: '',
          treatRst: '',
          memo: ''
        };
        this.dialogTableVisible = false;
        this.$emit('refresh')
      },
      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/limslrceqpmtns/', 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/limslrceqpmtns/', 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: '',
          eqpDesc: '',
          manufacturer: '',
          specModel: '',
          mtnId: '',
          strTime: '',
          endTime: '',
          mtnSort: '',
          mtnNotes: '',
          mtnPay: '',
          mtnPlace: '',
          mtnOpr: '',
          treatRst: '',
          memo: ''
        };
     },
},
   watch: {
     showFlag2 (arg) {
        this.dialogTableVisible = true;
        if (this.Params2 !== null) {
          this.formData = Object.assign({},this.Params2)
          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.mtnId = this.Params.mtnId;
          this.formData.eqpName = this.Params.eqpName;
          this.formTypeDsc = '新增维修保养信息';
        }
      }
   }
}
</script>
<style lang="less">
.tb-row {
    margin-bottom: 2px !important;
}
</style>
