小说小程序前端代码仓库(小程序)
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.

335 lines
6.3 KiB

  1. <template>
  2. <!-- 礼物购买页面 -->
  3. <view class="gift-purchase-page">
  4. <!-- 顶部导航栏 -->
  5. <navbar title="礼物购买" leftClick @leftClick="$utils.navigateBack" />
  6. <!-- 礼物购买卡片 -->
  7. <view class="card gift-card">
  8. <view class="card-title">礼物购买</view>
  9. <view class="form-row">
  10. <view class="form-label">礼物名称</view>
  11. <view class="form-value">{{ detail.title }}</view>
  12. </view>
  13. <view class="divider"></view>
  14. <view class="form-row">
  15. <view class="form-label required"><text class="star">*</text> 购买数量</view>
  16. <input class="form-input" placeholder="请输入数量" v-model="buyCount" type="number"
  17. :placeholder-style="'color:#bbb;'" :style="buyCount ? 'color:#222;' : ''" />
  18. </view>
  19. <view class="divider"></view>
  20. <view class="form-row">
  21. <view class="form-label">支付方式</view>
  22. </view>
  23. <view class="form-row">
  24. <view class="balance">账户余额<text class="bean">{{ userInfo.integerPrice }} 豆豆</text></view>
  25. </view>
  26. </view>
  27. <!-- 订单信息卡片 -->
  28. <view class="card order-card"
  29. v-if="totalIntegerPrice > userInfo.integerPrice">
  30. <view class="order-title">订单信息</view>
  31. <view class="row">
  32. <view class="order-content">内容</view>
  33. </view>
  34. <view class="row total-row">
  35. <view class="order-total-label">合计</view>
  36. <view class="order-total"><text class="order-total-highlight">{{ totalPrice.toFixed(2) }}</text>
  37. </view>
  38. </view>
  39. <view class="order-divider"></view>
  40. </view>
  41. <!-- 提示信息 -->
  42. <view class="tip-text">
  43. 请仔细核查并确认相关信息因用户个人疏忽导致的充值错误需由用户自行承担一旦完成充值概不退换
  44. </view>
  45. <!-- 底部购买按钮 -->
  46. <view class="footer-bar">
  47. <button class="buy-btn" @click="handleBuy">购买</button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. buyCount: 1,
  56. detail :{},
  57. giftId : 0,
  58. }
  59. },
  60. computed: {
  61. totalPrice() {
  62. const count = parseInt(this.buyCount, 10)
  63. return isNaN(count) ? 0 : count * this.detail.price
  64. },
  65. totalIntegerPrice(){
  66. const count = parseInt(this.buyCount, 10)
  67. return isNaN(count) ? 0 : count * this.detail.integerPrice
  68. },
  69. },
  70. onLoad(query) {
  71. // 支持通过路由参数动态显示礼物信息
  72. if (query.id) this.giftId = query.id
  73. if (query.count) this.buyCount = query.count
  74. },
  75. onShow() {
  76. this.$store.commit(('getUserInfo'))
  77. this.getGiftDetail()
  78. },
  79. methods: {
  80. async getGiftDetail(){
  81. this.detail = await this.$fetch('getGiftDetail', {
  82. giftId : this.giftId,
  83. })
  84. },
  85. async handleBuy() {
  86. if (!this.buyCount || parseInt(this.buyCount, 10) <= 0) {
  87. uni.showToast({
  88. title: '请输入购买数量',
  89. icon: 'none'
  90. })
  91. return
  92. }
  93. await this.$fetch('createOrder', {
  94. giftId : this.giftId,
  95. num : this.buyCount,
  96. token : uni.getStorageSync('token'),
  97. })
  98. // 这里可添加余额校验和购买逻辑
  99. uni.showToast({
  100. title: `成功购买${this.buyCount}${this.detail.title}`,
  101. icon: 'success'
  102. })
  103. setTimeout(uni.navigateBack, 1000, -1)
  104. }
  105. }
  106. }
  107. </script>
  108. <style scoped lang="scss">
  109. .gift-purchase-page {
  110. min-height: 100vh;
  111. background: #f8f8f8;
  112. padding-bottom: 120rpx;
  113. }
  114. .card {
  115. background: #fff;
  116. border-radius: 18rpx;
  117. margin: 24rpx 16rpx 0 16rpx;
  118. padding: 24rpx 24rpx 10rpx 24rpx;
  119. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03);
  120. }
  121. .card-title {
  122. font-size: 24rpx;
  123. font-weight: bold;
  124. color: #222;
  125. margin-bottom: 18rpx;
  126. }
  127. .row {
  128. display: flex;
  129. align-items: center;
  130. margin-bottom: 16rpx;
  131. }
  132. .label {
  133. color: #888;
  134. font-size: 26rpx;
  135. width: 160rpx;
  136. }
  137. .label.required {
  138. color: #222;
  139. font-weight: 500;
  140. }
  141. .value {
  142. color: #222;
  143. font-size: 26rpx;
  144. }
  145. .input {
  146. flex: 1;
  147. border: none;
  148. border-bottom: 1rpx solid #eee;
  149. font-size: 26rpx;
  150. padding: 8rpx 0;
  151. background: transparent;
  152. outline: none;
  153. }
  154. .order-card {
  155. border-radius: 20px;
  156. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  157. padding: 24px 20px 16px 20px;
  158. margin: 16px;
  159. position: relative;
  160. }
  161. .order-title {
  162. font-size: 18px;
  163. font-weight: bold;
  164. color: #222;
  165. margin-bottom: 12px;
  166. }
  167. .order-content {
  168. color: #bbb;
  169. font-size: 15px;
  170. margin-bottom: 8px;
  171. }
  172. .row.total-row {
  173. display: flex;
  174. align-items: center;
  175. margin-bottom: 0;
  176. }
  177. .order-total-label {
  178. color: #222;
  179. font-size: 18px;
  180. font-weight: 500;
  181. }
  182. .order-total {
  183. color: #222;
  184. font-size: 18px;
  185. font-weight: 500;
  186. margin-left: 8px;
  187. }
  188. .order-total-highlight {
  189. color: #ff7e00;
  190. font-size: 18px;
  191. font-weight: bold;
  192. margin: 0 2px;
  193. }
  194. .order-divider {
  195. width: 100%;
  196. height: 1px;
  197. background: #f2f2f2;
  198. margin-top: 16px;
  199. }
  200. .tip-text {
  201. color: #bbb;
  202. font-size: 22rpx;
  203. margin: 32rpx 32rpx 0 32rpx;
  204. line-height: 1.6;
  205. }
  206. .footer-bar {
  207. position: fixed;
  208. left: 0;
  209. right: 0;
  210. bottom: 90rpx;
  211. background: #fff;
  212. padding: 24rpx 32rpx 32rpx 32rpx;
  213. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  214. z-index: 10;
  215. }
  216. .buy-btn {
  217. width: 100%;
  218. background: #223a7a;
  219. color: #fff;
  220. font-size: 32rpx;
  221. border-radius: 32rpx;
  222. height: 88rpx;
  223. line-height: 88rpx;
  224. border: none;
  225. font-weight: 500;
  226. }
  227. .card.gift-card {
  228. border-radius: 20px;
  229. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  230. padding: 24px 20px 16px 20px;
  231. margin: 16px;
  232. position: relative;
  233. }
  234. .card-title {
  235. font-size: 18px;
  236. font-weight: bold;
  237. color: #222;
  238. margin-bottom: 12px;
  239. }
  240. .form-row {
  241. display: flex;
  242. flex-direction: column;
  243. align-items: flex-start;
  244. min-height: 36px;
  245. padding: 0;
  246. margin-top: 5rpx;
  247. }
  248. .form-label {
  249. color: #888;
  250. font-size: 14px;
  251. margin-bottom: 9px;
  252. font-weight: 400;
  253. margin-top: 5px;
  254. }
  255. .form-label.required {
  256. color: #222;
  257. font-weight: 500;
  258. display: flex;
  259. align-items: center;
  260. }
  261. .star {
  262. color: #e94f7a;
  263. margin-right: 2px;
  264. font-size: 16px;
  265. }
  266. .form-value {
  267. color: #0e0e0e;
  268. font-size: 14px;
  269. font-weight: 600;
  270. margin-bottom: 2px;
  271. }
  272. .form-input {
  273. flex: 1;
  274. border: none;
  275. background: transparent;
  276. font-size: 14px;
  277. outline: none;
  278. padding: 0;
  279. color: #222;
  280. }
  281. .divider {
  282. height: 1px;
  283. background: #f2f2f2;
  284. margin: 0 0 0 0;
  285. border: none;
  286. }
  287. .balance {
  288. color: #0e0e0e;
  289. font-size: 14px;
  290. margin: 0 0 8px 0;
  291. }
  292. .bean {
  293. color: #222;
  294. font-weight: 600;
  295. }
  296. </style>