推拿小程序前端代码仓库
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.

466 lines
11 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="提现" leftClick @leftClick="$utils.navigateBack" color="#fff" />
  5. <view class="content">
  6. <!-- 佣金信息 -->
  7. <view class="info">
  8. <image class="info-bg" src="/pages_order/static/withdraw/bg.png"></image>
  9. <view class="info-content">
  10. <view class="label">佣金</view>
  11. <view class="value">{{ userInfo.recommendAmount || 0 }}</view>
  12. <view class="flex desc">
  13. <!-- todo: 对接接口字段 -->
  14. <view>{{ `累积提现:${userInfo.cashoutSum || 0}` }}</view>
  15. <button plain class="btn" @click="toRunningWater">
  16. <text>提现记录</text>
  17. <image class="btn-icon" src="@/static/image/center/icon-arrow.png" mode="widthFix"></image>
  18. </button>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 我要提现 -->
  23. <view class="form">
  24. <view class="form-title">我要提现</view>
  25. <view class="form-item">
  26. <uv-input
  27. v-model.number="form.money"
  28. placeholder="请输入提现金额"
  29. :placeholderStyle="placeholderStyle"
  30. :customStyle="customStyle"
  31. color="#FF2A2A"
  32. >
  33. <template #prefix>
  34. <view class="unit"></view>
  35. </template>
  36. </uv-input>
  37. </view>
  38. <view class="form-item">
  39. <uv-input
  40. v-model.trim="form.name"
  41. placeholder="请输入真实姓名"
  42. :placeholderStyle="placeholderStyle"
  43. :customStyle="customStyle"
  44. ></uv-input>
  45. </view>
  46. </view>
  47. <!-- 提现说明 -->
  48. <view class="desc">
  49. <view class="desc-title">提现说明</view>
  50. <!-- todo: check -->
  51. <uv-parse class="desc-content" :content="configList.recharge_instructions"></uv-parse>
  52. <!-- <view v-html="configList.recharge_instructions" class="withdrawal-statement" style="color: #666666;"></view> -->
  53. </view>
  54. <view class="tools">
  55. <button class="flex btn" @click="withdraw">立即提现</button>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import mixinsList from '@/mixins/list.js'
  62. import mixinsConfigList from '@/mixins/configList.js'
  63. import {
  64. mapState
  65. } from 'vuex'
  66. export default {
  67. mixins: [mixinsList, mixinsConfigList],
  68. computed: {
  69. ...mapState(['userInfo', 'riceInfo']),
  70. },
  71. data() {
  72. return {
  73. form: {
  74. money: '',
  75. name: '',
  76. },
  77. placeholderStyle: {
  78. color: '#999999',
  79. fontSize: '28rpx',
  80. },
  81. customStyle: {
  82. backgroundColor: '#F5F5F5',
  83. border: 'none',
  84. borderRadius: '16rpx',
  85. padding: '28rpx 35rpx'
  86. }
  87. }
  88. },
  89. onLoad() {
  90. },
  91. onShow() {
  92. this.$store.commit('getUserInfo')
  93. this.$store.commit('getRiceInfo')
  94. },
  95. methods: {
  96. // #ifdef H5
  97. // 检查是否在微信环境
  98. isInWechat() {
  99. const ua = navigator.userAgent.toLowerCase()
  100. return ua.indexOf('micromessenger') !== -1
  101. },
  102. // #endif
  103. withdraw() { //立即提现
  104. if (!this.form.name) {
  105. uni.showToast({
  106. title: '请输入真实姓名',
  107. icon: 'none'
  108. })
  109. return
  110. }
  111. if (this.form.money < 1) {
  112. return uni.showToast({
  113. title: '提现只能是整数必须大于1!',
  114. icon: 'none'
  115. })
  116. }
  117. // todo
  118. // if (this.form.money < 300) {
  119. // return uni.showToast({
  120. // title: '未满300元不可提现哦!',
  121. // icon: 'none'
  122. // })
  123. // }
  124. let isOk = this.parameterVerification();
  125. if (isOk && !isOk.auth) {
  126. return uni.showToast({
  127. title: isOk.title,
  128. icon: 'none'
  129. })
  130. }
  131. // this.$api('recharge', this.form, res => {
  132. // if (res.code == 200) {
  133. // uni.showToast({
  134. // title: '提现成功',
  135. // icon: 'none'
  136. // })
  137. // this.$store.commit('getUserInfo')
  138. // this.$store.commit('getRiceInfo')
  139. // }
  140. // })
  141. // 显示提交中状态
  142. uni.showLoading({
  143. title: '提交中...'
  144. })
  145. // 提现
  146. this.$api('cashout', { transferAmount: this.form.money, userName: this.form.name }, res => {
  147. uni.hideLoading()
  148. if (res.code === 200) {
  149. // 处理待收款用户确认的情况
  150. if (res.result && res.result.state === 'WAIT_USER_CONFIRM' && res.result.packageInfo && res.result.outBillNo) {
  151. let data = res.result
  152. // #ifdef H5
  153. // H5环境下检查微信环境
  154. if (!this.isInWechat()) {
  155. uni.showToast({
  156. title: '请在微信中打开',
  157. icon: 'none'
  158. })
  159. return
  160. }
  161. // H5环境下使用专门的H5提现方法
  162. this.requestMerchantTransferH5(res.result.packageInfo, data.outBillNo)
  163. return
  164. // #endif
  165. // #ifdef MP-WEIXIN
  166. // 拉起微信收款确认页面
  167. if (!wx.canIUse('requestMerchantTransfer')) {
  168. wx.showModal({
  169. content: '你的微信版本过低,请更新至最新版本。',
  170. showCancel: false,
  171. });
  172. return
  173. }
  174. // 在真机环境中,调用API
  175. wx.requestMerchantTransfer({
  176. mchId: this.$config.mchId,
  177. appId: wx.getAccountInfoSync().miniProgram.appId,
  178. package: res.result.packageInfo,
  179. success: (res) => {
  180. uni.showToast({
  181. title: '提现申请已提交',
  182. icon: 'success'
  183. })
  184. this.form.money = ''
  185. this.form.name = ''
  186. this.$api('getMoney', {
  187. id : data.outBillNo,
  188. }).then(res => {
  189. this.$store.commit('getUserInfo')
  190. this.$store.commit('getRiceInfo')
  191. })
  192. },
  193. fail: (res) => {
  194. console.log('fail:', res);
  195. uni.showToast({
  196. title: '提现失败,请稍后再试',
  197. icon: 'none'
  198. })
  199. },
  200. complete: (res) => {
  201. console.log('requestMerchantTransfer完成:', res);
  202. }
  203. });
  204. // #endif
  205. } else {
  206. uni.showToast({
  207. title: '提现成功',
  208. icon: 'success'
  209. })
  210. this.$store.commit('getUserInfo')
  211. this.form.money = ''
  212. this.form.name = ''
  213. }
  214. }else{
  215. uni.showToast({
  216. title: res.message,
  217. icon: 'none'
  218. })
  219. }
  220. })
  221. },
  222. // #ifdef H5
  223. // H5环境下的微信收款确认
  224. requestMerchantTransferH5(packageInfo, outBillNo, callback) {
  225. // 使用Vue原型上的jWeixin
  226. const jWeixin = this.$jWeixin
  227. if (!jWeixin) {
  228. console.error('jWeixin未初始化')
  229. uni.showToast({
  230. title: '微信环境异常',
  231. icon: 'none'
  232. })
  233. return
  234. }
  235. jWeixin.ready(() => {
  236. jWeixin.checkJsApi({
  237. jsApiList: ['requestMerchantTransfer'],
  238. success: (res) => {
  239. if (res.checkResult['requestMerchantTransfer']) {
  240. // H5环境下使用WeixinJSBridge
  241. if (typeof WeixinJSBridge !== 'undefined') {
  242. WeixinJSBridge.invoke('requestMerchantTransfer', {
  243. appId: this.$config.appId,
  244. mchId: this.$config.mchId,
  245. package: packageInfo,
  246. }, (res) => {
  247. if (res.err_msg === 'requestMerchantTransfer:ok') {
  248. // 提现成功后的处理
  249. uni.showToast({
  250. title: '提现申请已提交',
  251. icon: 'success'
  252. })
  253. this.form.money = ''
  254. this.form.name = ''
  255. this.$api('getMoney', {
  256. id: outBillNo,
  257. }).then(res => {
  258. this.$store.commit('getUserInfo')
  259. this.$store.commit('getRiceInfo')
  260. })
  261. callback && callback()
  262. } else {
  263. console.log('提现失败:', res)
  264. uni.showToast({
  265. title: '提现失败,请稍后再试',
  266. icon: 'none'
  267. })
  268. }
  269. })
  270. } else {
  271. console.error('WeixinJSBridge未找到')
  272. uni.showToast({
  273. title: '请在微信中打开',
  274. icon: 'none'
  275. })
  276. }
  277. } else {
  278. uni.showToast({
  279. title: '你的微信版本过低,请更新至最新版本',
  280. icon: 'none'
  281. })
  282. }
  283. },
  284. fail: (error) => {
  285. console.error('checkJsApi失败:', error)
  286. uni.showToast({
  287. title: '微信接口检查失败',
  288. icon: 'none'
  289. })
  290. }
  291. })
  292. })
  293. jWeixin.error((res) => {
  294. console.error('微信配置失败:', res)
  295. uni.showToast({
  296. title: '微信配置失败',
  297. icon: 'none'
  298. })
  299. })
  300. },
  301. // #endif
  302. parameterVerification() { //验证用户参数合法性
  303. let {
  304. money
  305. } = this.form
  306. if (!money) {
  307. return {
  308. title: '请填写提现金额',
  309. auth: false
  310. }
  311. }
  312. return {
  313. title: '验证通过',
  314. auth: true
  315. }
  316. },
  317. toRunningWater() {
  318. uni.navigateTo({
  319. url: "/pages_order/mine/runningWater"
  320. })
  321. }
  322. }
  323. }
  324. </script>
  325. <style scoped lang="scss">
  326. .page {
  327. background-color: $uni-fg-color;
  328. min-height: 100vh;
  329. /deep/ .nav-bar__view {
  330. background-image: linear-gradient(#84A73F, #D8FF8F);
  331. }
  332. }
  333. .content {
  334. padding: 28rpx 13rpx;
  335. }
  336. .info {
  337. position: relative;
  338. width: 100%;
  339. height: 290rpx;
  340. &-bg {
  341. width: 100%;
  342. height: 100%;
  343. }
  344. &-content {
  345. position: absolute;
  346. top: 0;
  347. left: 0;
  348. width: 100%;
  349. box-sizing: border-box;
  350. padding: 42rpx 48rpx 0 35rpx;
  351. color: $uni-text-color-inverse;
  352. .label {
  353. font-size: 30rpx;
  354. }
  355. .value {
  356. margin-top: 18rpx;
  357. font-weight: 700;
  358. font-size: 55rpx;
  359. }
  360. .desc {
  361. justify-content: space-between;
  362. font-size: 22rpx;
  363. margin-top: 58rpx;
  364. }
  365. .btn {
  366. border: none;
  367. font-size: 22rpx;
  368. color: $uni-text-color-inverse;
  369. &-icon {
  370. width: 16rpx;
  371. height: 16rpx;
  372. margin-left: 7rpx;
  373. }
  374. }
  375. }
  376. }
  377. .form {
  378. margin-top: 30rpx;
  379. &-title {
  380. color: #000000;
  381. font-size: 28rpx;
  382. padding: 0 35rpx;
  383. }
  384. &-item {
  385. margin-top: 18rpx;
  386. .unit {
  387. color: #FF2A2A;
  388. padding-left: 42rpx;
  389. }
  390. }
  391. }
  392. .desc {
  393. margin-top: 45rpx;
  394. padding: 0 42rpx;
  395. font-size: 28rpx;
  396. &-title {
  397. color: #000000;
  398. }
  399. &-content {
  400. margin-top: 10rpx;
  401. color: #707070;
  402. }
  403. }
  404. .tools {
  405. margin-top: 166rpx;
  406. padding: 0 69rpx;
  407. .btn {
  408. width: 100%;
  409. padding: 29rpx 0;
  410. color: $uni-text-color-inverse;
  411. font-size: 28rpx;
  412. line-height: 40rpx;
  413. border-radius: 49rpx;
  414. border: none;
  415. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  416. }
  417. }
  418. </style>