敢为人鲜小程序前端代码仓库
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.

622 lines
16 KiB

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