quickReplenish.vue 9.1 KB

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