weight-modify.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="container">
  3. <u--form ref="formRef" :model="form" :rules="rules" label-width="165px" label-position="top"
  4. :labelStyle="{ fontSize: '32rpx' }" errorType="toast">
  5. <!-- 仓库选择 -->
  6. <u-form-item label="" prop="godownName">
  7. <view class="input-group">
  8. <u-input :customStyle="customStyle" :placeholder-style="placeholderStyle" v-model="selectedWarehouse"
  9. placeholder="请选择仓库" readonly border="surround" />
  10. <u-button :customStyle="customStyle" type="info" color="#a4adb3" @click="openWarehouseSelector"
  11. text="选择" />
  12. </view>
  13. </u-form-item>
  14. <!-- 物流单号输入 -->
  15. <u-form-item label="" prop="packageCode">
  16. <u-input :placeholderStyle="placeholderStyle" :customStyle="customStyle" v-model="form.packageCode"
  17. placeholder="扫描/输入物流单号" border="surround" name="packageCode" />
  18. </u-form-item>
  19. <!-- 重量输入 -->
  20. <u-form-item label="重量(kg)" prop="actualWeight">
  21. <u-input :placeholderStyle="placeholderStyle" :customStyle="customStyle" v-model="form.actualWeight"
  22. placeholder="请输入重量" border="surround" name="actualWeight" type="number" />
  23. </u-form-item>
  24. <!-- 图片上传 -->
  25. <u-form-item label="上传图片" prop="imgUrlList">
  26. <cy-upload v-model:filename="form.imgUrlList" name="imgUrlList" :limit="10" :max-size="1024 * 1024">
  27. </cy-upload>
  28. </u-form-item>
  29. </u--form>
  30. <!-- 底部按钮 -->
  31. <view class="fixed-bottom">
  32. <u-button size="large" type="warning" @click="scanCode" text="扫码" class="scan-button" />
  33. <u-button size="large" v-permission="'app:express:changeWeight:confirm'" type="success" @click="submitForm"
  34. text="提交" class="submit-button" />
  35. </view>
  36. <WarehouseSelector v-model:show="showSelector" @warehouse-selected="handleWarehouseSelected" />
  37. </view>
  38. </template>
  39. <script setup>
  40. import {
  41. ref,
  42. reactive,
  43. onUnmounted
  44. } from 'vue';
  45. import {
  46. onLoad,
  47. onShow
  48. } from '@dcloudio/uni-app'
  49. import cyUpload from '@/components/cy-upload/index.vue'
  50. import WarehouseSelector from './components/WarehouseSelector.vue';
  51. const placeholderStyle = "font-size:32rpx"
  52. const customStyle = reactive({
  53. height: '90rpx'
  54. })
  55. const formRef = ref(null);
  56. const selectedWarehouse = ref('');
  57. const showSelector = ref(false);
  58. const form = ref({
  59. "packageCode": "",
  60. "batchNum": "",
  61. "godownId": '',
  62. "godownName": '',
  63. "otherInfo": "",
  64. "actualWeight": '',
  65. "imgUrlList": []
  66. });
  67. const rules = {
  68. packageCode: [{
  69. required: true,
  70. message: '请输入物流单号',
  71. trigger: 'blur'
  72. }],
  73. actualWeight: [{
  74. required: true,
  75. message: '请输入重量',
  76. trigger: 'blur'
  77. }],
  78. godownId: [{
  79. required: true,
  80. message: '请选择仓库',
  81. trigger: 'blur'
  82. }]
  83. };
  84. function openWarehouseSelector() {
  85. showSelector.value = true;
  86. }
  87. //选择仓库之后后处理
  88. function handleWarehouseSelected(item) {
  89. selectedWarehouse.value = item.godownName || ''
  90. form.value.godownId = item.id || ''
  91. form.value.godownName = item.godownName || ''
  92. }
  93. //获取用户绑定的仓库
  94. function getUserBindWarehouse() {
  95. uni.$u.http.get('/app/appUser/getUserBindGodown').then(res => {
  96. if (res.code == 200) {
  97. selectedWarehouse.value = res.data?.godownName || ''
  98. form.value.godownId = res.data?.id || ''
  99. form.value.godownName = res.data?.godownName || ''
  100. }
  101. })
  102. }
  103. function scanCode() {
  104. uni.scanCode({
  105. success: (res) => {
  106. form.value.packageCode = res.result;
  107. },
  108. fail: (err) => {
  109. uni.$u.toast('扫码失败')
  110. }
  111. });
  112. }
  113. function submitForm() {
  114. formRef.value.validate().then((valid) => {
  115. if (valid) {
  116. uni.$u.http.post('/app/ordersign/changeWeight', form.value).then(res => {
  117. if (res.code == 200) {
  118. uni.$u.toast('重量修改成功')
  119. let text = form.value.packageCode + '已提交审核'
  120. uni.$u.ttsModule.speak(text)
  121. } else {
  122. let text = form.value.packageCode + '订单不存在'
  123. uni.$u.ttsModule.speak(text)
  124. }
  125. })
  126. }
  127. });
  128. }
  129. // #ifdef APP-PLUS
  130. const { unregister } = uni.$u.useEventListener((e) => {
  131. form.value.packageCode = e.barcode
  132. });
  133. // #endif
  134. onLoad(() => {
  135. getUserBindWarehouse()
  136. })
  137. onUnmounted(() => {
  138. // #ifdef APP-PLUS
  139. unregister();
  140. // #endif
  141. });
  142. </script>
  143. <style>
  144. page {
  145. background-color: #ffffff;
  146. }
  147. </style>
  148. <style scoped>
  149. .container {
  150. display: flex;
  151. flex-direction: column;
  152. padding: 20px;
  153. }
  154. .input-group {
  155. display: flex;
  156. gap: 10px;
  157. margin-bottom: 30rpx;
  158. }
  159. .input-group :deep(.u-button) {
  160. width: 160rpx
  161. }
  162. .input-group .u-input {
  163. background-color: #fff;
  164. }
  165. .fixed-bottom {
  166. position: fixed;
  167. bottom: 0;
  168. left: 0;
  169. right: 0;
  170. display: flex;
  171. gap: 20rpx;
  172. padding: 20rpx;
  173. background-color: white;
  174. border-top: 1px solid #eee;
  175. }
  176. .scan-button {
  177. flex: 1;
  178. background-color: #ff9500 !important;
  179. border-color: #ff9500 !important;
  180. }
  181. .submit-button {
  182. flex: 1;
  183. background-color: #52c41a !important;
  184. border-color: #52c41a !important;
  185. }
  186. </style>