add_allocate.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <template>
  2. <base-page>
  3. <view class="content-wrap" @click="goodsShow = false">
  4. <view class="title">添加调拨单</view>
  5. <view class="screen-warp form-content">
  6. <view class="form-item store-info" v-if="storeInfo">
  7. <view class="form-label">当前门店:</view>
  8. <view class="form-inline">{{ storeInfo.store_name }}</view>
  9. </view>
  10. <view class="form-item">
  11. <label class="form-label">
  12. <text class="required">*</text>
  13. 调拨方式
  14. </label>
  15. <view class="form-inline">
  16. <select-lay
  17. :zindex="10"
  18. :value="type"
  19. name="names"
  20. placeholder="请选择调拨方式"
  21. :options="screen.allocateTypeList"
  22. @selectitem="selectAllocateType"
  23. ></select-lay>
  24. </view>
  25. </view>
  26. <view class="form-item">
  27. <label class="form-label">
  28. <text class="required">*</text>
  29. {{ storeName }}
  30. </label>
  31. <view class="form-inline">
  32. <select-lay
  33. :zindex="10"
  34. :value="screen.store_id"
  35. name="names"
  36. :placeholder="'请选择' + storeName"
  37. :options="screen.storeList"
  38. @selectitem="selectStore"
  39. ></select-lay>
  40. </view>
  41. </view>
  42. <view class="form-item">
  43. <label class="form-label">
  44. <text class="required">*</text>
  45. 调拨时间
  46. </label>
  47. <view class="form-inline">
  48. <uni-datetime-picker :start="screen.startDate" v-model="screen.birthday" type="timestamp" :clearIcon="false" @change="changeTime" />
  49. </view>
  50. </view>
  51. </view>
  52. <view class="table-wrap">
  53. <view class="table-head">
  54. <view class="table-tr">
  55. <view class="table-th" style="flex: 3;">产品名称/规格/编码</view>
  56. <view class="table-th" style="flex: 1;">当前库存</view>
  57. <view class="table-th" style="flex: 1;">单位</view>
  58. <view class="table-th" style="flex: 2;">成本价</view>
  59. <view class="table-th" style="flex: 2;">数量</view>
  60. <view class="table-th" style="flex: 1;">总金额</view>
  61. <view class="table-th" style="flex: 1;">操作</view>
  62. </view>
  63. </view>
  64. <view class="table-body">
  65. <view class="table-tr">
  66. <view class="table-td select-goods-input" style="flex: 3;" @click.stop="goodsShow = true">
  67. <input type="text" v-model="name" @confirm="getGoodsData" placeholder="请输入产品名称/规格/编码" />
  68. <scroll-view class="select-goods-frame" :scroll-y="true" v-show="goodsShow">
  69. <view :class="['goods-item', { select: selectGoodsId == item.sku_id }]" v-for="(item, index) in searchGoodsList" @click.stop="selectGoods(item)">
  70. {{ item.sku_name }}
  71. </view>
  72. <view class="goods-item-empty" v-if="!searchGoodsList.length">暂无商品</view>
  73. </scroll-view>
  74. </view>
  75. <view class="table-td" style="flex: 1;"></view>
  76. <view class="table-td" style="flex: 1;"></view>
  77. <view class="table-td" style="flex: 2;"></view>
  78. <view class="table-td" style="flex: 2;"></view>
  79. <view class="table-td" style="flex: 1;"></view>
  80. <view class="table-td" style="flex: 1;"></view>
  81. </view>
  82. <block v-for="(item, index) in goodsList" :key="index">
  83. <view class="table-tr" v-if="goodsIdArr.includes(item.sku_id)">
  84. <view class="table-td goods-name" style="flex: 3;">
  85. <image :src="$util.img(item.sku_image, { size: 'small' })" mode="aspectFill"></image>
  86. <text class="name multi-hidden">{{ item.sku_name }}</text>
  87. </view>
  88. <view class="table-td" style="flex: 1;">{{ item.real_stock || 0 }}</view>
  89. <view class="table-td" style="flex: 1;">{{ item.unit }}</view>
  90. <view class="table-td" style="flex: 2;">{{ item.cost_price || 0 }}</view>
  91. <view class="table-td" style="flex: 2;">
  92. <input type="number" class="goods-num" v-model="item.goods_num" placeholder="请输入数量" @input="calcTotalData" />
  93. </view>
  94. <view class="table-td" style="flex: 1;">{{ (item.goods_num * item.cost_price || 0).toFixed(2) }}</view>
  95. <view class="table-td" style="flex: 1;"><button type="default" class="delete" @click="delGoods(item.sku_id)">删除</button></view>
  96. </view>
  97. </block>
  98. <view class="table-tr table-empty" v-if="!goodsIdArr.length">暂无数据,请选择商品数据</view>
  99. </view>
  100. </view>
  101. <view class="action-wrap">
  102. <view class="table-total">合计:共{{ totalData.kindsNum }}种{{ totalData.countNum }}{{ totalData.unit }}产品,合计金额{{ totalData.price.toFixed(2) }}</view>
  103. <view class="btn-wrap">
  104. <button type="default" class="stockout-btn" @click="stockOutFn">确认调拨</button>
  105. <button type="default" @click="backFn">返回</button>
  106. </view>
  107. </view>
  108. </view>
  109. </base-page>
  110. </template>
  111. <script>
  112. export default {
  113. data() {
  114. return {
  115. name: '', //产品名称
  116. goodsList:[],
  117. goodsIdArr:[],
  118. selectGoodsId: 0,
  119. goodsShow: false,
  120. totalData:{
  121. kindsNum:0,
  122. countNum:0,
  123. price: 0
  124. },
  125. isSubmit: false,
  126. // 筛选面板的时间
  127. type: 'out',
  128. storeName: '出库门店',
  129. screen:{
  130. store_id: "",
  131. storeList:[],
  132. startDate:'1998-01-30 00:00:00',
  133. birthday:'',
  134. allocateTypeList: [
  135. {
  136. label: '调拨入库',
  137. value: 'out'
  138. },
  139. {
  140. label: '调拨出库',
  141. value: 'in'
  142. }
  143. ]
  144. },
  145. scanCode: {
  146. code: '',
  147. lastTime: 0
  148. },
  149. searchGoodsList: []
  150. };
  151. },
  152. onLoad(option) {
  153. uni.hideTabBar();
  154. },
  155. onShow() {
  156. this.screen.birthday = this.$util.timeFormat(Date.parse(new Date())/1000);
  157. this.getStoreLists();
  158. this.getGoodsData();
  159. // #ifdef APP-PLUS
  160. plus.key.addEventListener('keyup', this.listenerScancode, true);
  161. // #endif
  162. // #ifdef H5
  163. window.addEventListener('keypress', this.listenerScancode, true);
  164. // #endif
  165. },
  166. onHide() {
  167. // #ifdef APP-PLUS
  168. plus.key.removeEventListener('keyup', this.listenerScancode, true);
  169. // #endif
  170. // #ifdef H5
  171. window.removeEventListener('keypress', this.listenerScancode, true);
  172. // #endif
  173. },
  174. watch: {
  175. goodsIdArr(data){
  176. this.calcTotalData();
  177. },
  178. name(){
  179. this.getGoodsData();
  180. }
  181. },
  182. methods: {
  183. selectAllocateType(id){
  184. this.type = id == -1 ? '' : this.screen.allocateTypeList[id].value;
  185. this.storeName = id == -1 ? '出库门店' : this.screen.allocateTypeList[id].label;
  186. if(this.type == 'in') this.getGoodsData(); //当是入库的时候,需要查出库门店的商品
  187. },
  188. selectStore(id){
  189. this.screen.store_id = id == -1 ? '' : this.screen.storeList[id].value;
  190. },
  191. changeTime(data){
  192. this.screen.birthday = data;
  193. },
  194. getGoodsData() {
  195. let data = {search: this.name};
  196. if(this.type == 'in') data.temp_store_id = this.screen.store_id;
  197. this.$api.sendRequest({
  198. url: '/stock/storeapi/manage/getskulist',
  199. data:data,
  200. success: res => {
  201. this.searchGoodsList = [];
  202. if (res.code >= 0 && res.data.length != 0) {
  203. this.searchGoodsList = res.data;
  204. } else{
  205. this.$util.showToast({
  206. title:res.message
  207. });
  208. }
  209. }
  210. });
  211. },
  212. selectGoods(data){
  213. this.selectGoodsId = data.sku_id;
  214. if(!this.goodsIdArr.includes(data.sku_id)) {
  215. this.goodsIdArr.push(data.sku_id);
  216. this.goodsList.push(data);
  217. }
  218. this.goodsShow = false;
  219. },
  220. delGoods(id){
  221. this.goodsList.splice(this.goodsIdArr.indexOf(id),1);
  222. this.goodsIdArr.splice(this.goodsIdArr.indexOf(id),1);
  223. this.$forceUpdate();
  224. },
  225. getStoreLists(){
  226. this.screen.storeList = [];
  227. this.$api.sendRequest({
  228. url: '/stock/storeapi/store/lists',
  229. success: res => {
  230. if(res.code >= 0){
  231. let data = res.data;
  232. let storeId = uni.getStorageSync('store_id');
  233. for(let i = 0; i < data.length; i++){
  234. if(storeId != data[i]['store_id']){
  235. this.screen.storeList.push({
  236. 'label': data[i]['store_name'],
  237. 'value': data[i]['store_id'].toString()
  238. });
  239. }
  240. }
  241. this.screen.store_id = this.screen.storeList[0].value;
  242. }
  243. }
  244. });
  245. },
  246. stockOutFn(){
  247. if(!this.type){
  248. this.$util.showToast({
  249. title: "请选择调拨方式"
  250. });
  251. return false;
  252. }
  253. if(!this.screen.store_id){
  254. this.$util.showToast({
  255. title: "请选择出库门店"
  256. });
  257. return false;
  258. }
  259. if(!this.screen.birthday){
  260. this.$util.showToast({
  261. title: "请选择调拨时间"
  262. });
  263. return false;
  264. }
  265. if(!this.goodsIdArr.length){
  266. this.$util.showToast({
  267. title: "请选择调拨数据"
  268. });
  269. return false;
  270. }
  271. // 检测库存是否填写,且提取数据
  272. let isStock = false;
  273. let saveData = [];
  274. try{
  275. this.goodsList.forEach((item,index)=>{
  276. if(this.goodsIdArr.includes(item.sku_id)){
  277. if(!parseFloat(item.goods_num || 0)){
  278. isStock = true;
  279. let toast = "请输入" + item.sku_name + "的调拨数量";
  280. this.$util.showToast({
  281. title: toast
  282. });
  283. return false;
  284. throw new Error('end');
  285. }
  286. var obj = {};
  287. obj.goods_num = item.goods_num;
  288. obj.goods_price = item.cost_price;
  289. obj.goods_sku_id = item.sku_id;
  290. saveData.push(obj);
  291. }
  292. })
  293. }catch(e){
  294. if(e.message != "end") throw e;
  295. }
  296. if(isStock) return false;
  297. if(this.isSubmit) return false;
  298. this.isSubmit = true;
  299. this.$api.sendRequest({
  300. url: '/stock/storeapi/allocate/addallocate',
  301. data:{
  302. allot_type: this.type,
  303. temp_store_id: this.screen.store_id,
  304. allot_time: this.screen.birthday,
  305. goods_sku_list: JSON.stringify(saveData)
  306. },
  307. success: res => {
  308. this.isSubmit = false;
  309. this.$util.showToast({
  310. title:res.message
  311. });
  312. if (res.code >= 0) {
  313. setTimeout(()=>{
  314. this.backFn();
  315. },500);
  316. this.resetFn();
  317. }
  318. }
  319. });
  320. },
  321. backFn(){
  322. this.$util.redirectTo('/pages/stock/allocate');
  323. },
  324. calcTotalData(){
  325. this.totalData.countNum = 0;
  326. this.totalData.kindsNum = 0;
  327. this.totalData.price = 0;
  328. this.goodsList.forEach((item,index)=>{
  329. if(this.goodsIdArr.includes(item.sku_id)){
  330. this.totalData.price += parseFloat(item.cost_price || 0) * parseFloat(item.goods_num || 1);
  331. this.totalData.countNum += parseFloat(item.goods_num || 0);
  332. this.totalData.unit = item.unit;
  333. }
  334. })
  335. this.totalData.kindsNum = this.goodsIdArr.length;
  336. },
  337. resetFn(){
  338. this.goodsIdArr = [];
  339. this.selectGoodsId = this.goodsList[0].sku_id;
  340. this.goodsShow = false;
  341. this.totalData.kindsNum = 0;
  342. this.totalData.countNum = 0;
  343. this.totalData.price = 0;
  344. },
  345. /**
  346. * 监听扫码事件
  347. * @param {Object} e
  348. */
  349. listenerScancode(e){
  350. const clearBarCode = ()=> {
  351. this.scanCode = { lastTime: 0, code: '' }
  352. }
  353. // #ifdef H5
  354. var currCode = e.keyCode || e.which || e.charCode;
  355. // #endif
  356. // #ifdef APP-PLUS
  357. const keycode = ['keycode_7': 0, 'keycode_8': 1, 'keycode_9': 2, 'keycode_10': 3, 'keycode_11': 4, 'keycode_12':
  358. 5, 'keycode_13': 6, 'keycode_14': 7, 'keycode_15': 8, 'keycode_16': 9
  359. ];
  360. var currCode = keyArr['keycode_' + e.keyCode] || '';
  361. // #endif
  362. var currTime = new Date().getTime();
  363. if (this.scanCode.lastTime > 0) {
  364. if (currTime - this.scanCode.lastTime <= 100) {
  365. this.scanCode.code += String.fromCharCode(currCode);
  366. } else if (currTime - this.scanCode.lastTime > 500) {
  367. // 输入间隔500毫秒清空
  368. clearBarCode();
  369. }
  370. } else {
  371. this.scanCode.code = String.fromCharCode(currCode);
  372. }
  373. this.scanCode.lastTime = currTime;
  374. // #ifdef H5
  375. if (currCode == 13) {
  376. // #endif
  377. // #ifdef APP-PLUS
  378. if (e.keyCode == 66) {
  379. // #endif
  380. if (this.scanCode.code && this.scanCode.code.length >= 8) this.getSkuBycode(this.scanCode.code)
  381. // 回车输入后清空
  382. clearBarCode();
  383. }
  384. },
  385. /**
  386. * 获取商品信息通过条形码
  387. */
  388. getSkuBycode(code){
  389. this.$api.sendRequest({
  390. url: '/cashier/storeapi/goods/skuinfo',
  391. data: {
  392. sku_no: code.trim()
  393. },
  394. success: res => {
  395. if (res.code == 0) {
  396. if (res.data) {
  397. res.data.goods_num = 0;
  398. this.selectGoods(res.data)
  399. } else {
  400. this.$util.showToast({
  401. title: '未找到该商品!'
  402. })
  403. }
  404. } else {
  405. this.$util.showToast({
  406. title: res.message,
  407. })
  408. }
  409. }
  410. })
  411. }
  412. }
  413. };
  414. </script>
  415. <style lang="scss">
  416. .form-content {
  417. display: flex;
  418. flex-wrap: wrap;
  419. margin-top: 0.2rem;
  420. .store-info {
  421. .form-inline {
  422. padding-left: 0.05rem;
  423. }
  424. }
  425. .form-item {
  426. margin-bottom: 0.1rem;
  427. display: flex;
  428. .form-label {
  429. width: 1.3rem;
  430. text-align: right;
  431. padding-right: 0.1rem;
  432. box-sizing: border-box;
  433. height: 0.32rem;
  434. line-height: 0.32rem;
  435. .required {
  436. color: red;
  437. margin-right: 0.03rem;
  438. }
  439. }
  440. .form-inline {
  441. width: 2.4rem;
  442. line-height: 0.32rem;
  443. margin-right: 0.1rem;
  444. box-sizing: border-box;
  445. .form-input {
  446. border-width: 0.01rem;
  447. border-style: solid;
  448. background-color: #fff;
  449. color: rgba(0, 0, 0, 0.85);
  450. border-radius: 0.02rem;
  451. padding-left: 0.1rem;
  452. height: 0.32rem;
  453. line-height: 0.32rem;
  454. font-size: 0.14rem;
  455. border-color: #e6e6e6;
  456. border-radius: 0.02rem;
  457. }
  458. }
  459. }
  460. }
  461. .content-wrap {
  462. position: relative;
  463. padding: 0.15rem;
  464. background-color: #fff;
  465. @extend %body-overhide;
  466. box-sizing: border-box;
  467. .title {
  468. font-size: 0.18rem;
  469. margin-bottom: 0.2rem;
  470. text-align: center;
  471. }
  472. .table-wrap {
  473. position: relative;
  474. margin-top: 40rpx;
  475. border: 1rpx solid #ccc;
  476. .table-head {
  477. background-color: #f7f7f7;
  478. }
  479. .table-body {
  480. overflow: auto;
  481. max-height: 5.5rem;
  482. @extend %body-overhide;
  483. .table-tr {
  484. &:nth-child(1) {
  485. position: absolute;
  486. left: 0;
  487. right: 0;
  488. background: #fff;
  489. z-index: 2;
  490. }
  491. &:nth-child(2) {
  492. margin-top: 0.51rem;
  493. }
  494. &:last-of-type .table-td {
  495. border-bottom: 0;
  496. }
  497. }
  498. }
  499. .table-tr {
  500. display: flex;
  501. }
  502. .table-th,
  503. .table-td {
  504. display: flex;
  505. align-items: center;
  506. justify-content: center;
  507. padding: 0.15rem 0.3rem;
  508. border-bottom: 0.01rem solid #ccc;
  509. border-right: 0.01rem solid #ccc;
  510. text-align: center;
  511. &:last-of-type {
  512. border-right: 0;
  513. justify-content: flex-end;
  514. }
  515. &.goods-name {
  516. justify-content: flex-start;
  517. image {
  518. width: 0.45rem;
  519. height: 0.45rem;
  520. flex-shrink: 0;
  521. }
  522. .name {
  523. margin-left: 0.1rem;
  524. }
  525. }
  526. }
  527. .goods-num {
  528. border: 0.01rem solid #eee;
  529. height: 0.35rem;
  530. line-height: 0.35rem;
  531. border-radius: 0.05rem;
  532. }
  533. input {
  534. font-size: $uni-font-size-base;
  535. }
  536. .delete {
  537. margin: 0;
  538. font-size: $uni-font-size-base;
  539. background-color: $uni-color-primary;
  540. color: #fff;
  541. }
  542. .table-empty {
  543. justify-content: center;
  544. padding: 0.3rem;
  545. color: #999;
  546. }
  547. }
  548. .action-wrap {
  549. position: absolute;
  550. bottom: 0;
  551. left: 0;
  552. right: 0;
  553. display: flex;
  554. justify-content: space-between;
  555. padding: 0.1rem 0.15rem 0.2rem;
  556. align-items: center;
  557. border-top: 0.01rem solid #ccc;
  558. .btn-wrap {
  559. display: flex;
  560. align-items: center;
  561. justify-content: center;
  562. button {
  563. margin: 0;
  564. min-width: 2.75rem;
  565. height: 0.4rem;
  566. line-height: 0.4rem;
  567. font-size: $uni-font-size-base;
  568. &.stockout-btn {
  569. margin-right: 0.15rem;
  570. background-color: $uni-color-primary;
  571. color: #fff;
  572. }
  573. }
  574. }
  575. }
  576. .select-goods-input {
  577. position: relative;
  578. input {
  579. flex: 1;
  580. font-size: $uni-font-size-base;
  581. }
  582. }
  583. .select-goods-frame {
  584. position: absolute;
  585. z-index: 2;
  586. padding: 0.05rem 0;
  587. top: 0.45rem;
  588. left: 0;
  589. width: 5rem;
  590. height: 5rem;
  591. background-color: #fff;
  592. box-shadow: 0 0 36rpx rgba(0, 0, 0, 0.4);
  593. .goods-item {
  594. padding: 10rpx 30rpx;
  595. line-height: 1.5;
  596. text-align: left;
  597. &.select {
  598. background-color: $uni-color-primary;
  599. color: #fff;
  600. }
  601. }
  602. .goods-item-empty {
  603. padding: 10rpx 30rpx;
  604. line-height: 1.5;
  605. text-align: center;
  606. }
  607. }
  608. }
  609. </style>