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

533 lines
14 KiB

4 weeks ago
4 weeks 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 }}</text>
  54. </view>
  55. <view class="info-item" v-if="this.orderDetail.status != '-1'" >
  56. <text class="info-label">创建时间:</text>
  57. <text class="info-value">{{ orderDetail.createTime }}</text>
  58. </view>
  59. <view class="info-item" v-if="this.orderDetail.status != '-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'" 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 }}</text>
  111. </view>
  112. <view class="pay-button" @tap="handlePay" v-if="orderStatus === '0' || orderStatus === '-1'">立即下单</view>
  113. <view class="pay-button" @tap="handlePay" v-if="orderStatus === '2'">立即取餐</view>
  114. </view>
  115. </view>
  116. </template>
  117. <script>
  118. import navbar from '@/components/base/navbar.vue'
  119. import { mapState } 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. cartDiscount: 0,
  132. teamLeader: {}
  133. }
  134. },
  135. computed: {
  136. ...mapState(['cartData']),
  137. showedFoods() {
  138. return this.showAllFoods ? this.orderDetail.goodsList : this.orderDetail.goodsList.slice(0, 3)
  139. },
  140. cartPay() {
  141. return this.orderDetail.priceAll - this.cartDiscount
  142. },
  143. orderStatus() {
  144. return this.orderDetail.status
  145. },
  146. // 格式为 goodId,goodNum;goodId2,goodsNum
  147. goodss() {
  148. return this.orderDetail.goodsList.map(item => {
  149. return `${item.id},${item.num},${item.goods.price * item.num}`
  150. }).join(';')
  151. }
  152. },
  153. onLoad(options) {
  154. // 如果是购物车调过来的结账页面
  155. if (options.status === 'cart') {
  156. this.showCartData()
  157. // 独一无二代表购物车的状态
  158. this.orderStatus = '-1'
  159. }
  160. else if (options.id) {
  161. this.getOrderDetail(options.id)
  162. }
  163. },
  164. methods: {
  165. // 返回上一页
  166. navigateBack() {
  167. uni.navigateBack()
  168. },
  169. // 如果是购物车结账页面
  170. showCartData() {
  171. this.$api('queryMyLeader', {}, res => {
  172. if (res.code === 200) {
  173. this.teamLeader = res.result
  174. }
  175. })
  176. this.orderDetail.goodsList = this.cartData.sendData
  177. this.orderDetail.priceAll = this.cartData.priceAll
  178. this.orderDetail.status = '-1'
  179. },
  180. // 获取订单详情
  181. getOrderDetail(id) {
  182. this.id = id
  183. this.$api('queryMemberOrderList', {
  184. id: this.id
  185. }, res => {
  186. if (res.code === 200) {
  187. this.orderDetail = res.result.records[0]
  188. }
  189. })
  190. },
  191. // 处理支付
  192. handlePay() {
  193. uni.showLoading({
  194. title: '支付处理中...'
  195. })
  196. // 正常订单调用支付接口
  197. if(this.orderStatus === '0'){
  198. this.$api('payOrder',{
  199. id: this.id,
  200. payMethod: this.payMethod
  201. }, res => {
  202. uni.hideLoading()
  203. console.log('res', res);
  204. })
  205. }
  206. // 购物车调用创造订单接口
  207. else if(this.orderStatus === '-1'){
  208. this.$api('createOrder',{
  209. priceAll: this.orderDetail.priceAll,
  210. pricePay: this.orderDetail.priceAll - 0,
  211. pricePreferential: 0,
  212. payType: this.payMethod,
  213. leaderId: this.teamLeader.id,
  214. goodss: this.goodss
  215. }, res => {
  216. uni.hideLoading()
  217. console.log('res', res);
  218. if(res.code === 200){
  219. }
  220. })
  221. }
  222. },
  223. // 去优惠页面
  224. gotoCoupon() {
  225. this.$utils.navigateTo({
  226. url: '/pages_order/mine/coupon?isUseinOrder=true'
  227. })
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss" scoped>
  233. .page {
  234. background-color: #f5f5f5;
  235. min-height: 100vh;
  236. padding-bottom: 120rpx;
  237. }
  238. .status-bar {
  239. background-color: #019245;
  240. padding: 30rpx;
  241. color: #fff;
  242. font-size: 32rpx;
  243. font-weight: 500;
  244. }
  245. .shop-info {
  246. background-color: #fff;
  247. margin: 20rpx;
  248. border-radius: 16rpx;
  249. padding: 20rpx;
  250. .shop-header {
  251. display: flex;
  252. align-items: center;
  253. // background-color: red;
  254. .shop-logo {
  255. width: 150rpx;
  256. height: 150rpx;
  257. // border-radius: 10rpx;
  258. margin-right: 20rpx;
  259. }
  260. .shop-name-container {
  261. flex: 1;
  262. .shop-name {
  263. font-size: 30rpx;
  264. font-weight: 500;
  265. margin-bottom: 10rpx;
  266. display: block;
  267. }
  268. .shop-address, .shop-phone {
  269. display: flex;
  270. align-items: start;
  271. font-size: 24rpx;
  272. color: $uni-color-third;
  273. margin-top: 8rpx;
  274. .address-text, .phone-text {
  275. margin-left: 8rpx;
  276. width: 80%;
  277. white-space: wrap;
  278. // overflow: hidden;
  279. // text-overflow: ellipsis;
  280. }
  281. }
  282. .shop-address-top{
  283. display: flex;
  284. align-items: start;
  285. background-color: red;
  286. // gap: 10rpx;
  287. }
  288. }
  289. }
  290. }
  291. .order-status{
  292. background-color: #fff;
  293. margin: 20rpx;
  294. border-radius: 16rpx;
  295. padding: 20rpx;
  296. .food-list {
  297. // gap: 20rpx;
  298. // background-color: #019245;
  299. .food-item {
  300. display: flex;
  301. margin-bottom: 20rpx;
  302. // background-color: red;
  303. .food-image {
  304. width: 120rpx;
  305. height: 120rpx;
  306. // border-radius: 10rpx;
  307. margin-right: 20rpx;
  308. }
  309. .food-info {
  310. flex: 1;
  311. display: flex;
  312. flex-direction: column;
  313. justify-content: space-between;
  314. position: relative;
  315. .food-name {
  316. font-size: 28rpx;
  317. font-weight: 500;
  318. }
  319. .food-sold {
  320. display: flex;
  321. align-items: center;
  322. font-size: 24rpx;
  323. color: $uni-color-third;
  324. }
  325. .food-price {
  326. font-size: 28rpx;
  327. color: #f00;
  328. }
  329. .food-count {
  330. color: black;
  331. position: absolute;
  332. bottom: 50%;
  333. right: 0;
  334. }
  335. }
  336. }
  337. .expand-more {
  338. display: flex;
  339. align-items: center;
  340. justify-content: center;
  341. padding: 20rpx 0 0;
  342. font-size: 24rpx;
  343. color: $uni-color-third;
  344. }
  345. }
  346. .order-info {
  347. padding-top: 20rpx;
  348. .info-item {
  349. display: flex;
  350. justify-content: space-between;
  351. margin-bottom: 15rpx;
  352. font-size: 26rpx;
  353. .info-label {
  354. color: black;
  355. }
  356. .info-value {
  357. color: #333;
  358. &.price {
  359. color: #f00;
  360. font-weight: 500;
  361. }
  362. }
  363. }
  364. }
  365. }
  366. .discount-info-container {
  367. background-color: #fff;
  368. margin: 20rpx;
  369. border-radius: 16rpx;
  370. padding: 20rpx;
  371. display: flex;
  372. flex-direction: column;
  373. gap: 40rpx;
  374. }
  375. .discount-info {
  376. display: flex;
  377. align-items: center;
  378. justify-content: space-between;
  379. .discount-header {
  380. font-size: 28rpx;
  381. }
  382. .discount-item {
  383. display: flex;
  384. justify-content: space-between;
  385. align-items: center;
  386. gap: 20rpx;
  387. .discount-left {
  388. display: flex;
  389. align-items: center;
  390. gap: 10rpx;
  391. .coupon-icon {
  392. width: 36rpx;
  393. height: 36rpx;
  394. margin-top: 6rpx;
  395. }
  396. }
  397. .discount-amount {
  398. color: #f00;
  399. font-weight: 500;
  400. }
  401. }
  402. }
  403. .remark-section {
  404. display: flex;
  405. // flex-direction: column;
  406. gap: 40rpx;
  407. // background-color: red;
  408. align-items: center;
  409. .remark-header {
  410. font-size: 28rpx;
  411. // font-weight: 500;
  412. }
  413. .remark-content {
  414. font-size: 26rpx;
  415. color: black;
  416. min-height: 60rpx;
  417. display: flex;
  418. align-items: center;
  419. }
  420. }
  421. .payment-methods {
  422. background-color: #fff;
  423. width: 100%;
  424. margin: 20rpx;
  425. border-radius: 16rpx;
  426. padding: 20rpx;
  427. display: flex;
  428. flex-direction: column;
  429. gap: 20rpx;
  430. .payment-item {
  431. display: flex;
  432. align-items: center;
  433. padding: 20rpx 0;
  434. border-bottom: 1rpx solid #f5f5f5;
  435. &:last-child {
  436. border-bottom: none;
  437. }
  438. .payment-name {
  439. flex: 1;
  440. margin-left: 20rpx;
  441. font-size: 28rpx;
  442. .balance-text {
  443. font-size: 24rpx;
  444. color: $uni-color-third;
  445. margin-left: 10rpx;
  446. }
  447. }
  448. }
  449. }
  450. .bottom-bar {
  451. position: fixed;
  452. bottom: 0;
  453. left: 0;
  454. right: 0;
  455. height: 100rpx;
  456. background-color: #fff;
  457. display: flex;
  458. align-items: center;
  459. padding: 0 30rpx;
  460. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  461. .total-section {
  462. flex: 1;
  463. .total-label {
  464. font-size: 26rpx;
  465. color: $uni-color-third;
  466. }
  467. .total-price {
  468. font-size: 32rpx;
  469. color: #f00;
  470. margin-left: 10rpx;
  471. }
  472. }
  473. .pay-button {
  474. width: 240rpx;
  475. height: 80rpx;
  476. background-color: #019245;
  477. color: #fff;
  478. font-size: 30rpx;
  479. display: flex;
  480. align-items: center;
  481. justify-content: center;
  482. border-radius: 40rpx;
  483. }
  484. }
  485. </style>