addBatch.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="addBatch">
  3. <uni-search-bar @confirm="getData" v-model="req.keyword" @cancel="reload">
  4. </uni-search-bar>
  5. <view class="dtl">
  6. <view class="">
  7. 物料编码:{{option.code}}
  8. </view>
  9. <view class="">
  10. 物料名称:{{option.name}}
  11. </view>
  12. <view class="">
  13. 供应商:{{option.supplierName || '无'}}
  14. </view>
  15. <view class="">
  16. 合同编号:{{option.purchaseBillNo}} <span>{{option.batch}}</span>
  17. </view>
  18. <view class="" style="color:#02A7F0">
  19. 待入库:{{option.notArrivalQty}}
  20. </view>
  21. </view>
  22. <view class="addQrcode-list" v-for="(i,index) in req.stockTagList" :key="i,index">
  23. <view class="fl" @click="toRouter(index)">
  24. <view class="code">
  25. <view class="">
  26. 编号:{{index + 1}}
  27. </view>
  28. <view class="">
  29. 绑定数量:{{i.quantity * 1}}
  30. </view>
  31. </view>
  32. </view>
  33. <view class="fr">
  34. <uni-icons type="trash-filled" size="30" @click="delelte(index)"></uni-icons>
  35. </view>
  36. </view>
  37. <view class="" style="margin:40rpx">
  38. <button size="mini" type="default" style="width: 500rpx;margin: 0 auto;display: block;"
  39. @click="toggle('bottom','1')">
  40. 添加明细
  41. </button>
  42. <button size="mini" type="default" style="width: 500rpx;margin: 30rpx auto;display: block;"
  43. @click="toggle('bottom','2')">
  44. 批量添加
  45. </button>
  46. <uni-popup ref="popup" background-color="#fff">
  47. <view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
  48. <view class="popup-input-warp">
  49. <uni-forms :modelValue="formData">
  50. <uni-forms-item label="绑定数量" name="name">
  51. <uni-easyinput type="number" v-model="formData.quantity" placeholder="请输入绑定数量" />
  52. </uni-forms-item>
  53. <uni-forms-item label="二维码个数" name="name" v-if="btnType == '2'">
  54. <uni-easyinput type="number" v-model="formData.num" placeholder="请输入二维码个数" />
  55. </uni-forms-item>
  56. </uni-forms>
  57. <button @click="submitForm">确定</button>
  58. </view>
  59. </view>
  60. </uni-popup>
  61. <!-- 提示信息弹窗 -->
  62. <uni-popup ref="message" type="message">
  63. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  64. </uni-popup>
  65. </view>
  66. <button type="primary" style="margin: 0 30rpx;" @click="addBatch()">
  67. 提交
  68. </button>
  69. </view>
  70. </template>
  71. <script>
  72. import {
  73. getInfo
  74. } from "@/util/api.js";
  75. export default {
  76. data() {
  77. return {
  78. listData: [],
  79. req: {
  80. keyword: null,
  81. materialId: null
  82. },
  83. option: {},
  84. formData: {
  85. number: 1,
  86. quantity: 0,
  87. },
  88. req: {
  89. stockTagList: [],
  90. purchaseContractDetailsId: null,
  91. },
  92. btnType: 1,
  93. }
  94. },
  95. onLoad(option) {
  96. const v = this
  97. v.option = JSON.parse(decodeURIComponent(option.data))
  98. console.log(v.option)
  99. v.req.purchaseContractDetailsId = v.option.contractDetailsId
  100. },
  101. methods: {
  102. delelte(index){
  103. this.req.stockTagList.splice(index,1)
  104. },
  105. addBatch(){
  106. const v = this
  107. if (v.req.stockTagList.length == 0) {
  108. uni.showToast({
  109. icon: "error",
  110. title: '请添加明细',
  111. duration: 2000
  112. });
  113. return
  114. }
  115. uni.showToast({
  116. icon: "loading",
  117. title: '加载中',
  118. duration: 2000
  119. });
  120. v.$post('/wx/createQrcode/addBatch',v.req).then(res=>{
  121. if(res.code == 200){
  122. uni.showToast({
  123. title:'生成成功,跳转中!'
  124. })
  125. setTimeout(()=>{
  126. wx.reLaunch({
  127. url: '/pages/home'
  128. })
  129. },1500)
  130. }
  131. })
  132. },
  133. submitForm() {
  134. const v = this
  135. if (v.formData.quantity == 0) {
  136. uni.showToast({
  137. icon: "none",
  138. title: '请输入绑定数量',
  139. duration: 2000
  140. });
  141. return
  142. }
  143. var total = 0
  144. for (var i = 0; i < v.req.stockTagList.length; i++) {
  145. total += v.req.stockTagList[i].quantity * 1
  146. }
  147. if (v.btnType == 1) {
  148. if((total + v.formData.quantity * 1) > v.option.notArrivalQty * 1.05){
  149. uni.showToast({
  150. icon: "none",
  151. title: '已超过总数的105%,请重新输入',
  152. duration: 2000
  153. });
  154. return
  155. }
  156. v.req.stockTagList.push({
  157. quantity: v.formData.quantity
  158. })
  159. } else {
  160. if((total + v.formData.quantity * v.formData.num) > v.option.notArrivalQty * 1.05){
  161. uni.showToast({
  162. icon: "none",
  163. title: '已超过总数的105%,请重新输入',
  164. duration: 2000
  165. });
  166. return
  167. }
  168. if (v.formData.num == 0 || !v.formData.num) {
  169. uni.showToast({
  170. icon: "none",
  171. title: '请输入二维码个数',
  172. duration: 2000
  173. });
  174. return
  175. }
  176. for (var i = 0; i < v.formData.num; i++) {
  177. v.req.stockTagList.push({
  178. quantity: v.formData.quantity
  179. })
  180. }
  181. }
  182. console.log(v.req.stockTagList)
  183. },
  184. toggle(type, btnType) {
  185. this.type = type
  186. this.btnType = btnType
  187. console.log(this.btnType)
  188. // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
  189. this.$refs.popup.open(type)
  190. },
  191. reload() {
  192. this.req.keyword = null
  193. this.getData()
  194. },
  195. getData() {
  196. const v = this
  197. v.$post('/wx/createQrcode/getPurchaseByMaterialIdList', v.req).then(res => {
  198. v.listData = res.data
  199. })
  200. },
  201. toRouter(i) {
  202. const v = this
  203. console.log(i)
  204. v.option = Object.assign(v.option, v.listData[i])
  205. uni.navigateTo({
  206. url: '/pages/addQrcode/addBatch?data=' + encodeURIComponent(JSON.stringify(v.option))
  207. })
  208. // uni.navigateTo({
  209. // url: '/pages/addQrcode/selectQrcode?id=' + i.materialId
  210. // })
  211. },
  212. },
  213. }
  214. </script>
  215. <style lang="less">
  216. .addBatch {
  217. font-size: 28rpx;
  218. .dtl {
  219. padding: 30rpx;
  220. border-bottom: 1rpx solid #dcdcdc;
  221. }
  222. .addQrcode-list {
  223. height: 100rpx;
  224. display: flex;
  225. justify-content: space-between;
  226. padding: 15rpx;
  227. border-bottom: 1rpx solid #dcdcdc;
  228. .fl {
  229. display: flex;
  230. padding-left: 20rpx;
  231. .code {
  232. margin-right: 20rpx;
  233. }
  234. }
  235. .fr {
  236. line-height: 100rpx;
  237. }
  238. }
  239. }
  240. .popup-input-warp {
  241. padding: 30rpx 40rpx;
  242. }
  243. </style>