<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="90px" :rules="monitorRules" ref="formData" >
          <el-row>
            <el-col :span='6'>
              <el-form-item prop="anlyItemNo" label="分析项目编号">
                <el-input v-model="formData.anlyItemNo" size="small" readonly disabled style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="unitNameTypeIndex" label="度量单位">
               <el-select v-model="formData.unitNo" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in unitNameType" :key="index" :label="item.unitName"
                    :value="item.unitNo" placeholder="请输入">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="minSignTypeIndex" label="下限符">
                <el-select v-model="formData.minSign" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in minSignType" :key="index" :label="item.minSign"
                    :value="item.minSign">
                  </el-option>
                </el-select>
                </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="isRareTypeIndex" label="是否贵重">
               <el-select v-model="formData.isRare" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in isRareType" :key="index" :label="item.isRare"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='6'>
              <el-form-item prop="testItemNo" label="测试任务编码">
               <el-input v-model="formData.testItemNo" readonly disabled size="small" style="width: 100%;" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="dataTypeNameTypeIndex" label="数据类型">
               <el-select v-model="formData.dataTypeCode" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in dataTypeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item  label="下限值">
               <el-input v-model="formData.minValue" size="small" placeholder="请输入" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="isLoginTypeIndex" label="是否必检">
                <el-select v-model="formData.isLogin" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in isLoginType" :key="index" :label="item.isLogin"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='6'>
              <el-form-item prop="testItemName" label="测试任务名称">
                <el-input v-model="formData.testItemName" readonly disabled size="small" style="width: 100%;" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="outputTypeNameTypeIndex" label="输出类型">
               <el-select v-model="formData.outputTypeCode" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in outputTypeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="maxSignTypeIndex" label="上限符">
                <el-select v-model="formData.maxSign" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in maxSignType" :key="index" :label="item.maxSign"
                    :value="item.maxSign">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="isAlarmTypeIndex" label="是否报警">
               <el-select v-model="formData.isAlarm" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in isAlarmType" :key="index" :label="item.isAlarm"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='6'>
              <el-form-item prop="anlyItemName" label="分析项目名称">
                <el-input v-model="formData.anlyItemName" disabled size="small" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="reviseRuleNameTypeIndex" label="修约规则">
               <el-select v-model="formData.reviseRuleNo" filterable clearable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in reviseRuleNameType" :key="index" :label="item.reviseRuleName"
                    :value="item.reviseRuleNo">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item label="上限值">
                <el-input v-model="formData.maxValue" size="small" placeholder="请输入" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="isComputeTypeIndex" label="是否计算">
               <el-select v-model="formData.isCompute" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in isComputeType" :key="index" :label="item.isCompute"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='6'>
              <el-form-item prop="anlyItemAlias" label="分析项目别名">
                <el-input v-model="formData.anlyItemAlias" size="small" style="width: 100%;" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="itemTypeNameTypeIndex" label="项目类型">
               <el-select v-model="formData.itemTypeCode" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in itemTypeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="defaultValue" label="默认值">
               <el-input v-model="formData.defaultValue" size="small" placeholder="请输入" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="isMidTypeIndex" label="是否中间项">
               <el-select v-model="formData.isMid" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in isMidType" :key="index" :label="item.isMid"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='6'>
              <el-form-item prop="dspOrder" label="显示顺序">
               <el-input v-model="formData.dspOrder" size="small" style="width: 100%;" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="formulaNameTypeIndex" label="计算公式">
               <el-select v-model="formData.formulaNo" filterable clearable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in formulaNameType" :key="index" :label="item.formulaName"
                    :value="item.formulaNo">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="anlyCnt" label="分析次数">
               <el-input v-model="formData.anlyCnt" size="small" style="width: 100%;" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item prop="isReportTypeIndex" label="是否报出">
               <el-select v-model="formData.isReport" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in isReportType" :key="index" :label="item.isReport"
                    :value="item.id">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='24'>
              <el-form-item prop="memo" label="备注">
               <el-input v-model="formData.memo" size="small" placeholder="请输入" style="width: 100%;"></el-input>
               </el-form-item>
            </el-col>
          </el-row>
       </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,
            seen: true,
            seenNo: true,
            beInvalid: false,
            testItemName: '',
            testItemNo: '',
            anlyItemNo: '',
            anlyItemName: '',
            minValue: '',
            anlyItemAlias: '',
            anlyItemDesc: '',
            maxValue: '',
            anlyItemEng: '',
            dspOrder: '',
            memo: '',
            anlyCnt: '',
            defaultValue: '',
            // minSign: '>',
            // maxSign: '<=',
            unitNameTypeIndex: 0,//度量单位
            minSignTypeIndex: 0,//下限符
            isRareTypeIndex: 1,//是否贵重
            dataTypeNameTypeIndex: 0,//数据类型
            isLoginTypeIndex: 1,// 是否必检
            outputTypeNameTypeIndex: 0,//输出类型
            maxSignTypeIndex: 0,//上限符
            isAlarmTypeIndex: 1,//是否报警
            reviseRuleNameTypeIndex: 0,//修约规则
            isComputeTypeIndex: 1,//是否计算
            itemTypeNameTypeIndex: 0,//项目类型
            isReportTypeIndex: 1,//是否报出
            isMidTypeIndex: 1,//是否中间项
            formulaNameTypeIndex: 0,//计算公式
            unitNameType: [],
            minSignType: [
              {minSign: '>='},
              {minSign: '>'}
            ],
            isRareType: [
              {id: '0', isRare: '否'},
              {id: '1', isRare: '是'}
            ],
            dataTypeNameType: [
              {testItemNo: '01', dataTypeName: '数据类型1'},
              {testItemNo: '02', dataTypeName: '数据类型2'}
            ],
            isLoginType: [
              {id: '0', isLogin: '否'},
              {id: '1', isLogin: '是'}
            ],
            outputTypeNameType: [
              {gradeNo: '01', outputTypeName: '输出类型1'},
              {gradeNo: '02', outputTypeName: '输出类型2'}
            ],
            maxSignType: [
              {maxSign: '<='},
              {maxSign: '<'}
            ],
            isAlarmType: [
              {id: '0', isAlarm: '否'},
              {id: '1', isAlarm: '是'}
            ],
            reviseRuleNameType: [],
            isComputeType: [
              {id: '0', isCompute: '否'},
              {id: '1', isCompute: '是'}
            ],
            formData: {
             // anlyItemName: '',
              minValue: '',
              maxValue: '',
            },
            itemTypeNameType: [],
            isReportType: [
              {id: '0', isReport: '否'},
              {id: '1', isReport: '是'}
            ],
            isMidType: [
              {id: '0', isMid: '否'},
              {id: '1', isMid: '是'}
            ],
            formulaNameType: [],
             monitorRules: {
              anlyItemName: [{ required: true, message: '该项不能为空', trigger: 'blur'}],
            },
            monitorForm: {
            tableData: [{}],
           
            }
        }
    },
    mounted () {
      this.getUnitNameTypeList ()
      this.getDataTypeNameType ()
      this.getOutputTypeNameType ()
      this.getReviseRuleNameType ()
      this.getItemTypeNameType ()
      this.getFormulaNameType ()
    },
    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] : '';
    },
      cancel () {
        let _this = this;
        this.formData = {}
        _this.dialogTableVisible = false
      },
      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['formData'].validate((valid) => {
        if (valid) {
        this.formData.updateMan = userName
        this.formData.updateNo = userId
        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/limsstdindexds/', 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)
          })
        }
        })
      },
      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 () {
       let _this = this;
       _this.formData={}
       _this.seen = true;
       _this.seenNo = true;
       _this.beInvalid = false;
     },
      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) {
          let _this = this;
          this.formData = Object.assign({},_this.Params[0])
          _this.dialogTableVisible = true;
          _this.seen = false;
          _this.beInvalid = true;
    }
    }
}
</script>
<style lang="less">
.customWidth_test{
  width: 1100px !important
}
</style>
