123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- import { T_PAY_ORDER } from '../constant'
- // import { mapState, mapGetters } from 'vuex'
- import store from '../store'
- // import { payOrderGoodsApi, payOrderGoodsAPPApi } from '../api/xxx'
- // import { payBOrderH5, payOtherPlatformApi } from '../api/xxx'
- import { getUserId } from './index'
- // export const payH5Method = (res, type) => {
- // uni.removeStorageSync(T_PAY_ORDER)
- // uni.setStorageSync(T_PAY_ORDER, {
- // type: type || 'DEFAULT',
- // TL_ORDER_NO: res.orderNo
- // })
- // if (res.errno === -1) {
- // uni.showToast({
- // title: res.errmsg,
- // duration: 2000,
- // icon: 'error'
- // })
- // }
- // if (res.data.isZeroOrder === '1') { // 零元支付情况
- // uni.redirectTo({
- // url: '/user/otherServe/payment-completed/index'
- // })
- // } else {
- // const payData = JSON.parse(res.data.h5PayUrl)
- // const form = document.createElement('form')
- // form.setAttribute('action', payData.url)
- // form.setAttribute('method', 'POST')
- // const data = JSON.parse(payData.data)
- // let input
- // for (const key in data) {
- // input = document.createElement('input')
- // input.name = key
- // input.value = data[key]
- // form.appendChild(input)
- // }
- // document.body.appendChild(form)
- // form.submit()
- // document.body.removeChild(form)
- // }
- // }
- export const payFn = (data, payType, type = 'DEFAULT', otherArgs = {}) => {
- // console.log({ ...mapState('app', [ 'isInMiniProgram' ]) })
- // console.log(mapState('app', [ 'isInMiniProgram' ]).isInMiniProgram)
- // console.log({ ...mapState({ 'isInMiniProgram': (state) => state.isInMiniProgram }) })
- console.log(store.state.app.isInMiniProgram)
- if (store.state.app.isInMiniProgram) { // || getApp().globalData.isInMiniprogram
- payOrderGoodsAPPApi({
- userId: getUserId(),
- orderNo: data.orderSn,
- payType,
- ...otherArgs
- }).then((res) => {
- if (res.errno === 0) {
- if (type) {
- uni.removeStorageSync(T_PAY_ORDER)
- uni.setStorageSync(T_PAY_ORDER, {
- type,
- TL_ORDER_NO: data.orderSn
- })
- }
- if (res.data.isZeroOrder === '1') { // 零元支付情况
- uni.redirectTo({
- url: '/user/otherServe/payment-completed/index'
- })
- } else {
- delete res.data.isZeroOrder
- let query = ''
- for (const key in res.data) {
- query += key + '=' + res.data[key] + '&'
- }
- wx.miniProgram.navigateTo({
- url: '/pages/loading/loading?' + query + 'orderNo=' + data.orderSn + '&userId=' + getUserId(),
- fail: () => {
- uni.switchTab({
- url: '/pages/order/order?type=shop&status=1'
- })
- }
- })
- }
- }
- })
- } else {
- // #ifdef H5
- payOrderGoodsApi({
- orderNo: data.orderSn,
- userId: getUserId(),
- payType,
- ...otherArgs
- }).then((res) => {
- if (type) {
- uni.removeStorageSync(T_PAY_ORDER)
- uni.setStorageSync(T_PAY_ORDER, {
- type,
- TL_ORDER_NO: data.orderSn
- })
- }
- if (res.data.isZeroOrder === '1') { // 零元支付情况
- uni.redirectTo({
- url: '/user/otherServe/payment-completed/index'
- })
- } else {
- const payData = JSON.parse(res.data.h5PayUrl)
- const form = document.createElement('form')
- form.setAttribute('action', payData.url)
- form.setAttribute('method', 'POST')
- const data = JSON.parse(payData.data)
- let input
- for (const key in data) {
- input = document.createElement('input')
- input.name = key
- input.value = data[key]
- form.appendChild(input)
- }
- document.body.appendChild(form)
- form.submit()
- document.body.removeChild(form)
- }
- })
- // #endif
- // #ifdef APP
- payOrderGoodsAPPApi({
- userId: getUserId(),
- orderNo: data.orderSn,
- payType,
- ...otherArgs
- }).then((res) => {
- if (res.errno === 0) {
- if (type) {
- uni.removeStorageSync(T_PAY_ORDER)
- uni.setStorageSync(T_PAY_ORDER, {
- type,
- TL_ORDER_NO: data.orderSn
- })
- }
- if (res.data.isZeroOrder === '1') { // 零元支付情况
- uni.redirectTo({
- url: '/user/otherServe/payment-completed/index'
- })
- } else {
- delete res.data.isZeroOrder
- let query = ''
- for (const key in res.data) {
- query += key + '=' + res.data[key] + '&'
- }
- plus.share.getServices(function (result) {
- let sweixin = null
- for (const i in result) {
- if (result[i].id == 'weixin') {
- sweixin = result[i]
- }
- }
- if (sweixin) {
- sweixin.launchMiniProgram({
- id: 'gh_e64a1a89a0ad', // 微信小程序的原始ID("g_"开头的字符串)
- type: 0,
- path: 'pages/orderDetail/orderDetail?' + query
- })
- }
- }, function (e) {
- console.log('获取分享服务列表失败:' + e.message)
- })
- }
- }
- })
- // #endif
- }
- }
- export const payShopFn = (data, payType, type = 'DEFAULT', otherArgs = {}) => {
- console.log(store.state.app.isInMiniProgram)
- if (store.state.app.isInMiniProgram) {
- payOtherPlatformApi({
- userId: getUserId(),
- orderNo: data.orderNo,
- payType,
- ...otherArgs
- }).then((resStr) => {
- const res = JSON.parse(resStr)
- if (type) {
- uni.removeStorageSync(T_PAY_ORDER)
- uni.setStorageSync(T_PAY_ORDER, {
- type,
- TL_ORDER_NO: data.orderNo
- })
- }
- if (res.isZeroOrder === '1') { // 零元支付情况
- uni.redirectTo({
- url: '/user/otherServe/payment-completed/index'
- })
- } else {
- let query = ''
- for (const key in res.data) {
- query += key + '=' + res.data[key] + '&'
- }
- wx.miniProgram.navigateTo({
- url: '/pages/loading/loading?' + query + 'orderNo=' + data.orderNo + '&userId=' + getUserId(),
- fail: () => {
- uni.switchTab({
- url: '/pages/order/order?type=shop&status=1'
- })
- }
- })
- }
- })
- } else {
- // #ifdef H5
- payBOrderH5({
- orderNo: data.orderNo,
- userId: getUserId(),
- payType,
- ...otherArgs
- }).then((resStr) => {
- const res = JSON.parse(resStr)
- // console.log(resStr)
- // console.log(res)
- // console.log(JSON.parse(res.data))
- if (type) {
- uni.removeStorageSync(T_PAY_ORDER)
- uni.setStorageSync(T_PAY_ORDER, {
- type,
- TL_ORDER_NO: data.orderNo
- })
- }
- if (res.isZeroOrder === '1') { // 零元支付情况
- uni.redirectTo({
- url: '/user/otherServe/payment-completed/index'
- })
- } else {
- const payData = res
- const form = document.createElement('form')
- form.setAttribute('action', payData.url)
- form.setAttribute('method', 'POST')
- const data = JSON.parse(payData.data)
- let input
- for (const key in data) {
- input = document.createElement('input')
- input.name = key
- input.value = data[key]
- form.appendChild(input)
- }
- document.body.appendChild(form)
- form.submit()
- document.body.removeChild(form)
- }
- })
- // #endif
- // #ifdef APP
- payOtherPlatformApi({
- userId: getUserId(),
- orderNo: data.orderNo,
- payType,
- ...otherArgs
- }).then((resStr) => {
- const res = JSON.parse(resStr)
- if (type) {
- uni.removeStorageSync(T_PAY_ORDER)
- uni.setStorageSync(T_PAY_ORDER, {
- type,
- TL_ORDER_NO: data.orderNo
- })
- }
- if (res.isZeroOrder === '1') { // 零元支付情况
- uni.redirectTo({
- url: '/user/otherServe/payment-completed/index'
- })
- } else {
- let query = ''
- for (const key in res.data) {
- query += key + '=' + res.data[key] + '&'
- }
- plus.share.getServices(function (result) {
- let sweixin = null
- for (const i in result) {
- if (result[i].id == 'weixin') {
- sweixin = result[i]
- }
- }
- if (sweixin) {
- sweixin.launchMiniProgram({
- id: 'gh_e64a1a89a0ad', // 微信小程序的原始ID("g_"开头的字符串)
- type: 0,
- path: 'pages/orderDetail/orderDetail?' + query
- })
- }
- }, function (e) {
- console.log('获取分享服务列表失败:' + e.message)
- })
- }
- })
- // #endif
- }
- }
|