
 <!-- 新增物品入库记录 -->
<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="69px" size="mini" :model="formData" :rules="formRules">
        <el-row>
        <el-col :span="8">
          <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">
            <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">
            <el-form-item label="入库数量" prop="qtyInstk">
              <el-input v-model="formData.qtyInstk" type="number"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="入库类型" prop="instkType">
              <el-input v-model="formData.instkType"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入库时间" prop="instkTime">
              <el-date-picker v-model="formData.instkTime" 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="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-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="存放位置" prop="strLoc">
              <el-input v-model="formData.strLoc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证书数量" prop="certNum">
              <el-input v-model="formData.certNum"></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="24">
            <el-form-item label="备注" prop="memo" style="width: 100%;">
              <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="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: ['showFlag31', 'Params', 'Params3', 'opFlag'],
  data () {
    return {
      dialogTableVisible: false,
      formTypeDsc: '修改物品入库记录',
      formType: 0,
      formRules: {
        qtyInstk: [{ required: true, message: '该项不能为空', trigger: 'input'}],
      },
      formData: {
        inId: '',
        strNo: '',
        stuffNo: '',
        stuffName: '',
        stuffUnit: '',
        instkType: '',
        qtyInstk: '',
        instkApp: '',
        instkHnd: '',
        instkTime: '',
        strLoc: '',
        stkId: '',
        memo: '',
        endDate: '',
        merchName: '',
        certNum: ''
      },
      unitNameType: [],
      strList: []
    }
  },
  mounted () {
    this.getUnitNameTypeList();
    this.getStrList();
  },
  methods: {
    getStrList() {
      // 获取仓库信息
      this.axios.get("pass/baseManagement/v1/limsbasestorages/" + "?pageNum=1&pageSize=9999").then(res => {
        this.strList = res.data.list;
      })
    },
      cancel () {
        this.formData = {
          inId: '',
          strNo: '',
          stuffNo: '',
          stuffName: '',
          stuffUnit: '',
          instkType: '',
          qtyInstk: '',
          instkApp: '',
          instkHnd: '',
          instkTime: '',
          strLoc: '',
          stkId: '',
          memo: '',
          endDate: '',
          merchName: '',
          certNum: ''
        };
        this.dialogTableVisible = false;
      },
      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;
        })
       },
      modifyData () {
        this.$refs['formData'].validate((valid) => {
        if (valid) {
            this.formData.updateMan = userName;
            this.formData.updateNo = userId;
            this.axios.put('pass/baseManagement/v1/limslrcstuffis/', this.formData, {individualType: 'json'}).then(res => {
               if (res.succeed) {
                this.dialogTableVisible = false;
                let msg = ''
                 if (!res.message || res.message === '') {
                   msg = '修改成功'
                 } else {
                   msg = res.message
                 }
                this.$message.success(msg)
                this.$emit('refresh')
                this.$emit('refresh2')
               } else {
                this.$message.error(res.message)
               }
               }).catch(e => {
                this.$message.error(e.message)
              })
           }
        })
      },
      closeDialog () {
        this.formData = {
          inId: '',
          strNo: '',
          stuffNo: '',
          stuffName: '',
          stuffUnit: '',
          instkType: '',
          qtyInstk: '',
          instkApp: '',
          instkHnd: '',
          instkTime: '',
          strLoc: '',
          stkId: '',
          memo: '',
          endDate: '',
          merchName: '',
          certNum: ''
        };
      },
    },
   watch: {
   showFlag31 (arg) {
        this.dialogTableVisible = true;
        if (this.opFlag && this.opFlag === '1') {
          // 操作标识  物品库存表tab页入库按钮触发
          this.formData = JSON.parse(JSON.stringify(this.Params))
        }
        if (this.Params3 !== null) {
          this.formData = Object.assign({},this.Params3)
          this.formType = 1;
          if (!this.formData.certNum || this.formData.certNum === '') {
            this.formData.certNum = '0'
          }
          this.formTypeDsc = '修改物品入库信息';
          if (!this.formData.instkType || this.formData.instkType === '') {
            this.formData.instkType = '采购入库'
          }
          this.beInvalid = true;
          this.seen = false;
        } else {
          this.formType = 0;
          this.seenNo = false;
          this.formData.stuffNo = this.Params.stuffNo;
          this.formData.inId = this.Params.inId;
          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>
