普兆健康管家前端代码仓库
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.

314 lines
7.0 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view>
  3. <uv-popup ref="popup" mode="bottom" bgColor="none" >
  4. <view class="popup__view">
  5. <view class="flex header">
  6. <view class="title">支付订单</view>
  7. <button class="btn" @click="close">关闭</button>
  8. </view>
  9. <view class="main">
  10. <view class="section flex flex-column info">
  11. <view class="info-title" v-if="orderData.title">{{ orderData.title }}</view>
  12. <view class="flex info-amount">¥<text class="highlight">{{ orderData.orderAmount }}</text></view>
  13. </view>
  14. <view class="section flex payment">
  15. <view class="flex">
  16. <image class="payment-icon" src="@/pages_order/static/order/icon-wx.png" mode="widthFix"></image>
  17. <view class="payment-text">微信</view>
  18. </view>
  19. <view>
  20. <uv-radio-group
  21. :value="1"
  22. shape="circle"
  23. size="36rpx"
  24. iconSize="36rpx"
  25. activeColor="#7451DE"
  26. >
  27. <uv-radio :name="1"></uv-radio>
  28. </uv-radio-group>
  29. </view>
  30. </view>
  31. <view class="section agreement">
  32. <uv-checkbox-group
  33. v-model="checkboxValue"
  34. shape="circle"
  35. >
  36. <uv-checkbox
  37. size="36rpx"
  38. icon-size="36rpx"
  39. activeColor="#7451DE"
  40. :name="1"
  41. ></uv-checkbox>
  42. </uv-checkbox-group>
  43. <view class="desc">
  44. 我已阅读并同意
  45. <text class="highlight" @click="$refs.modal.open('payment_user_agreement', '应用内支付用户协议')">应用内支付用户协议</text>
  46. <text class="highlight" @click="$refs.modal.open('statement_on_payment_and_privacy', '支付与隐私的声明')">支付与隐私的声明</text>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="flex footer">
  51. <button class="flex btn btn-cancel" @click="onCancel">暂不支付</button>
  52. <button class="flex btn btn-pay" @click="onPay">支付</button>
  53. </view>
  54. </view>
  55. </uv-popup>
  56. <agreementModal ref="modal" @confirm="onConfirmAgreement"></agreementModal>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. data() {
  62. return {
  63. orderData: {},
  64. checkboxValue: [],
  65. }
  66. },
  67. methods: {
  68. async fetchDelete(ids) {
  69. try {
  70. await this.$fetch('deleteCartBatch', { ids })
  71. } catch (err) {
  72. }
  73. },
  74. async open(data) {
  75. console.log('payPopup', data)
  76. try {
  77. const {
  78. id,
  79. title,
  80. list,
  81. addressId,
  82. orderAmount,
  83. } = data || {}
  84. let wxPayParams
  85. if (id) {
  86. wxPayParams = await this.$fetch('payOrder', { id })
  87. } else {
  88. console.log('list', list)
  89. let _list = list.map(item => ({ productId: item.id, specId: item.specId, num: 1, }))
  90. console.log('_list', _list)
  91. // todo: check is the time to create order?
  92. wxPayParams = await this.$fetch('createOrder', { list: JSON.stringify(_list), addressId })
  93. if (list[0].cartId) {
  94. let cartIds = list.map(item => item.cartId)
  95. this.fetchDelete(cartIds)
  96. }
  97. }
  98. this.orderData = {
  99. title,
  100. orderAmount,
  101. wxPayParams,
  102. }
  103. console.log('orderData', this.orderData)
  104. this.$refs.popup.open()
  105. } catch (err) {
  106. }
  107. },
  108. close() {
  109. this.$refs.popup.close()
  110. },
  111. onCancel() {
  112. this.close()
  113. this.$emit('payCancel')
  114. },
  115. onConfirmAgreement(confirm) {
  116. if (confirm) {
  117. this.checkboxValue = [1]
  118. } else {
  119. this.checkboxValue = []
  120. }
  121. },
  122. async onPay() {
  123. if(!this.checkboxValue.length){
  124. return uni.showToast({
  125. title: '请先同意《应用内支付用户协议》《支付与隐私的声明》',
  126. icon:'none'
  127. })
  128. }
  129. await uni.requestPaymentWxPay({ result: this.orderData.wxPayParams })
  130. uni.showToast({
  131. title: '支付成功',
  132. icon: 'none'
  133. })
  134. this.close()
  135. this.$emit('paySuccess')
  136. },
  137. },
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .popup__view {
  142. width: 100vw;
  143. display: flex;
  144. flex-direction: column;
  145. box-sizing: border-box;
  146. background: #FFFFFF;
  147. border-top-left-radius: 32rpx;
  148. border-top-right-radius: 32rpx;
  149. }
  150. .header {
  151. position: relative;
  152. width: 100%;
  153. padding: 24rpx 0;
  154. box-sizing: border-box;
  155. border-bottom: 2rpx solid #EEEEEE;
  156. .title {
  157. font-family: PingFang SC;
  158. font-weight: 500;
  159. font-size: 34rpx;
  160. line-height: 1.4;
  161. color: #181818;
  162. }
  163. .btn {
  164. font-family: PingFang SC;
  165. font-weight: 500;
  166. font-size: 32rpx;
  167. line-height: 1.4;
  168. color: #8B8B8B;
  169. position: absolute;
  170. top: 26rpx;
  171. left: 40rpx;
  172. }
  173. }
  174. .main {
  175. padding: 64rpx 40rpx;
  176. }
  177. .section {
  178. margin-top: 24rpx;
  179. }
  180. .info {
  181. row-gap: 8rpx;
  182. &-title {
  183. font-family: PingFang SC;
  184. font-weight: 400;
  185. font-size: 28rpx;
  186. line-height: 1.4;
  187. color: #000000;
  188. }
  189. &-amount {
  190. font-family: PingFang SC;
  191. font-weight: 500;
  192. font-size: 24rpx;
  193. line-height: 1.4;
  194. color: #7451DE;
  195. .highlight {
  196. font-size: 64rpx;
  197. margin-left: 8rpx;
  198. }
  199. }
  200. }
  201. .payment {
  202. justify-content: space-between;
  203. box-sizing: border-box;
  204. padding: 24rpx 32rpx;
  205. background: #FAFAFF;
  206. box-shadow: -4rpx -4rpx 20rpx 0 #FFFFFFC4,
  207. 4rpx 4rpx 20rpx 0 #AAAACC1F,
  208. 2rpx 2rpx 4rpx 0 #AAAACC40,
  209. -2rpx -2rpx 4rpx 0 #FFFFFF;
  210. border-radius: 32rpx;
  211. &-icon {
  212. width: 56rpx;
  213. height: auto;
  214. }
  215. &-text {
  216. margin-left: 16rpx;
  217. font-family: PingFang SC;
  218. font-weight: 400;
  219. font-size: 28rpx;
  220. line-height: 1.5;
  221. color: #252545;
  222. }
  223. }
  224. .agreement {
  225. margin-top: 24rpx;
  226. display: flex;
  227. .desc {
  228. font-family: PingFang SC;
  229. font-size: 24rpx;
  230. font-weight: 400;
  231. line-height: 1.4;
  232. color: #8B8B8B;
  233. }
  234. .highlight {
  235. color: $uni-color;
  236. }
  237. }
  238. .footer {
  239. width: 100%;
  240. padding: 32rpx 40rpx;
  241. box-sizing: border-box;
  242. border-top: 2rpx solid #F1F1F1;
  243. column-gap: 32rpx;
  244. .btn {
  245. flex: 1;
  246. font-family: PingFang SC;
  247. font-weight: 500;
  248. font-size: 36rpx;
  249. line-height: 1.4;
  250. border-radius: 41rpx;
  251. &-cancel {
  252. padding: 14rpx 0;
  253. color: #252545;
  254. border: 2rpx solid #252545;
  255. }
  256. &-pay {
  257. padding: 16rpx 0;
  258. color: #FFFFFF;
  259. background-image: linear-gradient(to right, #4B348F, #845CFA);
  260. }
  261. }
  262. }
  263. </style>