<template>
    <div class="examination">
     <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible" width='50%'>
        <div slot="title" class="titleBox">
        <i :class="tableType === 0? 'el-icon-document':'el-icon-edit-outline'" style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px">{{tableTypeDsc}}</span>
        </div>
         <el-form :model="formData" label-width="80px" :rules="monitorForm.monitorRules" ref="monitorForm">
           <el-row>
             <el-col :span='8'>
               <el-form-item prop="stdNo" label="标准名称">
               <el-select v-model="formData.stdNo" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="item in stdNameType" :key="item.stdNo" :label="item.stdName"
                    :value="item.stdNo">
                  </el-option>
                </el-select>
               </el-form-item>
             </el-col>
             <el-col :span='8'>
               <el-form-item prop="gradeNo" label="牌号/等级">
               <el-select v-model="formData.gradeNo" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in gradeNameType" :key="index" :label="item.gradeName"
                    :value="item.gradeNo">
                  </el-option> 
                </el-select>
               </el-form-item>
             </el-col>
             <el-col :span='8'>
               <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-row>
            <el-col :span='8'>
              <el-form-item prop="condition1" label="条件1">
               <el-input v-model="formData.condition1" size="small" style="width: 100%;" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='8'>
              <el-form-item prop="condition2" label="条件2">
               <el-input v-model="formData.condition2" size="small" style="width: 100%;" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='8'>
              <el-form-item prop="condition3" label="条件3">
               <el-input v-model="formData.condition3" size="small" style="width: 100%;" placeholder="请输入"></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="tableType === 0 ? addData():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 prdWthMaxVerify = (rule, value, callback) => {
	        if(this.formData.prdWthMax){
	          if(Number(this.formData.prdWthMax) > Number(this.formData.prdWthMin)){
	            callback();
	          }else{
	            callback(new Error('上限不能小于下限'));
	          }
	        }else{
	          callback();
          }
       };
        var prdLenMaxVerify = (rule, value, callback) => {
	        if(this.formData.prdLenMax){
	          if(Number(this.formData.prdLenMax) > Number(this.formData.prdLenMin)){
	            callback();
	          }else{
	            callback(new Error('上限不能小于下限'));
	          }
	        }else{
	          callback();
          }
       };
         var prdThkMaxVerify = (rule, value, callback) => {
	        if(this.formData.prdThkMax){
	          if(Number(this.formData.prdThkMax) > Number(this.formData.prdThkMin)){
	            callback();
	          }else{
	            callback(new Error('上限不能小于下限'));
	          }
	        }else{
	          callback();
          }
       };
        return {
            dialogTableVisible: false,
            tableTypeDsc: '新增标准内容主信息',
            tableType: 0,
            seen: true,
            seenNo: true,
            beInvalid: false,
            condition1: '',
            condition2: '',
            condition3: '',
            // lenMaxSign: '<=',//长度上限符号
            // lenMinSign: '>',//长度下限符号
            // wthMaxSign: '<=',//宽度上限符号
            // wthMinSign: '>',//宽度下限符号
            // thkMaxSign: '<=',//厚度上限符号
            // thkMinSign: '>',//厚度下限符号
            memo: '',
            formData: {
              prdLenMax: '',
              prdLenMin: '',
              prdWthMax: '',
              prdWthMin: '',
              prdThkMax: '',
              prdThkMin: '',
            },
            stdNameTypeIndex: 0,//标准名称
            gradeNameTypeIndex: 0,//牌号/等级
            lenMaxSignTypeIndex: 0,//长度上限符号
            lenMinSignTypeIndex: 0,//长度下限符号
            wthMaxSignTypeIndex: 0,//宽度上限符号
            wthMinSignTypeIndex: 0,//宽度下限符号
            thkMaxSignTypeIndex: 0,//厚度上限符号
            thkMinSignTypeIndex: 0,//厚度下限符号
            stdNameType:[],
            // lenMaxSignType: [],
            gradeNameType: [],
            // lenMinSignType: [],
            // wthMaxSignType: [],
            // wthMinSignType: [],
            // prdThkMaxType: [],
            minSignType: [
              {minSign: '>='},
              {minSign: '>'}
            ],
            maxSignType: [
              {maxSign: '<='},
              {maxSign: '<'}
            ],
            monitorForm: {
            tableData: [{}],
            monitorRules: {
              stdNo: [{ required: true, message: '该项不能为空', trigger: ['blur', 'change'] }],
              gradeNo: [{ required: true, message: '该项不能为空', trigger:'change' }]
              }
            }
        }
    },
    mounted () {
      this.getstdNameTypeList ()
      this.getGradeNameTypeType ()
    },
    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.$refs['monitorForm'].resetFields();
        this.formData = {}
        this.tableType = 0;
        this.tableTypeDsc = '新增标准内容主信息';
        this.dialogTableVisible = false
      },
      getstdNameTypeList () {
         let obj= {
         object:{validFlag:1},
         pageIndex:1,
         pageSize:9999
       }
        this.axios.post('pass/baseManagement/v1/limsstdinfos/queryLimsStdInfoList/',obj,{individualType: 'json'}).then(res => {
          this.stdNameType = res.data.list;
        })
      },
      getGradeNameTypeType () {
       let obj = {
        object:{grandTypeCode:'',gradeName:'',validFlag:1},
        pageIndex:1,
        pageSize:99999
      }
      this.axios.post('pass/baseManagement/v1/limsbasegrades/queryLimsBaseGradePage',obj, {individualType: 'json'}).then(res => {
        this.gradeNameType = res.data.list;
      }).catch(e => {
     
      });
      },
      addData () {
        let _this = this;
        _this.$refs['monitorForm'].validate((valid) => {
          if (valid) {
            this.formData.stdName = this.getCode(this.formData.stdNo,this.stdNameType,'stdNo','stdName')
            this.formData.gradeName = this.getCode(this.formData.gradeNo,this.gradeNameType,'gradeNo','gradeName')
            _this.axios.post('pass/baseManagement/v1/limsstdcontents/saveLimsStdContent', 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 () {
        let _this = this;
         _this.$refs['monitorForm'].validate((valid) => {
         if (valid) {
        this.formData.stdName = this.getCode(this.formData.stdNo,this.stdNameType,'stdNo','stdName')
        this.formData.gradeName = this.getCode(this.formData.gradeNo,this.gradeNameType,'gradeNo','gradeName')
        _this.axios.post('pass/baseManagement/v1/limsstdcontents/saveLimsStdContent', 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.$refs['monitorForm'].resetFields();
      this.formData = {}
      this.tableType = 0;
      this.tableTypeDsc = '新增标准内容主信息';
      this.dialogTableVisible = 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.dialogTableVisible = true;
        if (_this.Params !== null) {
          this.formData = Object.assign({},this.Params[0])
          _this.tableType = 1;
          _this.tableTypeDsc = '修改标准内容主信息';
        } else {
          _this.tableType = 0;
          _this.seenNo = false;
          _this.tableTypeDsc = '新增标准内容主信息';
        }
      }
    }
}
</script>
<style lang="less">
.customWidth_standar{
  width: 700px !important
}
</style>
