
 <!-- 新增设备处置弹窗 -->
<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="chkId">
            <el-input v-model="formData.chkId" :disabled="true"></el-input>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="8">
          <el-form-item label="仪器描述" prop="strTime" style="white-space:nowrap">
            <el-input v-model="formData.strTime"></el-input>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row>
        <el-col :span="8">
          <el-form-item label="制造厂商" prop="endTime" style="white-space:nowrap">
            <el-input v-model="formData.endTime"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
            <el-form-item label="规格型号" prop="">
                <el-input v-model="formData.earn"></el-input>
            </el-form-item>
        </el-col> -->
          <el-col :span="8">
          <el-form-item label="处置人" prop="trtOpr">
            <el-input v-model="formData.trtOpr"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="8">
          <el-form-item label="处置时间" prop="trtTime" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
            <el-date-picker v-model="formData.trtTime" 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="trtCause" style="white-space:nowrap">
             <el-select v-model="formData.trtCause" style="width:100%" clearable placeholder="请选择">
                  <el-option
                  v-for="(item, index) in stateFlagList"
                  :key="index"
                  :label="item.stateFlagName"
                  :value="item.id">
                  </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="处置前状态" prop="statusBfr">
            <el-select v-model="formData.statusBfr" style="width:100%" clearable placeholder="请选择">
                  <el-option
                  v-for="(item, index) in stateFlagList"
                  :key="index"
                  :label="item.stateFlagName"
                  :value="item.id">
                  </el-option>
            </el-select>
            <!-- <el-input v-model="formData.statusBfr"></el-input> -->
          </el-form-item>
        </el-col>
            <el-col :span="8">
          <el-form-item label="处置后状态" prop="statusAft">
            <el-select v-model="formData.statusAft" style="width:100%" clearable placeholder="请选择">
                  <el-option
                  v-for="(item, index) in stateFlagList"
                  :key="index"
                  :label="item.stateFlagName"
                  :value="item.id">
                  </el-option>
            </el-select>
            <!-- <el-input v-model="formData.statusAft"></el-input> -->
          </el-form-item>
        </el-col>
         </el-row>
         <el-row>
        <el-col :span="8">
          <el-form-item label="处置说明" prop="trtNotes">
            <el-input v-model="formData.trtNotes"></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: ['showFlag6', 'Params', 'Params6'],
  data () {
    return {
        dialogTableVisible: false,
        formTypeDsc: '修改仪器设备处置',
        formType: 0,
        seen: true,
        seenNo: true,
        beInvalid: false,
        formData : {
          eqpNo: '',
          eqpName: '',
          eqpTypeName: '',
          chkId: '',
          strTime: '',
          endTime: '',
          chkOpr: '',
          trtNotes: '',
          chkCycValue: '',
          chkCycUnit: '',
          nextChkDate: '',
          memo: ''
        },
         stateFlagList: [
          {id: '1', stateFlagName: '在用'},
          {id: '2', stateFlagName: '故障'},
          {id: '3', stateFlagName: '维修'},
          {id: '4', stateFlagName: '检定'},
          {id: '5', stateFlagName: '封存'},
          {id: '6', stateFlagName: '降级'},
          {id: '7', stateFlagName: '停用'},
          {id: '0', stateFlagName: '报废'},
        ],
        // 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: '',
          chkId: '',
          strTime: '',
          endTime: '',
          chkOpr: '',
          trtNotes: '',
          chkCycValue: '',
          chkCycUnit: '',
          nextChkDate: '',
          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/limslrceqptrts/', 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/limslrceqptrts/', 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: '',
          chkId: '',
          strTime: '',
          endTime: '',
          chkOpr: '',
          trtNotes: '',
          chkCycValue: '',
          chkCycUnit: '',
          nextChkDate: '',
          memo: ''
        };
      },
   },
   watch: {
   showFlag6 (arg) {
        this.dialogTableVisible = true;
        if (this.Params6 !== null) {
          this.formData = Object.assign({},this.Params6)
          this.formType = 1;
          this.formTypeDsc = '修改仪器设备处置';
        } else {
          this.formType = 0;
          this.formData.eqpNo = this.Params.eqpNo;
          this.formData.eqpName = this.Params.eqpName;
          this.formData.chkId = this.Params.chkId;
          this.formTypeDsc = '新增仪器设备处置';
        }
      }
        }
}
</script>
<style lang="less">
.tb-row {
    margin-bottom: 2px !important;
}
</style>
