quickReplenish.vue 7.7 KB

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