<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="monitorRules" ref="monitorForm" >
          <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 label="度量单位">
               <el-select v-model="formData.unitNo" clearable 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 label="下限符">
                <el-select v-model="formData.minSign" filterable clearable 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 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-option v-for="(item,index) in minSignType" :key="index" :label="item.minSign"
                    :value="item.minSign">
                  </el-option>
               </el-input>
               </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item 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 label="输出类型">
               <el-select v-model="formData.outputTypeCode" clearable 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 label="上限符">
                <el-select v-model="formData.maxSign" clearable 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 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" 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" clearable filterable 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 clearable 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 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 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 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 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='6'>
              <el-form-item label="方法上限值">
             <el-input v-model="formData.maxLimit" size="small" placeholder="请输入" style="width: 100%;"></el-input>
             </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item label="方法下限值">
             <el-input v-model="formData.minLimit" size="small" placeholder="请输入" style="width: 100%;"></el-input>
             </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item label="标准上限值">
                <el-input v-model="formData.maxStd" size="small" placeholder="请输入" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item label="标准下限值">
                <el-input v-model="formData.minStd" size="small" placeholder="请输入" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='12'>
              <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,
        unitNameType: [],
        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: {},
        itemTypeNameType: [],
        isReportType: [
          {id: '0', isReport: '否'},
          {id: '1', isReport: '是'}
        ],
        isMidType: [
          {id: '0', isMid: '否'},
          {id: '1', isMid: '是'}
        ],
        formulaNameType: [],
        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/limsbaseunits/queryLimsBaseUnitPage",{object:{validFlag:1},pageIndex:1,pageSize:9999}, {individualType: 'json'}).then(res => {
        this.unitNameType = res.data.list;
      })
      //数据类型
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4825}, {individualType: 'json'}).then(res => {
        this.dataTypeNameType = res.data
      })
      //输出类型
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4810}, {individualType: 'json'}).then(res => {
        this.outputTypeNameType = res.data
      })
      //修约规则
      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;
      })
      //项目类型
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4804}, {individualType: 'json'}).then(res => {
        this.itemTypeNameType = res.data
      })
      //计算公式
      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;
      })
    },
    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 () {
        this.formData = {}
        this.dialogTableVisible = false
      },
      modifyData () {
        this.$refs['monitorForm'].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 () {
        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)
        this.dialogTableVisible = true;
      }
    }
}
</script>
<style lang="less">
.customWidth_test{
  width: 1000px !important
}
</style>
