<template>
    <div class="examination">
     <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible" customClass="customWidth_syst">
        <div slot="title" class="titleBox">
        <i :class="tableType === 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">{{tableTypeDsc}}</span>
        </div>
       <el-form ref="baseData" label-width="80px" :rules="ruleValidate" :model="baseData">
         <el-row>
          <el-col :span="12">
            <el-form-item prop="merchItemName" label="客商信息名称">
              <el-input v-model="baseData.merchItemName"  size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="merchItemDesc" label="客商项目描述">
              <el-input v-model="baseData.merchItemDesc" size="small"></el-input>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="filePath" label="附件文件路径">
                <el-input v-model="baseData.filePath" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="memo" label="备注">
                <el-input v-model="baseData.memo" size="small"></el-input>
              </el-form-item>
            </el-col>
         </el-row>
         <el-row>
           <el-col :span="12">
             <el-form-item prop="memo" label="备注1">
               <el-input v-model="baseData.memo1" size="small"></el-input>
             </el-form-item>
           </el-col>
         </el-row>
       </el-form>
       <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" @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>
<!-- TODO dialog2      -->
      <el-dialog @close="closeDialog2" :visible.sync="dialogTableVisible2" customClass="customWidth_syst">
        <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 ref="baseData" label-width="80px" :rules="ruleValidate" :model="baseData">
          <el-row>
            <el-col :span="12">
              <el-form-item prop="evaName" label="评价名称">
                <el-input v-model="baseData.evaName"  size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="evaLevelName" label="评价等级">
                <el-input v-model="baseData.evaLevelName" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="evaVer" label="评价版本">
                <el-input v-model="baseData.evaVer" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="evaDesc" label="评价描述">
                <el-input v-model="baseData.evaDesc" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="filePath" label="附件">
                <el-input v-model="baseData.filePath" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="memo" label="备注">
                <el-input v-model="baseData.memo" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="memo1" label="备注1">
                <el-input v-model="baseData.memo1" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" @click="tableType === 0 ? addData1():modifyData1()">确定</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: ['showFlag2', 'Params', 'Params2','Params3'],
    data () {
        return {
            dialogTableVisible: false,
            dialogTableVisible2:false,
            tableTypeDsc: '新增客商产品信誉信息',
            tableType: 0,
            seen: true,
            seenNo: true,
            beInvalid: false,
            matClassNameTypeIndex: 0,
            matNameTypeIndex: 0,
            evaLevelNameTypeIndex: 0,
            matClassNameType: [],
            matNameType: [],
            evaLevelNameType: [],
            tableData: [],
          //TODO baseData
            baseData: {
              merchItemDesc:'',
              merchItemName:'',
              filePath:'',
              memo: '',
              memo1:'',
              evaName:'',
              evaLevelName:'',
              evaVer:'',
              evaDesc:''
            },
            ruleValidate: {
              //matName: [{ required: true, message: '该项不能为空', trigger: 'change' }],
              //merchName: [{ required: true, message: '该项不能为空', trigger: 'change' }],
              // matName: [{ required: true, message: '该项不能为空', trigger: 'change' }]
             }
        }
    },
    mounted () {
      this.getMatClassNameList (),
      this.getEvaLevelName ()
    },
    methods: {
      cancel () {
        let _this = this;
        _this.tableData = [];
        _this.matClassNameTypeIndex = 0,
        _this.matNameTypeIndex = 0,
        _this.evaLevelNameTypeIndex = 0,
        _this.baseData = {
          merchItemDesc:'',
          merchItemName:'',
          filePath:'',
          memo: '',
          memo1:'',
          evaName:'',
          evaLevelName:'',
          evaVer:'',
          evaDesc:'',
        }
        _this.dialogTableVisible = false
        _this.dialogTableVisible2 = false
        _this.$emit('refresh')
      },
       open(mag, typ, time) {
        this.$message({
          showClose: true,
          message: mag,
          type: typ,
          duration: time
        });
      },
      selectTrigger (val) {
        let _this = this;
         _this.matNameType = []
        // _this.monitorForm.tableData[row].companyNo = _this.companyNameType[val].companyNo
         _this.axios.get('pass/baseManagement/v1/limsbasematerialss/' + '?matClassName=' + _this.matClassNameType[val].matClassName + '&validFlag=1')
            .then(res => {
                for (let i = 0; i < res.data.list.length; i++) {
                  _this.$set(_this.matNameType,i,res.data.list[i])
                }
            })
            console.log(_this.matNameType)
      },
      // TODO addData
      addData () {
        let _this = this;
         _this.$refs['baseData'].validate((valid) => {
          if (valid) {
            let obj = {
              merchNo:this.Params.id,
              merchItemName:this.baseData.merchItemName,
              merchItemDesc:this.baseData.merchItemDesc,
              filePath:this.baseData.filePath,
              memo:this.baseData.memo,
              memo1:this.baseData.memo1,
              validFlag:'1',
              stateFlag:'1'
            }
             _this.axios.post('pass/baseManagement/v1/limsisomerchds/addLimsMerchD', obj , {individualType: 'json'}).then(res => {
                if (res.succeed) {
                 this.open('添加成功', 'success', 1200)
                 _this.$emit('refresh')
                  this.dialogTableVisible = false
                } else {
                 this.$message.error(res.message)
                }
                }).catch(e => {
                 this.$message.error(e.message)
               })
         }
       })
      },
      addData1(){
        let _this = this;
        _this.$refs['baseData'].validate((valid) => {
          if (valid) {
            let obj = {
              merchNo:this.Params.merchNo,
              merchItemDesc:this.baseData.merchItemDesc,
              merchItemName:this.baseData.merchItemName,
              filePath:this.baseData.filePath,
              memo: this.baseData.memo,
              memo1:this.baseData.memo1,
              evaName:this.baseData.evaName,
              evaLevelName:this.baseData.evaLevelName,
              evaVer:this.baseData.evaVer,
              evaDesc:this.baseData.evaDesc,
              validFlag: '1',
              stateFlag: '1'
            }
            _this.axios.post('pass/baseManagement/v1/limsisomerchevas/addLimsIsoMerchEva', obj , {individualType: 'json'}).then(res => {
              if (res.succeed) {
                this.open('添加成功', 'success', 1200)
                _this.$emit('refresh')
                this.dialogTableVisible2 = false
              } else {
                this.$message.error(res.message)
              }
            }).catch(e => {
              this.$message.error(e.message)
            })
          }
        })
      },
      modifyData () {
        let _this = this;
        _this.$refs['baseData'].validate((valid) => {
        if (valid) {
          let obj = {
            merchItemName:this.baseData.merchItemName,
            merchItemDesc: this.baseData.merchItemDesc,
            filePath:this.baseData.filePath,
            memo:this.baseData.memo,
            memo1:this.baseData.memo1,
            updateMan:userName,
            updateNo:userId,
            updateTime:new Date()
          }
        _this.axios.put('pass/baseManagement/v1/limsisomerchds/'+this.Params2.id,obj, {individualType: 'json'}).then(res => {
           if (res.succeed) {
            this.open('修改成功', 'success', 1200)
            _this.$emit('refresh')
             _this.dialogTableVisible = false;
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
        }
        })
      },
      modifyData1 () {
        let _this = this;
        _this.$refs['baseData'].validate((valid) => {
          if (valid) {
            let obj = {
              merchItemDesc:this.baseData.merchItemDesc,
              merchItemName:this.baseData.merchItemName,
              filePath:this.baseData.filePath,
              memo: this.baseData.memo,
              memo1:this.baseData.memo1,
              evaName:this.baseData.evaName,
              evaLevelName:this.baseData.evaLevelName,
              evaVer:this.baseData.evaVer,
              evaDesc:this.baseData.evaDesc,
              validFlag: '1',
              stateFlag: '1'
            }
            _this.axios.put('pass/baseManagement/v1/limsisomerchevas/'+this.Params2.id,obj, {individualType: 'json'}).then(res => {
              if (res.succeed) {
                this.open('修改成功', 'success', 1200)
                _this.$emit('refresh')
                _this.dialogTableVisible2 = false;
              } 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.tableData = [];
       _this.baseData = {
         merchItemDesc:'',
         merchItemName:'',
         filePath:'',
         memo: '',
         memo1:'',
         evaName:'',
         evaLevelName:'',
         evaVer:'',
         evaDesc:''
        }
       _this.seen = true;
       _this.seenNo = true;
       _this.beInvalid = false;
       _this.$emit('refresh')
     },
      closeDialog2 () {
        let _this = this;
        _this.tableData = [];
        _this.baseData = {
          merchItemDesc:'',
          merchItemName:'',
          filePath:'',
          memo: '',
          memo1:'',
          evaName:'',
          evaLevelName:'',
          evaVer:'',
          evaDesc:''
        }
        _this.seen = true;
        _this.seenNo = true;
        _this.beInvalid = false;
        _this.$emit('refresh')
      },
     getMatClassNameList () {
         this.axios.get('pass/baseManagement/v1/limsbasematerialsclasss/'+ '?validFlag=1')
            .then(res => {
              this.matClassNameType = res.data.list;
              this.getMatNameList (res.data.list[0].matClassName)
            }).catch(e => {
              // this.dataLoading = false;
            });
      },
      getMatNameList (matClassName) {
         this.axios.get('pass/baseManagement/v1/limsbasematerialss/'+'?matClassName=' + matClassName +'&validFlag=1')
            .then(res => {
              console.log(res.data.list)
              this.matNameType = res.data.list;
            })
      },
      getEvaLevelName () {
         this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4837}, {individualType: 'json'}).then(res => {
              this.evaLevelNameType = res.data;
            }).catch(e => {
              // this.dataLoading = 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: {
      showFlag2 (arg) {
        let _this = this;
        let variable = _this.Params3.activeName;
        if (variable === 'first'){
          _this.dialogTableVisible = true;
          if (_this.Params2 !== null) {
            _this.baseData = _this.Params2;
            _this.tableType = 1;
            _this.tableTypeDsc = '修改客商资料';
            _this.seen = false;
            _this.beInvalid = true;
            for (let j = 0; j < _this.matNameType.length; j++) {
              if (_this.matNameType[j].matName === _this.baseData.matName) {
                _this.matNameTypeIndex = j;
              }
            }
            for (let j = 0; j < _this.matClassNameType.length; j++) {
              if (_this.matClassNameType[j].matClassName === _this.baseData.matClassName) {
                _this.matClassNameTypeIndex = j;
              }
            }
            for (let j = 0; j < _this.evaLevelNameType.length; j++) {
              if (_this.evaLevelNameType[j].baseName === _this.baseData.evaLevelName) {
                _this.evaLevelNameTypeIndex = j;
              }
            }
          } else {
            _this.tableType = 0;
            _this.seenNo = false;
            _this.baseData.merchName = _this.Params.merchName;
            _this.baseData.merchTypeName = _this.Params.merchTypeName;
            _this.baseData.merchNo = _this.Params.merchNo;
            _this.tableTypeDsc = '新增客商资料';
          }
        }
        if (variable === 'second'){
          _this.dialogTableVisible2 = true;
          if (_this.Params2 !== null) {
            _this.baseData = _this.Params2;
            _this.tableType = 1;
            _this.tableTypeDsc = '修改客商评价';
            _this.seen = false;
            _this.beInvalid = true;
            for (let j = 0; j < _this.matNameType.length; j++) {
              if (_this.matNameType[j].matName === _this.baseData.matName) {
                _this.matNameTypeIndex = j;
              }
            }
            for (let j = 0; j < _this.matClassNameType.length; j++) {
              if (_this.matClassNameType[j].matClassName === _this.baseData.matClassName) {
                _this.matClassNameTypeIndex = j;
              }
            }
            for (let j = 0; j < _this.evaLevelNameType.length; j++) {
              if (_this.evaLevelNameType[j].baseName === _this.baseData.evaLevelName) {
                _this.evaLevelNameTypeIndex = j;
              }
            }
          } else {
            _this.tableType = 0;
            _this.seenNo = false;
            _this.baseData.merchName = _this.Params.merchName;
            _this.baseData.merchTypeName = _this.Params.merchTypeName;
            _this.baseData.merchNo = _this.Params.merchNo;
            _this.tableTypeDsc = '新增客商评价';
          }
        }
      }
    }
}
</script>
<style lang="less">
.customWidth_syst{
  width: 600px !important
}
</style>
