quickReplenish.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view class="content flex flex_column">
  3. <view class="head-info">
  4. <view class="p-title flex align_center">
  5. <view class="shelfName flex align_center"><text></text>{{basicInfoData.shelfName}}</view>
  6. </view>
  7. <view>系统检测到以下产品缺货,请选择需要补货的产品</view>
  8. </view>
  9. <view class="partlist">
  10. <quickProductList :list="partList" ref="productList" noDataText="暂无产品" @allChecked="allCheckedCallback"></quickProductList>
  11. </view>
  12. <view class="part-footer flex align_item justify_between">
  13. <view>
  14. <u-checkbox size="40" @change="allCheckeChange" v-model="allChecked" shape="circle">{{allChecked?'取消全选':'全选'}}</u-checkbox>
  15. </view>
  16. <view class="btns flex align_item justify_end">
  17. <kk-printer ref="kkprinter" printBtnStyle="default-mid" defaultText="打印贴签" @startPrint="startPrint"></kk-printer>
  18. <view style="padding: 0 10rpx;"></view>
  19. <view>
  20. <u-button class="handle-btn" :loading="loading" shape="circle" size="medium" hover-class="none" :custom-style="customBtnStyle" @click="replenish">快速补货</u-button>
  21. </view>
  22. </view>
  23. </view>
  24. <!-- 选择配送方式弹框 -->
  25. <choose-type-modal v-if="chooseModal" :openModal="chooseModal" @confirm="modalChooseType" @close="chooseModal = false" />
  26. <!-- 库存不足 弹框 -->
  27. <stock-modal v-if="stockModal" :openModal="stockModal" :list="stockList" :params="temParams" @confirm="modalStock" @close="stockModal=false" />
  28. </view>
  29. </template>
  30. <script>
  31. import quickProductList from './quickProductList.vue'
  32. import kkPrinter from '@/components/kk-printer/index.vue';
  33. import chooseTypeModal from './chooseTypeModal.vue'
  34. import stockModal from '@/pages/replenishmentManage/stockModal.vue'
  35. import {printTempl} from '@/libs/printTools.js'
  36. import {saveReplenishBill} from '@/api/shelfReplenish.js'
  37. export default {
  38. components: { quickProductList, kkPrinter, chooseTypeModal, stockModal },
  39. data() {
  40. return {
  41. loading: false,
  42. chooseModal: false,
  43. basicInfoData:null,
  44. partList: [],
  45. allChecked: false,
  46. printIndex: 0,
  47. isParinting: false,
  48. stockModal: false,
  49. stockList: [],
  50. temParams:null,
  51. customBtnStyle: { // 自定义按钮样式
  52. borderColor: this.$config('primaryColor'),
  53. backgroundColor: this.$config('primaryColor'),
  54. color: '#fff'
  55. },
  56. }
  57. },
  58. onReady() {
  59. uni.setNavigationBarColor({
  60. frontColor: '#ffffff',
  61. backgroundColor: this.$config('primaryColor')
  62. })
  63. this.$refs.productList.setData(this.partList)
  64. this.allCheckeChange({value:true})
  65. this.allChecked = true
  66. },
  67. onLoad(option) {
  68. this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
  69. this.partList = this.basicInfoData.list
  70. // 保持屏幕常亮
  71. uni.setKeepScreenOn({
  72. keepScreenOn: true
  73. });
  74. },
  75. onUnload() {
  76. this.partList = []
  77. // 保持屏幕常亮
  78. uni.setKeepScreenOn({
  79. keepScreenOn: false
  80. });
  81. },
  82. onBackPress(event){
  83. if(event.from == 'backbutton'){
  84. if(this.isParinting){
  85. uni.showToast({
  86. icon:'none',
  87. title: '正在打印中...'
  88. })
  89. }else{
  90. uni.navigateBack({delta: 1})
  91. }
  92. return true // 阻止默认返回行为(会导致无限循环)
  93. }
  94. },
  95. methods: {
  96. // 全选
  97. allCheckeChange(e){
  98. this.$refs.productList.allSelect(e.value)
  99. },
  100. allCheckedCallback(val){
  101. this.allChecked = val
  102. },
  103. // 补货
  104. replenish(){
  105. const result =this.$refs.productList.getAllChecked()
  106. console.log(result,result.length)
  107. if(result.length){
  108. this.chooseModal = true
  109. }else{
  110. this.toashMsg("请选择产品!")
  111. }
  112. },
  113. modalChooseType(data,confirm){
  114. const result =this.$refs.productList.getAllChecked()
  115. const arr = []
  116. result.map((item, index) => {
  117. arr.push({
  118. productSn: item.productSn,
  119. productCode: item.productCode,
  120. qty: item.printQty,
  121. shelfSn: this.basicInfoData.shelfSn,
  122. shelfPlaceCode: item.shelfPlaceCode,
  123. shelfPlaceSn: item.shelfPlaceSn
  124. })
  125. })
  126. const params = {
  127. detailList: arr,
  128. dispatchType: data.dispatchType,
  129. remarks: data.remarks,
  130. shelfSn:this.basicInfoData.shelfSn,
  131. confirm: confirm
  132. }
  133. console.log(params)
  134. uni.showLoading({
  135. title: "正在提交..."
  136. })
  137. this.loading = true
  138. saveReplenishBill(params).then(res => {
  139. console.log(res)
  140. if(res.status == 200){
  141. // 库存不足
  142. if(res.data&&res.data.length){
  143. this.temParams = params
  144. this.stockList = res.data
  145. this.stockModal = true
  146. }else{
  147. uni.navigateBack()
  148. this.toashMsg(res.message)
  149. }
  150. }
  151. this.loading = false
  152. this.chooseModal = false
  153. uni.hideLoading()
  154. })
  155. },
  156. // 继续补货
  157. modalStock(params){
  158. this.modalChooseType(params,1)
  159. this.stockModal = false
  160. },
  161. printOnce(opt,tsc,blesdk,data){
  162. const _this = this
  163. const dealer = this.$store.state.vuex_userData
  164. // 60*40 打印模板
  165. const command = printTempl(tsc,{
  166. dealerName: dealer.orgName,
  167. shelfName: data.shelfName || '',
  168. productCode: data.productCode || '',
  169. productName: data.productName || '',
  170. shelfPlaceCode: data.shelfPlaceCode || '',
  171. currentInven: data.printQty,
  172. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  173. printUser: dealer.userNameCN,
  174. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  175. })
  176. // 开始批量打印
  177. blesdk.senBlData(
  178. opt.deviceId,
  179. opt.serviceId,
  180. opt.writeId,
  181. command.getData(),
  182. function(){
  183. const result =_this.$refs.productList.getAllChecked()
  184. _this.printIndex = _this.printIndex + 1
  185. if(_this.printIndex < result.length){
  186. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  187. }else{
  188. _this.printIndex = 0
  189. _this.$refs.kkprinter.onPrintSuccess()
  190. _this.isParinting = false
  191. }
  192. });
  193. },
  194. // 批量打印
  195. startPrint(opt,tsc,blesdk){
  196. const _this = this
  197. const result =_this.$refs.productList.getAllChecked()
  198. console.log(result,result.length)
  199. if(result.length){
  200. if(_this.isParinting){
  201. return
  202. }
  203. clzConfirm({
  204. title: '提示',
  205. content: '开始打印后,无法撤回,系统将默认按照每个产品的补货数量批量打印',
  206. success (ret) {
  207. if (ret.confirm || ret.index == 0) {
  208. _this.isParinting = true
  209. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  210. }
  211. }
  212. })
  213. }else{
  214. _this.toashMsg("请选择产品!")
  215. _this.$refs.kkprinter.onPrintFail()
  216. }
  217. },
  218. }
  219. }
  220. </script>
  221. <style lang="less">
  222. .content{
  223. width: 100%;
  224. height: 100vh;
  225. background: #fff;
  226. .head-info{
  227. padding: 20rpx 20rpx 0;
  228. border-bottom: 2rpx solid #eee;
  229. > view{
  230. padding: 10rpx;
  231. color: darkorange;
  232. }
  233. .p-title{
  234. padding: 0 20rpx;
  235. display: flex;
  236. align-items: center;
  237. color: #222;
  238. font-size: 32rpx;
  239. .shelfName{
  240. flex-grow: 1;
  241. font-weight: bold;
  242. text{
  243. display: block;
  244. height: 30rpx;
  245. width: 6rpx;
  246. background: #0485F6;
  247. margin-right: 10rpx;
  248. border-radius: 10rpx;
  249. }
  250. }
  251. }
  252. }
  253. .partlist{
  254. flex-grow: 1;
  255. padding: 0 30rpx;
  256. overflow: auto;
  257. }
  258. .part-footer{
  259. padding: 20rpx 30rpx;
  260. border-top: 2rpx solid #eee;
  261. > view{
  262. &:first-child{
  263. width: 30%;
  264. text-align: left;
  265. padding-top: 10rpx;
  266. }
  267. text-align: right;
  268. }
  269. .btns{
  270. flex-grow: 1;
  271. button{
  272. width: 200rpx;
  273. }
  274. }
  275. }
  276. }
  277. </style>