index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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 v-if="valiFormData.search_order_choice === 1" 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. <printer-list-scan></printer-list-scan>
  93. </view>
  94. </template>
  95. <script>
  96. import permision from '@/common/permission.js';
  97. import printerListScan from '@/components/printerListScan';
  98. import { ref, reactive, nextTick, provide } from 'vue';
  99. import { instockScanURL, outStockScanURL, weighScanURL, checkWaybillGoodsURL, getWarehouseSpaceURL, getBindParamsURL, getPrinterListURL } from '@/utils/api.js';
  100. export default {
  101. data() {
  102. const token = ref(null);
  103. const user = ref(null);
  104. const loading = ref(false);
  105. return {
  106. token,
  107. user,
  108. messageType: '',
  109. messageText: '',
  110. batchOptions: [],
  111. spaces: [],
  112. printerList: {},
  113. instockHistory: [],
  114. focusType: true,
  115. loading,
  116. // 校验表单数据
  117. valiFormData: {
  118. orderNum: '',
  119. batch_number: '',
  120. space_code: '',
  121. weight: '',
  122. search_pkg: true,
  123. typing: true,
  124. search_order: true,
  125. search_order_choice: 1
  126. },
  127. searchOrderChoice: [
  128. {
  129. text: '更新为已入库,状态为【已入库】',
  130. value: 1
  131. },
  132. {
  133. text: '更新为已出库,状态为【已出库】',
  134. value: 2
  135. },
  136. {
  137. text: '称重计费',
  138. value: 3
  139. }
  140. ]
  141. };
  142. },
  143. provide() {
  144. return {
  145. printerList: this.printerList
  146. };
  147. },
  148. computed: {
  149. rules: function () {
  150. return {
  151. orderNum: {
  152. rules: [
  153. {
  154. required: this.valiFormData.search_order_choice !== 2,
  155. errorMessage: '单号不能为空'
  156. }
  157. ]
  158. },
  159. weight: {
  160. rules: [
  161. {
  162. required: true,
  163. errorMessage: '重量不能为空'
  164. },
  165. {
  166. format: 'number',
  167. errorMessage: '重量只能输入数字'
  168. }
  169. ]
  170. }
  171. };
  172. },
  173. spaceRes: function () {
  174. const res = this.spaces.find((item) => item.value === this.valiFormData.space_code);
  175. console.log(res);
  176. return res?.text;
  177. }
  178. },
  179. onShow() {
  180. this.focusType = true;
  181. this.loading = false;
  182. this.token = uni.getStorageSync('token');
  183. this.user = uni.getStorageSync('user');
  184. this.getWarehouseSpace();
  185. this.getBindParams();
  186. this.getPrinterList();
  187. },
  188. onHide() {
  189. this.focusType = false;
  190. this.loading = false;
  191. },
  192. onReady() {},
  193. onNavigationBarButtonTap(event) {
  194. if (event.index === 0) {
  195. uni.navigateTo({
  196. url: '/pages/instock/instockLog'
  197. });
  198. }
  199. },
  200. methods: {
  201. getWarehouseSpace() {
  202. uni.request({
  203. url: getWarehouseSpaceURL,
  204. method: 'POST',
  205. header: {
  206. batoken: this.token
  207. },
  208. data: {
  209. code: ''
  210. },
  211. success: (res) => {
  212. if (res.data.code === 1) {
  213. this.spaces = res.data.data.spaces.map((item) => {
  214. return {
  215. text: item.name,
  216. value: item.code
  217. };
  218. });
  219. }
  220. }
  221. });
  222. },
  223. getBindParams() {
  224. uni.request({
  225. url: getBindParamsURL,
  226. method: 'GET',
  227. header: {
  228. batoken: this.token
  229. },
  230. success: (res) => {
  231. if (res.data.code === 1) {
  232. this.batchOptions = res.data.data.batch_number.map((item) => {
  233. return { text: item.name, value: item.id };
  234. });
  235. }
  236. },
  237. fail(e) {
  238. console.log('fail--', e);
  239. }
  240. });
  241. },
  242. getPrinterList() {
  243. uni.request({
  244. url: getPrinterListURL,
  245. method: 'GET',
  246. header: {
  247. batoken: this.token
  248. },
  249. success: (res) => {
  250. if (res.data.code === 1) {
  251. this.printerList = res.data.data.printers;
  252. }
  253. },
  254. fail(e) {
  255. console.log('fail--', e);
  256. }
  257. });
  258. },
  259. batchText(batch_number) {
  260. return this.batchOptions.find((item) => item.value === batch_number)?.text;
  261. },
  262. searchPkgChange() {
  263. this.valiFormData.search_pkg = !this.valiFormData.search_pkg;
  264. this.valiFormData.typing = this.valiFormData.search_pkg;
  265. },
  266. searchOrderChoiceChange() {
  267. this.valiFormData.search_order = !this.valiFormData.search_order;
  268. this.valiFormData.search_order_choice = this.valiFormData.search_order ? 3 : '';
  269. },
  270. reset() {
  271. this.loading = false;
  272. this.focusType = false;
  273. this.valiFormData = {
  274. ...this.valiFormData,
  275. orderNum: '',
  276. // space_code: '',
  277. batch_number: '',
  278. weight: '',
  279. search_pkg: true,
  280. typing: true,
  281. search_order: true
  282. };
  283. nextTick(() => {
  284. this.focusType = true;
  285. });
  286. },
  287. async scan() {
  288. // #ifdef APP-PLUS
  289. let status = await this.checkPermission();
  290. if (status !== 1) {
  291. return;
  292. }
  293. // #endif
  294. uni.scanCode({
  295. success: (res) => {
  296. this.result = res.result;
  297. this.valiFormData.orderNum = res.result;
  298. // this.onsubmit();
  299. },
  300. fail: (err) => {
  301. // 需要注意的是小程序扫码不需要申请相机权限
  302. }
  303. });
  304. },
  305. // #ifdef APP-PLUS
  306. async checkPermission(code) {
  307. let status = permision.isIOS ? await permision.requestIOS('camera') : await permision.requestAndroid('android.permission.CAMERA');
  308. if (status === null || status === 1) {
  309. status = 1;
  310. } else {
  311. uni.showModal({
  312. content: 'Camera permission required',
  313. confirmText: 'Setting',
  314. success: function (res) {
  315. if (res.confirm) {
  316. permision.gotoAppSetting();
  317. }
  318. }
  319. });
  320. }
  321. return status;
  322. },
  323. // #endif
  324. async warehouseScan() {
  325. this.st && clearTimeout(this.st);
  326. if (this.valiFormData.search_order_choice === 1) {
  327. await this.checkWaybillGoods();
  328. } else if (this.valiFormData.search_order_choice === 2) {
  329. await this.scanOutstock();
  330. } else if (this.valiFormData.search_order_choice === 3) {
  331. await this.weighScan();
  332. }
  333. },
  334. async checkWaybillGoods() {
  335. this.loading = true;
  336. uni.request({
  337. url: checkWaybillGoodsURL,
  338. method: 'POST',
  339. header: {
  340. batoken: this.token
  341. },
  342. data: {
  343. order_no: this.valiFormData.orderNum
  344. },
  345. success: (res) => {
  346. this.loading = false;
  347. if (res.data.code === 1 && res.data.data.is_goods_empty) {
  348. this.$refs.alertDialog.open();
  349. } else {
  350. this.instockScan(0);
  351. }
  352. }
  353. });
  354. },
  355. instockScan(is_save_goods) {
  356. uni.request({
  357. url: instockScanURL,
  358. method: 'POST',
  359. header: {
  360. batoken: this.token
  361. },
  362. data: {
  363. order_no: this.valiFormData.orderNum,
  364. weight: this.valiFormData.weight,
  365. space_code: this.valiFormData.space_code,
  366. is_save_goods: is_save_goods
  367. },
  368. success: (res) => {
  369. this.loading = false;
  370. if (res.data.code == 1) {
  371. this.messageType = 'success';
  372. this.messageText = res.data.msg;
  373. this.$refs.message.open();
  374. if (res.data.data.labels && res.data.data.labels.length > 0) {
  375. console.log('有打印面单');
  376. this.printerList.visible = true;
  377. this.printerList.batoken = this.token;
  378. this.printerList.title = '打印尾程面单';
  379. this.printerList.postData = {
  380. order_no: this.valiFormData.orderNum
  381. };
  382. // this.printerList.resetForm = () => resetForm(ruleFormRef.value);
  383. // res.data.data.labels.map((url: string) => {
  384. // let path = fullUrl(url);
  385. // window.open(path, '_blank');
  386. // });
  387. }
  388. const historyItem = {
  389. orderNum: this.valiFormData.orderNum,
  390. createTime: new Date(),
  391. space: this.spaceRes,
  392. type: '入库',
  393. status: true
  394. };
  395. this.instockHistory.unshift(historyItem);
  396. uni.setStorageSync('instockHistory', this.instockHistory);
  397. this.getHistory();
  398. } else {
  399. this.messageType = 'error';
  400. this.messageText = res.data.msg;
  401. this.$refs.message.open();
  402. const historyItem = {
  403. orderNum: this.valiFormData.orderNum,
  404. createTime: new Date(),
  405. space: this.spaceRes,
  406. type: '入库',
  407. status: false
  408. };
  409. this.instockHistory.unshift(historyItem);
  410. uni.setStorageSync('instockHistory', this.instockHistory);
  411. this.getHistory();
  412. }
  413. this.st = setTimeout(() => {
  414. this.reset();
  415. this.st && clearTimeout(this.st);
  416. }, 1000);
  417. }
  418. });
  419. },
  420. scanOutstock() {
  421. console.log(this.valiFormData.orderNum, this.valiFormData.batch_number);
  422. if (this.valiFormData.orderNum.length === 0 && this.valiFormData.batch_number.length === 0) {
  423. this.messageType = 'error';
  424. this.messageText = '单号或批次号至少填一个';
  425. this.$refs.message.open();
  426. return;
  427. }
  428. this.loading = true;
  429. uni.request({
  430. url: outStockScanURL,
  431. method: 'POST',
  432. header: {
  433. batoken: this.token
  434. },
  435. data: {
  436. order_no: this.valiFormData.orderNum,
  437. batch_number: this.valiFormData.batch_number
  438. },
  439. success: (res) => {
  440. this.loading = false;
  441. if (res.data.code == 1) {
  442. this.messageType = 'success';
  443. this.messageText = res.data.msg;
  444. this.$refs.message.open();
  445. if (res.data.data.labels && res.data.data.labels.length > 0) {
  446. console.log('有打印面单');
  447. this.printerList.visible = true;
  448. this.printerList.batoken = this.token;
  449. this.printerList.title = '打印尾程面单';
  450. this.printerList.postData = {
  451. order_no: this.valiFormData.orderNum
  452. };
  453. // res.data.data.labels.map((url: string) => {
  454. // let path = fullUrl(url);
  455. // window.open(path, '_blank');
  456. // });
  457. }
  458. const historyItem = {
  459. orderNum: this.valiFormData.orderNum,
  460. batch_text: this.batchText(this.valiFormData.batch_number),
  461. createTime: new Date(),
  462. type: '出库',
  463. status: true
  464. };
  465. this.instockHistory.unshift(historyItem);
  466. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  467. uni.setStorageSync('instockHistory', this.instockHistory);
  468. this.getHistory();
  469. } else {
  470. this.messageType = 'error';
  471. this.messageText = res.data.msg;
  472. this.$refs.message.open();
  473. const historyItem = {
  474. orderNum: this.valiFormData.orderNum,
  475. batch_text: this.batchText(this.valiFormData.batch_number),
  476. createTime: new Date(),
  477. type: '出库',
  478. status: false
  479. };
  480. this.instockHistory.unshift(historyItem);
  481. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  482. uni.setStorageSync('instockHistory', this.instockHistory);
  483. this.getHistory();
  484. }
  485. this.st = setTimeout(() => {
  486. this.reset();
  487. this.st && clearTimeout(this.st);
  488. }, 1000);
  489. }
  490. });
  491. },
  492. weighScan() {
  493. this.loading = true;
  494. uni.request({
  495. url: weighScanURL,
  496. method: 'POST',
  497. header: {
  498. batoken: this.token
  499. },
  500. data: {
  501. order_no: this.valiFormData.orderNum,
  502. weight: this.valiFormData.weight
  503. },
  504. success: (res) => {
  505. this.loading = false;
  506. if (res.data.code == 1) {
  507. this.messageType = 'success';
  508. this.messageText = res.data.msg;
  509. this.$refs.message.open();
  510. const historyItem = {
  511. orderNum: this.valiFormData.orderNum,
  512. createTime: new Date(),
  513. type: '称重',
  514. status: true
  515. };
  516. this.instockHistory.unshift(historyItem);
  517. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  518. uni.setStorageSync('instockHistory', this.instockHistory);
  519. this.getHistory();
  520. } else {
  521. this.messageType = 'error';
  522. this.messageText = res.data.msg;
  523. this.$refs.message.open();
  524. const historyItem = {
  525. orderNum: this.valiFormData.orderNum,
  526. createTime: new Date(),
  527. type: '称重',
  528. status: false
  529. };
  530. this.instockHistory.unshift(historyItem);
  531. this.instockHistory.length > 10 && (this.instockHistory.length = 10);
  532. uni.setStorageSync('instockHistory', this.instockHistory);
  533. this.getHistory();
  534. }
  535. this.st = setTimeout(() => {
  536. this.reset();
  537. this.st && clearTimeout(this.st);
  538. }, 1000);
  539. }
  540. });
  541. },
  542. isNotGoods() {
  543. this.instockScan(0);
  544. },
  545. dialogConfirm() {
  546. console.log('点击确认');
  547. this.instockScan(1);
  548. },
  549. dialogClose() {
  550. this.instockScan(0);
  551. },
  552. onsubmit() {
  553. this.printerList.visible = true;
  554. this.printerList.batoken = this.token;
  555. this.printerList.title = '打印尾程面单';
  556. this.printerList.postData = {
  557. order_no: this.valiFormData.orderNum
  558. };
  559. // this.$refs.valiForm
  560. // .validate()
  561. // .then((res) => {
  562. // this.warehouseScan();
  563. // })
  564. // .catch((err) => {
  565. // console.log('err', err);
  566. // });
  567. },
  568. getHistory() {
  569. // this.instockHistory = uni.getStorageSync('history')
  570. }
  571. }
  572. };
  573. </script>
  574. <style lang="scss">
  575. .example {
  576. padding: 15px;
  577. background-color: #fff;
  578. }
  579. .checkbox-cum {
  580. margin-bottom: 20rpx;
  581. font-size: 14rpx;
  582. }
  583. .sub-choice {
  584. margin-bottom: 20rpx;
  585. margin-left: 20rpx;
  586. font-size: 14rpx;
  587. }
  588. .button-group {
  589. margin-top: 15px;
  590. display: flex;
  591. flex-direction: row;
  592. justify-content: space-around;
  593. button {
  594. display: flex;
  595. align-items: center;
  596. justify-content: center;
  597. height: 35px;
  598. width: 50%;
  599. margin-left: 10px;
  600. font-size: 16rpx;
  601. }
  602. .uni-icons {
  603. margin-right: 10px;
  604. }
  605. }
  606. .weight-right {
  607. padding-right: 10rpx;
  608. font-size: 14rpx;
  609. }
  610. .history {
  611. display: flex;
  612. width: 100%;
  613. flex-direction: column;
  614. justify-items: start;
  615. .title {
  616. padding: 20rpx;
  617. font-size: 24rpx;
  618. font-weight: 600;
  619. }
  620. .code {
  621. font-weight: 600;
  622. }
  623. .item {
  624. padding: 20rpx;
  625. font-size: 20rpx;
  626. color: #666;
  627. .status {
  628. padding-left: 20rpx;
  629. }
  630. .fail {
  631. font-weight: 600;
  632. color: #f00;
  633. }
  634. }
  635. }
  636. </style>