pay.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <template>
  2. <view :class="[AppTheme]" class="app">
  3. <view class="price-box">
  4. <text>支付金额</text>
  5. <text class="price text-neutral">{{payprice}}</text>
  6. </view>
  7. <view class="pay-type-list">
  8. <view class="type-item b-b" @click="changePayType(1)">
  9. <u-icon name="weixin-fill" color="#62b900" size="30"></u-icon>
  10. <view class="con">
  11. <text class="tit">微信支付</text>
  12. <text>推荐使用微信支付</text>
  13. </view>
  14. <label class="radio">
  15. <radio value="" :color="primary" :checked='payType == 1' />
  16. </radio>
  17. </label>
  18. </view>
  19. <view class="type-item" @click="changePayType(2)">
  20. <u-icon name="red-packet-fill" color="rgb(224, 116, 114)" size="30"></u-icon>
  21. <view class="con">
  22. <text class="tit">余额支付</text>
  23. <text>可用余额 ¥{{money}}</text>
  24. </view>
  25. <label class="radio">
  26. <radio value="" :color="primary" :checked='payType == 2' />
  27. </radio>
  28. </label>
  29. </view>
  30. </view>
  31. <text class="mix-btn bg-linear-gradient" @click="confirm">确认支付</text>
  32. <u-keyboard ref="uKeyboard" mode="number" :tooltip="false" :safeAreaInsetBottom="true" :overlay="true"
  33. :closeOnClickOverlay="true" :dotDisabled="false" @change="onChange" @backspace="onBackspace" :show="show">
  34. <view>
  35. <view class="u-text-center u-padding-20 money">
  36. <view class="text-neutral">
  37. <text>{{payprice}}</text>
  38. <text class="u-font-20 u-padding-left-10">元</text>
  39. </view>
  40. <view class="u-padding-10 close" data-flag="false" @tap="showPop(false)">
  41. <u-icon name="close" color="#333333" size="28"></u-icon>
  42. </view>
  43. </view>
  44. <view class="u-flex u-row-center codeinput" style="margin: 20rpx 0; padding: auto;100%;">
  45. <u-code-input :color="primary" :borderColor="primary" :space="20" size="40" mode="box"
  46. :maxlength="6" :dot="true" v-model="password" :disabledKeyboard="true" @finish="finish">
  47. </u-code-input>
  48. </view>
  49. </view>
  50. </u-keyboard>
  51. </view>
  52. </template>
  53. <script>
  54. import wallApi from '@/api/wall/index.js';
  55. import cart from '@/api/cart/index.js';
  56. import api from '@/api/mall/index.js';
  57. import adoptApi from '@/api/home/index.js';
  58. import loginApi from '@/api/login/login.js';
  59. export default {
  60. data() {
  61. return {
  62. primary: this.$theme.primary,
  63. settingFile: getApp().globalData.siteinfo,
  64. payType: 1,
  65. orderInfo: {},
  66. money: '',
  67. show: false,
  68. password: '',
  69. payprice: '',
  70. orderid: '',
  71. djqid: '',
  72. n_type: 0,
  73. oid: '',
  74. goodids: '',
  75. params: {
  76. // 支付方式
  77. paytype: 1, //为1是微信支付 2是支付宝支付
  78. rid: '',
  79. systype: '', //h5 或 app
  80. money: 1
  81. }
  82. };
  83. },
  84. computed: {
  85. },
  86. onLoad(options) {
  87. console.log(options)
  88. this.goodids = options.goodids ? options.goodids : ''
  89. this.orderid = options.orderid ? options.orderid : '';
  90. this.djqid = options.djqid ? options.djqid : '';
  91. this.payprice = parseFloat(options.payprice ? options.payprice : 0).toFixed(2);
  92. this.params.money = Number(this.payprice)
  93. this.n_type = options.type ? options.type : 0
  94. this.oid = options.oid ? options.oid : 0
  95. wallApi.income({}).then(res => {
  96. console.log(res)
  97. if (res.status == 200) {
  98. this.money = res.data.money; //余额
  99. }
  100. });
  101. },
  102. methods: {
  103. //选择支付方式
  104. changePayType(type) {
  105. this.payType = type;
  106. },
  107. //确认支付
  108. confirm() {
  109. // // #ifdef H5
  110. // // H5支付
  111. // console.log('进来了');
  112. // this.params.systype = 'h5'
  113. // if (this.params.paytype === 1) {
  114. // this.params.paytype = 'wxpay'
  115. // //paytype为1使用微信支付
  116. // wallApi.Wxpaycz(this.params).then(res => {
  117. // this.params.paytype = 1
  118. // if (res.status == 200) {
  119. //
  120. // this.wxPay(res.data)
  121. // } else {
  122. // uni.showToast({
  123. // icon: 'none',
  124. // title: res.msg
  125. // })
  126. // }
  127. // })
  128. // }
  129. // // #endif
  130. // // #ifdef APP-PLUS
  131. // if(this.payType == 1){
  132. // let orderInfo = JSON.stringify(this.params)
  133. // this.params.systype = 'app'
  134. // let payplatform = ''
  135. // if (this.params.paytype === 1 || this.params.paytype === 2) {
  136. // //paytype为1使用微信支付,为2使用支付宝支付
  137. // payplatform = this.params.paytype === 1 ? 'wxpay' : 'alipay'
  138. // this.params.paytype = 'wxpay'
  139. // console.log(this.params);
  140. // wallApi.Wxpaycz(this.params).then(res => {
  141. // this.params.paytype = 1
  142. //
  143. // if (res.code === 1) {
  144. // uni.requestPayment({
  145. // provider: payplatform,
  146. // orderInfo: res.data,
  147. // //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  148. // success: function(res) {
  149. //
  150. // uni.showToast({
  151. // title: '购买会员成功',
  152. // icon: 'none'
  153. // })
  154. // setTimeout(() => {
  155. // uni.navigateBack({
  156. // delta: 1
  157. // })
  158. // }, 1000)
  159. // },
  160. // fail: function(err) {
  161. // console.log(err);
  162. // uni.showToast({
  163. // title: err.errMsg,
  164. // icon: 'none'
  165. // })
  166. // }
  167. // })
  168. // } else {
  169. // uni.showToast({
  170. // title: res.msg,
  171. // icon: 'none'
  172. // })
  173. // }
  174. // })
  175. // } else {
  176. // // paytype为3,使用余额支付
  177. // // this.balancepayment(this.params)
  178. // console.log('错误');
  179. // }
  180. // }
  181. // // #endif
  182. if (this.payType == 2) {
  183. this.show = true;
  184. this.password = ''
  185. } else {
  186. if (this.n_type == 1) {
  187. this.wxZf(); // 农场微信支付
  188. } else {
  189. console.log('走到这了');
  190. this.pay(); // 支付
  191. }
  192. }
  193. },
  194. onChange(val) {
  195. if (this.password.length < 6) {
  196. this.password += val;
  197. }
  198. if (this.password.length >= 6) {
  199. if (this.n_type == 1) {
  200. this.goZf()
  201. } else {
  202. this.pay(); // 支付
  203. }
  204. }
  205. },
  206. onBackspace(e) {
  207. if (this.password.length > 0) {
  208. this.password = this.password.substring(0, this.password.length - 1);
  209. }
  210. },
  211. pay() {
  212. let that = this
  213. uni.showLoading({
  214. title: '支付中'
  215. })
  216. if (this.payType == 1) {
  217. pays(this.payType)
  218. return
  219. }
  220. cart.checkPayPassword({
  221. password: this.password
  222. }).then(res => {
  223. console.log(res)
  224. uni.hideLoading();
  225. if (res.status == 200) {
  226. this.showPop(false)
  227. pays(this.payType)
  228. } else if (res.status == 0) {
  229. this.showPop(false)
  230. this.$refs.uTips.show({
  231. title: res.msg,
  232. type: 'error',
  233. duration: '2300',
  234. icon: "none"
  235. })
  236. if (res.msg === '未设置支付密码,现在进行设置!') {
  237. console.log(res.msg)
  238. setTimeout(() => {
  239. that.$u.route({
  240. url: '/pagesD/pages/set/changemima/changemima'
  241. })
  242. }, 1000)
  243. }
  244. }
  245. })
  246. function pays(payType) {
  247. if (that.orderid) {
  248. var obj = {
  249. orderid: that.orderid,
  250. sid: 0
  251. };
  252. payType === 1 ? obj["type"] = 'wxpay' : obj["type"] = 'money';
  253. payType === 1 ? wxpay(obj) : money(obj);
  254. return
  255. }
  256. var pages = getCurrentPages();
  257. if (pages[pages.length - 2] && pages[pages.length - 2].$vm) {
  258. var page = pages[pages.length - 2].$vm;
  259. page.goumai(payType)
  260. }
  261. function wxpay(res) {
  262. api.wxpay(res).then(ret => {
  263. if (ret.return_msg) {
  264. uni.showToast({
  265. title: ret.return_msg,
  266. icon: 'error',
  267. duration: 1500
  268. });
  269. } else {
  270. uni.requestPayment({
  271. provider: 'wxpay',
  272. timeStamp: ret.timeStamp,
  273. nonceStr: ret.nonceStr,
  274. package: ret.package,
  275. signType: ret.signType,
  276. paySign: ret.paySign,
  277. success: function(res) {
  278. uni.showToast({
  279. title: '微信支付成功',
  280. icon: 'success',
  281. duration: 1500
  282. });
  283. uni.redirectTo({
  284. url: '/pagesD/pages/money/paySuccess'
  285. });
  286. },
  287. fail: function(err) {
  288. console.log('fail999999')
  289. }
  290. });
  291. }
  292. });
  293. }
  294. function money(res) {
  295. /* 支付 */
  296. api.pay(res).then(ret => {
  297. console.log(ret, "ret");
  298. that.$u.toast(ret.msg);
  299. if (ret.status == 200) {
  300. if (ret.data.id) {
  301. that.$u.route('/pagesD/pages/mall/groupShare', {
  302. id: ret.data.id
  303. });
  304. } else {
  305. uni.redirectTo({
  306. url: '/pagesD/pages/money/paySuccess'
  307. });
  308. }
  309. }
  310. });
  311. }
  312. }
  313. },
  314. showPop(flag = true) {
  315. this.password = '';
  316. this.show = flag;
  317. },
  318. finish() {
  319. console.log(11111)
  320. },
  321. // #ifdef H5
  322. wxPay(paydata) {
  323. WeixinJSBridge.invoke(
  324. 'getBrandWCPayRequest', {
  325. 'appId': paydata.appId, //公众号id名称,由商户传入
  326. 'timeStamp': paydata.timeStamp, //时间戳
  327. 'nonceStr': paydata.nonceStr, //随机串
  328. 'package': paydata.package,
  329. 'signType': paydata.signType, //微信签名方式:
  330. 'paySign': paydata.paySign //微信签名
  331. },
  332. function(res) {
  333. if (res.err_msg === 'get_brand_wcpay_request:ok') {
  334. uni.showToast({
  335. title: '购买会员成功',
  336. icon: 'none'
  337. })
  338. setTimeout(() => {
  339. uni.navigateBack({
  340. delta: 1
  341. })
  342. }, 1000)
  343. } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
  344. uni.showToast({
  345. icon: 'none',
  346. title: '已取消支付'
  347. })
  348. } else {
  349. uni.showToast({
  350. icon: 'none',
  351. title: '支付失败'
  352. })
  353. }
  354. })
  355. },
  356. // #endif
  357. wxZf() {
  358. let obj = {
  359. oid: this.oid,
  360. paytype: 'wxpay',
  361. money: this.payprice,
  362. }
  363. adoptApi.renyang_pay(obj).then(ret => {
  364. // #ifdef H5
  365. uni.showToast({
  366. title: '此商家的收款功能已被限制,暂无法支付。商家可以登录微信商户平台/微信支付商家助手小程序查看原因和解决方案。',
  367. icon: 'none'
  368. })
  369. // #endif
  370. console.log(ret);
  371. uni.requestPayment({
  372. provider: 'wxpay',
  373. timeStamp: ret.timeStamp,
  374. nonceStr: ret.nonceStr,
  375. package: ret.package,
  376. signType: ret.signType,
  377. paySign: ret.paySign,
  378. success: function(res) {
  379. uni.showToast({
  380. title: '微信支付成功',
  381. icon: 'success',
  382. duration: 1500
  383. });
  384. uni.redirectTo({
  385. url: `/pagesD/pages/money/paySuccess?type=1`
  386. });
  387. },
  388. fail: function(err) {
  389. console.log('fail:' + JSON.stringify(err));
  390. }
  391. });
  392. });
  393. },
  394. //农场跳转过来支付
  395. //余额支付
  396. goZf() {
  397. let type;
  398. if (this.payType == 2) {
  399. type = 1;
  400. } else {
  401. }
  402. cart.checkPayPassword({
  403. password: this.password
  404. }).then(res => {
  405. console.log(res)
  406. uni.hideLoading();
  407. if (res.status == 200) {
  408. adoptApi.payNew({
  409. orderid: this.orderid,
  410. djqid: this.djqid,
  411. type: type,
  412. paypass: this.password
  413. })
  414. .then(res => {
  415. if (res.status == 0) {
  416. uni.showToast({
  417. title: res.msg,
  418. icon: "none"
  419. });
  420. } else {
  421. uni.showToast({
  422. title: res.msg,
  423. icon: "none"
  424. });
  425. uni.redirectTo({
  426. url: `/pagesD/pages/money/paySuccess?type=1`
  427. });
  428. }
  429. });
  430. } else if (res.status == 0) {
  431. // this.showPop(false)
  432. this.$refs.uTips.show({
  433. title: res.msg,
  434. type: 'error',
  435. duration: '2300',
  436. icon: "none"
  437. })
  438. if (res.msg === '未设置支付密码,现在进行设置!') {
  439. console.log(res.msg, "失败啦")
  440. setTimeout(() => {
  441. this.$u.route({
  442. url: '/pagesD/pages/set/changemima/changemima'
  443. })
  444. }, 1000)
  445. }
  446. }
  447. })
  448. }
  449. }
  450. }
  451. </script>
  452. <style lang='scss'>
  453. .codeinput {
  454. justify-content: space-evenly;
  455. display: flex;
  456. }
  457. .app {
  458. width: 100%;
  459. }
  460. .money {
  461. font-size: 80rpx;
  462. position: relative;
  463. text-align: center;
  464. .close {
  465. position: absolute;
  466. top: 20rpx;
  467. right: 20rpx;
  468. line-height: 28rpx;
  469. font-size: 28rpx;
  470. }
  471. }
  472. .tips {
  473. color: $u-tips-color;
  474. text-align: center;
  475. }
  476. .price-box {
  477. background-color: #fff;
  478. height: 265upx;
  479. display: flex;
  480. flex-direction: column;
  481. justify-content: center;
  482. align-items: center;
  483. font-size: 28upx;
  484. color: #909399;
  485. .price {
  486. font-size: 50upx;
  487. margin-top: 12upx;
  488. &:before {
  489. content: '¥';
  490. font-size: 40upx;
  491. }
  492. }
  493. }
  494. .pay-type-list {
  495. /* margin-top: 20upx; */
  496. background-color: #fff;
  497. padding-left: 60upx;
  498. .type-item {
  499. height: 120upx;
  500. padding: 20upx 0;
  501. display: flex;
  502. justify-content: space-between;
  503. align-items: center;
  504. padding-right: 60upx;
  505. font-size: 30upx;
  506. position: relative;
  507. .con {
  508. margin-left: 20rpx;
  509. }
  510. }
  511. .icon {
  512. width: 100upx;
  513. font-size: 52upx;
  514. }
  515. .icon-erjiye-yucunkuan {
  516. color: #fe8e2e;
  517. }
  518. .icon-weixinzhifu {
  519. color: #36cb59;
  520. }
  521. .icon-alipay {
  522. color: #01aaef;
  523. }
  524. .tit {
  525. font-size: $font-lg;
  526. color: $font-color-dark;
  527. margin-bottom: 4upx;
  528. }
  529. .con {
  530. flex: 1;
  531. display: flex;
  532. flex-direction: column;
  533. font-size: $font-sm;
  534. color: $font-color-light;
  535. }
  536. }
  537. .mix-btn {
  538. display: flex;
  539. align-items: center;
  540. justify-content: center;
  541. width: 630upx;
  542. height: 80upx;
  543. margin: 80upx auto 30upx;
  544. font-size: $font-lg;
  545. color: #fff;
  546. border-radius: 10upx;
  547. }
  548. </style>