detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <!-- 订单详情 -->
  2. <template>
  3. <s-layout title="订单详情" class="index-wrap" navbar="inner">
  4. <!-- 订单状态 TODO -->
  5. <view
  6. class="state-box ss-flex-col ss-col-center ss-row-right"
  7. :style="[
  8. {
  9. marginTop: '-' + Number(statusBarHeight + 88) + 'rpx',
  10. paddingTop: Number(statusBarHeight + 88) + 'rpx',
  11. },
  12. ]"
  13. >
  14. <view class="ss-flex ss-m-t-32 ss-m-b-20">
  15. <view class="ss-font-40">{{ state.orderInfo.phone.slice(-4) }}</view>
  16. </view>
  17. <view class="ss-font-26 ss-m-x-20 ss-m-b-70">{{
  18. '取餐码'
  19. }}</view>
  20. </view>
  21. <!-- 收货地址 -->
  22. <view class="order-address-box" >
  23. <view class="ss-flex ss-col-center">
  24. <text class="address-username">
  25. {{ state.orderInfo.receiverName }}
  26. </text>
  27. <text class="address-phone">{{ state.orderInfo.phone }}</text>
  28. </view>
  29. <view class="address-detail">
  30. {{ state.orderInfo.name }} {{ state.orderInfo.address }}
  31. </view>
  32. </view>
  33. <view
  34. class="detail-goods"
  35. :style="[{ marginTop: state.orderInfo.receiverAreaId > 0 ? '0' : '-40rpx' }]"
  36. >
  37. <!-- 订单信 -->
  38. </view>
  39. <!-- 订单信息 -->
  40. <view class="notice-box">
  41. <view class="notice-box__content">
  42. <view class="notice-item--center">
  43. <view class="ss-flex ss-flex-1">
  44. <text class="title">订单编号:</text>
  45. <text class="detail">{{ state.orderInfo.id }}</text>
  46. </view>
  47. <button class="ss-reset-button copy-btn" @tap="onCopy">复制</button>
  48. </view>
  49. <view class="notice-item">
  50. <text class="title">下单时间:</text>
  51. <text class="detail">
  52. {{ sheep.$helper.timeFormat(state.orderInfo.createTime, 'yyyy-mm-dd hh:MM:ss') }}
  53. </text>
  54. </view>
  55. <view class="notice-item" v-if="state.orderInfo.payTime">
  56. <text class="title">支付时间:</text>
  57. <text class="detail">
  58. {{ sheep.$helper.timeFormat(state.orderInfo.payTime, 'yyyy-mm-dd hh:MM:ss') }}
  59. </text>
  60. </view>
  61. <view class="notice-item">
  62. <text class="title">类型:</text>
  63. <text class="detail">{{ state.orderInfo.type==1?'外卖':'堂食' || '-' }}</text>
  64. </view>
  65. </view>
  66. </view>
  67. <view v-for="(i,j) in state.orderInfo.goodsInfoList" :key="j" class="minmi" style="width: 100vw;background-color: #fff;" >
  68. <image class="imgPic" :src="i.goodsIcon" mode=""></image>
  69. <view class="rightContainer">
  70. <view class="foodName">
  71. {{i.goodsName}}
  72. </view>
  73. <view class="foodPrice">
  74. <view class="priceflex">
  75. <text class="zero">¥</text>
  76. {{i.goodsPrice}}
  77. </view>
  78. <view class="shopCar iconfont-themeColor-write" v-show="i.num == 0" @tap="addcart(i)">
  79. <text class="lg text-white cuIcon-add" ></text>
  80. </view>
  81. <view class="" v-if="i.num > 0" >
  82. <!-- <text class="lg text-white cuIcon-minus" @tap="addcart(i)" ></text> -->
  83. <!-- <uni-number-box :min="0" :max="100" :step="1" v-model="i.num" @tap="chengeCart(i)" /> -->
  84. <text>{{ i.num }}</text>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 价格信息 -->
  90. <view class="order-price-box">
  91. <view class="notice-item ss-flex ss-row-between">
  92. <text class="title">商品总额</text>
  93. <view class="ss-flex">
  94. <text class="detail">¥{{ state.orderInfo.price }}</text>
  95. </view>
  96. </view>
  97. <!-- <view class="notice-item all-rpice-item ss-flex ss-m-t-20">
  98. <text class="title">{{ state.orderInfo.payStatus ? '已付款' : '需付款' }}</text>
  99. <text class="detail all-price">¥{{ state.orderInfo.price }}</text>
  100. </view> -->
  101. </view>
  102. <!-- 底部按钮 -->
  103. <!-- TODO: 查看物流、等待成团、评价完后返回页面没刷新页面 -->
  104. </s-layout>
  105. </template>
  106. <script setup>
  107. import sheep from '@/sheep';
  108. import { onLoad } from '@dcloudio/uni-app';
  109. import { reactive } from 'vue';
  110. import { isEmpty } from 'lodash';
  111. import {
  112. fen2yuan,
  113. formatOrderStatus,
  114. formatOrderStatusDescription,
  115. handleOrderButtons,
  116. } from '@/sheep/hooks/useGoods';
  117. import OrderApi from '@/sheep/api/trade/order';
  118. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  119. const headerBg = sheep.$url.css('/static/img/shop/order/order_bg.png');
  120. const state = reactive({
  121. orderInfo: {},
  122. merchantTradeNo: '', // 商户订单号
  123. comeinType: '', // 进入订单详情的来源类型
  124. });
  125. // 复制
  126. const onCopy = () => {
  127. sheep.$helper.copyText(state.orderInfo.sn);
  128. };
  129. // 去支付
  130. function onPay(payOrderId) {
  131. sheep.$router.go('/pages/pay/index', {
  132. id: payOrderId,
  133. });
  134. }
  135. // 查看商品
  136. function onGoodsDetail(id) {
  137. sheep.$router.go('/pages/goods/index', {
  138. id,
  139. });
  140. }
  141. // 取消订单
  142. async function onCancel(orderId) {
  143. uni.showModal({
  144. title: '提示',
  145. content: '确定要取消订单吗?',
  146. success: async function (res) {
  147. if (!res.confirm) {
  148. return;
  149. }
  150. const { code } = await OrderApi.cancelOrder(orderId);
  151. if (code === 0) {
  152. await getOrderDetail(orderId);
  153. }
  154. },
  155. });
  156. }
  157. // 查看物流
  158. async function onExpress(id) {
  159. sheep.$router.go('/pages/order/express/log', {
  160. id,
  161. });
  162. }
  163. // 确认收货 TODO 芋艿:待测试
  164. async function onConfirm(orderId, ignore = false) {
  165. // 需开启确认收货组件
  166. // todo: 芋艿:待接入微信
  167. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  168. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  169. let isOpenBusinessView = true;
  170. if (
  171. sheep.$platform.name === 'WechatMiniProgram' &&
  172. !isEmpty(state.orderInfo.wechat_extra_data) &&
  173. isOpenBusinessView &&
  174. !ignore
  175. ) {
  176. mpConfirm(orderId);
  177. return;
  178. }
  179. // 正常的确认收货流程
  180. const { code } = await OrderApi.receiveOrder(orderId);
  181. if (code === 0) {
  182. await getOrderDetail(orderId);
  183. }
  184. }
  185. // #ifdef MP-WEIXIN
  186. // 小程序确认收货组件
  187. function mpConfirm(orderId) {
  188. if (!wx.openBusinessView) {
  189. sheep.$helper.toast(`请升级微信版本`);
  190. return;
  191. }
  192. wx.openBusinessView({
  193. businessType: 'weappOrderConfirm',
  194. extraData: {
  195. merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
  196. transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
  197. },
  198. success(response) {
  199. console.log('success:', response);
  200. if (response.errMsg === 'openBusinessView:ok') {
  201. if (response.extraData.status === 'success') {
  202. onConfirm(orderId, true);
  203. }
  204. }
  205. },
  206. fail(error) {
  207. console.log('error:', error);
  208. },
  209. complete(result) {
  210. console.log('result:', result);
  211. },
  212. });
  213. }
  214. // #endif
  215. // 评价
  216. function onComment(id) {
  217. sheep.$router.go('/pages/goods/comment/add', {
  218. id
  219. });
  220. }
  221. async function getOrderDetail(id) {
  222. // 对详情数据进行适配
  223. let res;
  224. if (state.comeinType === 'wechat') {
  225. // TODO 芋艿:微信场景下
  226. res = await OrderApi.getOrder(id, {
  227. merchant_trade_no: state.merchantTradeNo,
  228. });
  229. } else {
  230. res = await OrderApi.getOrder(id);
  231. }
  232. if (res.code === 0) {
  233. state.orderInfo = res.data;
  234. handleOrderButtons(state.orderInfo);
  235. } else {
  236. sheep.$router.back();
  237. }
  238. }
  239. onLoad(async (options) => {
  240. let id = 0;
  241. if (options.id) {
  242. id = options.id;
  243. }
  244. // TODO 芋艿:下面两个变量,后续接入
  245. state.comeinType = options.comein_type;
  246. if (state.comeinType === 'wechat') {
  247. state.merchantTradeNo = options.merchant_trade_no;
  248. }
  249. await getOrderDetail(id);
  250. });
  251. </script>
  252. <style lang="scss" scoped>
  253. .score-img {
  254. width: 36rpx;
  255. height: 36rpx;
  256. margin: 0 4rpx;
  257. }
  258. .apply-btn {
  259. width: 140rpx;
  260. height: 50rpx;
  261. border-radius: 25rpx;
  262. font-size: 24rpx;
  263. border: 2rpx solid #dcdcdc;
  264. line-height: normal;
  265. margin-left: 16rpx;
  266. }
  267. .state-box {
  268. color: rgba(#fff, 0.9);
  269. width: 100%;
  270. background: v-bind(headerBg) no-repeat,
  271. linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  272. background-size: 750rpx 100%;
  273. box-sizing: border-box;
  274. .state-img {
  275. width: 60rpx;
  276. height: 60rpx;
  277. margin-right: 20rpx;
  278. }
  279. }
  280. .order-address-box {
  281. background-color: #fff;
  282. border-radius: 10rpx;
  283. margin: -50rpx 20rpx 16rpx 20rpx;
  284. padding: 44rpx 34rpx 42rpx 20rpx;
  285. font-size: 30rpx;
  286. box-sizing: border-box;
  287. font-weight: 500;
  288. color: rgba(51, 51, 51, 1);
  289. .address-username {
  290. margin-right: 20rpx;
  291. }
  292. .address-detail {
  293. font-size: 26rpx;
  294. font-weight: 500;
  295. color: rgba(153, 153, 153, 1);
  296. margin-top: 20rpx;
  297. }
  298. }
  299. .detail-goods {
  300. border-radius: 10rpx;
  301. margin: 0 20rpx 20rpx 20rpx;
  302. .order-list {
  303. margin-bottom: 20rpx;
  304. background-color: #fff;
  305. .order-card {
  306. padding: 20rpx 0;
  307. .order-sku {
  308. font-size: 24rpx;
  309. font-weight: 400;
  310. color: rgba(153, 153, 153, 1);
  311. width: 450rpx;
  312. margin-bottom: 20rpx;
  313. .order-num {
  314. margin-right: 10rpx;
  315. }
  316. }
  317. .tag-btn {
  318. margin-left: 16rpx;
  319. font-size: 24rpx;
  320. height: 36rpx;
  321. color: var(--ui-BG-Main);
  322. border: 2rpx solid var(--ui-BG-Main);
  323. border-radius: 14rpx;
  324. padding: 0 4rpx;
  325. }
  326. }
  327. }
  328. }
  329. // 订单信息。
  330. .notice-box {
  331. background: #fff;
  332. border-radius: 10rpx;
  333. margin: 0 20rpx 20rpx 20rpx;
  334. .notice-box__head {
  335. font-size: 30rpx;
  336. font-weight: 500;
  337. color: rgba(51, 51, 51, 1);
  338. line-height: 80rpx;
  339. border-bottom: 1rpx solid #dfdfdf;
  340. padding: 0 25rpx;
  341. }
  342. .notice-box__content {
  343. padding: 20rpx;
  344. .self-pickup-box {
  345. width: 100%;
  346. .self-pickup--img {
  347. width: 200rpx;
  348. height: 200rpx;
  349. margin: 40rpx 0;
  350. }
  351. }
  352. }
  353. .notice-item,
  354. .notice-item--center {
  355. display: flex;
  356. align-items: center;
  357. line-height: normal;
  358. margin-bottom: 24rpx;
  359. .title {
  360. font-size: 28rpx;
  361. color: #999;
  362. }
  363. .detail {
  364. font-size: 28rpx;
  365. color: #333;
  366. flex: 1;
  367. }
  368. }
  369. }
  370. .copy-btn {
  371. width: 100rpx;
  372. line-height: 50rpx;
  373. border-radius: 25rpx;
  374. padding: 0;
  375. background: rgba(238, 238, 238, 1);
  376. font-size: 22rpx;
  377. font-weight: 400;
  378. color: rgba(51, 51, 51, 1);
  379. }
  380. // 订单价格信息
  381. .order-price-box {
  382. background-color: #fff;
  383. border-radius: 10rpx;
  384. padding: 20rpx;
  385. margin: 0 20rpx 20rpx 20rpx;
  386. .notice-item {
  387. line-height: 70rpx;
  388. .title {
  389. font-size: 28rpx;
  390. color: #999;
  391. }
  392. .detail {
  393. font-size: 28rpx;
  394. color: #333;
  395. font-family: OPPOSANS;
  396. }
  397. }
  398. .all-rpice-item {
  399. justify-content: flex-end;
  400. align-items: center;
  401. .title {
  402. font-size: 26rpx;
  403. font-weight: 500;
  404. color: #333333;
  405. line-height: normal;
  406. }
  407. .all-price {
  408. font-size: 26rpx;
  409. font-family: OPPOSANS;
  410. line-height: normal;
  411. color: $red;
  412. }
  413. }
  414. }
  415. // 底部
  416. .footer-box {
  417. height: 100rpx;
  418. width: 100%;
  419. box-sizing: border-box;
  420. border-radius: 10rpx;
  421. padding-right: 20rpx;
  422. .cancel-btn {
  423. width: 160rpx;
  424. height: 60rpx;
  425. background: #eeeeee;
  426. border-radius: 30rpx;
  427. margin-right: 20rpx;
  428. font-size: 26rpx;
  429. font-weight: 400;
  430. color: #333333;
  431. }
  432. .pay-btn {
  433. width: 160rpx;
  434. height: 60rpx;
  435. font-size: 26rpx;
  436. border-radius: 30rpx;
  437. font-weight: 500;
  438. color: #fff;
  439. }
  440. }
  441. .minmi {
  442. display: flex;
  443. width: 592upx;
  444. margin-left: 25upx;
  445. padding-top: 51upx;
  446. .imgPic {
  447. width: 208upx;
  448. height: 167upx;
  449. border-radius: 10upx;
  450. margin-left: 20upx;
  451. }
  452. .rightContainer {
  453. display: flex;
  454. flex-direction: column;
  455. height: 167upx;
  456. box-sizing: border-box;
  457. justify-content: space-between;
  458. align-items: flex-start;
  459. padding-left: 18upx;
  460. padding-right: 18upx;
  461. padding-top: 18upx;
  462. // padding-bottom: 18upx;
  463. flex: 1;
  464. .foodName {
  465. font-weight: 700;
  466. font-size: 25upx;
  467. }
  468. .foodPrice {
  469. display: flex;
  470. justify-content: space-between;
  471. width: 375upx;
  472. color: #F9BE3E;
  473. .priceflex {
  474. display: flex;
  475. align-items: center;
  476. .zero {
  477. font-size: 15upx;
  478. }
  479. }
  480. .shopCar {
  481. background-color: #F9BE3E;
  482. border-radius: 45upx;
  483. width: 112upx;
  484. height: 45upx;
  485. font-size: 25upx;
  486. text-align: center;
  487. line-height: 46upx;
  488. }
  489. }
  490. }
  491. }
  492. </style>