index.vue 19 KB

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