敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

555 lines
14 KiB

1 week ago
1 week ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="订单详情 " leftClick @leftClick="navigateBack" bgColor="#019245" color="#fff" />
  5. <!-- 店铺信息 -->
  6. <view class="shop-info">
  7. <view class="shop-header">
  8. <image class="shop-logo" :src="teamLeader.spotImage" mode="aspectFill"></image>
  9. <view class="shop-name-container">
  10. <text class="shop-name"> {{ teamLeader.spotName }} </text>
  11. <view class="shop-address">
  12. <view style="padding-top: 7rpx;">
  13. <!-- 需要置顶 -->
  14. <uv-icon name="map-fill" color="#019245" size="28rpx"></uv-icon>
  15. </view>
  16. <text class="address-text">{{ teamLeader.area }} {{ teamLeader.address }}</text>
  17. </view>
  18. <view class="shop-phone">
  19. <view style="padding-top: 7rpx;">
  20. <!-- 需要置顶 -->
  21. <uv-icon name="phone-fill" color="#019245" size="28rpx"></uv-icon>
  22. </view>
  23. <text class="phone-text">{{teamLeader.phone}}</text>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="order-status">
  29. <!-- 商品列表 -->
  30. <view class="food-list">
  31. <view class="food-item" v-for="(food, index) in showedFoods" :key="food.id">
  32. <image class="food-image" :src="food.goods.image" mode="aspectFill" />
  33. <view class="food-info">
  34. <text class="food-name">{{food.goods.title}}</text>
  35. <view class="food-sold">
  36. <uv-icon name="bag" size="28rpx"></uv-icon>
  37. <text>已售出 {{ food.goods.sales }}</text>
  38. </view>
  39. <text class="food-price"> <text style="font-size: 20rpx;"></text> {{food.goods.price}}</text>
  40. <text class="food-count">×{{food.num}}</text>
  41. </view>
  42. </view>
  43. <view class="expand-more" @tap="showAllFoods = !showAllFoods" v-if="orderDetail.goodsList.length > 3">
  44. <text>{{showAllFoods ? '收起' : '展开'}} ({{orderDetail.goodsList.length}})</text>
  45. <uv-icon :name="showAllFoods ? 'arrow-up' : 'arrow-down'" size="28rpx"></uv-icon>
  46. </view>
  47. </view>
  48. <!-- 订单信息 -->
  49. <view class="order-info">
  50. <view class="info-item">
  51. <text class="info-label">合计:</text>
  52. <text class="info-value price">{{ orderDetail.pricePay }}</text>
  53. </view>
  54. <view class="info-item">
  55. <text class="info-label">创建时间:</text>
  56. <text class="info-value">{{ orderDetail.createTime }}</text>
  57. </view>
  58. <view class="info-item">
  59. <text class="info-label">订单编号:</text>
  60. <text class="info-value">{{orderDetail.id}}</text>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="discount-info-container">
  65. <!-- 优惠信息 -->
  66. <view class="discount-info">
  67. <view class="discount-header">
  68. <text>优惠</text>
  69. </view>
  70. <view class="discount-item">
  71. <view class="discount-left" v-if="orderDetail.pricePreferential">
  72. <image src="@/static/image/券.webp" mode="aspectFill" class="coupon-icon" />
  73. <view>新用户立减</view>
  74. </view>
  75. <text v-if="orderDetail.pricePreferential" class="discount-amount"> - {{orderDetail.pricePreferential}}</text>
  76. <text v-else class="none-discount-amount">未使用优惠卷</text>
  77. </view>
  78. </view>
  79. <!-- 备注 -->
  80. <view class="remark-section">
  81. <view class="remark-header">
  82. <text>备注</text>
  83. </view>
  84. <view class="remark-content">
  85. <input v-if="orderStatus === '0' " type="text" v-model="orderDetail.remark"
  86. placeholder="请输入您要备注的内容" placeholder-style="font-size: 28rpx" />
  87. <text v-else>{{orderDetail.remark || '无备注信息'}}</text>
  88. </view>
  89. </view>
  90. <!-- 支付方式 -->
  91. <uv-radio-group v-model="payMethod" v-if="orderStatus === '0' ">
  92. <view class="payment-methods">
  93. <view class="payment-item">
  94. <uv-icon name="weixin-circle-fill" size="70rpx" color="#019245" />
  95. <text class="payment-name">微信支付</text>
  96. <uv-radio activeColor="#019245" size="40rpx" name="0" />
  97. </view>
  98. <view class="payment-item">
  99. <uv-icon name="red-packet" size="70rpx" color="#019245" />
  100. <text class="payment-name">账户余额<text class="balance-text">(余额: {{ userInfo.balance }})</text></text>
  101. <!-- 钱不够就会禁用 -->
  102. <uv-radio activeColor="#019245" size="40rpx" name="1" :disabled="userInfo.balance < orderDetail.pricePay" />
  103. </view>
  104. </view>
  105. </uv-radio-group>
  106. <!-- 底部支付栏 -->
  107. <view class="bottom-bar">
  108. <view class="total-section">
  109. <text class="total-label">
  110. {{ (orderDetail.goodsList || []).length }}
  111. <text style="color: black;">合计</text>
  112. </text>
  113. <text class="total-price">{{ ( orderDetail.pricePay || 0 ).toFixed(2) || 0 }}</text>
  114. </view>
  115. <view class="pay-button" @tap="handlePay" v-if="orderStatus === '0' ">立即下单</view>
  116. <view class="pay-button" @tap="handleTake" v-if="orderStatus === '3'">取餐完成</view>
  117. </view>
  118. </view>
  119. </view>
  120. </template>
  121. <script>
  122. import navbar from '@/components/base/navbar.vue'
  123. import { mapState, mapMutations } from 'vuex'
  124. export default {
  125. components: {
  126. navbar
  127. },
  128. data() {
  129. return {
  130. id: '',
  131. payMethod: '0',
  132. showAllFoods: false,
  133. // orderStatus: '',
  134. orderDetail: {
  135. status: '',
  136. remark: '',
  137. goodsList: [],
  138. priceAll: 0,
  139. pricePay: 0,
  140. pricePreferential: 0,
  141. },
  142. cartDiscount: 0,
  143. teamLeader: {}
  144. }
  145. },
  146. computed: {
  147. ...mapState([ 'userInfo']),
  148. showedFoods() {
  149. return this.showAllFoods ? this.orderDetail.goodsList : (this.orderDetail.goodsList.length > 3 ? this.orderDetail.goodsList.slice(0, 3) : this.orderDetail.goodsList)
  150. },
  151. orderStatus() {
  152. return this.orderDetail.status
  153. },
  154. },
  155. onLoad(options) {
  156. // 如果是购物车调过来的结账页面
  157. if (options.id) {
  158. this.getOrderDetail(options.id)
  159. }
  160. },
  161. methods: {
  162. ...mapMutations([ 'clearCouponData']),
  163. // 返回上一页
  164. navigateBack() {
  165. uni.navigateBack()
  166. },
  167. // 获取订单详情
  168. getOrderDetail(id) {
  169. this.id = id
  170. this.$api('queryMemberOrderList', {
  171. id: this.id
  172. }, res => {
  173. if (res.code === 200) {
  174. this.orderDetail = res.result.records[0]
  175. this.teamLeader = res.result.records[0].teamLeader
  176. }
  177. })
  178. },
  179. // 处理支付
  180. handlePay() {
  181. uni.showLoading({
  182. title: '支付处理中...'
  183. })
  184. this.$api('payOrder',{
  185. payType: this.payMethod,
  186. orderId: this.id,
  187. }, res => {
  188. uni.hideLoading()
  189. if (res.code === 200) {
  190. if (this.payMethod == '0') {
  191. uni.requestPaymentWxPay(res)
  192. .then(n => {
  193. setTimeout(uni.redirectTo, 500, {
  194. url: '/pages/index/order?tabIndex=1'
  195. })
  196. })
  197. .catch(err => {
  198. uni.showToast({
  199. title: '支付失败',
  200. icon: 'error'
  201. })
  202. setTimeout(uni.redirectTo, 500, {
  203. url: '/pages/index/order?tabIndex=0'
  204. })
  205. })
  206. } else {
  207. uni.showModal({
  208. title: '提示',
  209. content: '确认使用余额支付吗?',
  210. confirmColor: '#019245',
  211. success: (result) => {
  212. if (result.confirm) {
  213. uni.showToast({
  214. title: '下单成功',
  215. icon: 'success'
  216. })
  217. // 重新刷新剩余金额
  218. this.$store.commit('getUserInfo')
  219. setTimeout(uni.redirectTo, 700, {
  220. url: '/pages/index/order?tabIndex=1'
  221. })
  222. }
  223. }
  224. })
  225. }
  226. }
  227. })
  228. },
  229. // 取餐完成
  230. handleTake() {
  231. console.log(this.id,'id');
  232. this.$api('finishMemberOrderById', {
  233. memberOrderId: this.id
  234. }, res => {
  235. if (res.code === 200) {
  236. uni.showToast({
  237. title: '取餐完成',
  238. icon: 'success'
  239. })
  240. setTimeout( () => {
  241. uni.navigateBack()
  242. }, 1000)
  243. }
  244. })
  245. }
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .page {
  251. background-color: #f5f5f5;
  252. min-height: 100vh;
  253. padding-bottom: 120rpx;
  254. }
  255. .status-bar {
  256. background-color: #019245;
  257. padding: 30rpx;
  258. color: #fff;
  259. font-size: 32rpx;
  260. font-weight: 500;
  261. }
  262. .shop-info {
  263. background-color: #fff;
  264. margin: 20rpx;
  265. border-radius: 16rpx;
  266. padding: 20rpx;
  267. .shop-header {
  268. display: flex;
  269. align-items: center;
  270. // background-color: red;
  271. .shop-logo {
  272. width: 150rpx;
  273. height: 150rpx;
  274. // border-radius: 10rpx;
  275. margin-right: 20rpx;
  276. }
  277. .shop-name-container {
  278. flex: 1;
  279. .shop-name {
  280. font-size: 30rpx;
  281. font-weight: 500;
  282. margin-bottom: 10rpx;
  283. display: block;
  284. }
  285. .shop-address, .shop-phone {
  286. display: flex;
  287. align-items: start;
  288. font-size: 24rpx;
  289. color: $uni-color-third;
  290. margin-top: 8rpx;
  291. .address-text, .phone-text {
  292. margin-left: 8rpx;
  293. width: 80%;
  294. white-space: wrap;
  295. // overflow: hidden;
  296. // text-overflow: ellipsis;
  297. }
  298. }
  299. .shop-address-top{
  300. display: flex;
  301. align-items: start;
  302. background-color: red;
  303. // gap: 10rpx;
  304. }
  305. }
  306. }
  307. }
  308. .order-status{
  309. background-color: #fff;
  310. margin: 20rpx;
  311. border-radius: 16rpx;
  312. padding: 20rpx;
  313. .food-list {
  314. // gap: 20rpx;
  315. // background-color: #019245;
  316. .food-item {
  317. display: flex;
  318. margin-bottom: 20rpx;
  319. // background-color: red;
  320. .food-image {
  321. width: 120rpx;
  322. height: 120rpx;
  323. // border-radius: 10rpx;
  324. margin-right: 20rpx;
  325. }
  326. .food-info {
  327. flex: 1;
  328. display: flex;
  329. flex-direction: column;
  330. justify-content: space-between;
  331. position: relative;
  332. .food-name {
  333. font-size: 28rpx;
  334. font-weight: 500;
  335. }
  336. .food-sold {
  337. display: flex;
  338. align-items: center;
  339. font-size: 24rpx;
  340. color: $uni-color-third;
  341. }
  342. .food-price {
  343. font-size: 28rpx;
  344. color: #f00;
  345. }
  346. .food-count {
  347. color: black;
  348. position: absolute;
  349. bottom: 50%;
  350. right: 0;
  351. }
  352. }
  353. }
  354. .expand-more {
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. padding: 20rpx 0 0;
  359. font-size: 24rpx;
  360. color: $uni-color-third;
  361. }
  362. }
  363. .order-info {
  364. padding-top: 20rpx;
  365. .info-item {
  366. display: flex;
  367. justify-content: space-between;
  368. margin-bottom: 15rpx;
  369. font-size: 26rpx;
  370. .info-label {
  371. color: black;
  372. }
  373. .info-value {
  374. color: #333;
  375. &.price {
  376. color: #f00;
  377. font-weight: 500;
  378. }
  379. }
  380. }
  381. }
  382. }
  383. .discount-info-container {
  384. background-color: #fff;
  385. margin: 20rpx;
  386. border-radius: 16rpx;
  387. padding: 20rpx;
  388. display: flex;
  389. flex-direction: column;
  390. gap: 40rpx;
  391. }
  392. .discount-info {
  393. display: flex;
  394. align-items: center;
  395. justify-content: space-between;
  396. .discount-header {
  397. font-size: 28rpx;
  398. }
  399. .discount-item {
  400. display: flex;
  401. justify-content: space-between;
  402. align-items: center;
  403. gap: 20rpx;
  404. .discount-left {
  405. display: flex;
  406. align-items: center;
  407. gap: 10rpx;
  408. .coupon-icon {
  409. width: 36rpx;
  410. height: 36rpx;
  411. margin-top: 6rpx;
  412. }
  413. }
  414. .discount-amount {
  415. color: #f00;
  416. font-weight: 500;
  417. }
  418. .none-discount-amount{
  419. color: gray;
  420. font-weight: 500;
  421. }
  422. }
  423. }
  424. .remark-section {
  425. display: flex;
  426. // flex-direction: column;
  427. gap: 40rpx;
  428. // background-color: red;
  429. align-items: center;
  430. .remark-header {
  431. font-size: 28rpx;
  432. // font-weight: 500;
  433. }
  434. .remark-content {
  435. font-size: 26rpx;
  436. color: black;
  437. min-height: 60rpx;
  438. display: flex;
  439. align-items: center;
  440. }
  441. }
  442. .payment-methods {
  443. background-color: #fff;
  444. width: 100%;
  445. margin: 20rpx;
  446. border-radius: 16rpx;
  447. padding: 20rpx;
  448. display: flex;
  449. flex-direction: column;
  450. gap: 20rpx;
  451. .payment-item {
  452. display: flex;
  453. align-items: center;
  454. padding: 20rpx 0;
  455. border-bottom: 1rpx solid #f5f5f5;
  456. &:last-child {
  457. border-bottom: none;
  458. }
  459. .payment-name {
  460. flex: 1;
  461. margin-left: 20rpx;
  462. font-size: 28rpx;
  463. .balance-text {
  464. font-size: 24rpx;
  465. color: $uni-color-third;
  466. margin-left: 10rpx;
  467. }
  468. }
  469. }
  470. }
  471. .bottom-bar {
  472. position: fixed;
  473. bottom: 0;
  474. left: 0;
  475. right: 0;
  476. height: 100rpx;
  477. background-color: #fff;
  478. display: flex;
  479. align-items: center;
  480. padding: 0 30rpx;
  481. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  482. .total-section {
  483. flex: 1;
  484. .total-label {
  485. font-size: 26rpx;
  486. color: $uni-color-third;
  487. }
  488. .total-price {
  489. font-size: 32rpx;
  490. color: #f00;
  491. margin-left: 10rpx;
  492. }
  493. }
  494. .pay-button {
  495. width: 240rpx;
  496. height: 80rpx;
  497. background-color: #019245;
  498. color: #fff;
  499. font-size: 30rpx;
  500. display: flex;
  501. align-items: center;
  502. justify-content: center;
  503. border-radius: 40rpx;
  504. }
  505. }
  506. </style>