| <template> | 
|     <view> | 
|         <cu-custom bgColor="bg-white" :isBack="true"> | 
|             <block slot="backText"> | 
|             </block> | 
|             <block slot="content">旧件入库</block> | 
|         </cu-custom> | 
|         <view class="flex justify-end align-center padding_right30rpx padding_top12rpx"> | 
|             <text class="fontSize12rpx"> 操作人:{{operator}} </text> | 
|         </view> | 
|         <u-form labelPosition="top" :model="warehouse" ref="warehouseRef"> | 
|             <u-row  class="border_bottom margin_top10rpx padding10" style="background-color: #fff;"> | 
|                 <u-col span="12"> | 
|                     <u-form-item label="物料编号:"  style="font-size: 16px;font-weight: bold;padding: 0 0 10rpx;"> | 
|                         <u-input v-model.trim="warehouse.materialCode" ref="materialRef" placeholder="请扫码录入" @focus="warehouse.materialCode = ''"  @blur="getMaterialDetails"  style="font-weight: bolder;margin-left: 15rpx;" | 
|                          class="width padding_left25rpx"> | 
|                         </u-input> | 
|                     </u-form-item> | 
|                 </u-col> | 
|                 <u-col span="2"> | 
|                     <button-modal :cleaningShow='true' allTitle='全部取消' cleaningTitle='确认组盘' @allsubmit="reset" @submit='submit' /> | 
|                 </u-col> | 
|             </u-row> | 
|         </u-form> | 
|         <modal-code :rescode='rescode' :resmessage='resmessage' ref="resmodal" /> | 
|         <view style="margin-bottom: 200rpx;"> | 
|             <view v-for="(item, eindex) in singlist" :key="item.code" style="width: 100vw;display: flex;"> | 
|                 <u-swipe-action :show="item.show" :index="eindex" @click="longpress" | 
|                  @open="open" @close='close' :options="options" style="margin-bottom: 10rpx;width: 100vw;"> | 
|                     <view class="title-wrap fontSize32rpx background_fff" :class="item.showBg ? 'bg_item' : '' " style="width: 100vw;"> | 
|                         <u-row> | 
|                             <u-col span="1"> | 
|                                 <text class="flex justify-center align-center" style="background-color: #f18202;color: #fff;border-radius: 50vh;width: 20px;height: 20px;"> | 
|                                     {{eindex+1}} | 
|                                 </text> | 
|                             </u-col> | 
|                             <u-col span="10"> | 
|                                 <text class="color_f18202"> | 
|                                     物料编号:{{item.materialCode}} | 
|                                 </text> | 
|                             </u-col> | 
|                         </u-row> | 
|                         <u-row style="margin-top: 20rpx;padding: 5rpx;"> | 
|                             <u-col span="6"> | 
|                                 <u-input class="border_bottom_f18202 width text-left fontSize32rpx padding_left10rpx" v-model="item.quantity" | 
|                                  type="number"   @blur="changeNum(item)"   :min="1" placeholder="请输入入库数量" /> | 
|                             </u-col> | 
|                              | 
|                             <u-col span="6"> | 
|                                 <!-- <u-input class="border_bottom_f18202 width text-left fontSize32rpx padding_left10rpx" v-model.trim="item.locationCode" | 
|                                  @focus="warehoueFouce(eindex)"  placeholder="请选择库区" /> --> | 
|                                  <u-input class="border_bottom_f18202 width text-left fontSize32rpx padding_left10rpx" v-model.trim="item.locationCode" | 
|                                     placeholder="请扫码或录入库位" /> | 
|                             </u-col> | 
|                         </u-row> | 
|                     </view> | 
|                 </u-swipe-action> | 
|             </view> | 
|         </view> | 
|         <!-- 库区选择器 --> | 
|         <u-select v-model="selectVisible"  :list="warehouseList" label-name="name" value-name="code"  @confirm="confirm"></u-select> | 
|         <button-modal :cleaningShow='true' allTitle='全部取消' cleaningTitle='确认入库' @allsubmit="reset" @submit='submit'/> | 
|     </view> | 
| </template> | 
| <script> | 
|     import ButtonModal from '../../components/buttonModal.vue' | 
|     import ModalCode from '../../components/ModalCode.vue' | 
|     import {putInOfOld,getOldWarehouseList} from '../../api/old/index.js' | 
|     import {getDate} from '../../utils/dateTime.js' | 
|     import {getAttrValue} from '../../utils/tool.js' | 
|     export default { | 
|         data() { | 
|             return { | 
|                 rescode: 0, | 
|                 resmessage: "", | 
|                 operator: '', | 
|                 singlist: [], //物料详情 | 
|                 options: [ | 
|                     { | 
|                         text: '删除', | 
|                         style: { | 
|                             backgroundColor: '#fc4b4b' | 
|                         } | 
|                     } | 
|                 ], | 
|                 warehouse: { | 
|                     materialCode: '', | 
|                 }, | 
|                 selectVisible: false, //库区选择器 | 
|                 warehouseList: [], //旧件库列表 | 
|                 activeIndex: 1000, //当前选中的材料 | 
|             }; | 
|         }, | 
|         components: { | 
|             ButtonModal, | 
|             ModalCode | 
|         }, | 
|         mounted() { | 
|             this.operator = JSON.parse(uni.getStorageSync('userInfo')).name; | 
|         }, | 
|         onLoad() { | 
|             this.getOldWarehouseList(); | 
|         }, | 
|         methods: { | 
|             //获取旧件库列表 | 
|             getOldWarehouseList() { | 
|                 getOldWarehouseList().then(res => { | 
|                     this.warehouseList = res.data.rows; | 
|                 }) | 
|             }, | 
|             //物料编码点击 | 
|             materialClick() { | 
|                 uni.scanCode({ | 
|                     scanType: ['barCode','qrCode'], | 
|                     autoDecodeCharset: true, | 
|                     success:(res) => { | 
|                         this.warehouse.materialCode = getAttrValue(res.result,'PARTSNUMBER') | 
|                     }, | 
|                     fail:(err) => { | 
|                         this.rescode = 400 | 
|                         this.resmessage = `扫描失败${err}` | 
|                         this.$refs.resmodal.show = true | 
|                     } | 
|                 }) | 
|             }, | 
|             //物料查询 | 
|             getMaterialDetails() { | 
|                 if(!this.warehouse.materialCode) { | 
|                     return  | 
|                 } | 
|                 if(this.warehouse.materialCode.length > 50) { | 
|                     this.warehouse.materialCode = getAttrValue(this.warehouse.materialCode,'PARTSNUMBER') | 
|                     if(this.singlist.length > 0) { | 
|                         //判断当次扫描的物料是否已存在同批次 | 
|                         let index = this.singlist.findIndex(item => item.materialCode == this.warehouse.materialCode) | 
|                         //置顶 | 
|                         if(index > -1) { | 
|                             this.singlist.unshift(...this.singlist.splice(index,1)) | 
|                             return | 
|                         } | 
|                     } | 
|                      | 
|                     if(this.warehouse.materialCode.length > 3) { | 
|                         this.singlist.unshift({materialCode: this.warehouse.materialCode,quantity: '',showBg: true,locationCode: ''}) | 
|                     } | 
|                 } | 
|             }, | 
|             //删除详情 | 
|             longpress(index, eindex) { | 
|                 this.singlist.splice(index, 1) | 
|   | 
|             }, | 
|             // 如果打开一个的时候,不需要关闭其他,则无需实现本方法 | 
|             open(index) { | 
|                 // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制, | 
|                 this.$forceUpdate() | 
|                 this.singlist[index].show = true; | 
|                 this.singlist.map((val, idx) => { | 
|                     if (index != idx) this.singlist[idx].show = false; | 
|                 }) | 
|             }, | 
|             close(index) { | 
|                 this.singlist[index].show = false; | 
|                 this.$forceUpdate() | 
|             }, | 
|             //入库数量 | 
|             changeNum(opt) { | 
|                 console.log(opt.quantity) | 
|                 if(Number(opt.quantity <= 0) || opt.quantity == '') { | 
|                     this.rescode = 400 | 
|                     this.resmessage = '入库数量不能小于等于0' | 
|                     this.$refs.resmodal.show = true | 
|                 } | 
|             }, | 
|             //库位 | 
|             changeLocation(opt) { | 
|                 if(opt.locationCode.length == 0) { | 
|                     this.rescode = 400 | 
|                     this.resmessage = '库位编号不能为空' | 
|                     this.$refs.resmodal.show = true | 
|                 } | 
|             }, | 
|             // 库位聚焦 | 
|             warehoueFouce(index) { | 
|                 this.activeIndex = index; | 
|                 this.selectVisible = true; | 
|             }, | 
|             //库区选择确定 | 
|             confirm(opt) { | 
|                 this.singlist[this.activeIndex].locationCode = opt[0].value; | 
|                 console.log(this.singlist) | 
|             }, | 
|             //全部取消 | 
|             reset() { | 
|                 this.singlist = []; | 
|                 this.warehouse.materialCode = '' | 
|                 this.$forceUpdate() | 
|             }, | 
|             //确认 | 
|             submit() { | 
|                 if(this.singlist.length == 0) { | 
|                     this.rescode = 400 | 
|                     this.resmessage = '入库详情不能为空' | 
|                     this.$refs.resmodal.show = true | 
|                     return; | 
|                 } | 
|                  | 
|                 //判断物料 | 
|                 const index = this.singlist.findIndex(item =>item.quantity == '' || Number(item.quantity) <= 0 || item.locationCode == ''); | 
|                 if(index >= 0) { | 
|                     this.rescode = 400; | 
|                     this.resmessage = '物料详情数据有错误' | 
|                     this.$refs.resmodal.show = true; | 
|                     return; | 
|                 } | 
|                  | 
|                 //判断库位 | 
|                 const idx = this.singlist.findIndex(item => item.locationCode == ''); | 
|                 if(idx >= 0) { | 
|                     this.rescode = 400; | 
|                     this.resmessage = '入库详情中存在库位为空' | 
|                     this.$refs.resmodal.show = true; | 
|                     return; | 
|                 } | 
|                  | 
|                 putInOfOld(this.singlist).then(res => { | 
|                     this.rescode = 200; | 
|                     this.resmessage = '旧件入库成功' | 
|                     this.$refs.resmodal.show = true; | 
|                     this.reset(); | 
|                 }) | 
|                  | 
|             } | 
|         } | 
|     } | 
| </script> | 
| <style lang="scss" scoped> | 
|     .el_batchNo { | 
|         padding: 10rpx 0 10rpx 45rpx; | 
|         color: #808080; | 
|     } | 
|     .bg_item { | 
|            background: #FFEBCD !important; | 
|     } | 
| </style> |