quickReplenish.vue 8.3 KB

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