quickReplenish.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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,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. setTimeout(()=>{
  76. uni.hideLoading()
  77. },Math.floor(this.partList.length * 15))
  78. },
  79. onLoad(option) {
  80. uni.showLoading({
  81. title: "正在加载数据...",
  82. mask:true
  83. })
  84. this.basicInfoData = this.$store.state.vuex_tempData;
  85. this.partList = this.basicInfoData.list
  86. // 保持屏幕常亮
  87. uni.setKeepScreenOn({
  88. keepScreenOn: true
  89. });
  90. },
  91. onUnload() {
  92. // this.$refs.kkprinter.closeConnect()
  93. this.partList = []
  94. this.$store.state.vuex_tempData = null
  95. // 保持屏幕常亮
  96. uni.setKeepScreenOn({
  97. keepScreenOn: false
  98. });
  99. },
  100. onBackPress(event){
  101. if(event.from == 'backbutton'){
  102. if(this.isParinting){
  103. uni.showToast({
  104. icon:'none',
  105. title: '正在打印中...'
  106. })
  107. }else{
  108. uni.navigateBack({delta: 1})
  109. }
  110. return true // 阻止默认返回行为(会导致无限循环)
  111. }
  112. },
  113. methods: {
  114. // 全选
  115. allCheckeChange(e){
  116. this.$refs.productList.allSelect(e.value)
  117. },
  118. allCheckedCallback(val){
  119. this.allChecked = val
  120. },
  121. // 补货
  122. replenish(){
  123. const result =this.$refs.productList.getAllChecked()
  124. console.log(result,result.length)
  125. if(result.length){
  126. this.chooseModal = true
  127. }else{
  128. this.toashMsg("请选择产品!")
  129. }
  130. },
  131. modalChooseType(data,confirm){
  132. const result =this.$refs.productList.getAllChecked()
  133. const arr = []
  134. result.map((item, index) => {
  135. arr.push({
  136. productSn: item.productSn,
  137. productCode: item.productCode,
  138. qty: item.printQty,
  139. shelfSn: this.basicInfoData.shelfSn,
  140. shelfPlaceCode: item.shelfPlaceCode,
  141. shelfPlaceSn: item.shelfPlaceSn,
  142. id: item.id
  143. })
  144. })
  145. const params = {
  146. detailList: arr,
  147. dispatchType: data.dispatchType,
  148. remarks: data.remarks,
  149. shelfSn:this.basicInfoData.shelfSn,
  150. confirm: confirm
  151. }
  152. console.log(params)
  153. uni.showLoading({
  154. title: "正在提交...",
  155. mask: true
  156. })
  157. this.loading = true
  158. saveReplenishBill(params).then(res => {
  159. console.log(res)
  160. if(res.status == 200){
  161. // 库存不足
  162. if(res.data&&res.data.length){
  163. this.temParams = params
  164. this.stockList = res.data
  165. this.stockModal = true
  166. }else{
  167. uni.navigateBack()
  168. this.toashMsg(res.message)
  169. }
  170. }else{
  171. uni.navigateBack()
  172. this.toashMsg(res.message)
  173. }
  174. this.loading = false
  175. this.chooseModal = false
  176. uni.hideLoading()
  177. })
  178. },
  179. // 继续补货
  180. modalStock(params){
  181. this.modalChooseType(params,1)
  182. this.stockModal = false
  183. },
  184. closeConnect(){
  185. this.isParinting = false
  186. uni.hideLoading()
  187. },
  188. onPrintError(){
  189. this.$refs.kkprinter.onPrintFail()
  190. this.isParinting = false
  191. this.show = false
  192. uni.showToast({
  193. title: '打印失败,请重试!'
  194. })
  195. },
  196. printOnce(opt,cmd,blesdk,data){
  197. const _this = this
  198. const dealer = this.$store.state.vuex_userData
  199. const paramsData = {
  200. dealerName: dealer.orgName,
  201. shelfName: this.basicInfoData.shelfName || '',
  202. productCode: data.productCode || '',
  203. productName: data.productName || '',
  204. shelfPlaceCode: data.shelfPlaceCode || '',
  205. currentInven: data.printQty,
  206. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  207. printUser: dealer.userNameCN,
  208. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  209. }
  210. const onPrintSuccess = function(){
  211. const result =_this.$refs.productList.getAllChecked()
  212. _this.printIndex = _this.printIndex + 1
  213. if(_this.printIndex < result.length){
  214. _this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
  215. }else{
  216. // 打印结束
  217. _this.printIndex = 0
  218. _this.$refs.kkprinter.onPrintSuccess()
  219. _this.isParinting = false
  220. clzConfirm({
  221. title: '提示',
  222. content: '打印已经结束,是否返回上页!',
  223. success (ret) {
  224. if (ret.confirm || ret.index == 0) {
  225. uni.navigateBack()
  226. }
  227. }
  228. })
  229. }
  230. }
  231. // 开始批量打印
  232. // tsc 指令 // 60*40 打印模板
  233. console.log(cmd,cmd.type)
  234. if(cmd.type&&cmd.type=='tsc'){
  235. // 60*40 打印模板
  236. const command = printTempl(cmd,paramsData)
  237. // 开始批量打印
  238. blesdk.senBlData(
  239. opt.deviceId,
  240. opt.serviceId,
  241. opt.writeId,
  242. command.getData(),
  243. onPrintSuccess);
  244. }else{
  245. const resultData = printCpclTempl(cmd,paramsData)
  246. blesdk.sendDataToDevice({
  247. deviceId: opt.deviceId,
  248. serviceId: opt.serviceId,
  249. characteristicId: opt.writeId,
  250. value: resultData,
  251. lasterSuccess: onPrintSuccess,
  252. lasterError: this.onPrintError
  253. });
  254. }
  255. },
  256. // 批量打印
  257. startPrint(opt,cmd,blesdk){
  258. const _this = this
  259. const result =_this.$refs.productList.getAllChecked()
  260. console.log(result,result.length)
  261. if(result.length){
  262. if(_this.isParinting){
  263. return
  264. }
  265. clzConfirm({
  266. title: '提示',
  267. content: '开始打印后,无法撤回,系统将默认按照每个产品的补货数量批量打印',
  268. success (ret) {
  269. if (ret.confirm || ret.index == 0) {
  270. _this.isParinting = true
  271. _this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
  272. }else{
  273. _this.$refs.kkprinter.onPrintFail()
  274. _this.isParinting = false
  275. }
  276. }
  277. })
  278. }else{
  279. _this.toashMsg("请选择产品!")
  280. _this.$refs.kkprinter.onPrintFail()
  281. }
  282. },
  283. }
  284. }
  285. </script>
  286. <style lang="less">
  287. .content{
  288. width: 100%;
  289. height: 100vh;
  290. background: #fff;
  291. .head-info{
  292. padding: 20rpx 20rpx 0;
  293. border-bottom: 2rpx solid #eee;
  294. > view{
  295. padding: 10rpx;
  296. color: darkorange;
  297. }
  298. .p-title{
  299. padding: 0 10rpx;
  300. display: flex;
  301. align-items: center;
  302. color: #222;
  303. font-size: 30rpx;
  304. > text{
  305. display: block;
  306. height: 30rpx;
  307. width: 6rpx;
  308. background: #0485F6;
  309. margin-right: 10rpx;
  310. border-radius: 10rpx;
  311. }
  312. .shelfName{
  313. flex-grow: 1;
  314. font-weight: bold;
  315. width: 80%;
  316. > view{
  317. overflow: hidden;
  318. white-space: nowrap;
  319. text-overflow: ellipsis;
  320. }
  321. }
  322. }
  323. }
  324. .partlist{
  325. flex-grow: 1;
  326. padding: 0 30rpx;
  327. overflow: auto;
  328. }
  329. .part-footer{
  330. padding: 20rpx 30rpx;
  331. border-top: 2rpx solid #eee;
  332. > view{
  333. &:first-child{
  334. width: 30%;
  335. text-align: left;
  336. padding-top: 10rpx;
  337. }
  338. }
  339. .btns{
  340. flex-grow: 1;
  341. button{
  342. width: 200rpx;
  343. }
  344. }
  345. }
  346. }
  347. </style>