index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="flex-col flex-center py-78">
  4. <baseMoney :money="payPriceShow" symbolSize="48" integerSize="64" decimalSize="48" color="#333" weight>
  5. </baseMoney>
  6. <view class="flex-y-center mt-20">
  7. <text class="fs-24 text--w111-333 lh-36rpx pr-10">支付剩余时间</text>
  8. <countDown :is-day="false" tip-text=" " day-text=" " hour-text=":" minute-text=":" second-text=" "
  9. bgColor="#FFFFFF" dotColor="var(--view-theme)" :datatime="invalidTime"></countDown>
  10. </view>
  11. </view>
  12. <view class="px-20">
  13. <view class="bg--w111-fff rd-24rpx pay_card">
  14. <view class="flex-between-center pay_item" v-for="(item, index) in payTypeList" :key="index"
  15. @tap="payType(item.value, index)">
  16. <view class="flex-y-center">
  17. <image class="w-52 h-52" :src="item.icon"></image>
  18. <view class="pl-20">
  19. <view class="text--w111-333 fs-28 lh-38rpx">{{item.name}}</view>
  20. <view class="fs-22 text--w111-999 lh-30rpx mt-8" v-if="item.value == 'yue'">
  21. 可用余额¥{{now_money}}</view>
  22. <view class="fs-22 text--w111-999 lh-30rpx mt-8" v-else>{{item.title}}</view>
  23. </view>
  24. </view>
  25. <text class="iconfont fs-40 text--w111-999"
  26. :class="active==index ? 'icon-a-ic_CompleteSelect' : 'icon-ic_unselect'"></text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="w-full h-128 fixed-lb pb-safe flex-center">
  31. <view class="w-710 h-80 flex-center rd-40rpx text--w111-fff bg-color fs-28" @click="goPay()">确认付款</view>
  32. </view>
  33. <view v-show="false" v-html="formContent"></view>
  34. </view>
  35. </template>
  36. <script>
  37. import countDown from '@/components/countDown';
  38. import colors from "@/mixins/color";
  39. import {
  40. getCashierOrder,
  41. orderPay
  42. } from "@/api/order";
  43. import {
  44. rechargePayAPi,
  45. memberCardPayApi
  46. } from "@/api/user.js"
  47. import {
  48. HTTP_REQUEST_URL
  49. } from '@/config/app';
  50. export default {
  51. data() {
  52. return {
  53. invalidTime: 0,
  54. checked: false,
  55. orderId: 0,
  56. fromType: '',
  57. active: -1,
  58. payPrice: 0,
  59. payPriceShow: 0,
  60. now_money: '',
  61. payPostage: 0,
  62. offlinePostage: false,
  63. invalidTime: 0,
  64. initIn: false,
  65. jumpData: {
  66. orderId: '',
  67. msg: ''
  68. },
  69. formContent: '',
  70. cartArr: [{
  71. "name": "微信支付",
  72. "icon": HTTP_REQUEST_URL + "/statics/images/order/wx_pay.png",
  73. value: 'weixin',
  74. title: '使用微信快捷支付',
  75. payStatus: 1,
  76. },
  77. {
  78. "name": "支付宝支付",
  79. "icon": HTTP_REQUEST_URL + "/statics/images/order/alipay.png",
  80. value: 'alipay',
  81. title: '使用线上支付宝支付',
  82. payStatus: 1,
  83. },
  84. {
  85. "name": "余额支付",
  86. "icon": HTTP_REQUEST_URL + "/statics/images/order/yue_pay.png",
  87. value: 'yue',
  88. title: '可用余额:',
  89. payStatus: 1,
  90. },
  91. {
  92. "name": "线下支付",
  93. "icon": HTTP_REQUEST_URL + "/statics/images/order/xianxia_pay.png",
  94. value: 'offline',
  95. title: '选择线下付款方式',
  96. payStatus: 2,
  97. },
  98. // {
  99. // "name": "lakala",
  100. // "icon": HTTP_REQUEST_URL + "/statics/images/order/xianxia_pay.png",
  101. // value: 'lakala',
  102. // title: '选择线lakala支付',
  103. // payStatus: 1,
  104. // }
  105. ],
  106. paytype: '',
  107. // #ifdef APP
  108. showApp: false
  109. // #endif
  110. // #ifndef APP
  111. showApp: true
  112. // #endif
  113. }
  114. },
  115. mixins: [colors],
  116. components: {
  117. countDown,
  118. },
  119. computed: {
  120. payTypeList() {
  121. let list = [];
  122. this.cartArr.forEach(item => {
  123. if (item.payStatus == 1) {
  124. list.push(item);
  125. }
  126. })
  127. list.length && this.payType(list[0].value, 0)
  128. return list
  129. }
  130. },
  131. onLoad(options) {
  132. // #ifdef APP
  133. this.showApp = uni.getStorageSync("showAppHistary") || false
  134. // #endif
  135. if (options.order_id) this.orderId = options.order_id;
  136. if (options.from_type) this.fromType = options.from_type;
  137. this.getCashierOrder();
  138. },
  139. methods: {
  140. payType(paytype, index) {
  141. this.active = index;
  142. this.paytype = paytype;
  143. if (this.offlinePostage) {
  144. if (paytype == 'offline') {
  145. this.payPriceShow = this.$util.$h.Sub(this.payPrice, this.payPostage);
  146. } else {
  147. this.payPriceShow = this.payPrice;
  148. }
  149. }
  150. },
  151. getCashierOrder() {
  152. getCashierOrder(this.orderId, this.fromType).then(res => {
  153. //微信支付是否开启
  154. if (this.showApp) {
  155. this.cartArr[0].payStatus = res.data.pay_weixin_open || 0
  156. } else {
  157. this.cartArr[0].payStatus = 0
  158. }
  159. //支付宝是否开启
  160. // #ifdef MP-WEIXIN
  161. /*微信小程序环境中不允许支付宝支付*/
  162. this.cartArr[1].payStatus = 0;
  163. // #endif
  164. // #ifdef H5
  165. /*微信公众号环境中不允许支付宝支付*/
  166. this.cartArr[1].payStatus = this.$wechat.isWeixin() ? 0 : res.data.ali_pay_status;
  167. // #endif
  168. // #ifdef APP-PLUS
  169. this.cartArr[1].payStatus = res.data.ali_pay_status || 0;
  170. // #endif
  171. //余额支付是否开启
  172. this.cartArr[2].payStatus = res.data.yue_pay_status;
  173. this.now_money = res.data.now_money;
  174. //线下支付是否开启
  175. if (res.data.offline_pay_status == 1) {
  176. this.cartArr[3].payStatus = 1
  177. } else {
  178. this.cartArr[3].payStatus = 0
  179. }
  180. // 订单价格
  181. this.payPrice = this.payPriceShow = res.data.pay_price
  182. //剩余时间
  183. this.invalidTime = res.data.invalid_time;
  184. // 邮费
  185. this.payPostage = res.data.pay_postage;
  186. this.getShowPay();
  187. }).catch(err => {
  188. uni.hideLoading();
  189. return this.$util.Tips({
  190. title: err
  191. })
  192. })
  193. },
  194. getShowPay() {
  195. //付费会员购买和余额充值不允许使用线下支付和余额支付,未开启线上支付支付的话给出提示并且返回上一页
  196. //检查支付类型列表数组的payStatus是不是都是0或者2
  197. const isAllPayStatusZero = this.cartArr.every(item => item.payStatus == 0 || item.payStatus == 2);
  198. if (isAllPayStatusZero && ['vip', 'recharge'].includes(this.fromType)) {
  199. return this.$util.Tips({
  200. title: '未开启线上支付,请联系管理员'
  201. }, {
  202. tab: 3,
  203. });
  204. }
  205. },
  206. goPay() {
  207. let that = this;
  208. if (that.active == -1) return that.$util.Tips({
  209. title: '请选择付款方式'
  210. });
  211. if (!that.orderId) return that.$util.Tips({
  212. title: '请选择要支付的订单'
  213. });
  214. if (that.paytype == 'yue' && parseFloat(this.now_money) < parseFloat(that.payPriceShow)) return that.$util
  215. .Tips({
  216. title: '余额不足'
  217. });
  218. uni.showLoading({
  219. title: '支付中'
  220. });
  221. let funApi = '';
  222. if (this.fromType == 'order') {
  223. funApi = orderPay({
  224. uni: that.orderId,
  225. paytype: that.paytype,
  226. // #ifdef MP
  227. 'from': 'routine',
  228. // #endif
  229. // #ifdef H5
  230. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  231. // #endif
  232. // #ifdef H5
  233. quitUrl: location.port ? location.protocol + '//' + location.hostname + ':' + location
  234. .port + '/pages/goods/order_pay_status/index?order_id=' + this.orderId : location
  235. .protocol + '//' + location.hostname +
  236. '/pages/goods/order_pay_status/index?order_id=' + this.orderId
  237. // #endif
  238. // #ifdef APP-PLUS
  239. quitUrl: '/pages/goods/order_pay_status/index?order_id=' + this.orderId
  240. // #endif
  241. })
  242. } else if (this.fromType == 'recharge') {
  243. funApi = rechargePayAPi({
  244. uni: this.orderId,
  245. paytype: that.paytype,
  246. // #ifdef MP
  247. 'from': 'routine',
  248. // #endif
  249. // #ifdef H5
  250. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  251. // #endif
  252. // #ifdef H5
  253. quitUrl: location.port ? location.protocol + '//' + location.hostname + ':' + location
  254. .port + '/pages/users/user_payment/index' : location.protocol + '//' + location
  255. .hostname + '/pages/users/user_payment/index'
  256. // #endif
  257. // #ifdef APP-PLUS
  258. quitUrl: '/pages/users/user_payment/index'
  259. // #endif
  260. })
  261. } else if (this.fromType == 'vip') {
  262. funApi = memberCardPayApi({
  263. uni: this.orderId,
  264. paytype: this.paytype,
  265. // #ifdef MP
  266. 'from': 'routine',
  267. // #endif
  268. // #ifdef H5
  269. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  270. quitUrl: '/pages/annex/vip_paid/index',
  271. // #endif
  272. // #ifdef APP-PLUS
  273. quitUrl: '/pages/annex/vip_paid/index',
  274. // #endif
  275. })
  276. }
  277. // if(data.pay_type == 'lakala'){
  278. // uni.navigateTo({
  279. // url: goPages + '&status=1'
  280. // })
  281. // // #ifdef H5
  282. // window.open(res.data.result.counter_url);
  283. // // #endif
  284. // // #ifdef APP-PLUS
  285. // plus.runtime.openURL(res.data.result.counter_url);
  286. // // #endif
  287. // }
  288. funApi.then(res => {
  289. console.log(res,"res")
  290. let status = res.data.status,
  291. orderId = res.data.result.order_id || '',
  292. jsConfig = res.data.result.jsConfig;
  293. //页面回调地址
  294. let PageObj = {
  295. 'order': '/pages/goods/order_pay_status/index?order_id=' + this.orderId + '&msg=' + res
  296. .msg + '&type=3' + '&totalPrice=' + this.payPriceShow,
  297. 'recharge': '/pages/users/user_payment/index',
  298. 'vip': '/pages/annex/vip_paid/index',
  299. };
  300. let backUrl = PageObj[this.fromType];
  301. switch (status) {
  302. case 'ORDER_EXIST':
  303. case 'EXTEND_ORDER':
  304. case 'PAY_ERROR':
  305. this.pageReject(res.msg, backUrl);
  306. break;
  307. case 'SUCCESS':
  308. this.pageReject(res.msg, backUrl);
  309. break;
  310. case 'WECHAT_PAY':
  311. this.wechatPayFun(jsConfig, backUrl);
  312. break;
  313. case 'PAY_DEFICIENCY':
  314. uni.hideLoading();
  315. this.pageReject(res.msg, backUrl);
  316. break;
  317. case "WECHAT_H5_PAY":
  318. uni.hideLoading();
  319. // that.$util.Tips({
  320. // title: '订单创建成功!'
  321. // });
  322. setTimeout(() => {
  323. location.href = res.data.result.jsConfig.mweb_url;
  324. }, 500);
  325. break;
  326. case 'ALIPAY_PAY':
  327. //#ifdef H5
  328. uni.hideLoading();
  329. that.formContent = res.data.result.jsConfig;
  330. that.$nextTick(() => {
  331. document.getElementById('alipaysubmit').submit();
  332. })
  333. //#endif
  334. // #ifdef APP-PLUS
  335. uni.requestPayment({
  336. provider: 'alipay',
  337. orderInfo: jsConfig,
  338. success: (e) => {
  339. that.pageReject('支付成功', backUrl);
  340. },
  341. fail: (e) => {
  342. that.pageReject('支付失败', backUrl);
  343. },
  344. complete: () => {
  345. uni.hideLoading();
  346. },
  347. });
  348. // #endif
  349. break;
  350. }
  351. }).catch(err => {
  352. uni.hideLoading();
  353. return that.$util.Tips({
  354. title: err
  355. });
  356. })
  357. },
  358. wechatPayFun(jsConfig, backUrl) {
  359. let that = this;
  360. // #ifdef MP
  361. uni.requestPayment({
  362. timeStamp: jsConfig.timestamp,
  363. nonceStr: jsConfig.nonceStr,
  364. package: jsConfig.package,
  365. signType: jsConfig.signType,
  366. paySign: jsConfig.paySign,
  367. success: function(res) {
  368. console.log("success");
  369. that.pageReject('支付成功', backUrl);
  370. },
  371. fail: function(e) {
  372. console.log("fail");
  373. that.pageReject('支付失败', backUrl);
  374. },
  375. })
  376. // #endif
  377. // #ifdef H5
  378. this.$wechat.pay(jsConfig).then(res => {
  379. this.pageReject('支付成功', backUrl);
  380. }).catch(res => {
  381. if (!this.$wechat.isWeixin()) {
  382. this.pageReject('支付失败', backUrl);
  383. }
  384. if (res.errMsg == 'chooseWXPay:cancel') {
  385. this.pageReject('取消支付', backUrl);
  386. }
  387. })
  388. // #endif
  389. // #ifdef APP-PLUS
  390. uni.requestPayment({
  391. provider: 'wxpay',
  392. orderInfo: jsConfig,
  393. success: (e) => {
  394. that.pageReject('支付成功', backUrl);
  395. },
  396. fail: (e) => {
  397. that.pageReject('支付失败', backUrl);
  398. },
  399. });
  400. // #endif
  401. },
  402. pageReject(msg, backUrl) {
  403. uni.hideLoading();
  404. return this.$util.Tips({
  405. title: msg
  406. }, {
  407. tab: 5,
  408. url: backUrl
  409. });
  410. }
  411. }
  412. }
  413. </script>
  414. <style lang="scss">
  415. /deep/ .styleAll {
  416. padding: 0 6rpx;
  417. border: 1rpx solid #DDDDDD;
  418. border-radius: 8rpx;
  419. }
  420. .pay_card {
  421. padding: 40rpx 32rpx;
  422. }
  423. .pay_item~.pay_item {
  424. margin-top: 56rpx;
  425. }
  426. .icon-ic_unselect {
  427. color: #ccc;
  428. }
  429. .icon-a-ic_CompleteSelect {
  430. color: var(--view-theme)
  431. }
  432. </style>