index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <view class="container">
  3. <view class="example">
  4. <!-- 基础表单校验 -->
  5. <uni-forms ref="valiForm" label-align="right" :rules="rules" :modelValue="valiFormData">
  6. <uni-forms-item label="单号" :required="valiFormData.search_order_choice !== 2" name="orderNum">
  7. <uni-easyinput v-model="valiFormData.orderNum" placeholder="请输入单号" suffixIcon="scan" :focus="focusType" @iconClick="scan" />
  8. </uni-forms-item>
  9. <uni-forms-item v-if="valiFormData.search_order_choice === 2" label="批次号" name="batch_number">
  10. <uni-data-select v-model="valiFormData.batch_number" :localdata="batchOptions" placeholder="请选择批次号"></uni-data-select>
  11. </uni-forms-item>
  12. <uni-forms-item label="仓位编码" name="space_code">
  13. <uni-data-select v-model="valiFormData.space_code" :localdata="spaces" placeholder="请选择仓位编码"></uni-data-select>
  14. </uni-forms-item>
  15. <uni-forms-item v-if="valiFormData.search_order_choice !== 2" label="重量" required name="weight">
  16. <uni-easyinput
  17. v-model="valiFormData.weight"
  18. placeholder="请输入重量"
  19. oninput="value=value.replace(/[^\d.]/g,'').replace(/^\./g, '').replace(/\.{2,}/g, '').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').match(/^\d*(\.?\d{0,2})/g)[0] || null"
  20. >
  21. <template #right>
  22. <view class="weight-right">KG</view>
  23. </template>
  24. </uni-easyinput>
  25. </uni-forms-item>
  26. <uni-forms-item>
  27. <view @click="searchPkgChange" class="checkbox-cum" :style="{ color: valiFormData.search_pkg ? '#007AFF' : 'gray' }">
  28. <checkbox :checked="valiFormData.search_pkg" @click="searchPkgChange" />
  29. 搜索寄存包裹
  30. </view>
  31. <view class="sub-choice">
  32. <checkbox :disabled="!valiFormData.search_pkg" :checked="valiFormData.typing" />
  33. <text
  34. @click="
  35. () => {
  36. if (valiFormData.search_pkg) {
  37. valiFormData.typing = !valiFormData.typing;
  38. }
  39. }
  40. "
  41. :style="{ color: valiFormData.search_pkg && valiFormData.typing ? '#007AFF' : 'gray' }"
  42. >
  43. 包裹寄存、代购、运单都找不到时手工添加包裹
  44. </text>
  45. </view>
  46. <view @click="searchOrderChoiceChange" class="checkbox-cum" :style="{ color: valiFormData.search_order ? '#007AFF' : 'gray' }">
  47. <checkbox :checked="valiFormData.search_order" @click="searchOrderChoiceChange" />
  48. 搜索运单
  49. </view>
  50. <view>
  51. <uni-data-checkbox :disabled="!valiFormData.search_order" v-model="valiFormData.search_order_choice" :localdata="searchOrderChoice" />
  52. </view>
  53. </uni-forms-item>
  54. </uni-forms>
  55. <view class="button-group">
  56. <button type="info" @click="reset">重置</button>
  57. <button type="primary" @click="onsubmit" :loading="loading">
  58. <uni-icons v-if="!loading" type="checkmarkempty" size="18" color="white"></uni-icons>
  59. 提交
  60. </button>
  61. </view>
  62. </view>
  63. <view class="history">
  64. <view class="item" v-for="(item, i) in instockHistory.slice(0, 5)" :key="i">
  65. <text class="code" :style="{ color: item.status ? 'green' : '#666' }">
  66. {{ item.orderNum }}
  67. <text v-if="item.batch_text">批次号: {{ item.batch_text }}</text>
  68. <text v-if="item.space">仓位编码: {{ item.space }}</text>
  69. {{ item.type }}
  70. </text>
  71. <uni-icons v-if="item.status" type="checkmarkempty" class="status" size="16" color="green"></uni-icons>
  72. <text class="status fail" v-else>F</text>
  73. <text style="margin-left: 10rpx; font-weight: 300">
  74. {{ '\r\n' + item.createTime }}
  75. </text>
  76. </view>
  77. </view>
  78. <uni-popup ref="message" type="message">
  79. <uni-popup-message :type="messageType" :message="messageText" :duration="2000"></uni-popup-message>
  80. </uni-popup>
  81. <uni-popup ref="alertDialog" type="dialog">
  82. <uni-popup-dialog
  83. type="info"
  84. cancelText="否"
  85. confirmText="是"
  86. title="提示"
  87. content="是否按默认申报(默认申报为:衣服,10件,单价1)"
  88. @confirm="dialogConfirm"
  89. @close="dialogClose"
  90. ></uni-popup-dialog>
  91. </uni-popup>
  92. </view>
  93. </template>
  94. <script>
  95. import permision from '@/common/permission.js';
  96. import { ref, reactive, nextTick } from 'vue';
  97. import { instockScanURL, outStockScanURL, weighScanURL, checkWaybillGoodsURL, getWarehouseSpaceURL, getBindParamsURL } from '@/utils/api.js';
  98. export default {
  99. data() {
  100. const token = ref(null);
  101. const user = ref(null);
  102. const loading = ref(false);
  103. return {
  104. token,
  105. user,
  106. messageType: '',
  107. messageText: '',
  108. batchOptions: [],
  109. spaces: [],
  110. instockHistory: [],
  111. focusType: true,
  112. loading,
  113. // 校验表单数据
  114. valiFormData: {
  115. orderNum: '',
  116. batch_number: '',
  117. space_code: '',
  118. weight: '',
  119. search_pkg: true,
  120. typing: true,
  121. search_order: true,
  122. search_order_choice: 1
  123. },
  124. searchOrderChoice: [
  125. {
  126. text: '更新为已入库,状态为【已入库】',
  127. value: 1
  128. },
  129. {
  130. text: '更新为已出库,状态为【已出库】',
  131. value: 2
  132. },
  133. {
  134. text: '称重计费',
  135. value: 3
  136. }
  137. ]
  138. };
  139. },
  140. computed: {
  141. rules: function () {
  142. return {
  143. orderNum: {
  144. rules: [
  145. {
  146. required: this.valiFormData.search_order_choice !== 2,
  147. errorMessage: '单号不能为空'
  148. }
  149. ]
  150. },
  151. weight: {
  152. rules: [
  153. {
  154. required: true,
  155. errorMessage: '重量不能为空'
  156. },
  157. {
  158. format: 'number',
  159. errorMessage: '重量只能输入数字'
  160. }
  161. ]
  162. }
  163. };
  164. },
  165. spaceRes: function () {
  166. const res = this.spaces.find((item) => item.value === this.valiFormData.space_code);
  167. console.log(res);
  168. return res?.text;
  169. }
  170. },
  171. onShow() {
  172. this.focusType = true;
  173. this.loading = false;
  174. this.token = uni.getStorageSync('token');
  175. this.user = uni.getStorageSync('user');
  176. this.getWarehouseSpace();
  177. this.getBindParams();
  178. },
  179. onHide() {
  180. this.focusType = false;
  181. this.loading = false;
  182. },
  183. onReady() {},
  184. onNavigationBarButtonTap(event) {
  185. if (event.index === 0) {
  186. uni.navigateTo({
  187. url: '/pages/instock/instockLog'
  188. });
  189. }
  190. },
  191. methods: {
  192. getWarehouseSpace() {
  193. uni.request({
  194. url: getWarehouseSpaceURL,
  195. method: 'POST',
  196. header: {
  197. batoken: this.token
  198. },
  199. data: {
  200. code: ''
  201. },
  202. success: (res) => {
  203. if (res.data.code === 1) {
  204. this.spaces = res.data.data.spaces.map((item) => {
  205. return {
  206. text: item.name,
  207. value: item.code
  208. };
  209. });
  210. }
  211. }
  212. });
  213. },
  214. getBindParams() {
  215. uni.request({
  216. url: getBindParamsURL,
  217. method: 'GET',
  218. header: {
  219. batoken: this.token
  220. },
  221. success: (res) => {
  222. if (res.data.code === 1) {
  223. this.batchOptions = res.data.data.batch_number.map((item) => {
  224. return { text: item.name, value: item.id };
  225. });
  226. }
  227. },
  228. fail(e) {
  229. console.log('fail--', e);
  230. }
  231. });
  232. },
  233. batchText(batch_number) {
  234. return this.batchOptions.find((item) => item.value === batch_number).text;
  235. },
  236. searchPkgChange() {
  237. this.valiFormData.search_pkg = !this.valiFormData.search_pkg;
  238. this.valiFormData.typing = this.valiFormData.search_pkg;
  239. },
  240. searchOrderChoiceChange() {
  241. this.valiFormData.search_order = !this.valiFormData.search_order;
  242. this.valiFormData.search_order_choice = this.valiFormData.search_order ? 3 : '';
  243. },
  244. reset() {
  245. this.loading = false;
  246. this.focusType = false;
  247. this.valiFormData = {
  248. ...this.valiFormData,
  249. orderNum: '',
  250. // space_code: '',
  251. batch_number: '',
  252. weight: '',
  253. search_pkg: true,
  254. typing: true,
  255. search_order: true
  256. };
  257. nextTick(() => {
  258. this.focusType = true;
  259. });
  260. },
  261. async scan() {
  262. // #ifdef APP-PLUS
  263. let status = await this.checkPermission();
  264. if (status !== 1) {
  265. return;
  266. }
  267. // #endif
  268. uni.scanCode({
  269. success: (res) => {
  270. this.result = res.result;
  271. this.valiFormData.orderNum = res.result;
  272. // this.onsubmit();
  273. },
  274. fail: (err) => {
  275. // 需要注意的是小程序扫码不需要申请相机权限
  276. }
  277. });
  278. },
  279. // #ifdef APP-PLUS
  280. async checkPermission(code) {
  281. let status = permision.isIOS ? await permision.requestIOS('camera') : await permision.requestAndroid('android.permission.CAMERA');
  282. if (status === null || status === 1) {
  283. status = 1;
  284. } else {
  285. uni.showModal({
  286. content: 'Camera permission required',
  287. confirmText: 'Setting',
  288. success: function (res) {
  289. if (res.confirm) {
  290. permision.gotoAppSetting();
  291. }
  292. }
  293. });
  294. }
  295. return status;
  296. },
  297. // #endif
  298. async warehouseScan() {
  299. this.st && clearTimeout(this.st);
  300. if (this.valiFormData.search_order_choice === 1) {
  301. await this.checkWaybillGoods();
  302. } else if (this.valiFormData.search_order_choice === 2) {
  303. await this.scanOutstock();
  304. } else if (this.valiFormData.search_order_choice === 3) {
  305. await this.weighScan();
  306. }
  307. },
  308. async checkWaybillGoods() {
  309. this.loading = true;
  310. uni.request({
  311. url: checkWaybillGoodsURL,
  312. method: 'POST',
  313. header: {
  314. batoken: this.token
  315. },
  316. data: {
  317. order_no: this.valiFormData.orderNum
  318. },
  319. success: (res) => {
  320. this.loading = false;
  321. if (res.data.code === 1 && res.data.data.is_goods_empty) {
  322. this.$refs.alertDialog.open();
  323. } else {
  324. this.instockScan(0);
  325. }
  326. }
  327. });
  328. },
  329. instockScan(is_save_goods) {
  330. uni.request({
  331. url: instockScanURL,
  332. method: 'POST',
  333. header: {
  334. batoken: this.token
  335. },
  336. data: {
  337. order_no: this.valiFormData.orderNum,
  338. weight: this.valiFormData.weight,
  339. space_code: this.valiFormData.space_code,
  340. is_save_goods: is_save_goods
  341. },
  342. success: (res) => {
  343. this.loading = false;
  344. if (res.data.code == 1) {
  345. this.messageType = 'success';
  346. this.messageText = res.data.msg;
  347. this.$refs.message.open();
  348. if (res.data.data.labels && res.data.data.labels.length > 0) {
  349. console.log('有打印面单');
  350. // res.data.data.labels.map((url: string) => {
  351. // let path = fullUrl(url);
  352. // window.open(path, '_blank');
  353. // });
  354. }
  355. const historyItem = {
  356. orderNum: this.valiFormData.orderNum,
  357. createTime: new Date(),
  358. space: this.spaceRes,
  359. type: '入库',
  360. status: true
  361. };
  362. this.instockHistory.unshift(historyItem);
  363. uni.setStorageSync('instockHistory', this.instockHistory);
  364. this.getHistory();
  365. } else {
  366. this.messageType = 'error';
  367. this.messageText = res.data.msg;
  368. this.$refs.message.open();
  369. const historyItem = {
  370. orderNum: this.valiFormData.orderNum,
  371. createTime: new Date(),
  372. space: this.spaceRes,
  373. type: '入库',
  374. status: false
  375. };
  376. this.instockHistory.unshift(historyItem);
  377. uni.setStorageSync('instockHistory', this.instockHistory);
  378. this.getHistory();
  379. }
  380. this.st = setTimeout(() => {
  381. this.reset();
  382. this.st && clearTimeout(this.st);
  383. }, 1000);
  384. }
  385. });
  386. },
  387. scanOutstock() {
  388. console.log(this.valiFormData.orderNum, this.valiFormData.batch_number);
  389. if (this.valiFormData.orderNum.length === 0 && this.valiFormData.batch_number.length === 0) {
  390. this.messageType = 'error';
  391. this.messageText = '单号或批次号至少填一个';
  392. this.$refs.message.open();
  393. return;
  394. }
  395. this.loading = true;
  396. uni.request({
  397. url: outStockScanURL,
  398. method: 'POST',
  399. header: {
  400. batoken: this.token
  401. },
  402. data: {
  403. order_no: this.valiFormData.orderNum,
  404. batch_number: this.valiFormData.batch_number
  405. },
  406. success: (res) => {
  407. this.loading = false;
  408. if (res.data.code == 1) {
  409. this.messageType = 'success';
  410. this.messageText = res.data.msg;
  411. this.$refs.message.open();
  412. if (res.data.data.labels && res.data.data.labels.length > 0) {
  413. console.log('有打印面单');
  414. // res.data.data.labels.map((url: string) => {
  415. // let path = fullUrl(url);
  416. // window.open(path, '_blank');
  417. // });
  418. }
  419. const historyItem = {
  420. orderNum: this.valiFormData.orderNum,
  421. batch_text: this.batchText(this.valiFormData.batch_number),
  422. createTime: new Date(),
  423. type: '出库',
  424. status: true
  425. };
  426. this.instockHistory.unshift(historyItem);
  427. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  428. uni.setStorageSync('instockHistory', this.instockHistory);
  429. this.getHistory();
  430. } else {
  431. this.messageType = 'error';
  432. this.messageText = res.data.msg;
  433. this.$refs.message.open();
  434. const historyItem = {
  435. orderNum: this.valiFormData.orderNum,
  436. batch_text: this.batchText(this.valiFormData.batch_number),
  437. createTime: new Date(),
  438. type: '出库',
  439. status: false
  440. };
  441. this.instockHistory.unshift(historyItem);
  442. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  443. uni.setStorageSync('instockHistory', this.instockHistory);
  444. this.getHistory();
  445. }
  446. this.st = setTimeout(() => {
  447. this.reset();
  448. this.st && clearTimeout(this.st);
  449. }, 1000);
  450. }
  451. });
  452. },
  453. weighScan() {
  454. this.loading = true;
  455. uni.request({
  456. url: weighScanURL,
  457. method: 'POST',
  458. header: {
  459. batoken: this.token
  460. },
  461. data: {
  462. order_no: this.valiFormData.orderNum,
  463. weight: this.valiFormData.weight
  464. },
  465. success: (res) => {
  466. this.loading = false;
  467. if (res.data.code == 1) {
  468. this.messageType = 'success';
  469. this.messageText = res.data.msg;
  470. this.$refs.message.open();
  471. const historyItem = {
  472. orderNum: this.valiFormData.orderNum,
  473. createTime: new Date(),
  474. type: '称重',
  475. status: true
  476. };
  477. this.instockHistory.unshift(historyItem);
  478. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  479. uni.setStorageSync('instockHistory', this.instockHistory);
  480. this.getHistory();
  481. } else {
  482. this.messageType = 'error';
  483. this.messageText = res.data.msg;
  484. this.$refs.message.open();
  485. const historyItem = {
  486. orderNum: this.valiFormData.orderNum,
  487. createTime: new Date(),
  488. type: '称重',
  489. status: false
  490. };
  491. this.instockHistory.unshift(historyItem);
  492. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  493. uni.setStorageSync('instockHistory', this.instockHistory);
  494. this.getHistory();
  495. }
  496. this.st = setTimeout(() => {
  497. this.reset();
  498. this.st && clearTimeout(this.st);
  499. }, 1000);
  500. }
  501. });
  502. },
  503. isNotGoods() {
  504. this.instockScan(0);
  505. },
  506. dialogConfirm() {
  507. console.log('点击确认');
  508. this.instockScan(1);
  509. },
  510. dialogClose() {
  511. this.instockScan(0);
  512. },
  513. onsubmit() {
  514. this.$refs.valiForm
  515. .validate()
  516. .then((res) => {
  517. this.warehouseScan();
  518. })
  519. .catch((err) => {
  520. console.log('err', err);
  521. });
  522. },
  523. getHistory() {
  524. // this.instockHistory = uni.getStorageSync('history')
  525. }
  526. }
  527. };
  528. </script>
  529. <style lang="scss">
  530. .example {
  531. padding: 15px;
  532. background-color: #fff;
  533. }
  534. .checkbox-cum {
  535. margin-bottom: 20rpx;
  536. font-size: 14rpx;
  537. }
  538. .sub-choice {
  539. margin-bottom: 20rpx;
  540. margin-left: 20rpx;
  541. font-size: 14rpx;
  542. }
  543. .button-group {
  544. margin-top: 15px;
  545. display: flex;
  546. flex-direction: row;
  547. justify-content: space-around;
  548. button {
  549. display: flex;
  550. align-items: center;
  551. justify-content: center;
  552. height: 35px;
  553. width: 50%;
  554. margin-left: 10px;
  555. font-size: 16rpx;
  556. }
  557. .uni-icons {
  558. margin-right: 10px;
  559. }
  560. }
  561. .weight-right {
  562. padding-right: 10rpx;
  563. font-size: 14rpx;
  564. }
  565. .history {
  566. display: flex;
  567. width: 100%;
  568. flex-direction: column;
  569. justify-items: start;
  570. .title {
  571. padding: 20rpx;
  572. font-size: 24rpx;
  573. font-weight: 600;
  574. }
  575. .code {
  576. font-weight: 600;
  577. }
  578. .item {
  579. padding: 20rpx;
  580. font-size: 20rpx;
  581. color: #666;
  582. .status {
  583. padding-left: 20rpx;
  584. }
  585. .fail {
  586. font-weight: 600;
  587. color: #f00;
  588. }
  589. }
  590. }
  591. </style>