move-warehouse-detail.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view>
  3. <uni-section title='单据信息' type='line' :strong="true" class="bg-white"/>
  4. <table-list :list="list" class="mt-2">
  5. <template v-slot:itemnum="{record,index}">
  6. <view class="height-100 flex align-center justify-center">
  7. <view class="">
  8. <!-- {{JSON.stringify(record.itemnum)}} -->
  9. <input type="text" v-model="record.itemnum" :class="record.itemnum > record.kwxyl ? 'border-red' : 'border'" @input="onInputItemnum(index,$event)">
  10. <view>移库现有量:{{record.kwxyl}}</view>
  11. </view>
  12. </view>
  13. </template>
  14. <template v-slot:kwh="{record,index}">
  15. <view class="border">
  16. <view class="bg-light p-1">
  17. <view class="">自-库位(号)</view>
  18. <picker class="py-1 border bg-white" :value='record.fromKwIndex' :range='defaultKwList' range-key='KWH' @change="onChangeKW('自',index,$event)">
  19. <view v-if='defaultKwList[record.fromKwIndex] && defaultKwList[record.fromKwIndex].KWH'>
  20. {{defaultKwList[record.fromKwIndex].KWH}}
  21. </view>
  22. <view v-else>--</view>
  23. </picker>
  24. <!-- <view class="">
  25. (库位现有量:{{record.kwxyl}})
  26. </view> -->
  27. </view>
  28. <view class="p-1 pt-0 bg-warning"></view>
  29. <view class="bg-light p-1">
  30. <view>至-库位(号)</view>
  31. <picker class="py-1 border bg-white" :value='record.toKwIndex' :range='defaultKwList' range-key='KWH' @change="onChangeKW('至',index,$event)">
  32. <view v-if='defaultKwList[record.toKwIndex] && defaultKwList[record.toKwIndex].KWH'>
  33. {{defaultKwList[record.toKwIndex].KWH}}
  34. </view>
  35. <view v-else>--</view>
  36. </picker>
  37. </view>
  38. </view>
  39. </template>
  40. </table-list>
  41. <btn-save @save='onSave' back :disabledOk="disabledSubmit"/>
  42. </view>
  43. </template>
  44. <script>
  45. import uniSection from "@/components/uni-ui/uni-section/uni-section.vue"
  46. import listInput from "@/components/common/list-input.vue"
  47. import tableList from "@/components/common/table-list.vue"
  48. import btnSave from "@/components/common/btn-save.vue"
  49. import {mapState,mapGetters} from "vuex"
  50. import {amount} from "@/common/utils/reg.js"
  51. import {queryDefaultStorage,saveMoveWarehouseInfo} from "@/api/api.js"
  52. const headData=[
  53. {key:'itemno',dataIndex:"itemno",title:"物品号",},
  54. {key:'itemnum',dataIndex:"itemnum",title:"转移数量",scope:"itemnum",},
  55. {key:'kwh',dataIndex:"kwh",title:"库位(号)",scope:"kwh",width:"300rpx",},
  56. ]
  57. const demo=[ {
  58. "KWMC": "C1001",
  59. "KWH": "kuwei1"
  60. },
  61. {
  62. "KWMC": "C1001",
  63. "KWH": "kuwei2"
  64. },
  65. {
  66. "KWMC": "C1001",
  67. "KWH": "kuwei3"
  68. },
  69. ]
  70. export default {
  71. components:{
  72. uniSection,
  73. listInput,
  74. tableList,
  75. btnSave
  76. },
  77. data () {
  78. return {
  79. defaultCkIndex:0, // 仓库索引
  80. defaultCkList:[], // 仓库列表
  81. list:{ // 表格
  82. head:headData,
  83. body:[]
  84. },
  85. }
  86. },
  87. computed:{
  88. ...mapGetters(['disabledSubmit']),
  89. ...mapState(["movewarehouseList"]),
  90. // 库位列表
  91. defaultKwList () {
  92. if (this.defaultCkList.length > 0) {
  93. return this.defaultCkList[this.defaultCkIndex].storageloca
  94. }
  95. return []
  96. }
  97. },
  98. onLoad (e) {
  99. if (e.list) {
  100. this.list.body=JSON.parse(e.list)
  101. this.list.body.map(item=>{
  102. item.fromKwIndex=-1 // 为数组每一项添加 自库位和至库位索引
  103. item.toKwIndex=-1
  104. item.kwh=item.KW
  105. return item
  106. })
  107. }
  108. this.initPage()
  109. },
  110. onPageScroll(res) {
  111. uni.$emit('onPageScroll',res);
  112. },
  113. methods:{
  114. // 初始化页面
  115. async initPage () {
  116. await this._queryDefaultStorage()
  117. },
  118. //查询对应的库位现有量
  119. _queryKwxyl (itemno) {
  120. if (typeof itemno ==='undefined') {
  121. return {
  122. kwxyl:0
  123. }
  124. }
  125. const arr=this.movewarehouseList.filter(item=>{
  126. return item.WPH===itemno
  127. })
  128. return {
  129. kwxyl:arr[0].kwxyl
  130. }
  131. },
  132. //获取默认仓库
  133. async _queryDefaultStorage () {
  134. const resdata=await queryDefaultStorage()
  135. this.defaultCkList=resdata
  136. return resdata
  137. },
  138. // 改变数量
  139. onInputItemnum (index,event) {
  140. const value=event.detail.value
  141. const item=this.list.body[index]
  142. let ok=true;
  143. let msg="";
  144. if (!amount.test(value)) {
  145. ok=false;
  146. msg="请输入准确的数字"
  147. }else if (value > item.kwxyl) {
  148. ok=false;
  149. msg="输入的数量不得大于库位现有量"
  150. }
  151. if (!ok) {
  152. uni.showToast({
  153. title:msg,
  154. icon:"none"
  155. })
  156. }else{
  157. }
  158. },
  159. // 改变库位
  160. onChangeKW (key,index,event) {
  161. let ok=true;
  162. let msg="";
  163. const value=event.detail.value
  164. const item=this.list.body[index]
  165. const itemno=item.WPH
  166. const itemnum=item.itemnum
  167. switch (key) {
  168. case "自":
  169. if (value===item.toKwIndex) {
  170. ok=false;
  171. msg="自库位号和至库位号不能为同一个库位号";
  172. }else{
  173. // 查询对应的库位现有量
  174. const amount=this._queryKwxyl(itemno)
  175. if (itemnum > amount) {
  176. ok=false
  177. msg='所填写的数量大于库位现有量'
  178. item.itemnum=item.kwxyl
  179. }
  180. item.fromKwIndex=value
  181. this.$set(this.list.body,index,item)
  182. }
  183. break;
  184. case "至":
  185. if (value===item.fromKwIndex) {
  186. ok=false;
  187. msg="至库位号和自库位号不能为同一个库位号";
  188. }else{
  189. item.toKwIndex=value
  190. this.$set(this.list.body,index,item)
  191. }
  192. break;
  193. }
  194. if (!ok) {
  195. uni.showToast({
  196. title:msg,
  197. icon:"none"
  198. })
  199. }else{
  200. this.$forceUpdate()
  201. }
  202. },
  203. //保存接口
  204. async _saveMoveWarehouseInfo () {
  205. let items=[]
  206. this.list.body.forEach(item=>{
  207. items.push({
  208. "WPH":item.itemno, //物品号
  209. "SL":item.itemnum,
  210. "KHWOUT":this.defaultKwList[item.fromKwIndex].KWH,
  211. "KHWIN":this.defaultKwList[item.toKwIndex].KWH
  212. })
  213. })
  214. const reqdata={
  215. items:items
  216. }
  217. const resdata=await saveMoveWarehouseInfo(reqdata)
  218. return resdata
  219. },
  220. // 提交
  221. onSave () {
  222. let ok=true;
  223. let msg="";
  224. this.list.body.forEach(item=>{
  225. if (!amount.test(item.itemnum)) {
  226. ok=false;
  227. msg="请输入准确的数字"
  228. }else if (item.itemnum > item.kwxyl) {
  229. ok=false;
  230. msg="输入的数量不得大于库位现有量"
  231. }else if (item.fromKwIndex < 0) {
  232. ok=false;
  233. msg="请选择自库位号"
  234. }else if (item.toKwIndex < 0) {
  235. ok=false;
  236. msg="请选择至库位号"
  237. }
  238. })
  239. if (!ok) {
  240. return uni.showToast({
  241. title:msg,
  242. icon:"none"
  243. })
  244. }
  245. uni.showModal({
  246. title:"确认保存吗?",
  247. success:async res=>{
  248. if (res.confirm) {
  249. await this._saveMoveWarehouseInfo()
  250. uni.showToast({
  251. title:"保存成功"
  252. })
  253. uni.reLaunch({
  254. url:"/pages/index/index"
  255. })
  256. }
  257. }
  258. })
  259. }
  260. }
  261. }
  262. </script>
  263. <style scoped>
  264. </style>