quickReplenish.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 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="打印贴签" @closeConnect="closeConnect" @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. closeConnect(){
  172. this.isParinting = false
  173. uni.hideLoading()
  174. },
  175. printOnce(opt,tsc,blesdk,data){
  176. const _this = this
  177. const dealer = this.$store.state.vuex_userData
  178. // 60*40 打印模板
  179. const command = printTempl(tsc,{
  180. dealerName: dealer.orgName,
  181. shelfName: this.basicInfoData.shelfName || '',
  182. productCode: data.productCode || '',
  183. productName: data.productName || '',
  184. shelfPlaceCode: data.shelfPlaceCode || '',
  185. currentInven: data.printQty,
  186. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  187. printUser: dealer.userNameCN,
  188. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  189. })
  190. // 开始批量打印
  191. blesdk.senBlData(
  192. opt.deviceId,
  193. opt.serviceId,
  194. opt.writeId,
  195. command.getData(),
  196. function(){
  197. const result =_this.$refs.productList.getAllChecked()
  198. _this.printIndex = _this.printIndex + 1
  199. if(_this.printIndex < result.length){
  200. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  201. }else{
  202. // 打印结束
  203. _this.printIndex = 0
  204. _this.$refs.kkprinter.onPrintSuccess()
  205. _this.isParinting = false
  206. clzConfirm({
  207. title: '提示',
  208. content: '打印已经结束,是否返回上页!',
  209. success (ret) {
  210. if (ret.confirm || ret.index == 0) {
  211. uni.navigateBack()
  212. }
  213. }
  214. })
  215. }
  216. });
  217. },
  218. // 批量打印
  219. startPrint(opt,tsc,blesdk){
  220. const _this = this
  221. const result =_this.$refs.productList.getAllChecked()
  222. console.log(result,result.length)
  223. if(result.length){
  224. if(_this.isParinting){
  225. return
  226. }
  227. clzConfirm({
  228. title: '提示',
  229. content: '开始打印后,无法撤回,系统将默认按照每个产品的补货数量批量打印',
  230. success (ret) {
  231. if (ret.confirm || ret.index == 0) {
  232. _this.isParinting = true
  233. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  234. }else{
  235. _this.$refs.kkprinter.onPrintFail()
  236. _this.isParinting = false
  237. }
  238. }
  239. })
  240. }else{
  241. _this.toashMsg("请选择产品!")
  242. _this.$refs.kkprinter.onPrintFail()
  243. }
  244. },
  245. }
  246. }
  247. </script>
  248. <style lang="less">
  249. .content{
  250. width: 100%;
  251. height: 100vh;
  252. background: #fff;
  253. .head-info{
  254. padding: 20rpx 20rpx 0;
  255. border-bottom: 2rpx solid #eee;
  256. > view{
  257. padding: 10rpx;
  258. color: darkorange;
  259. }
  260. .p-title{
  261. padding: 0 10rpx;
  262. display: flex;
  263. align-items: center;
  264. color: #222;
  265. font-size: 30rpx;
  266. > text{
  267. display: block;
  268. height: 30rpx;
  269. width: 6rpx;
  270. background: #0485F6;
  271. margin-right: 10rpx;
  272. border-radius: 10rpx;
  273. }
  274. .shelfName{
  275. flex-grow: 1;
  276. font-weight: bold;
  277. width: 80%;
  278. > view{
  279. overflow: hidden;
  280. white-space: nowrap;
  281. text-overflow: ellipsis;
  282. }
  283. }
  284. }
  285. }
  286. .partlist{
  287. flex-grow: 1;
  288. padding: 0 30rpx;
  289. overflow: auto;
  290. }
  291. .part-footer{
  292. padding: 20rpx 30rpx;
  293. border-top: 2rpx solid #eee;
  294. > view{
  295. &:first-child{
  296. width: 30%;
  297. text-align: left;
  298. padding-top: 10rpx;
  299. }
  300. text-align: right;
  301. }
  302. .btns{
  303. flex-grow: 1;
  304. button{
  305. width: 200rpx;
  306. }
  307. }
  308. }
  309. }
  310. </style>