add_check.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <base-page>
  3. <view class="content-wrap" @click="goodsShow = false">
  4. <view class="title">添加盘点单</view>
  5. <view class="table-wrap">
  6. <view class="table-head">
  7. <view class="table-tr">
  8. <view class="table-th" style="flex: 3;">产品名称/规格/编码</view>
  9. <view class="table-th" style="flex: 1;">当前库存</view>
  10. <view class="table-th" style="flex: 1;">销售库存</view>
  11. <view class="table-th" style="flex: 1;">单位</view>
  12. <view class="table-th" style="flex: 2;">实盘数量</view>
  13. <view class="table-th" style="flex: 1;">盈亏数量</view>
  14. <view class="table-th" style="flex: 1;">操作</view>
  15. </view>
  16. </view>
  17. <view class="table-body">
  18. <view class="table-tr">
  19. <view class="table-td select-goods-input" style="flex: 3;" @click.stop="goodsShow = true">
  20. <input type="text" v-model="name" @confirm="getGoodsData" placeholder="请输入产品名称/规格/编码" />
  21. <scroll-view class="select-goods-frame" :scroll-y="true" v-show="goodsShow">
  22. <view :class="['goods-item', { select: selectGoodsId == item.sku_id }]" v-for="(item, index) in searchGoodsList" @click.stop="selectGoods(item)">
  23. {{ item.sku_name }}
  24. </view>
  25. <view class="goods-item-empty" v-if="!searchGoodsList.length">暂无商品</view>
  26. </scroll-view>
  27. </view>
  28. <view class="table-td" style="flex: 1;"></view>
  29. <view class="table-td" style="flex: 1;"></view>
  30. <view class="table-td" style="flex: 1;"></view>
  31. <view class="table-td" style="flex: 2;"></view>
  32. <view class="table-td" style="flex: 1;"></view>
  33. <view class="table-td" style="flex: 1;"></view>
  34. </view>
  35. <block v-for="(item, index) in goodsList" :key="index">
  36. <view class="table-tr" v-if="goodsIdArr.includes(item.sku_id)">
  37. <view class="table-td goods-name" style="flex: 3;">
  38. <image :src="$util.img(item.sku_image, { size: 'small' })" mode="aspectFill"></image>
  39. <text class="name multi-hidden">{{ item.sku_name }}</text>
  40. </view>
  41. <view class="table-td" style="flex: 1;">{{ item.real_stock }}</view>
  42. <view class="table-td" style="flex: 1;">{{ item.stock }}</view>
  43. <view class="table-td" style="flex: 1;">{{ item.unit }}</view>
  44. <view class="table-td" style="flex: 2;">
  45. <input type="number" class="goods-num" v-model="item.goods_num" placeholder="请输入数量" @input="calcTotalData" />
  46. </view>
  47. <view class="table-td" style="flex: 1;">{{ parseFloat(item.goods_num - item.stock) || 0 }}</view>
  48. <view class="table-td" style="flex: 1;"><button type="default" class="delete" @click="delGoods(item.sku_id)">删除</button></view>
  49. </view>
  50. </block>
  51. <view class="table-tr table-empty" v-if="!goodsIdArr.length">暂无数据,请选择商品数据</view>
  52. </view>
  53. </view>
  54. <view class="action-wrap">
  55. <view class="table-total">
  56. 合计:共{{ totalData.kindsNum }}种商品,盘盈:{{ totalData.upNum }}种,盘亏:{{ totalData.downNum }}种,持平:{{ totalData.sameNum }}种
  57. </view>
  58. <view class="btn-wrap">
  59. <button type="default" class="stockout-btn" @click="stockOutFn">盘点</button>
  60. <button type="default" @click="backFn">返回</button>
  61. </view>
  62. </view>
  63. </view>
  64. </base-page>
  65. </template>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. name: '', //产品名称
  71. goodsList:[],
  72. goodsIdArr:[],
  73. selectGoodsId: 0,
  74. goodsShow: false,
  75. totalData:{
  76. kindsNum:0,
  77. upNum: 0,
  78. downNum: 0,
  79. sameNum: 0
  80. },
  81. isSubmit: false,
  82. scanCode: {
  83. code: '',
  84. lastTime: 0
  85. },
  86. searchGoodsList: []
  87. };
  88. },
  89. onLoad(option) {
  90. uni.hideTabBar();
  91. },
  92. onHide() {
  93. // #ifdef APP-PLUS
  94. plus.key.removeEventListener('keyup', this.listenerScancode, true);
  95. // #endif
  96. // #ifdef H5
  97. window.removeEventListener('keypress', this.listenerScancode, true);
  98. // #endif
  99. },
  100. onShow() {
  101. this.getGoodsData();
  102. // #ifdef APP-PLUS
  103. plus.key.addEventListener('keyup', this.listenerScancode, true);
  104. // #endif
  105. // #ifdef H5
  106. window.addEventListener('keypress', this.listenerScancode, true);
  107. // #endif
  108. },
  109. watch: {
  110. goodsIdArr(data){
  111. this.calcTotalData();
  112. },
  113. name(){
  114. this.getGoodsData();
  115. }
  116. },
  117. methods: {
  118. getGoodsData() {
  119. this.$api.sendRequest({
  120. url: '/stock/storeapi/manage/getskulist',
  121. data:{search: this.name},
  122. success: res => {
  123. this.searchGoodsList = [];
  124. if (res.code >= 0 && res.data.length != 0) {
  125. this.searchGoodsList = res.data;
  126. } else{
  127. this.$util.showToast({
  128. title:res.message
  129. });
  130. }
  131. }
  132. });
  133. },
  134. selectGoods(data){
  135. this.selectGoodsId = data.sku_id;
  136. if(!this.goodsIdArr.includes(data.sku_id)) {
  137. this.goodsIdArr.push(data.sku_id);
  138. this.goodsList.push(data);
  139. }
  140. this.goodsShow = false;
  141. },
  142. delGoods(id){
  143. this.goodsList.splice(this.goodsIdArr.indexOf(id),1);
  144. this.goodsIdArr.splice(this.goodsIdArr.indexOf(id),1);
  145. this.$forceUpdate();
  146. },
  147. stockOutFn(){
  148. if(!this.goodsIdArr.length){
  149. this.$util.showToast({
  150. title: "请选择盘点数据"
  151. });
  152. return false;
  153. }
  154. // 检测库存是否填写,且提取数据
  155. let isStock = false;
  156. let saveData = [];
  157. try{
  158. this.goodsList.forEach((item,index)=>{
  159. if(this.goodsIdArr.includes(item.sku_id)){
  160. if(!parseFloat(item.goods_num || 0)){
  161. isStock = true;
  162. let toast = "请输入" + item.sku_name + "的盘点数量";
  163. this.$util.showToast({
  164. title: toast
  165. });
  166. throw new Error('end');
  167. }
  168. var obj = {};
  169. obj.goods_num = item.goods_num;
  170. obj.goods_sku_id = item.sku_id;
  171. saveData.push(obj);
  172. }
  173. })
  174. }catch(e){
  175. if(e.message != "end") throw e;
  176. }
  177. if(isStock) return false;
  178. if(this.isSubmit) return false;
  179. this.isSubmit = true;
  180. this.$api.sendRequest({
  181. url: '/stock/storeapi/check/add',
  182. data:{stock_json: JSON.stringify(saveData)},
  183. success: res => {
  184. this.isSubmit = false;
  185. this.$util.showToast({
  186. title:res.message
  187. });
  188. if (res.code >= 0) {
  189. setTimeout(()=>{
  190. this.backFn();
  191. },500);
  192. this.resetFn();
  193. }
  194. }
  195. });
  196. },
  197. backFn(){
  198. this.$util.redirectTo('/pages/stock/check');
  199. },
  200. calcTotalData(){
  201. this.totalData.kindsNum = 0;
  202. this.totalData.upNum = 0;
  203. this.totalData.downNum = 0;
  204. this.totalData.sameNum = 0;
  205. this.goodsList.forEach((item,index)=>{
  206. if(this.goodsIdArr.includes(item.sku_id) && item.goods_num){
  207. if((item.goods_num - item.stock) == 0){
  208. this.totalData.sameNum++;
  209. }else if((item.goods_num - item.stock) > 0){
  210. this.totalData.upNum++;
  211. }else if((item.goods_num - item.stock) < 0){
  212. this.totalData.downNum++;
  213. }
  214. }
  215. })
  216. this.totalData.kindsNum = this.goodsIdArr.length;
  217. },
  218. resetFn(){
  219. this.goodsIdArr = [];
  220. this.selectGoodsId = this.goodsList[0].sku_id;
  221. this.goodsShow = false;
  222. this.totalData.kindsNum = 0;
  223. this.totalData.countNum = 0;
  224. this.totalData.price = 0;
  225. },
  226. /**
  227. * 监听扫码事件
  228. * @param {Object} e
  229. */
  230. listenerScancode(e){
  231. const clearBarCode = ()=> {
  232. this.scanCode = { lastTime: 0, code: '' }
  233. }
  234. // #ifdef H5
  235. var currCode = e.keyCode || e.which || e.charCode;
  236. // #endif
  237. // #ifdef APP-PLUS
  238. const keycode = ['keycode_7': 0, 'keycode_8': 1, 'keycode_9': 2, 'keycode_10': 3, 'keycode_11': 4, 'keycode_12':
  239. 5, 'keycode_13': 6, 'keycode_14': 7, 'keycode_15': 8, 'keycode_16': 9
  240. ];
  241. var currCode = keyArr['keycode_' + e.keyCode] || '';
  242. // #endif
  243. var currTime = new Date().getTime();
  244. if (this.scanCode.lastTime > 0) {
  245. if (currTime - this.scanCode.lastTime <= 100) {
  246. this.scanCode.code += String.fromCharCode(currCode);
  247. } else if (currTime - this.scanCode.lastTime > 500) {
  248. // 输入间隔500毫秒清空
  249. clearBarCode();
  250. }
  251. } else {
  252. this.scanCode.code = String.fromCharCode(currCode);
  253. }
  254. this.scanCode.lastTime = currTime;
  255. // #ifdef H5
  256. if (currCode == 13) {
  257. // #endif
  258. // #ifdef APP-PLUS
  259. if (e.keyCode == 66) {
  260. // #endif
  261. if (this.scanCode.code && this.scanCode.code.length >= 8) this.getSkuBycode(this.scanCode.code)
  262. // 回车输入后清空
  263. clearBarCode();
  264. }
  265. },
  266. /**
  267. * 获取商品信息通过条形码
  268. */
  269. getSkuBycode(code){
  270. this.$api.sendRequest({
  271. url: '/cashier/storeapi/goods/skuinfo',
  272. data: {
  273. sku_no: code.trim()
  274. },
  275. success: res => {
  276. if (res.code == 0) {
  277. if (res.data) {
  278. res.data.goods_num = 0;
  279. this.selectGoods(res.data)
  280. } else {
  281. this.$util.showToast({
  282. title: '未找到该商品!'
  283. })
  284. }
  285. } else {
  286. this.$util.showToast({
  287. title: res.message,
  288. })
  289. }
  290. }
  291. })
  292. }
  293. }
  294. };
  295. </script>
  296. <style lang="scss">
  297. .content-wrap {
  298. position: relative;
  299. padding: 0.15rem;
  300. background-color: #fff;
  301. @extend %body-overhide;
  302. box-sizing: border-box;
  303. .title {
  304. font-size: 0.18rem;
  305. margin-bottom: 0.2rem;
  306. }
  307. .table-wrap {
  308. position: relative;
  309. margin-top: 40rpx;
  310. border: 2rpx solid #ccc;
  311. .table-head {
  312. background-color: #f7f7f7;
  313. }
  314. .table-body {
  315. @extend %body-overhide;
  316. max-height: 6rem;
  317. .table-tr {
  318. &:nth-child(1) {
  319. position: absolute;
  320. left: 0;
  321. right: 0;
  322. background: #fff;
  323. z-index: 2;
  324. }
  325. &:nth-child(2) {
  326. margin-top: 0.51rem;
  327. }
  328. &:last-of-type .table-td {
  329. border-bottom: 0;
  330. }
  331. }
  332. }
  333. .table-tr {
  334. display: flex;
  335. }
  336. .table-th,
  337. .table-td {
  338. display: flex;
  339. align-items: center;
  340. justify-content: center;
  341. padding: 0.15rem 0.3rem;
  342. border-bottom: 0.01rem solid #ccc;
  343. border-right: 0.01rem solid #ccc;
  344. text-align: center;
  345. &:last-of-type {
  346. border-right: 0;
  347. justify-content: flex-end;
  348. }
  349. &.goods-name {
  350. justify-content: flex-start;
  351. image {
  352. width: 0.45rem;
  353. height: 0.45rem;
  354. flex-shrink: 0;
  355. }
  356. .name {
  357. margin-left: 0.1rem;
  358. }
  359. }
  360. }
  361. .goods-num {
  362. border: 0.01rem solid #eee;
  363. height: 0.35rem;
  364. line-height: 0.35rem;
  365. border-radius: 0.05rem;
  366. }
  367. input {
  368. font-size: $uni-font-size-base;
  369. }
  370. .delete {
  371. margin: 0;
  372. font-size: $uni-font-size-base;
  373. background-color: $uni-color-primary;
  374. color: #fff;
  375. }
  376. .table-empty {
  377. justify-content: center;
  378. padding: 0.3rem;
  379. color: #999;
  380. }
  381. }
  382. .action-wrap {
  383. position: absolute;
  384. bottom: 0;
  385. left: 0;
  386. right: 0;
  387. display: flex;
  388. justify-content: space-between;
  389. padding: 0 0.15rem 0.2rem;
  390. align-items: center;
  391. .btn-wrap {
  392. display: flex;
  393. align-items: center;
  394. justify-content: center;
  395. button {
  396. margin: 0;
  397. min-width: 2.75rem;
  398. height: 0.4rem;
  399. line-height: 0.4rem;
  400. font-size: $uni-font-size-base;
  401. &.stockout-btn {
  402. margin-right: 0.15rem;
  403. background-color: $uni-color-primary;
  404. color: #fff;
  405. }
  406. }
  407. }
  408. }
  409. .select-goods-input {
  410. position: relative;
  411. input {
  412. flex: 1;
  413. font-size: $uni-font-size-base;
  414. }
  415. }
  416. .select-goods-frame {
  417. position: absolute;
  418. z-index: 2;
  419. padding: 0.05rem 0;
  420. top: 0.45rem;
  421. left: 0;
  422. width: 5rem;
  423. height: 5rem;
  424. background-color: #fff;
  425. box-shadow: 0 0 36rpx rgba(0, 0, 0, 0.4);
  426. .goods-item {
  427. padding: 10rpx 30rpx;
  428. line-height: 1.5;
  429. text-align: left;
  430. &.select {
  431. background-color: $uni-color-primary;
  432. color: #fff;
  433. }
  434. }
  435. .goods-item-empty {
  436. padding: 10rpx 30rpx;
  437. line-height: 1.5;
  438. text-align: center;
  439. }
  440. }
  441. }
  442. </style>