quickReplenish.vue 7.7 KB

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