index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view class="ali-hb-pay-content">
  3. <u-popup
  4. v-model="showPopup" class="pay-type-popup" mode="bottom" border-radius="14"
  5. close-icon-pos="top-right"
  6. close-icon-size="20"
  7. >
  8. <view class="pay-type-item">
  9. <radio-group v-model="flowerObj.paymentMode" @change="payTypeChange">
  10. <view class="pay-type-radio">
  11. <view class="pay-type-img">
  12. <img class="pay-type-img-inner" src="../../static/images/origin/alipay.png" />
  13. </view>
  14. <label class="pay-type-label">支付宝支付</label>
  15. <radio
  16. class="pay-type-radio-item" style="transform:scale(0.7)" :checked="flowerObj.paymentMode === '2'"
  17. value="2"
  18. />
  19. </view>
  20. <view class="pay-type-radio">
  21. <view class="pay-type-img">
  22. <img class="pay-type-img-inner" src="../../static/images/origin/huabei.png" />
  23. </view>
  24. <label class="pay-type-label">花呗分期</label>
  25. <radio
  26. class="pay-type-radio-item" style="transform:scale(0.7)" :disabled="totalPrice < 0.03"
  27. :checked="flowerObj.paymentMode === '3'" value="3"
  28. />
  29. </view>
  30. </radio-group>
  31. <view v-if="flowerObj.paymentMode === '3'" class="huabei-detail">
  32. <radio-group v-model="flowerObj.hbByStagesPeriods" @change="handleChangePeriods">
  33. <view v-for="stages in flowerObj.hbByStagesList" class="period-radio">
  34. <view class="period-amount">
  35. <label class="period-each">¥ {{ stages.price }}x{{ stages.numberOfStages }}期</label>
  36. <label class="period-each-charge">手续费¥{{ stages.serviceCharge }}/期</label>
  37. </view>
  38. <radio
  39. class="period-type-radio-item" style="transform:scale(0.7)" :disabled="stages.disabled"
  40. :checked="Number(flowerObj.hbByStagesPeriods) === stages.numberOfStages"
  41. :value="stages.numberOfStages + ''"
  42. />
  43. </view>
  44. </radio-group>
  45. </view>
  46. </view>
  47. <view class="paytype-confirm">
  48. <view v-if="totalPrice >= 0.03 && flowerObj.paymentMode === '3'" class="fenqi-total-amount">
  49. <label class="fenqi-all">分期总额 ¥{{ totalPrice }}</label>
  50. <label class="charge-fee-all">手续费 ¥{{ flowerObj.hbServiceChargeTotal }}</label>
  51. </view>
  52. <view v-if="flowerObj.paymentMode === '2'" class="fenqi-total-amount">
  53. <label class="order-amount">订单总额 ¥{{ totalPrice }}</label>
  54. </view>
  55. <view class="fenqi-confirm">
  56. <text class="btn active" @click="handleAliPayConfirm">
  57. 确认
  58. </text>
  59. </view>
  60. </view>
  61. </u-popup>
  62. </view>
  63. </template>
  64. <script>
  65. import NET from '../../utils/request'
  66. import API from '../../config/api'
  67. import { handleDoPay } from '../../utils/payUtil'
  68. export default {
  69. name: 'AliHbPay',
  70. model: {
  71. prop: 'show',
  72. event: 'change'
  73. },
  74. props: {
  75. totalPrice: {
  76. type: Number | String,
  77. default: () => 0
  78. },
  79. show: {
  80. type: Boolean,
  81. default: false
  82. },
  83. alipayInfo: {
  84. type: Object,
  85. default: () => ({})
  86. }
  87. },
  88. data() {
  89. return {
  90. // 花呗相关
  91. flowerObj: {
  92. paymentMode: '2', // 支付方式 1-微信支付 2-支付宝支付 3-花呗分期
  93. hbChargeType: 1, // 花呗手续费支付方式 1-商户支付 2-用户支付 后端接口返回
  94. hbByStagesPeriods: '-1', // 花呗分期期数 3 6 12
  95. hbByStagesList: [
  96. {
  97. rate: 0,
  98. price: 0,
  99. numberOfStages: 3,
  100. serviceCharge: 0,
  101. disabled: false
  102. },
  103. {
  104. rate: 0,
  105. price: 0,
  106. numberOfStages: 6,
  107. serviceCharge: 0,
  108. disabled: false
  109. },
  110. {
  111. rate: 0,
  112. price: 0,
  113. numberOfStages: 12,
  114. serviceCharge: 0,
  115. disabled: false
  116. }
  117. ], // 花呗手续费比例列表 【{3期},{6期},{12期}】
  118. hbServiceChargeTotal: 0 // 花呗支付总手续费
  119. }
  120. }
  121. },
  122. computed: {
  123. showPopup: {
  124. get() {
  125. return this.show
  126. },
  127. set(value) {
  128. this.$emit('change', value)
  129. }
  130. }
  131. },
  132. mounted() {
  133. this.getTheFlowerConfig()
  134. },
  135. methods: {
  136. /**
  137. * 获取花呗分期配置
  138. */
  139. async getTheFlowerConfig() {
  140. const { data } = await NET.request(API.GetHuabeiConfig, {}, 'GET')
  141. const { flowerObj } = this
  142. flowerObj.hbChargeType = data.huabeiChargeType
  143. // 如果后端返回的是用户支付手续费,设置费率信息
  144. if (data.huabeiChargeType === 2) {
  145. data.huabeiFeeRateList.forEach((rate, index) => {
  146. flowerObj.hbByStagesList[index].rate = rate
  147. })
  148. }
  149. },
  150. /**
  151. * 处理花呗期数选择
  152. * @param event
  153. */
  154. handleChangePeriods(event) {
  155. this.flowerObj.hbByStagesPeriods = event
  156. this.handleHbStagesAndPrice()
  157. },
  158. /**
  159. * 处理支付宝支付方式选择逻辑
  160. * @param event
  161. */
  162. payTypeChange(event) {
  163. const flowerObj = this.flowerObj
  164. const paymentMode = flowerObj.paymentMode = event.target.value
  165. if (paymentMode === '2') {
  166. // 支付宝支付,取消分期选择
  167. flowerObj.hbByStagesPeriods = '-1'
  168. // 3 6 12 全部禁止
  169. flowerObj.hbByStagesList.map((item) => {
  170. item.disabled = true
  171. })
  172. } else {
  173. // 分期支付,默认选三期
  174. flowerObj.hbByStagesPeriods = '3'
  175. }
  176. this.handleHbStagesAndPrice()
  177. },
  178. /**
  179. * 处理花呗价格和手续费显示
  180. */
  181. handleHbStagesAndPrice() {
  182. const { flowerObj, totalPrice } = this
  183. if (flowerObj.paymentMode !== '3') return
  184. flowerObj.hbByStagesList.forEach((stages) => {
  185. // 根据价格填充每一期价格和手续费信息
  186. stages.price = ((totalPrice * (1 + stages.rate / 100)) / stages.numberOfStages).toFixed(2) // 每一期价格
  187. stages.serviceCharge = ((totalPrice * (stages.rate / 100)) / stages.numberOfStages).toFixed(2) // 每一期手续费
  188. // 计算总手续费
  189. if (stages.numberOfStages === Number(flowerObj.hbByStagesPeriods)) {
  190. flowerObj.hbServiceChargeTotal = (totalPrice * (stages.rate / 100)).toFixed(2)
  191. }
  192. // 处理允许分期的区间,公式为总价格要大于分期数/100
  193. if (this.totalPrice < stages.numberOfStages / 100) {
  194. stages.disabled = true
  195. }
  196. })
  197. },
  198. /**
  199. * 确认支付宝支付
  200. * @return {Promise<void>}
  201. */
  202. async handleAliPayConfirm() {
  203. const payInfo = Object.assign({}, this.alipayInfo, {
  204. 'paymentMode': this.flowerObj.paymentMode,
  205. 'huabeiPeriod': this.flowerObj.hbByStagesPeriods
  206. })
  207. await handleDoPay.call(this, payInfo)
  208. this.$emit('confirm', {
  209. 'paymentMode': this.flowerObj.paymentMode,
  210. 'huabeiPeriod': this.flowerObj.hbByStagesPeriods
  211. })
  212. }
  213. }
  214. }
  215. </script>
  216. <style
  217. lang="scss"
  218. scoped
  219. >
  220. .pay-type-item {
  221. .pay-type-radio {
  222. background-color: white;
  223. border-bottom: 1upx solid #EDEDED;
  224. margin-bottom: 20upx;
  225. padding: 24upx 20upx 24upx 20upx;
  226. .pay-type-img {
  227. display: inline-block;
  228. .pay-type-img-inner {
  229. width: 50upx;
  230. height: 50upx;
  231. vertical-align: middle;
  232. }
  233. }
  234. .pay-type-label {
  235. vertical-align: middle;
  236. margin-left: 30upx;
  237. }
  238. .pay-type-radio-item {
  239. float: right;
  240. margin-right: 20upx;
  241. width: 50upx;
  242. height: 50upx;
  243. }
  244. }
  245. .huabei-detail {
  246. margin-top: 20upx;
  247. .fenqi-wenzi {
  248. display: inline-block;
  249. margin-left: 64upx;
  250. }
  251. .fenqi-amount {
  252. display: block;
  253. margin-left: 64upx;
  254. margin-top: 14upx;
  255. color: #BABBBC;
  256. }
  257. .fenqi-charge-fee {
  258. float: right;
  259. margin-right: 68upx;
  260. color: #BABBBC;
  261. }
  262. .fenqi-modal {
  263. width: 40upx;
  264. height: 40upx;
  265. margin-left: 20upx;
  266. float: right;
  267. position: relative;
  268. top: -80upx;
  269. }
  270. }
  271. }
  272. .paytype-confirm {
  273. height: 120upx;
  274. padding: 0upx 108upx 0upx 32upx;
  275. .fenqi-all {
  276. display: inline-block;
  277. width: 100%;
  278. }
  279. .fenqi-total-amount {
  280. width: 65%;
  281. float: left;
  282. }
  283. .fenqi-confirm {
  284. float: right;
  285. width: 160upx;
  286. padding: 0upx 20upx;
  287. .btn {
  288. width: 216upx;
  289. height: 80upx;
  290. line-height: 80upx;
  291. border-radius: 40upx;
  292. font-size: 28upx;
  293. text-align: center;
  294. background: linear-gradient(90deg, rgba(255, 162, 0, 1), rgba(255, 121, 17, 1));
  295. color: #fff;
  296. display: inline-block;
  297. margin-right: 66upx;
  298. }
  299. }
  300. }
  301. .period-radio {
  302. margin: 30upx;
  303. padding-right: 100upx;
  304. width: 95%;
  305. border-bottom: 1px solid #EFEFEF;
  306. .period-amount {
  307. display: inline-block;
  308. .period-each-charge {
  309. display: inline-block;
  310. margin-top: 12upx;
  311. margin-left: 6upx;
  312. font-size: 26upx;
  313. color: #b7b7b7;
  314. margin-bottom: 13upx;
  315. }
  316. }
  317. .period-each {
  318. display: block;
  319. }
  320. .period-type-radio-item {
  321. float: right;
  322. }
  323. }
  324. </style>