
<!-- 新增物品库存信息 -->
<template>
  <div class="resource">
      <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible">
     <div slot="title" class="titleBox">
        <i :class="formType === 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">{{formTypeDsc}}</span>
        </div>
        <!-- 表单 -->
      <el-form ref="formData" label-width="70px" :rules="formRules" size="mini" :model="formData">
        <el-row>
        <el-col :span="8" class="tb-row">
          <el-form-item label="物品名称" prop="stuffName">
            <el-input v-model="formData.stuffName" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="8" class="tb-row">
          <el-form-item label="库房名称" prop="strNo">
            <el-select v-model="formData.strNo" clearable filterable collapse-tags size="small" style="width: 100%;">
              <el-option v-for="(item,index) in strList" :key="index" :label="item.strName"
                         :value="item.strName" placeholder="请选择">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
          <el-col :span="8" class="tb-row">
            <el-form-item label="库存数量" prop="stuffQty">
              <el-input v-model="formData.stuffQty" type="number"></el-input>
            </el-form-item>
          </el-col>
         </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="有效期至" prop="endDate">
              <el-date-picker v-model="formData.endDate" style="width: 100%;" type="datetime" placeholder="选择时间" size="small"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证书数量" prop="certNum">
              <el-input v-model="formData.certNum" type="number"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产厂家" prop="merchName">
              <el-input v-model="formData.merchName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
        <el-col :span="8" class="tb-row">
            <el-form-item label="存放位置" prop="strLoc">
                <el-input v-model="formData.strLoc"></el-input>
                </el-form-item>
        </el-col>
         <el-col :span="16" class="tb-row">
            <el-form-item label="备注" prop="memo">
                <el-input v-model="formData.memo"></el-input>
                </el-form-item>
        </el-col>
        </el-row>
      </el-form>
          <span slot="footer" class="dialog-footer">
       <el-button type="primary" icon="el-icon-check" size="mini" @click="formType === 0 ? addData():modifyData()">确定</el-button>
        <el-button size="mini" type="primary" 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,
        formTypeDsc: '修改物品库存信息',
        formType: 0,
        seen: true,
        seenNo: true,
        beInvalid: false,
        strList: [],
        formData : {
            stkId:'',
            stuffNo: '',
            stuffName: '',
            strNo: '',
            stuffUnit: '',
            stuffQty: '',
            strLoc: '',
            memo: '',
            endDate: '',
            merchName: '',
            certNum: ''
        },
        formRules: {},
        unitNameType: [],
    }
  },
   mounted () {
     // this.getUnitNameTypeList ()
     this.getStrList()
  },
    methods: {
       cancel () {
        this.formData = {
          stkId:'',
          stuffNo: '',
          stuffName: '',
          strNo: '',
          stuffUnit: '',
          stuffQty: '',
          strLoc: '',
          memo: '',
          endDate: '',
          merchName: '',
          certNum: ''
        };
        this.dialogTableVisible = false;
        this.$emit('refresh')
      },
      getStrList() {
         // 获取仓库信息
        this.axios.get("pass/baseManagement/v1/limsbasestorages/" + "?pageNum=1&pageSize=9999").then(res => {
          this.strList = res.data.list;
        })
      },
      // 获取计量单位
      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;
        })
     },
     addData () {
        this.$refs['formData'].validate((valid) => {
        if (valid) {
            this.formData.createMan = userName;
            this.formData.createNo = userId;
            this.axios.post('pass/baseManagement/v1/limslrcstuffstks/', 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 () {
        this.$refs['formData'].validate((valid) => {
        if (valid) {
            this.formData.updateMan = userName;
            this.formData.updateNo = userId;
            this.axios.put('pass/baseManagement/v1/limslrcstuffstks/', 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)
              })
            }
        })
      },
       closeDialog () {
        this.formData = {
          stkId:'',
          stuffNo: '',
          stuffName: '',
          strNo: '',
          stuffUnit: '',
          stuffQty: '',
          strLoc: '',
          memo: '',
          endDate: '',
          merchName: '',
          certNum: ''
        };
     },
     },
   watch: {
       showFlag2 (arg) {
        this.dialogTableVisible = true;
        if (this.Params2 !== null) {
          this.formData = Object.assign({},this.Params2)
          this.formType = 1;
          if (!this.formData.certNum || this.formData.certNum === '') {
            this.formData.certNum = 0
          }
          this.formTypeDsc = '修改物品库存信息';
          this.beInvalid = true;
          this.seen = false;
        } else {
          this.formType = 0;
          this.seenNo = false;
         this.formData.stuffNo = this.Params.stuffNo;
          if (!this.formData.certNum || this.formData.certNum === '') {
            this.formData.certNum = '0'
          }
         this.formData.stkId = this.Params.stkId;
         this.formData.stuffName = this.Params.stuffName;
         this.formData.stuffUnit = this.Params.stuffUnit;
          this.formTypeDsc = '新增物品库存信息';
        }
      }
        }
}
</script>
<style lang="less">
.tb-row {
    margin-bottom: 2px !important;
}
</style>
