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