index.vue 15 KB

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