
 <!-- 新增物品出库弹窗 -->
<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="stkId">
              <el-input v-model="formData.stkId" :disabled="true" placeholder="系统自动绑定"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
        <el-col :span="8">
            <el-form-item label="出库类型" prop="outstkType">
                <el-input v-model="formData.outstkType"></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="出库数量" prop="qtyOutstk">
            <el-input v-model="formData.qtyOutstk" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="出库时间" prop="outstkTime">
             <el-date-picker v-model="formData.outstkTime" value-format="yyyy-MM-dd HH:mm:ss" 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="outstkTime">
             <el-select v-model="formData.merchName" clearable filterable collapse-tags size="small" style="width: 100%;">
              <el-option v-for="(item,index) in merchNameList" :key="index" :label="item.merchName"
                         :value="item.merchName" placeholder="请输入">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="16">
           <el-form-item label="备注" prop="memo" style="width: 100%;">
                <el-input size="mini" 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: ['showFlag4', 'Params', 'Params4'],
  data () {
    return {
        dialogTableVisible: false,
        formTypeDsc: '修改物品出库记录',
        formType: 0,
        seen: true,
        seenNo: true,
        beInvalid: false,
         formRules:{
           qtyOutstk: [{required: true, message: '该项不能为空', trigger: 'input'}]
         },
        strList: [],
        merchNameList: [],
        formData : {
          outId: '',
          strNo: '',
          stuffNo: '',
          stuffName: '',
          stuffUnit: '',
          merchName: '',
          outstkType: '',
          qtyOutstk: '',
          outstkApp: '',
          outstkHnd: '',
          outstkTime: '',
          stkId: '',
          memo: ''
        },
        unitNameType: [],
          // eqpTypeNameList: []
    }
  },
  mounted () {
    // this.getUnitNameTypeList ()
    // 获取仓库信息
    this.axios.get("pass/baseManagement/v1/limsbasestorages/" + "?pageNum=1&pageSize=9999").then(res => {
      this.strList = res.data.list;
    })
    this.axios.get('pass/baseManagement/v1/limslrcstuffstks/' + '?pageNum=1&pageSize=9999&validFlag=1').then(res => {
      res.data.list.forEach(element => {
        if(element.merchName != null){
          this.merchNameList.push(element)
        }
      });
    })
  },
  methods: {
   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;
     })
    },
   cancel () {
       this.formData = {
          outId: '',
          strNo: '',
          stuffNo: '',
          stuffName: '',
          stuffUnit: '',
          outstkType: '',
          qtyOutstk: '',
          merchName: '',
          outstkApp: '',
          outstkHnd: '',
          outstkTime: '',
          stkId: '',
          memo: ''
        };
       this.dialogTableVisible = false;
      },
  addData () {
     this.$refs['formData'].validate((valid) => {
        if (valid) {
           this.formData.createMan = userName;
           this.formData.outstkApp = userName;
           this.formData.createNo = userId;
           this.axios.post('pass/baseManagement/v1/limslrcstuffos/',this.formData, {individualType: 'json'}).then(res => {
                    if (res.succeed) {
                    this.dialogTableVisible = false;
                    this.$message.success(res.message)
                    this.$emit('refresh')
                    this.$emit('refresh2')
                    } 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/limslrcstuffos/',this.formData, {individualType: 'json'}).then(res => {
           if (res.succeed) {
             this.dialogTableVisible = false;
             this.$message.success(res.message)
             this.$emit('refresh')
             this.$emit('refresh2')
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
        }
        })
      },
   closeDialog () {
         this.formData = {
          outId: '',
          strNo: '',
          stuffNo: '',
          stuffName: '',
          stuffUnit: '',
          merchName: '',
          outstkType: '',
          qtyOutstk: '',
          outstkApp: '',
          outstkHnd: '',
          outstkTime: '',
          stkId: '',
          memo: ''
        };
     },
   },
   watch: {
   showFlag4 (arg) {
       this.dialogTableVisible = true;
        if (this.Params4 !== null) {
         this.formData = Object.assign({},this.Params4)
         this.formType = 1;
         this.formTypeDsc = '修改物品出库记录';
        } else {
         this.formType = 0;
         this.formData.outstkTime = new Date();
         this.formData.stuffNo =this.Params.stuffNo;
         this.formData.outId =this.Params.outId;
         this.formData.stuffName =this.Params.stuffName;
         this.formData.stuffUnit =this.Params.stuffUnit;
         this.formData.merchName = this.Params.merchName;
         this.formData.outstkType = '消耗出库'
         this.formTypeDsc = '新增物品出库记录';
        }
      }
    }
}
</script>
<style lang="less">
.tb-row {
    margin-bottom: 2px !important;
}
</style>
