多租户商城-商户小程序端
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.

324 lines
8.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <!--
  2. * @FileDescription: 收银台
  3. * @Author: kahu
  4. * @Date: 2022/11/21
  5. * @LastEditors: kahu
  6. * @LastEditTime: 2022/11/21
  7. -->
  8. <template>
  9. <view class="cashier-list-content">
  10. <u-radio-group
  11. v-model="paymentMode"
  12. placement="row"
  13. iconPlacement="right"
  14. @change="handleChangePaymentMode"
  15. >
  16. <view
  17. class="cashier"
  18. v-for="payment in paymentList"
  19. :key="payment.id"
  20. >
  21. <view class="cashier-item" @click="handleChangePaymentMode(payment.paymentMode,payment.disabled)"
  22. >
  23. <view class="icon-text">
  24. <image
  25. class="pay-type-img-inner"
  26. :src="payment.icon"
  27. mode="widthFix"
  28. />
  29. {{ payment.label }}
  30. <span v-if="paymentMode===3 && paymentMode === payment.paymentMode">手续费{{ flowerObj.hbServiceChargeTotal }}</span>
  31. </view>
  32. <view class="radio">
  33. <u-radio
  34. :disabled="payment.disabled"
  35. activeColor="#c5aa7b"
  36. :name="payment.paymentMode"
  37. />
  38. </view>
  39. </view>
  40. <!-- 花呗分期 -->
  41. <view
  42. class="ali-hb-content"
  43. v-if="paymentMode===3 && paymentMode === payment.paymentMode"
  44. >
  45. <u-radio-group
  46. v-model="flowerObj.hbByStagesPeriods"
  47. placement="row"
  48. iconPlacement="right"
  49. @change="handleChangePeriods"
  50. >
  51. <view
  52. class="cashier"
  53. v-for="(flowerItem,index) in flowerObj.hbByStagesList"
  54. :key="index"
  55. >
  56. <view class="cashier-item" @click="handleChangePeriods(flowerItem.numberOfStages,flowerItem.disabled)">
  57. <view class="icon-text">
  58. {{ flowerItem.numberOfStages }}{{ flowerItem.price }}/
  59. </view>
  60. <view class="radio-context">
  61. 手续费{{ flowerItem.serviceCharge }}/
  62. <u-radio
  63. class="radio"
  64. activeColor="#c5aa7b"
  65. :disabled="flowerItem.disabled"
  66. :name="flowerItem.numberOfStages"
  67. />
  68. </view>
  69. </view>
  70. </view>
  71. </u-radio-group>
  72. </view>
  73. </view>
  74. </u-radio-group>
  75. </view>
  76. </template>
  77. <script>
  78. import NET from "../../utils/request";
  79. import API from "../../config/api";
  80. export default {
  81. name: "CashierList",
  82. props: {
  83. totalPrice: {
  84. type: Number,
  85. default: () => 200
  86. }
  87. },
  88. data() {
  89. return {
  90. paymentMode: 1, // 支付方式 1微信 2支付宝 3花呗分期
  91. paymentList: [
  92. {
  93. id: 1,
  94. label: '微信支付',
  95. paymentMode: 1,
  96. icon: 'https://ceres.zkthink.com/static/images/wechat_pay.png',
  97. disabled:false
  98. },
  99. {
  100. id: 2,
  101. label: '支付宝支付',
  102. paymentMode: 2,
  103. icon: 'https://ceres.zkthink.com/static/images/alipay.png',
  104. disabled:false
  105. },
  106. {
  107. id: 3,
  108. label: '花呗分期',
  109. paymentMode: 3,
  110. icon: 'https://ceres.zkthink.com/static/images/huabei.png',
  111. disabled:false
  112. }
  113. ],
  114. // 花呗相关
  115. flowerObj: {
  116. hbChargeType: 1,// 花呗手续费支付方式 1-商户支付 2-用户支付 后端接口返回
  117. hbByStagesPeriods: -1, // 花呗分期期数 3 6 12
  118. hbByStagesList: [
  119. {
  120. rate: 0,
  121. price: 0,
  122. numberOfStages: 3,
  123. serviceCharge: 0,
  124. disabled: false
  125. },
  126. {
  127. rate: 0,
  128. price: 0,
  129. numberOfStages: 6,
  130. serviceCharge: 0,
  131. disabled: false
  132. },
  133. {
  134. rate: 0,
  135. price: 0,
  136. numberOfStages: 12,
  137. serviceCharge: 0,
  138. disabled: false
  139. }
  140. ], // 花呗手续费比例列表 【{3期},{6期},{12期}】
  141. hbServiceChargeTotal: 0, // 花呗支付总手续费
  142. },
  143. }
  144. },
  145. mounted(){
  146. this.getTheFlowerConfig()
  147. this.handleSetDisable()
  148. this.handleNoticeFather()
  149. },
  150. methods: {
  151. /**
  152. * 根据环境更改可选支付项
  153. */
  154. handleSetDisable(){
  155. // #ifdef MP-WEIXIN
  156. this.paymentList[0].disabled = false
  157. this.paymentList[1].disabled = true
  158. this.paymentList[2].disabled = true
  159. this.paymentList.splice(1, 1)
  160. this.paymentList.splice(1, 1)
  161. this.paymentMode = 1
  162. // #endif
  163. // #ifdef MP-ALIPAY
  164. this.paymentList[0].disabled = true
  165. this.paymentList[1].disabled = false
  166. this.paymentList[2].disabled = false
  167. this.paymentMode = 2
  168. // #endif
  169. // #ifdef APP-PLUS || H5
  170. console.log("H5")
  171. this.paymentList[0].disabled = false
  172. this.paymentList[1].disabled = true
  173. this.paymentList[2].disabled = true
  174. this.paymentList.splice(1, 1)
  175. this.paymentList.splice(1, 1)
  176. this.paymentMode = 1
  177. // #endif
  178. },
  179. /**
  180. * 支付方式改变事件
  181. * @param paymentMode
  182. * @param disabled
  183. */
  184. handleChangePaymentMode(paymentMode,disabled=false) {
  185. if(disabled) return
  186. this.paymentMode = paymentMode
  187. const { flowerObj } = this
  188. if ([1, 2].includes(paymentMode)) {
  189. // 支付宝支付,取消分期选择
  190. flowerObj.hbByStagesPeriods = -1
  191. // 3 6 12 全部禁止
  192. flowerObj.hbByStagesList.map(item => {
  193. item.disabled = true
  194. })
  195. } else {
  196. // 分期支付,默认选三期
  197. flowerObj.hbByStagesPeriods = 3
  198. }
  199. this.handleHbStagesAndPrice()
  200. this.handleNoticeFather()
  201. },
  202. /**
  203. * 获取花呗分期配置
  204. */
  205. async getTheFlowerConfig() {
  206. const {data} = await NET.request(API.GetHuabeiConfig, {}, 'GET')
  207. const {flowerObj} = this
  208. flowerObj.hbChargeType = data.huabeiChargeType
  209. // 如果后端返回的是用户支付手续费,设置费率信息
  210. if (data.huabeiChargeType === 1) {
  211. data.huabeiFeeRateList.forEach((rate, index) => {
  212. flowerObj.hbByStagesList[index].rate = rate
  213. })
  214. }
  215. },
  216. /**
  217. * 处理花呗期数选择
  218. * @param periods 期数
  219. * @param disabled
  220. */
  221. handleChangePeriods(periods,disable=false) {
  222. if(disable)return
  223. const { flowerObj } = this
  224. flowerObj.hbByStagesPeriods = periods
  225. this.handleHbStagesAndPrice()
  226. this.handleNoticeFather()
  227. },
  228. /**
  229. * 处理花呗价格和手续费显示
  230. */
  231. handleHbStagesAndPrice() {
  232. const {flowerObj, totalPrice} = this
  233. if (this.paymentMode !== 3) return
  234. flowerObj.hbByStagesList.forEach(stages => {
  235. // 根据价格填充每一期价格和手续费信息
  236. stages.price = ((totalPrice * (1 + stages.rate / 100)) / stages.numberOfStages).toFixed(2) // 每一期价格
  237. stages.serviceCharge = ((totalPrice * (stages.rate / 100)) / stages.numberOfStages).toFixed(2) // 每一期手续费
  238. // 计算总手续费
  239. if (stages.numberOfStages === Number(flowerObj.hbByStagesPeriods)) {
  240. flowerObj.hbServiceChargeTotal = (totalPrice * (stages.rate / 100)).toFixed(2)
  241. }
  242. // 处理允许分期的区间,公式为总价格要大于分期数/100
  243. this.totalPrice < stages.numberOfStages / 100?stages.disabled = true:stages.disabled = false
  244. })
  245. },
  246. /**
  247. * 通知父组件
  248. */
  249. handleNoticeFather(){
  250. const { paymentMode,flowerObj } = this
  251. const params = {
  252. paymentMode,
  253. huabeiPeriod:flowerObj.hbByStagesPeriods
  254. }
  255. this.$emit('change',params)
  256. }
  257. }
  258. }
  259. </script>
  260. <style
  261. lang="scss"
  262. scoped
  263. >
  264. .cashier-list-content {
  265. width: 100%;
  266. padding: 0rpx 15rpx;
  267. box-sizing: border-box;
  268. background: #fff;
  269. .u-radio-group {
  270. display: block !important;
  271. }
  272. .cashier {
  273. border-bottom: 2rpx solid #d0d0d0;
  274. &:last-child {
  275. border-bottom: none
  276. }
  277. .cashier-item {
  278. display: flex;
  279. align-items: center;
  280. justify-content: space-between;
  281. padding: 20rpx 0;
  282. box-sizing: border-box;
  283. position: relative;
  284. .icon-text {
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. image {
  289. width: 50rpx;
  290. height: 50rpx;
  291. margin-right: 15rpx;
  292. }
  293. }
  294. .radio-context{
  295. display: flex;
  296. align-items: center;
  297. font-size: 14rpx;
  298. .radio{
  299. margin-left: 15rpx;
  300. }
  301. }
  302. }
  303. .ali-hb-content {
  304. padding: 10rpx 20px;
  305. box-sizing: border-box;
  306. border-top: 2rpx solid #d0d0d0;
  307. }
  308. }
  309. }
  310. </style>