order.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <text class="title">确认订单</text>
  5. <text class="subtitle">请确认测评订单信息并完成支付</text>
  6. </view>
  7. <!-- 订单信息 -->
  8. <view class="section">
  9. <view class="section-title">订单详情</view>
  10. <view class="info-row">
  11. <text class="info-label">任务模板名称</text>
  12. <text class="info-value">{{ packageName }}</text>
  13. </view>
  14. <view class="info-row">
  15. <text class="info-label">成长规划师</text>
  16. <text class="info-value">{{ guideName }}</text>
  17. </view>
  18. <view class="info-row">
  19. <text class="info-label">预约日期</text>
  20. <text class="info-value">{{ appointmentDate }}</text>
  21. </view>
  22. <view class="info-row">
  23. <text class="info-label">预约时间</text>
  24. <text class="info-value">{{ appointmentTime }}</text>
  25. </view>
  26. </view>
  27. <!-- 费用信息 -->
  28. <view class="section">
  29. <view class="section-title">费用信息</view>
  30. <view class="price-row">
  31. <text class="price-label">测评费用</text>
  32. <text class="price-value">{{ formatPriceWithSymbol(totalPrice) }}</text>
  33. </view>
  34. <view class="price-row" v-if="discountAmount > 0">
  35. <text class="price-label">优惠金额</text>
  36. <text class="price-value discount">-{{ formatPriceWithSymbol(discountAmount) }}</text>
  37. </view>
  38. <view class="price-row total">
  39. <text class="price-label">实付金额</text>
  40. <text class="price-value highlight">{{ formatPriceWithSymbol(actualPrice) }}</text>
  41. </view>
  42. </view>
  43. <!-- 支付方式 -->
  44. <view class="section">
  45. <view class="section-title">支付方式</view>
  46. <view class="pay-methods">
  47. <view class="pay-method-item" :class="{ active: payMethod === 'wechat' }" @click="payMethod = 'wechat'">
  48. <text class="pay-icon">💳</text>
  49. <text class="pay-name">微信支付</text>
  50. <view class="pay-radio" v-if="payMethod === 'wechat'">
  51. <view class="radio-inner" />
  52. </view>
  53. </view>
  54. <view class="pay-method-item" :class="{ active: payMethod === 'alipay' }" @click="payMethod = 'alipay'">
  55. <text class="pay-icon">🔷</text>
  56. <text class="pay-name">支付宝</text>
  57. <view class="pay-radio" v-if="payMethod === 'alipay'">
  58. <view class="radio-inner" />
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <button class="btn-submit" @click="handlePay">确认支付 {{ formatPriceWithSymbol(actualPrice) }}</button>
  64. </view>
  65. </template>
  66. <script>
  67. import { createAssessmentAppointment, payAssessmentOrder } from '../../utils/api.js'
  68. export default {
  69. data() {
  70. return {
  71. packageName: '',
  72. guideName: '',
  73. appointmentDate: '',
  74. appointmentTime: '',
  75. totalPrice: '0',
  76. discountAmount: '0',
  77. actualPrice: '0',
  78. payMethod: 'wechat',
  79. childId: null,
  80. guideId: null,
  81. packageId: null
  82. }
  83. },
  84. onLoad(options) {
  85. this.packageName = decodeURIComponent(options.packageName || 'DAN专注力测评')
  86. this.guideName = decodeURIComponent(options.guideName || '')
  87. this.appointmentDate = options.appointmentDate || ''
  88. this.appointmentTime = options.appointmentTime || ''
  89. this.totalPrice = options.totalPrice || '0'
  90. this.discountAmount = options.discountAmount || '0'
  91. this.actualPrice = options.actualPrice || this.totalPrice
  92. this.childId = options.childId || null
  93. this.guideId = options.guideId || null
  94. this.packageId = options.packageId || null
  95. },
  96. methods: {
  97. async handlePay() {
  98. if (!this.guideId) {
  99. uni.showToast({ title: '请选择成长规划师', icon: 'none' })
  100. return
  101. }
  102. try {
  103. uni.showLoading({ title: '创建订单中...' })
  104. const res = await createAssessmentAppointment({
  105. childId: this.childId,
  106. guideId: this.guideId,
  107. assessorId: this.guideId,
  108. packageId: this.packageId,
  109. appointmentDate: this.appointmentDate,
  110. appointmentTime: this.appointmentTime,
  111. notes: '',
  112. totalPrice: this.totalPrice,
  113. guideName: this.guideName,
  114. packageName: this.packageName,
  115. discountAmount: this.discountAmount
  116. })
  117. if (res.code !== 200) {
  118. uni.hideLoading()
  119. return
  120. }
  121. const orderNo = res.data.orderNo
  122. uni.showLoading({ title: '支付中...' })
  123. const payRes = await payAssessmentOrder(orderNo, this.payMethod)
  124. uni.hideLoading()
  125. if (payRes.code === 200) {
  126. uni.removeStorageSync('assessmentFlowData')
  127. uni.removeStorageSync('assessmentChildInfo')
  128. uni.showModal({
  129. title: '支付成功',
  130. content: '您的测评订单已支付,请按时参加测评',
  131. showCancel: false,
  132. success: () => {
  133. uni.redirectTo({ url: '/pages/assessment/results' })
  134. }
  135. })
  136. } else {
  137. uni.showToast({ title: payRes.message || '支付失败', icon: 'none' })
  138. }
  139. } catch (e) {
  140. uni.hideLoading()
  141. uni.showToast({ title: '操作失败,请重试', icon: 'none' })
  142. }
  143. }
  144. }
  145. }
  146. </script>
  147. <style scoped>
  148. .container {
  149. padding: 30rpx;
  150. background: #F8F8F8;
  151. min-height: 100vh;
  152. }
  153. .header {
  154. text-align: center;
  155. padding: 40rpx 0 30rpx;
  156. }
  157. .title {
  158. font-size: 48rpx;
  159. font-weight: bold;
  160. color: #333;
  161. display: block;
  162. margin-bottom: 16rpx;
  163. }
  164. .subtitle {
  165. font-size: 26rpx;
  166. color: #666;
  167. }
  168. .section {
  169. background: #fff;
  170. border-radius: 20rpx;
  171. padding: 30rpx;
  172. margin-bottom: 24rpx;
  173. }
  174. .section-title {
  175. font-size: 32rpx;
  176. font-weight: bold;
  177. color: #333;
  178. margin-bottom: 24rpx;
  179. padding-bottom: 16rpx;
  180. border-bottom: 1rpx solid #eee;
  181. }
  182. .info-row {
  183. display: flex;
  184. justify-content: space-between;
  185. padding: 16rpx 0;
  186. font-size: 28rpx;
  187. }
  188. .info-label { color: #666; }
  189. .info-value { color: #333; font-weight: 500; }
  190. .price-row {
  191. display: flex;
  192. justify-content: space-between;
  193. padding: 16rpx 0;
  194. font-size: 28rpx;
  195. }
  196. .price-label { color: #666; }
  197. .price-value { color: #333; font-weight: bold; }
  198. .price-value.discount { color: #F97316; }
  199. .price-row.total {
  200. margin-top: 16rpx;
  201. padding-top: 24rpx;
  202. border-top: 1rpx dashed #eee;
  203. }
  204. .price-value.highlight {
  205. font-size: 36rpx;
  206. color: #F97316;
  207. }
  208. .pay-methods {
  209. display: flex;
  210. flex-direction: column;
  211. gap: 20rpx;
  212. }
  213. .pay-method-item {
  214. display: flex;
  215. align-items: center;
  216. padding: 24rpx;
  217. background: #F8F8F8;
  218. border-radius: 12rpx;
  219. border: 2rpx solid transparent;
  220. }
  221. .pay-method-item.active {
  222. border-color: #667eea;
  223. background: #F0F4FF;
  224. }
  225. .pay-icon {
  226. font-size: 40rpx;
  227. margin-right: 20rpx;
  228. }
  229. .pay-name {
  230. font-size: 28rpx;
  231. color: #333;
  232. flex: 1;
  233. }
  234. .pay-radio {
  235. width: 40rpx;
  236. height: 40rpx;
  237. border-radius: 50%;
  238. border: 2rpx solid #667eea;
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. }
  243. .radio-inner {
  244. width: 20rpx;
  245. height: 20rpx;
  246. border-radius: 50%;
  247. background: #667eea;
  248. }
  249. .btn-submit {
  250. width: 100%;
  251. height: 90rpx;
  252. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  253. color: #fff;
  254. border-radius: 45rpx;
  255. font-size: 32rpx;
  256. font-weight: bold;
  257. margin-top: 40rpx;
  258. margin-bottom: 40rpx;
  259. }
  260. </style>