quickReplenish.vue 9.3 KB

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