detail.vue 14 KB

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