create.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <view class="app-main app-content">
  3. <view class="express-form-container">
  4. <!-- 订单信息显示 -->
  5. <view class="order-info-section" v-if="orderInfo">
  6. <view class="section-title">
  7. 订单信息
  8. <button class="admin-button-com mini-btn" @click="goToModifyPage" style="float: right;">修改</button>
  9. </view>
  10. <view class="info-item">
  11. <text class="label">下单客户:</text>
  12. <text class="value">{{ orderInfo.customName }}</text>
  13. </view>
  14. <view class="info-item">
  15. <text class="label">下单手机:</text>
  16. <text class="value">{{ orderInfo.bookMobile }}</text>
  17. </view>
  18. <view class="info-item">
  19. <text class="label">订单编号:</text>
  20. <text class="value">{{ orderInfo.orderSn }}</text>
  21. </view>
  22. <view class="info-item">
  23. <text class="label">收货姓名:</text>
  24. <text class="value">{{ expressForm.user_name }}</text>
  25. </view>
  26. <view class="info-item">
  27. <text class="label">手机号码:</text>
  28. <text class="value">{{ expressForm.user_phone }}</text>
  29. </view>
  30. <view class="info-item">
  31. <text class="label">详细地址:</text>
  32. <view class="value-container">
  33. <text class="value">{{orderInfo.address}}{{orderInfo.floor}}</text>
  34. <view v-if="orderInfo.fullAddress!=orderInfo.showAddress && orderInfo.showAddress!=''" class="secondary-address">
  35. <text style="color:#a7a0a0;">{{ orderInfo.showAddress }}</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 包裹信息 -->
  41. <view class="form-section">
  42. <view class="section-title">商品信息</view>
  43. <view class="form-item">
  44. <text class="item-label">商品数量</text>
  45. <view class="item-value">
  46. <input class="item-input" type="number" v-model="expressForm.packageNum" placeholder="请输入包裹数量" />
  47. </view>
  48. </view>
  49. <view class="form-item required">
  50. <text class="item-label">商品重量</text>
  51. <view class="item-value">
  52. <input class="item-input" type="digit" v-model="expressForm.weight" placeholder="公斤" @focus="expressForm.weight=''" />
  53. </view>
  54. </view>
  55. <view class="form-item">
  56. <text class="item-label">配送费用</text>
  57. <view class="item-value">
  58. <text class="fee-text">¥{{ deliveryFee }}</text>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 操作按钮 -->
  63. <view class="button-section" style="display: flex; justify-content: center; gap: 50rpx;">
  64. <button class="admin-button-com blue big" @click="queryDeliveryFee">
  65. 查运费
  66. </button>
  67. <button class="admin-button-com blue big" style="padding: 0 30rpx; display: flex; align-items: center; justify-content: center;" @click="submitExpress">提交</button>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import { getStoreFee, createExpressOrder } from '@/api/shop-express'
  74. import { getDetail } from '@/api/order'
  75. export default {
  76. name: 'ExpressCreate',
  77. data() {
  78. return {
  79. orderId: '',
  80. orderInfo: null,
  81. // 配送表单数据
  82. expressForm: {
  83. packageNum: 1,
  84. price: 0,
  85. weight:'',
  86. user_name: '',
  87. user_phone: '',
  88. user_lng: 0,
  89. user_lat: 0,
  90. user_address: '',
  91. note: ''
  92. },
  93. cargo: {
  94. name: '',
  95. price: 0,
  96. type: 0,
  97. num: 0,
  98. },
  99. // 配送费用
  100. deliveryFee: 0,
  101. refreshPage:0
  102. }
  103. },
  104. onLoad(options) {
  105. if (options.orderId) {
  106. this.orderId = options.orderId
  107. }
  108. //返回上一页时刷新
  109. let pages = getCurrentPages();
  110. let prevPage = pages[ pages.length - 2 ];
  111. prevPage.$vm.refreshPage = 1
  112. },
  113. onShow() {
  114. if(this.orderId){
  115. this.getOrderDetail()
  116. } else {
  117. setTimeout(() => {
  118. this.getOrderDetail()
  119. }, 100)
  120. }
  121. if(this.refreshPage == 1){
  122. this.getOrderDetail()
  123. this.refreshPage = 0
  124. }
  125. },
  126. methods: {
  127. init(){},
  128. /**
  129. * 跳转到修改订单页面
  130. */
  131. goToModifyPage() {
  132. uni.navigateTo({
  133. url: `/admin/order/modify?id=${this.orderId}`
  134. })
  135. },
  136. /**
  137. * 获取订单详情
  138. */
  139. async getOrderDetail() {
  140. const res = await getDetail({ id: this.orderId })
  141. if (res.code === 1) {
  142. this.orderInfo = res.data
  143. this.expressForm.weight = res.data.weight?parseFloat(res.data.weight):0
  144. this.expressForm.price = res.data.prePrice || 0
  145. // 自动填充收货信息
  146. this.expressForm.user_name = res.data.receiveUserName || res.data.bookName || ''
  147. this.expressForm.user_phone = res.data.receiveMobile || res.data.bookMobile || ''
  148. this.expressForm.user_address = res.data.dist + res.data.address + res.data.floor
  149. this.expressForm.user_lng = res.data.long || 0
  150. this.expressForm.user_lat = res.data.lat || 0
  151. }
  152. },
  153. /**
  154. * 查询配送运费
  155. */
  156. async queryDeliveryFee() {
  157. // 验证必填字段
  158. if (!this.expressForm.weight || Number(this.expressForm.weight) <= 0) {
  159. this.$msg('请输入重量')
  160. return
  161. }
  162. if (!this.expressForm.user_name) {
  163. this.$msg('收货人姓名不能为空')
  164. return
  165. }
  166. if (!this.expressForm.user_phone) {
  167. this.$msg('收货人手机号不能为空')
  168. return
  169. }
  170. if (!this.expressForm.user_address) {
  171. this.$msg('收货地址不能为空')
  172. return
  173. }
  174. const data = {
  175. orderId: this.orderId,
  176. price: this.expressForm.price,
  177. weight: Number(this.expressForm.weight),
  178. packageNum: this.expressForm.packageNum,
  179. user_name: this.expressForm.user_name,
  180. user_phone: this.expressForm.user_phone,
  181. user_address: this.expressForm.user_address,
  182. user_lng: this.expressForm.user_lng,
  183. user_lat: this.expressForm.user_lat
  184. }
  185. const res = await getStoreFee(data)
  186. if (res.code === 1) {
  187. const deliveryFee = res.data.est_fee || '0'
  188. this.deliveryFee = deliveryFee/100.0
  189. this.$msg('运费查询成功')
  190. }
  191. },
  192. /**
  193. * 提交配送订单
  194. */
  195. async submitExpress() {
  196. // 验证必填字段
  197. if (!this.expressForm.weight || Number(this.expressForm.weight) <= 0) {
  198. this.$msg('请输入重量')
  199. return
  200. }
  201. if (!this.expressForm.user_name) {
  202. this.$msg('收货人姓名不能为空')
  203. return
  204. }
  205. if (!this.expressForm.user_phone) {
  206. this.$msg('收货人手机号不能为空')
  207. return
  208. }
  209. if (!this.expressForm.user_address) {
  210. this.$msg('收货地址不能为空')
  211. return
  212. }
  213. this.$util.confirmModal({content: '确认呼叫跑腿?'}, async () => {
  214. const data = {
  215. orderId: this.orderId,
  216. weight: Number(this.expressForm.weight),
  217. packageNum: this.expressForm.packageNum,
  218. user_name: this.expressForm.user_name,
  219. user_phone: this.expressForm.user_phone,
  220. user_address: this.expressForm.user_address,
  221. user_lng: this.expressForm.user_lng,
  222. user_lat: this.expressForm.user_lat,
  223. note: this.expressForm.note
  224. }
  225. const res = await createExpressOrder(data)
  226. if (res.code === 1) {
  227. this.$msg('提交成功')
  228. // 返回订单列表页面
  229. setTimeout(() => {
  230. uni.navigateBack()
  231. }, 1500)
  232. }
  233. })
  234. }
  235. }
  236. }
  237. </script>
  238. <style lang="scss" scoped>
  239. .app-content {
  240. padding: 20upx;
  241. background-color: #f5f5f5;
  242. min-height: 100vh;
  243. }
  244. .express-form-container {
  245. max-width: 750upx;
  246. margin: 0 auto;
  247. }
  248. .order-info-section {
  249. background: white;
  250. border-radius: 12upx;
  251. padding: 30upx;
  252. margin-bottom: 20upx;
  253. .info-item {
  254. display: flex;
  255. align-items: center;
  256. margin-bottom: 20upx;
  257. &:last-child {
  258. margin-bottom: 0;
  259. }
  260. .label {
  261. width: 150upx;
  262. color: #666;
  263. font-size: 28upx;
  264. }
  265. .value-container {
  266. flex: 1;
  267. }
  268. .value {
  269. color: black;
  270. font-size: 28upx;
  271. }
  272. .secondary-address {
  273. margin-top: 10upx;
  274. font-size: 28upx;
  275. }
  276. }
  277. }
  278. .form-section {
  279. background: white;
  280. border-radius: 12upx;
  281. padding: 30upx;
  282. margin-bottom: 20upx;
  283. }
  284. .section-title {
  285. font-size: 32upx;
  286. font-weight: bold;
  287. color: #333;
  288. margin-bottom: 30upx;
  289. padding-bottom: 20upx;
  290. border-bottom: 2upx solid #eee;
  291. }
  292. .section-header {
  293. display: flex;
  294. justify-content: space-between;
  295. align-items: center;
  296. margin-bottom: 30upx;
  297. padding-bottom: 20upx;
  298. border-bottom: 2upx solid #eee;
  299. .title {
  300. font-size: 32upx;
  301. font-weight: bold;
  302. color: #333;
  303. }
  304. }
  305. .form-item {
  306. display: flex;
  307. align-items: flex-start;
  308. margin-bottom: 20upx;
  309. &:last-child {
  310. margin-bottom: 0;
  311. }
  312. &.required .item-label::after {
  313. content: '*';
  314. color: #ff4d4f;
  315. margin-left: 4upx;
  316. }
  317. .item-label {
  318. width: 140upx;
  319. color: #333;
  320. font-size: 28upx;
  321. padding-top: 16upx;
  322. flex-shrink: 0;
  323. }
  324. .item-value {
  325. flex: 1;
  326. display: flex;
  327. align-items: center;
  328. min-height: 80upx;
  329. .fee-text {
  330. color: #ff2842;
  331. font-weight: bold;
  332. font-size: 36upx;
  333. line-height: 80upx;
  334. }
  335. }
  336. .item-input {
  337. width: 100%;
  338. height: 80upx;
  339. line-height: 80upx;
  340. border: 2upx solid #eee;
  341. border-radius: 8upx;
  342. padding: 0 20upx;
  343. font-size: 28upx;
  344. background: #fff;
  345. &:focus {
  346. border-color: #007aff;
  347. }
  348. }
  349. .item-textarea {
  350. flex: 1;
  351. max-height: 150upx;
  352. min-height: 80upx;
  353. border: 2upx solid #eee;
  354. border-radius: 8upx;
  355. padding: 20upx;
  356. font-size: 28upx;
  357. background: #fff;
  358. &.large {
  359. min-height: 160upx;
  360. }
  361. &:focus {
  362. border-color: #007aff;
  363. }
  364. }
  365. }
  366. .fee-display {
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. padding: 30upx;
  371. background: #f0f9ff;
  372. border-radius: 12upx;
  373. border: 1upx solid #09C567;
  374. .fee-label {
  375. font-size: 32upx;
  376. color: #333;
  377. font-weight: bold;
  378. }
  379. .fee-amount {
  380. font-size: 36upx;
  381. color: #ff4d4f;
  382. font-weight: bold;
  383. margin-left: 20upx;
  384. }
  385. }
  386. .button-section {
  387. margin-top: 40upx;
  388. display: flex;
  389. gap: 20upx;
  390. }
  391. .express-button {
  392. flex: 1;
  393. height: 88upx;
  394. line-height: 88upx;
  395. border-radius: 12upx;
  396. font-size: 32upx;
  397. font-weight: bold;
  398. border: none;
  399. &.query-button {
  400. background: #f0f9ff;
  401. color: #09C567;
  402. border: 2upx solid #09C567;
  403. &:disabled {
  404. background: #f5f5f5;
  405. color: #ccc;
  406. border-color: #ddd;
  407. }
  408. }
  409. &.submit-button {
  410. background: #09C567;
  411. color: white;
  412. &:disabled {
  413. background: #ccc;
  414. }
  415. }
  416. }
  417. </style>