<template>
    <div class="examination">
     <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible">
        <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="plineName" label="产线名称">
              <el-input v-model="baseData.plineName" readonly size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="processName" label="工序描述">
              <el-input v-model="baseData.processName"  size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="processAbbr" label="工序简写">
              <el-input v-model="baseData.processAbbr" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item  label="备注">
              <el-input v-model="baseData.memo" 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>
    </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'],
    data () {
        return {
            dialogTableVisible: false,
            tableTypeDsc: '新增工序信息',
            tableType: 0,
            seen: true,
            seenNo: true,
            beInvalid: false,
            tableData: [],
            baseData: {
              plineNo: '',
              plineName: '',
              processAbbr: '',
              processNo: '',
              processName: ''
            },
            ruleValidate: {
              processName: [{ required: true, message: '该项不能为空', trigger: 'change' }],
              plineName: [{ required: true, message: '该项不能为空', trigger: 'blur' }]
              //dataTypeName: [{ required: true, message: '该项不能为空', trigger: 'change' }],
              // plineName: [{ required: true, message: '该项不能为空', trigger: 'change' }],
              // dataTypeName: [{ required: true, message: '该项不能为空', trigger: 'change' }]
             }
        }
    },
    methods: {
      cancel () {
        let _this = this;
        _this.tableData = [];
        _this.ruleItemSourceTypeIndex = 0,
        _this.dataTypeNameTypeIndex = 0,
        _this.isParaTypeIndex = 0,
        _this.baseData = {
              plineNo: '',
              plineName: '',
              processAbbr: '',
              processNo: '',
              processName: ''
        }
        _this.dialogTableVisible = false
        _this.$emit('refresh')
      },
      addData () {
        let _this = this;
         _this.tableData = [];
         _this.$refs['baseData'].validate((valid) => {
          if (valid) {
             _this.dialogTableVisible = false;
             _this.baseData.createMan = userName;
             _this.baseData.createNo = userId;
             _this.tableData.push(_this.baseData)
             _this.axios.post('pass/baseManagement/v1/limsbaseprocesss/', _this.tableData, {individualType: 'json'}).then(res => {
                if (res.succeed) {
                 this.$message.success('添加成功')
                 _this.$emit('refresh')
                } else {
                 this.$message.error(res.message)
                }
                }).catch(e => {
                 this.$message.error(e.message)
               })
         }
       })
      },
      modifyData () {
        let _this = this;
        _this.tableData = [];
        _this.$refs['baseData'].validate((valid) => {
        if (valid) {
        _this.dialogTableVisible = false;
        _this.baseData.updateMan = userName;
        _this.baseData.updateNo = userId;
        _this.axios.put('pass/baseManagement/v1/limsbaseprocesss/', _this.baseData, {individualType: 'json'}).then(res => {
           if (res.succeed) {
            this.$message.success('修改成功')
            _this.$emit('refresh')
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
        }
        })
      },
     closeDialog () {
       let _this = this;
       _this.tableData = [];
       _this.baseData = {
              plineNo: '',
              plineName: '',
              processAbbr: '',
              processNo: '',
              processName: ''
        }
       _this.seen = true;
       _this.seenNo = true;
       _this.beInvalid = false;
       _this.$emit('refresh')
     }
    },
    watch: {
      showFlag2 (arg) {
        let _this = this;
        _this.dialogTableVisible = true;
        if (_this.Params2 !== null) {
          _this.baseData = _this.Params2[0];
          _this.tableType = 1;
          _this.tableTypeDsc = '修改工序信息';
          _this.seen = false;
          _this.beInvalid = true;
        } else {
          _this.tableType = 0;
          _this.seenNo = false;
          _this.baseData.plineNo = _this.Params[0].plineNo;
          _this.baseData.plineName = _this.Params[0].plineName;
          // _this.baseData.merchNo = _this.Params.merchNo;
          _this.tableTypeDsc = '新增工序信息';
        }
      }
    }
}
</script>
<style lang="less">
.customWidth_syst{
  width: 600px !important
}
</style>

