stockout.vue 11 KB

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