<template>
    <div class="examination">
     <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible" customClass="customWidth_test">
        <div slot="title" class="titleBox">
         <i class='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">修改分析项目</span>
        </div>
        <el-form :model="formData" label-width="80px" :rules="monitorForm.monitorRules" ref="monitorForm" >
         <table class="common-table-style4">
           <tr>
             <td>
               <el-form-item prop="anlyItemNo" label="分析项目编号">
               <el-input v-model="formData.anlyItemNo" size="small" readonly disabled style="width: 150px;"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="unitNameTypeIndex" label="度量单位">
               <el-select v-model="formData.unitNo" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in unitNameType" :key="index" :label="item.unitName"
                    :value="item.unitNo" placeholder="请输入">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
             <td>
                <!-- <el-input v-model="minSign" size="small" readonly disabled style="width: 150px;"></el-input> -->
                <el-form-item prop="minSignTypeIndex" label="下限符">
                <el-select v-model="formData.minSign" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in minSignType" :key="index" :label="item.minSign"
                    :value="item.minSign">
                  </el-option>
                </el-select>
                </el-form-item>
             </td>
             <td>
               <el-form-item prop="isRareTypeIndex" label="是否贵重">
               <el-select v-model="formData.isRare" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in isRareType" :key="index" :label="item.isRare"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
            </tr>
            <tr>
             <td>
               <el-form-item prop="testItemNo" label="测试任务编码">
               <el-input v-model="formData.testItemNo" readonly disabled size="small" style="width: 150px;" placeholder="请输入"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="dataTypeNameTypeIndex" label="数据类型">
               <el-select v-model="formData.dataTypeCode" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in dataTypeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
             <td>
               <el-form-item label="下限值">
               <el-input v-model="formData.minValue" size="small" placeholder="请输入" style="width: 150px;"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="isLoginTypeIndex" label="是否必检">
                <el-select v-model="formData.isLogin" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in isLoginType" :key="index" :label="item.isLogin"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
           </tr>
           <tr>
             <td>
               <el-form-item prop="testItemName" label="测试任务名称">
               <el-input v-model="formData.testItemName" readonly disabled size="small" style="width: 150px;" placeholder="请输入"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="outputTypeNameTypeIndex" label="输出类型">
               <el-select v-model="formData.outputTypeCode" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in outputTypeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
             <td>
                <!-- <el-input v-model="maxSign" size="small" readonly disabled style="width: 150px;"></el-input> -->
                <el-form-item prop="maxSignTypeIndex" label="上限符">
                <el-select v-model="formData.maxSign" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in maxSignType" :key="index" :label="item.maxSign"
                    :value="index">
                  </el-option>
                </el-select>
                </el-form-item>
             </td>
             <td>
               <el-form-item prop="isAlarmTypeIndex" label="是否报警">
               <el-select v-model="formData.isAlarm" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in isAlarmType" :key="index" :label="item.isAlarm"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
           </tr>
           <tr>
             <td>
               <el-form-item prop="anlyItemName" label="分析项目名称">
                 <el-select v-model="formData.anlyItemNo" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in anlyNameType" :key="index" :label="item.anlyItemName"
                    :value="item.anlyItemNo">
                  </el-option>
                </el-select>
               </el-form-item>
            </td>
             <td>
               <el-form-item prop="reviseRuleNo" label="修约规则">
               <el-select v-model="formData.reviseRuleNo" filterable clearable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in reviseRuleNameType" :key="index" :label="item.reviseRuleName"
                    :value="item.reviseRuleNo">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
             <td>
             <el-form-item label="上限值">
             <el-input v-model="formData.maxValue" size="small" placeholder="请输入" style="width: 150px;"></el-input>
             </el-form-item>
             </td>
             <td>
               <el-form-item prop="isComputeTypeIndex" label="是否计算">
               <el-select v-model="formData.isCompute" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in isComputeType" :key="index" :label="item.isCompute"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
           </tr>
            <tr>
             <td>
                <el-form-item prop="anlyItemAlias" label="分析项目别名">
                <el-input v-model="formData.anlyItemAlias" size="small" style="width: 150px;" placeholder="请输入"></el-input>
                </el-form-item>
             </td>
             <td>
               <el-form-item prop="itemTypeNameTypeIndex" label="项目类型">
               <el-select v-model="formData.itemTypeCode" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in itemTypeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="isReportTypeIndex" label="是否报出">
               <el-select v-model="formData.isReport" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in isReportType" :key="index" :label="item.isReport"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="isMidTypeIndex" label="是否中间项">
               <el-select v-model="formData.isMid" filterable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in isMidType" :key="index" :label="item.isMid"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
            </tr>
            <tr>
             <td>
               <el-form-item prop="dspOrder" label="显示顺序">
               <el-input v-model="formData.dspOrder" size="small" style="width: 150px;" placeholder="请输入"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="formulaNo" label="计算公式">
               <el-select v-model="formData.formulaNo" filterable clearable collapse-tags size="small" style="width: 150px;">
                  <el-option v-for="(item,index) in formulaNameType" :key="index" :label="item.formulaName"
                    :value="item.formulaNo">
                  </el-option>
                </el-select>
               </el-form-item>
             </td>
             <td colspan="3">
               <el-form-item prop="memo" label="备注">
               <el-input v-model="formData.memo" size="small" placeholder="请输入" style="width: 100%;"></el-input>
               </el-form-item>
             </td>
            </tr>
             <tr>
             <td>
               <el-form-item prop="anlyCnt" label="分析次数">
               <el-input v-model="formData.anlyCnt" size="small" style="width: 150px;" placeholder="请输入"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="defaultValue" label="方法上限值">
               <el-input v-model="formData.maxLimit" size="small" placeholder="请输入" style="width: 100%;"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="defaultValue" label="方法下限值">
               <el-input v-model="formData.minLimit" size="small" placeholder="请输入" style="width: 100%;"></el-input>
               </el-form-item>
             </td>
             <td>
               <el-form-item prop="defaultValue" label="默认值">
               <el-input v-model="formData.defaultValue" size="small" placeholder="请输入" style="width: 100%;"></el-input>
               </el-form-item>
             </td>
             </tr>
         </table>
       </el-form>
       <span slot="footer" class="dialog-footer">
        <el-button type="goon" icon="el-icon-check" size="mini" @click="modifyData">确定</el-button>
        <el-button size="mini" type="goon" 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: ['showFlag', 'Params'],
    data () {
      var maxValueVerify = (rule, value, callback) => {
	        if(this.maxValue){
	          if(Number(this.maxValue) > Number(this.minValue)){
	            callback();
	          }else{
	            callback(new Error('上限不能小于下限'));
	          }
	        }else{
	          callback();
          }
       };
      return {
          dialogTableVisible: false,
          unitNameType: [],
          anlyNameType:[],
          minSignType: [
            {minSign: '>='},
            {minSign: '>'}
          ],
          isRareType: [
            {id: '0', isRare: '否'},
            {id: '1', isRare: '是'}
          ],
          dataTypeNameType: [],
          isLoginType: [
            {id: '0', isLogin: '否'},
            {id: '1', isLogin: '是'}
          ],
          outputTypeNameType: [],
          maxSignType: [
            {maxSign: '<='},
            {maxSign: '<'}
          ],
          isAlarmType: [
            {id: '0', isAlarm: '否'},
            {id: '1', isAlarm: '是'}
          ],
          reviseRuleNameType: [],
          isComputeType: [
            {id: '0', isCompute: '否'},
            {id: '1', isCompute: '是'}
          ],
          formData: {
           // anlyItemName: '',
            minValue: '',
            maxValue: '',
            reviseRuleNo: '',
            formulaNo: ''
          },
          itemTypeNameType: [],
          isReportType: [
            {id: '0', isReport: '否'},
            {id: '1', isReport: '是'}
          ],
          isMidType: [
            {id: '0', isMid: '否'},
            {id: '1', isMid: '是'}
          ],
          formulaNameType: [],
          monitorForm: {
          tableData: [{}],
          
          monitorRules: {
          // maxValue: [{ required: true, message: '该项不能为空', trigger: ['blur', 'change']},{ required: true,validator: maxValueVerify, trigger: 'blur' }],
          //anlyItemName: [{ required: true, message: '该项不能为空', trigger: ['blur', 'change']}],
          // minValue: [{ required: true, message: '该项不能为空', trigger: ['blur', 'change']}]
          }
          }
      }
    },
    mounted () {
      this.axios.post("pass/baseManagement/v1/limsstdanlyitems/queryLimsStdAnlyItemPage",{object:{validFlag:1}, pageIndex: 1,pageSize: 9999}, {individualType: 'json'}).then(res => {
        this.anlyNameType = res.data.list
      })
      this.getUnitNameTypeList ()
      this.getDataTypeNameType ()
      this.getOutputTypeNameType ()
      this.getReviseRuleNameType ()
      this.getItemTypeNameType ()
      this.getFormulaNameType ()
    },
    methods: {
      cancel () {
        this.formData = {}
        this.dialogTableVisible = false
      },
       getCode (code, arr, codeKey, nameKey) {
         if (!code) {
           return '';
         }
         let targetRow = arr.find(item => {
           return item[codeKey] === code;
         });
         return targetRow ? targetRow[nameKey] : '';
       },
      getUnitNameTypeList () {
        this.axios.post("pass/baseManagement/v1/limsbaseunits/queryLimsBaseUnitPage",{object:{validFlag:1},pageIndex:1,pageSize:9999}, {individualType: 'json'}).then(res => {
          this.unitNameType = res.data.list;
        })
      },
      getDataTypeNameType () {
        this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4825}, {individualType: 'json'}).then(res => {
              this.dataTypeNameType = res.data
            })
      },
      getOutputTypeNameType () {
        this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4810}, {individualType: 'json'}).then(res => {
              this.outputTypeNameType = res.data
            })
      },
      getReviseRuleNameType () {
        this.axios.post('pass/baseManagement/v1/limsbasereviserules/queryLimsBaseReviseRulePage',{object: {reviseRuleName: "",validFlag:1}, pageIndex: 1, pageSize: 9999}, {individualType: 'json'}).then(res => {
          this.reviseRuleNameType = res.data.list;
        }).catch(e => {
                // this.dataLoading = false;
        });
      },
      getItemTypeNameType () {
        this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4804}, {individualType: 'json'}).then(res => {
              this.itemTypeNameType = res.data
            })
      },
      getFormulaNameType () {
        this.axios.post('pass/baseManagement/v1/limsbaseformulas/queryLimsBaseFormulaPage',{object: {formulaNo: "", formulaName: "",validFlag:1},pageIndex:1,pageSize: 9999},{individualType: 'json'}).then(res => {
          this.formulaNameType = res.data.list;
        })
      },
      modifyData () {
        let _this = this;
        // _this.$refs['monitorForm'].validate((valid) => {
        // if (valid) {
        this.formData.updateMan = userName
        this.formData.updateNo = userId
         this.formData.anlyItemName = this.getCode (this.formData.anlyItemNo, this.anlyNameType, 'anlyItemNo', 'anlyItemName')
        this.formData.unitName = this.getCode (this.formData.unitNo, this.unitNameType, 'unitNo', 'unitName')
        this.formData.dataTypeName = this.getCode (this.formData.dataTypeCode, this.dataTypeNameType, 'baseCode', 'baseName')
        this.formData.outputTypeName = this.getCode (this.formData.outputTypeCode, this.outputTypeNameType, 'baseCode', 'baseName')
        this.formData.reviseRuleName = this.getCode (this.formData.reviseRuleNo, this.reviseRuleNameType, 'reviseRuleNo', 'reviseRuleName')
        this.formData.itemTypeName = this.getCode (this.formData.itemTypeCode, this.itemTypeNameType, 'baseCode', 'baseName')
        this.formData.formulaName=  this.getCode (this.formData.formulaNo, this.formulaNameType, 'formulaNo', 'formulaName')
        this.axios.put('pass/baseManagement/v1/limsstdtestitemds/', this.formData, {individualType: 'json'}).then(res => {
           if (res.code == 0 || res.code == 200) {
             this.dialogTableVisible = false;
              this.$message.success('修改成功')
              this.$emit('refresh')
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
        // }
        // })
      },
      renderHeader (h) {
         return (
             <div style="cursor: pointer ;line-height:20px" onClick={() => this.addRow()}>
             <i class="el-icon-plus" style="font-size:20px; color:rgb(18, 52, 243)"></i>
             </div>
         )
      },
     closeDialog () {
      this.formData = {}
     },
      tableHeaderCellStyle () {
      return 'background-color: rgb(249,249,249) !important;color: rgb(73, 72, 72);border-bottom: 1px solid #DCDFE7;border-top:3px solid #3ac1ea;'
      }
    },
    watch: {
      showFlag (arg) {
        this.formData = Object.assign({},this.Params[0]);
        this.dialogTableVisible = true;
      }
    }
}
</script>
<style lang="less">
.customWidth_test{
  width: 1000px !important
}
</style>
