quickReplenish.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view class="content flex flex_column">
  3. <view class="head-info">
  4. <view class="p-title flex align_center">
  5. <text></text>
  6. <view class="shelfName flex align_center">
  7. <view>
  8. {{basicInfoData.shelfName}}
  9. </view>
  10. </view>
  11. </view>
  12. <view>系统检测到以下产品缺货,请选择需要补货的产品</view>
  13. </view>
  14. <view class="partlist">
  15. <quickProductList :list="partList" ref="productList" noDataText="暂无产品" @allChecked="allCheckedCallback"></quickProductList>
  16. </view>
  17. <view class="part-footer flex align_item justify_between">
  18. <view>
  19. <u-checkbox size="40" @change="allCheckeChange" v-model="allChecked" shape="circle">{{allChecked?'取消全选':'全选'}}</u-checkbox>
  20. </view>
  21. <view class="btns flex align_item justify_end">
  22. <view>
  23. <kk-printer ref="kkprinter" :autoConnect="false" printBtnStyle="default-mid" defaultText="打印贴签" @startPrint="startPrint"></kk-printer>
  24. </view>
  25. <view style="padding: 0 10rpx;"></view>
  26. <view>
  27. <u-button class="handle-btn" :loading="loading" shape="circle" size="medium" hover-class="none" :custom-style="customBtnStyle" @click="replenish">快速补货</u-button>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 选择配送方式弹框 -->
  32. <choose-type-modal v-if="chooseModal" :openModal="chooseModal" @confirm="modalChooseType" @close="chooseModal = false" />
  33. <!-- 库存不足 弹框 -->
  34. <stock-modal v-if="stockModal" :openModal="stockModal" :list="stockList" :params="temParams" @confirm="modalStock" @close="stockModal=false" />
  35. </view>
  36. </template>
  37. <script>
  38. import quickProductList from './quickProductList.vue'
  39. import kkPrinter from '@/components/kk-printer/index.vue';
  40. import chooseTypeModal from './chooseTypeModal.vue'
  41. import stockModal from '@/pages/replenishmentManage/stockModal.vue'
  42. import {printTempl} from '@/libs/printTools.js'
  43. import {saveReplenishBill} from '@/api/shelfReplenish.js'
  44. import {clzConfirm} from '@/libs/tools.js'
  45. export default {
  46. components: { quickProductList, kkPrinter, chooseTypeModal, stockModal },
  47. data() {
  48. return {
  49. loading: false,
  50. chooseModal: false,
  51. basicInfoData:null,
  52. partList: [],
  53. allChecked: false,
  54. printIndex: 0,
  55. isParinting: false,
  56. stockModal: false,
  57. stockList: [],
  58. temParams:null,
  59. customBtnStyle: { // 自定义按钮样式
  60. borderColor: this.$config('primaryColor'),
  61. backgroundColor: this.$config('primaryColor'),
  62. color: '#fff'
  63. },
  64. }
  65. },
  66. onReady() {
  67. uni.setNavigationBarColor({
  68. frontColor: '#ffffff',
  69. backgroundColor: this.$config('primaryColor')
  70. })
  71. this.$refs.productList.setData(this.partList)
  72. this.allCheckeChange({value:true})
  73. this.allChecked = true
  74. },
  75. onLoad(option) {
  76. this.basicInfoData = this.$store.state.vuex_tempData;
  77. this.partList = this.basicInfoData.list
  78. // 保持屏幕常亮
  79. uni.setKeepScreenOn({
  80. keepScreenOn: true
  81. });
  82. },
  83. onUnload() {
  84. this.partList = []
  85. this.$store.state.vuex_tempData = null
  86. // 保持屏幕常亮
  87. uni.setKeepScreenOn({
  88. keepScreenOn: false
  89. });
  90. },
  91. onBackPress(event){
  92. if(event.from == 'backbutton'){
  93. if(this.isParinting){
  94. uni.showToast({
  95. icon:'none',
  96. title: '正在打印中...'
  97. })
  98. }else{
  99. uni.navigateBack({delta: 1})
  100. }
  101. return true // 阻止默认返回行为(会导致无限循环)
  102. }
  103. },
  104. methods: {
  105. // 全选
  106. allCheckeChange(e){
  107. this.$refs.productList.allSelect(e.value)
  108. },
  109. allCheckedCallback(val){
  110. this.allChecked = val
  111. },
  112. // 补货
  113. replenish(){
  114. const result =this.$refs.productList.getAllChecked()
  115. console.log(result,result.length)
  116. if(result.length){
  117. this.chooseModal = true
  118. }else{
  119. this.toashMsg("请选择产品!")
  120. }
  121. },
  122. modalChooseType(data,confirm){
  123. const result =this.$refs.productList.getAllChecked()
  124. const arr = []
  125. result.map((item, index) => {
  126. arr.push({
  127. productSn: item.productSn,
  128. productCode: item.productCode,
  129. qty: item.printQty,
  130. shelfSn: this.basicInfoData.shelfSn,
  131. shelfPlaceCode: item.shelfPlaceCode,
  132. shelfPlaceSn: item.shelfPlaceSn
  133. })
  134. })
  135. const params = {
  136. detailList: arr,
  137. dispatchType: data.dispatchType,
  138. remarks: data.remarks,
  139. shelfSn:this.basicInfoData.shelfSn,
  140. confirm: confirm
  141. }
  142. console.log(params)
  143. uni.showLoading({
  144. title: "正在提交..."
  145. })
  146. this.loading = true
  147. saveReplenishBill(params).then(res => {
  148. console.log(res)
  149. if(res.status == 200){
  150. // 库存不足
  151. if(res.data&&res.data.length){
  152. this.temParams = params
  153. this.stockList = res.data
  154. this.stockModal = true
  155. }else{
  156. uni.navigateBack()
  157. this.toashMsg(res.message)
  158. }
  159. }
  160. this.loading = false
  161. this.chooseModal = false
  162. uni.hideLoading()
  163. })
  164. },
  165. // 继续补货
  166. modalStock(params){
  167. this.modalChooseType(params,1)
  168. this.stockModal = false
  169. },
  170. printOnce(opt,tsc,blesdk,data){
  171. const _this = this
  172. const dealer = this.$store.state.vuex_userData
  173. // 60*40 打印模板
  174. const command = printTempl(tsc,{
  175. dealerName: dealer.orgName,
  176. shelfName: data.shelfName || '',
  177. productCode: data.productCode || '',
  178. productName: data.productName || '',
  179. shelfPlaceCode: data.shelfPlaceCode || '',
  180. currentInven: data.printQty,
  181. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  182. printUser: dealer.userNameCN,
  183. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  184. })
  185. // 开始批量打印
  186. blesdk.senBlData(
  187. opt.deviceId,
  188. opt.serviceId,
  189. opt.writeId,
  190. command.getData(),
  191. function(){
  192. const result =_this.$refs.productList.getAllChecked()
  193. _this.printIndex = _this.printIndex + 1
  194. if(_this.printIndex < result.length){
  195. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  196. }else{
  197. _this.printIndex = 0
  198. _this.$refs.kkprinter.onPrintSuccess()
  199. _this.isParinting = false
  200. }
  201. });
  202. },
  203. // 批量打印
  204. startPrint(opt,tsc,blesdk){
  205. const _this = this
  206. const result =_this.$refs.productList.getAllChecked()
  207. console.log(result,result.length)
  208. if(result.length){
  209. if(_this.isParinting){
  210. return
  211. }
  212. clzConfirm({
  213. title: '提示',
  214. content: '开始打印后,无法撤回,系统将默认按照每个产品的补货数量批量打印',
  215. success (ret) {
  216. if (ret.confirm || ret.index == 0) {
  217. _this.isParinting = true
  218. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  219. }
  220. }
  221. })
  222. }else{
  223. _this.toashMsg("请选择产品!")
  224. _this.$refs.kkprinter.onPrintFail()
  225. }
  226. },
  227. }
  228. }
  229. </script>
  230. <style lang="less">
  231. .content{
  232. width: 100%;
  233. height: 100vh;
  234. background: #fff;
  235. .head-info{
  236. padding: 20rpx 20rpx 0;
  237. border-bottom: 2rpx solid #eee;
  238. > view{
  239. padding: 10rpx;
  240. color: darkorange;
  241. }
  242. .p-title{
  243. padding: 0 10rpx;
  244. display: flex;
  245. align-items: center;
  246. color: #222;
  247. font-size: 30rpx;
  248. > text{
  249. display: block;
  250. height: 30rpx;
  251. width: 6rpx;
  252. background: #0485F6;
  253. margin-right: 10rpx;
  254. border-radius: 10rpx;
  255. }
  256. .shelfName{
  257. flex-grow: 1;
  258. font-weight: bold;
  259. width: 80%;
  260. > view{
  261. overflow: hidden;
  262. white-space: nowrap;
  263. text-overflow: ellipsis;
  264. }
  265. }
  266. }
  267. }
  268. .partlist{
  269. flex-grow: 1;
  270. padding: 0 30rpx;
  271. overflow: auto;
  272. }
  273. .part-footer{
  274. padding: 20rpx 30rpx;
  275. border-top: 2rpx solid #eee;
  276. > view{
  277. &:first-child{
  278. width: 30%;
  279. text-align: left;
  280. padding-top: 10rpx;
  281. }
  282. text-align: right;
  283. }
  284. .btns{
  285. flex-grow: 1;
  286. button{
  287. width: 200rpx;
  288. }
  289. }
  290. }
  291. }
  292. </style>