| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- <template>
- <view>
- <uni-section title='单据信息' type='line' :strong="true" class="bg-white"/>
- <table-list :list="list" class="mt-2">
- <template v-slot:itemnum="{record,index}">
- <view class="height-100 flex align-center justify-center">
- <view class="">
- <!-- {{JSON.stringify(record.itemnum)}} -->
- <input type="text" v-model="record.itemnum" :class="record.itemnum > record.kwxyl ? 'border-red' : 'border'" @input="onInputItemnum(index,$event)">
- <view>移库现有量:{{record.kwxyl}}</view>
- </view>
- </view>
- </template>
- <template v-slot:kwh="{record,index}">
- <view class="border">
- <view class="bg-light p-1">
- <view class="">自-库位(号)</view>
- <picker class="py-1 border bg-white" :value='record.fromKwIndex' :range='defaultKwList' range-key='KWH' @change="onChangeKW('自',index,$event)">
- <view v-if='defaultKwList[record.fromKwIndex] && defaultKwList[record.fromKwIndex].KWH'>
- {{defaultKwList[record.fromKwIndex].KWH}}
- </view>
- <view v-else>--</view>
- </picker>
- <!-- <view class="">
- (库位现有量:{{record.kwxyl}})
- </view> -->
- </view>
- <view class="p-1 pt-0 bg-warning"></view>
- <view class="bg-light p-1">
- <view>至-库位(号)</view>
- <picker class="py-1 border bg-white" :value='record.toKwIndex' :range='defaultKwList' range-key='KWH' @change="onChangeKW('至',index,$event)">
- <view v-if='defaultKwList[record.toKwIndex] && defaultKwList[record.toKwIndex].KWH'>
- {{defaultKwList[record.toKwIndex].KWH}}
- </view>
- <view v-else>--</view>
- </picker>
- </view>
- </view>
- </template>
- </table-list>
- <btn-save @save='onSave' back :disabledOk="disabledSubmit"/>
- </view>
- </template>
- <script>
- import uniSection from "@/components/uni-ui/uni-section/uni-section.vue"
- import listInput from "@/components/common/list-input.vue"
- import tableList from "@/components/common/table-list.vue"
- import btnSave from "@/components/common/btn-save.vue"
- import {mapState,mapGetters} from "vuex"
- import {amount} from "@/common/utils/reg.js"
- import {queryDefaultStorage,saveMoveWarehouseInfo} from "@/api/api.js"
-
- const headData=[
- {key:'itemno',dataIndex:"itemno",title:"物品号",},
- {key:'itemnum',dataIndex:"itemnum",title:"转移数量",scope:"itemnum",},
- {key:'kwh',dataIndex:"kwh",title:"库位(号)",scope:"kwh",width:"300rpx",},
- ]
- const demo=[ {
- "KWMC": "C1001",
- "KWH": "kuwei1"
- },
- {
- "KWMC": "C1001",
- "KWH": "kuwei2"
- },
- {
- "KWMC": "C1001",
- "KWH": "kuwei3"
- },
- ]
-
- export default {
- components:{
- uniSection,
- listInput,
- tableList,
- btnSave
- },
- data () {
- return {
- defaultCkIndex:0, // 仓库索引
- defaultCkList:[], // 仓库列表
- list:{ // 表格
- head:headData,
- body:[]
- },
- }
- },
- computed:{
- ...mapGetters(['disabledSubmit']),
- ...mapState(["movewarehouseList"]),
- // 库位列表
- defaultKwList () {
- if (this.defaultCkList.length > 0) {
- return this.defaultCkList[this.defaultCkIndex].storageloca
- }
- return []
- }
- },
- onLoad (e) {
- if (e.list) {
- this.list.body=JSON.parse(e.list)
- this.list.body.map(item=>{
- item.fromKwIndex=-1 // 为数组每一项添加 自库位和至库位索引
- item.toKwIndex=-1
- item.kwh=item.KW
- return item
- })
- }
- this.initPage()
- },
- onPageScroll(res) {
- uni.$emit('onPageScroll',res);
- },
- methods:{
- // 初始化页面
- async initPage () {
- await this._queryDefaultStorage()
- },
- //查询对应的库位现有量
- _queryKwxyl (itemno) {
- if (typeof itemno ==='undefined') {
- return {
- kwxyl:0
- }
- }
- const arr=this.movewarehouseList.filter(item=>{
- return item.WPH===itemno
- })
- return {
- kwxyl:arr[0].kwxyl
- }
- },
- //获取默认仓库
- async _queryDefaultStorage () {
- const resdata=await queryDefaultStorage()
- this.defaultCkList=resdata
- return resdata
- },
- // 改变数量
- onInputItemnum (index,event) {
- const value=event.detail.value
- const item=this.list.body[index]
- let ok=true;
- let msg="";
- if (!amount.test(value)) {
- ok=false;
- msg="请输入准确的数字"
- }else if (value > item.kwxyl) {
- ok=false;
- msg="输入的数量不得大于库位现有量"
- }
-
- if (!ok) {
- uni.showToast({
- title:msg,
- icon:"none"
- })
- }else{
- }
- },
- // 改变库位
- onChangeKW (key,index,event) {
- let ok=true;
- let msg="";
- const value=event.detail.value
- const item=this.list.body[index]
- const itemno=item.WPH
- const itemnum=item.itemnum
-
- switch (key) {
- case "自":
- if (value===item.toKwIndex) {
- ok=false;
- msg="自库位号和至库位号不能为同一个库位号";
- }else{
- // 查询对应的库位现有量
- const amount=this._queryKwxyl(itemno)
- if (itemnum > amount) {
- ok=false
- msg='所填写的数量大于库位现有量'
- item.itemnum=item.kwxyl
- }
- item.fromKwIndex=value
- this.$set(this.list.body,index,item)
- }
- break;
- case "至":
- if (value===item.fromKwIndex) {
- ok=false;
- msg="至库位号和自库位号不能为同一个库位号";
- }else{
- item.toKwIndex=value
- this.$set(this.list.body,index,item)
- }
- break;
- }
- if (!ok) {
- uni.showToast({
- title:msg,
- icon:"none"
- })
- }else{
- this.$forceUpdate()
- }
- },
- //保存接口
- async _saveMoveWarehouseInfo () {
- let items=[]
- this.list.body.forEach(item=>{
- items.push({
- "WPH":item.itemno, //物品号
- "SL":item.itemnum,
- "KHWOUT":this.defaultKwList[item.fromKwIndex].KWH,
- "KHWIN":this.defaultKwList[item.toKwIndex].KWH
- })
- })
- const reqdata={
- items:items
- }
- const resdata=await saveMoveWarehouseInfo(reqdata)
- return resdata
- },
- // 提交
- onSave () {
- let ok=true;
- let msg="";
-
- this.list.body.forEach(item=>{
- if (!amount.test(item.itemnum)) {
- ok=false;
- msg="请输入准确的数字"
- }else if (item.itemnum > item.kwxyl) {
- ok=false;
- msg="输入的数量不得大于库位现有量"
- }else if (item.fromKwIndex < 0) {
- ok=false;
- msg="请选择自库位号"
- }else if (item.toKwIndex < 0) {
- ok=false;
- msg="请选择至库位号"
- }
- })
-
-
- if (!ok) {
- return uni.showToast({
- title:msg,
- icon:"none"
- })
- }
-
- uni.showModal({
- title:"确认保存吗?",
- success:async res=>{
- if (res.confirm) {
- await this._saveMoveWarehouseInfo()
- uni.showToast({
- title:"保存成功"
- })
- uni.reLaunch({
- url:"/pages/index/index"
- })
- }
- }
- })
- }
- }
- }
-
- </script>
- <style scoped>
- </style>
|