CashierList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view class="cashier-list-content">
  3. <view v-if="show">
  4. <tui-radio-group v-model="paymentMode" @change="handleChangePaymentMode">
  5. <view v-for="payment in paymentList" :key="payment.paymentMode" class="cashier">
  6. <view class="cashier-item">
  7. <view class="icon-text">
  8. <image class="pay-type-img-inner" :src="payment.icon" mode="widthFix" />
  9. <text>{{ payment.label }}</text>
  10. <text v-if="(payment.paymentMode === '5')">(余额:{{ pricePlatformInfo.totalPrice }})</text>
  11. <text v-if="(payment.paymentMode === '6')">(余额:{{ priceShopInfo.current }})</text>
  12. <text v-if="(paymentMode === '3') && (paymentMode === payment.paymentMode)">
  13. (手续费:¥{{ flowerObj.hbServiceChargeTotal }})
  14. </text>
  15. </view>
  16. <view class="radio">
  17. <tui-radio
  18. :checked="false" :disabled="payment.disabled" :value="payment.paymentMode" color="#07c160"
  19. border-color="#999"
  20. >
  21. </tui-radio>
  22. </view>
  23. </view>
  24. <!-- 花呗分期 -->
  25. <view v-if="(paymentMode === '3') && (paymentMode === payment.paymentMode)" class="ali-hb-content">
  26. <tui-radio-group v-model="flowerObj.hbByStagesPeriods" @change="handleChangePeriods">
  27. <view v-for="(flowerItem, index) in flowerObj.hbByStagesList" :key="index" class="cashier">
  28. <view class="cashier-item">
  29. <view class="icon-text">
  30. {{ flowerItem.numberOfStages }}期(¥{{ flowerItem.price }}/期)
  31. </view>
  32. <view class="radio-context">
  33. 手续费:¥{{ flowerItem.serviceCharge }}/期
  34. <tui-radio
  35. class="radio" :checked="false" :disabled="flowerItem.disabled"
  36. :value="flowerItem.numberOfStages" color="#c5aa7b" border-color="#999"
  37. >
  38. </tui-radio>
  39. </view>
  40. </view>
  41. </view>
  42. </tui-radio-group>
  43. </view>
  44. </view>
  45. </tui-radio-group>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { getOrderHuabeiConfigApi, getPricePlatformAllApi, getRechargeTotalCustomersApi } from '../../api/anotherTFInterface'
  51. export default {
  52. name: 'CashierList',
  53. props: {
  54. pricePay: {
  55. type: Number,
  56. default: 0
  57. },
  58. // 是否显示,用于默认某一个支付
  59. show: {
  60. type: Boolean,
  61. default: false
  62. },
  63. showWechatPay: {
  64. type: Boolean,
  65. default: false
  66. },
  67. showAliPay: {
  68. type: Boolean,
  69. default: false
  70. },
  71. showHuabeiPay: {
  72. type: Boolean,
  73. default: false
  74. },
  75. showTonglianPay: {
  76. type: Boolean,
  77. default: true
  78. },
  79. // 平台余额支付
  80. showPlatformPay: {
  81. type: Boolean,
  82. default: false
  83. },
  84. // 用户的商家充值的余额支付
  85. shopIdPay: {
  86. type: [String, Number],
  87. default: ''
  88. }
  89. },
  90. data() {
  91. return {
  92. paymentMode: '', // 支付方式 1微信 2支付宝 3花呗分期
  93. paymentList: [],
  94. // 花呗相关
  95. flowerObj: {
  96. huabeiChargeType: 0, // 花呗手续费支付方式 1-商户支付 2-用户支付 后端接口返回
  97. hbByStagesPeriods: '-1', // 花呗分期期数 3 6 12
  98. hbByStagesList: [
  99. {
  100. rate: 0,
  101. price: 0,
  102. numberOfStages: '3',
  103. serviceCharge: 0,
  104. disabled: false
  105. },
  106. {
  107. rate: 0,
  108. price: 0,
  109. numberOfStages: '6',
  110. serviceCharge: 0,
  111. disabled: false
  112. },
  113. {
  114. rate: 0,
  115. price: 0,
  116. numberOfStages: '12',
  117. serviceCharge: 0,
  118. disabled: false
  119. }
  120. ], // 花呗手续费比例列表 【{3期},{6期},{12期}】
  121. hbServiceChargeTotal: 0 // 花呗支付总手续费
  122. },
  123. // 平台余额相关
  124. pricePlatformInfo: {
  125. totalPrice: 0 // 账户总余额
  126. },
  127. // 用户的商家充值的余额相关
  128. priceShopInfo: {
  129. current: 0
  130. }
  131. }
  132. },
  133. watch: { // 对于watch,按书写顺序执行(如果由同步代码触发)。shopIdPay->pricePay
  134. showPlatformPay: {
  135. handler(newValue, oldValue) {
  136. if (newValue) {
  137. uni.showLoading()
  138. if (!this.paymentList.find((item) => item.paymentMode === '5')) {
  139. this.paymentList.push({
  140. label: '平台余额支付',
  141. paymentMode: '5',
  142. icon: require('../../static/images/user/pay/platform-pay.png'),
  143. disabled: true
  144. })
  145. }
  146. getPricePlatformAllApi({})
  147. .then((res) => {
  148. this.pricePlatformInfo = res.data
  149. this.paymentList.find((item) => item.paymentMode === '5').disabled = !this.pricePay || (this.pricePay > this.pricePlatformInfo.totalPrice)
  150. if (this.paymentList.find((item) => item.paymentMode === '5').disabled && (this.paymentMode === '5')) this.handleSetDisable()
  151. this.handleNoticeFather()
  152. uni.hideLoading()
  153. })
  154. .catch((e) => {
  155. if (this.paymentMode === '5') this.handleSetDisable()
  156. if (this.paymentList.find((item) => item.paymentMode === '5')) this.paymentList.splice(this.paymentList.findIndex((item) => item.paymentMode === '5'), 1)
  157. this.handleNoticeFather()
  158. uni.hideLoading()
  159. })
  160. } else {
  161. if (this.paymentMode === '5') this.handleSetDisable()
  162. if (this.paymentList.find((item) => item.paymentMode === '5')) this.paymentList.splice(this.paymentList.findIndex((item) => item.paymentMode === '5'), 1)
  163. this.handleNoticeFather()
  164. }
  165. },
  166. immediate: false,
  167. deep: true
  168. },
  169. shopIdPay: {
  170. handler(newValue, oldValue) {
  171. // console.log(2222)
  172. if (newValue && (newValue !== oldValue)) {
  173. uni.showLoading()
  174. if (!this.paymentList.find((item) => item.paymentMode === '6')) {
  175. this.paymentList.push({
  176. label: '商家余额支付',
  177. paymentMode: '6',
  178. icon: require('../../static/images/user/pay/shop-id-pay.png'),
  179. disabled: true
  180. })
  181. }
  182. getRechargeTotalCustomersApi({ shopId: this.shopIdPay })
  183. .then((res) => {
  184. // console.log(3333)
  185. this.priceShopInfo = res.data
  186. this.paymentList.find((item) => item.paymentMode === '6').disabled = !this.pricePay || (this.pricePay > this.priceShopInfo.current)
  187. if (this.paymentList.find((item) => item.paymentMode === '6').disabled && (this.paymentMode === '6')) this.handleSetDisable()
  188. this.handleNoticeFather()
  189. uni.hideLoading()
  190. })
  191. .catch((e) => {
  192. if (this.paymentMode === '6') this.handleSetDisable()
  193. if (this.paymentList.find((item) => item.paymentMode === '6')) this.paymentList.splice(this.paymentList.findIndex((item) => item.paymentMode === '6'), 1)
  194. this.handleNoticeFather()
  195. uni.hideLoading()
  196. })
  197. } else if (!newValue) {
  198. if (this.paymentMode === '6') this.handleSetDisable()
  199. if (this.paymentList.find((item) => item.paymentMode === '6')) this.paymentList.splice(this.paymentList.findIndex((item) => item.paymentMode === '6'), 1)
  200. this.handleNoticeFather()
  201. }
  202. },
  203. immediate: false,
  204. deep: true
  205. },
  206. pricePay: {
  207. handler(newValue, oldValue) {
  208. // console.log(1111)
  209. if (newValue !== oldValue) {
  210. if (this.paymentMode === '3') {
  211. this.handleHbStagesAndPrice()
  212. }
  213. if (this.showPlatformPay) {
  214. this.paymentList.find((item) => item.paymentMode === '5').disabled = !this.pricePay || (this.pricePay > this.pricePlatformInfo.totalPrice)
  215. if (this.paymentList.find((item) => item.paymentMode === '5').disabled && (this.paymentMode === '5')) this.handleSetDisable()
  216. } else if (!this.showPlatformPay && (this.paymentMode === '5')) {
  217. this.handleSetDisable()
  218. }
  219. if (this.shopIdPay) { // pricePay依赖shopIdPay,所以pricePay放后面
  220. if (this.paymentList.find((item) => item.paymentMode === '6')) {
  221. this.paymentList.find((item) => item.paymentMode === '6').disabled = !this.pricePay || (this.pricePay > this.priceShopInfo.current)
  222. if (this.paymentList.find((item) => item.paymentMode === '6').disabled && (this.paymentMode === '6')) this.handleSetDisable()
  223. }
  224. } else if (!this.shopIdPay && (this.paymentMode === '6')) {
  225. this.handleSetDisable()
  226. }
  227. this.handleNoticeFather()
  228. }
  229. },
  230. immediate: false,
  231. deep: true
  232. }
  233. },
  234. created() {
  235. this.paymentList = []
  236. if (this.showWechatPay) {
  237. this.paymentList.push({
  238. label: '微信支付',
  239. paymentMode: '1',
  240. icon: require('../../static/images/user/pay/wechat_pay.png'),
  241. disabled: true
  242. })
  243. }
  244. if (this.showAliPay) {
  245. this.paymentList.push({
  246. label: '支付宝支付',
  247. paymentMode: '2',
  248. icon: require('../../static/images/user/pay/alipay.png'),
  249. disabled: true
  250. })
  251. }
  252. if (this.showHuabeiPay) {
  253. this.paymentList.push({
  254. label: '花呗分期',
  255. paymentMode: '3',
  256. icon: require('../../static/images/user/pay/huabei.png'),
  257. disabled: true
  258. })
  259. }
  260. if (this.showTonglianPay) {
  261. this.paymentList.push({
  262. label: '通联支付',
  263. paymentMode: '4',
  264. icon: require('../../static/images/user/pay/tonglian.png'),
  265. disabled: true
  266. })
  267. }
  268. if (this.showPlatformPay) {
  269. this.paymentList.push({
  270. label: '平台余额支付',
  271. paymentMode: '5',
  272. icon: require('../../static/images/user/pay/platform-pay.png'),
  273. disabled: true
  274. })
  275. getPricePlatformAllApi({})
  276. .then((res) => {
  277. this.pricePlatformInfo = res.data
  278. this.paymentList.find((item) => item.paymentMode === '5').disabled = !this.pricePay || (this.pricePay > this.pricePlatformInfo.totalPrice)
  279. })
  280. }
  281. if (this.shopIdPay) {
  282. this.paymentList.push({
  283. label: '商家余额支付',
  284. paymentMode: '6',
  285. icon: require('../../static/images/user/pay/shop-id-pay.png'),
  286. disabled: true
  287. })
  288. getRechargeTotalCustomersApi({ shopId: this.shopIdPay })
  289. .then((res) => {
  290. this.priceShopInfo = res.data
  291. this.paymentList.find((item) => item.paymentMode === '6').disabled = !this.pricePay || (this.pricePay > this.priceShopInfo.current)
  292. })
  293. }
  294. },
  295. mounted() {
  296. // 获取花呗分期配置
  297. getOrderHuabeiConfigApi({})
  298. .then((res) => {
  299. this.flowerObj.huabeiChargeType = res.data.huabeiChargeType
  300. if (this.flowerObj.huabeiChargeType === 1) { // 如果后端返回的是用户支付手续费,设置费率信息
  301. res.data.huabeiFeeRateList.forEach((rate, index) => {
  302. this.flowerObj.hbByStagesList[index].rate = rate
  303. })
  304. }
  305. this.handleSetDisable()
  306. this.handleNoticeFather()
  307. })
  308. .catch((e) => {
  309. this.handleSetDisable()
  310. this.handleNoticeFather()
  311. })
  312. },
  313. methods: {
  314. /**
  315. * 根据环境更改可选支付项
  316. */
  317. handleSetDisable() {
  318. // #ifdef MP-WEIXIN
  319. // this.paymentList.find((item) => item.paymentMode === '1').disabled = false
  320. this.paymentList.find((item) => item.paymentMode === '4').disabled = false
  321. this.paymentMode = '4' // 1
  322. // #endif
  323. // #ifdef MP-ALIPAY
  324. // this.paymentList.find((item) => item.paymentMode === '2').disabled = false
  325. // if(this.flowerObj.huabeiChargeType) this.paymentList.find((item) => item.paymentMode === '3').disabled = false
  326. this.paymentList.find((item) => item.paymentMode === '4').disabled = false
  327. this.paymentMode = '4' // 2
  328. // #endif
  329. // #ifdef APP || H5
  330. // this.paymentList.find((item) => item.paymentMode === '1').disabled = false
  331. this.paymentList.find((item) => item.paymentMode === '4').disabled = false
  332. this.paymentMode = '4' // 1
  333. // #endif
  334. },
  335. /**
  336. * 支付方式改变事件
  337. * @param paymentMode
  338. * @param disabled
  339. */
  340. handleChangePaymentMode(e) {
  341. console.log(e.detail.value)
  342. if (this.paymentList.find((item) => item.paymentMode === e.detail.value).disabled) return
  343. this.paymentMode = e.detail.value
  344. const { flowerObj } = this
  345. if (this.paymentMode !== '3') {
  346. // 支付宝支付,取消分期选择
  347. flowerObj.hbByStagesPeriods = '-1'
  348. // 3 6 12 全部禁止
  349. flowerObj.hbByStagesList.forEach((item) => {
  350. item.disabled = true
  351. })
  352. } else {
  353. // 分期支付,默认选三期
  354. flowerObj.hbByStagesPeriods = '3'
  355. }
  356. this.handleHbStagesAndPrice()
  357. this.handleNoticeFather()
  358. },
  359. /**
  360. * 处理花呗期数选择
  361. * @param periods 期数
  362. * @param disabled
  363. */
  364. handleChangePeriods(e) {
  365. if (this.flowerObj.hbByStagesList.find((item) => item.numberOfStages === e.detail.value).disabled) return
  366. this.flowerObj.hbByStagesPeriods = e.detail.value
  367. this.handleHbStagesAndPrice()
  368. this.handleNoticeFather()
  369. },
  370. /**
  371. * 处理花呗价格和手续费显示
  372. */
  373. handleHbStagesAndPrice() {
  374. if (this.paymentMode !== '3') return
  375. this.flowerObj.hbByStagesList.forEach((stages) => {
  376. // 根据价格填充每一期价格和手续费信息
  377. stages.price = ((this.pricePay * (1 + stages.rate / 100)) / Number(stages.numberOfStages)).toFixed(2) // 每一期价格
  378. stages.serviceCharge = ((this.pricePay * (stages.rate / 100)) / Number(stages.numberOfStages)).toFixed(2) // 每一期手续费
  379. // 计算总手续费
  380. if (Number(stages.numberOfStages) === Number(this.flowerObj.hbByStagesPeriods)) {
  381. this.flowerObj.hbServiceChargeTotal = (this.pricePay * (stages.rate / 100)).toFixed(2)
  382. }
  383. // 处理允许分期的区间,公式为总价格要大于分期数/100
  384. this.pricePay < Number(stages.numberOfStages) / 100 ? stages.disabled = true : stages.disabled = false
  385. })
  386. },
  387. /**
  388. * 通知父组件
  389. */
  390. handleNoticeFather() {
  391. this.$emit('change', {
  392. paymentMode: Number(this.paymentMode),
  393. huabeiPeriod: this.paymentMode === '3' ? Number(this.flowerObj.hbByStagesPeriods) : -1
  394. })
  395. }
  396. }
  397. }
  398. </script>
  399. <style lang="less" scoped>
  400. .cashier-list-content {
  401. width: 100%;
  402. padding: 0rpx 15rpx;
  403. box-sizing: border-box;
  404. background: #fff;
  405. .u-radio-group {
  406. display: block !important;
  407. }
  408. .cashier {
  409. border-bottom: 2rpx solid #d0d0d0;
  410. &:last-child {
  411. border-bottom: none
  412. }
  413. .cashier-item {
  414. display: flex;
  415. align-items: center;
  416. justify-content: space-between;
  417. padding: 20rpx 0;
  418. box-sizing: border-box;
  419. position: relative;
  420. .icon-text {
  421. display: flex;
  422. align-items: center;
  423. justify-content: center;
  424. image {
  425. width: 50rpx;
  426. height: 50rpx;
  427. margin-right: 15rpx;
  428. }
  429. }
  430. .radio-context {
  431. display: flex;
  432. align-items: center;
  433. font-size: 24rpx;
  434. .radio {
  435. margin-left: 15rpx;
  436. }
  437. }
  438. }
  439. .ali-hb-content {
  440. padding: 10rpx 20px;
  441. box-sizing: border-box;
  442. border-top: 2rpx solid #d0d0d0;
  443. }
  444. }
  445. }
  446. </style>