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

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