提交 bc503d12 authored 作者: pengxiaohui's avatar pengxiaohui

增加微信网页支付

上级 3f513e55
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": false,
"useCompilerModule": false,
"userConfirmedUseCompilerModuleSwitch": false,
"showShadowRootInWxmlPanel": true
},
"compileType": "miniprogram",
"libVersion": "2.17.0",
"appid": "touristappid",
"projectname": "shop-h5",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"gamePlugin": {
"current": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
\ No newline at end of file
...@@ -26,3 +26,14 @@ export function phoneCodeLogin(data) { ...@@ -26,3 +26,14 @@ export function phoneCodeLogin(data) {
data data
}) })
} }
/**
* 修改用户信息
*/
export function getOpenId(data) {
return httpRequest({
url: '/api/usercenter/v1/wechat/get-openid',
method: 'post',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data
})
}
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
</template> </template>
</van-field> </van-field>
<div style="margin: 16px;"> <div style="margin: 16px;">
<p class="account-login" @click="goLogin">账号密码登录</p>
<van-button type="primary" round block color="#C01540" size="small" :disabled="payBtnDisabled">登录</van-button> <van-button type="primary" round block color="#C01540" size="small" :disabled="payBtnDisabled">登录</van-button>
</div> </div>
</van-form> </van-form>
...@@ -50,6 +51,9 @@ export default { ...@@ -50,6 +51,9 @@ export default {
} }
}, },
methods: { methods: {
goLogin() {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
},
handleSuccess(val) { handleSuccess(val) {
this.fetchPhoneCodeLogin() this.fetchPhoneCodeLogin()
}, },
...@@ -125,6 +129,11 @@ h5{ ...@@ -125,6 +129,11 @@ h5{
line-height:33px; line-height:33px;
} }
} }
.account-login{
color:#C01540;
font-size:12px;
margin-bottom:15px;
}
.code-btn{ .code-btn{
.van-button__text{ .van-button__text{
color:#C01540; color:#C01540;
......
...@@ -132,7 +132,7 @@ export default { ...@@ -132,7 +132,7 @@ export default {
spu_id: this.spu_id, spu_id: this.spu_id,
sku_id: this.spec, sku_id: this.spec,
buy_count: this.form.count, buy_count: this.form.count,
payment_method: '4', product_price: this.price,
app_button_text: JSON.stringify(fields) app_button_text: JSON.stringify(fields)
} }
this.$emit('placeOrder', params) this.$emit('placeOrder', params)
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</van-cell> </van-cell>
</div> </div>
<div class="bottom-bar"> <div class="bottom-bar">
<van-button type="primary" round block color="#C01540" size="small" @click="popupVisiable = true">立即购买</van-button> <van-button type="primary" round block color="#C01540" size="small" @click="handleBuy">立即购买</van-button>
</div> </div>
<buy-popup v-model="popupVisiable" :options="popupOptions" @placeOrder="handlePlaceOrder"/> <buy-popup v-model="popupVisiable" :options="popupOptions" @placeOrder="handlePlaceOrder"/>
<phone-code-login-popup v-model="loginPopupVisiable" @loginSuccess="handleHasLogin"/> <phone-code-login-popup v-model="loginPopupVisiable" @loginSuccess="handleHasLogin"/>
...@@ -49,9 +49,10 @@ ...@@ -49,9 +49,10 @@
import BuyPopup from './components/BuyPopup.vue' import BuyPopup from './components/BuyPopup.vue'
import PhoneCodeLoginPopup from '@/components/PhoneCodeLoginPopup.vue' import PhoneCodeLoginPopup from '@/components/PhoneCodeLoginPopup.vue'
import { getGoodsList, getShopList, createOrder, checkPayStatus } from '@/api/common.js' import { getGoodsList, getShopList, createOrder, checkPayStatus } from '@/api/common.js'
import { getOpenId } from '@/api/account.js'
import store from '@/store' import store from '@/store'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { Dialog } from 'vant' import { Dialog, Toast } from 'vant'
export default { export default {
components: { BuyPopup, PhoneCodeLoginPopup }, components: { BuyPopup, PhoneCodeLoginPopup },
data() { data() {
...@@ -63,12 +64,14 @@ export default { ...@@ -63,12 +64,14 @@ export default {
imgList: [], imgList: [],
shopInfo: {}, shopInfo: {},
popupOptions: {}, popupOptions: {},
orderInfo: {}, payment_order_id: '',
payment_order_id: '' payment_method: '4',
order_params: '',
openId: ''
} }
}, },
computed: { computed: {
...mapGetters(['user']), ...mapGetters(['user', 'isWxBrowser']),
query() { query() {
return this.$route.query return this.$route.query
}, },
...@@ -85,7 +88,7 @@ export default { ...@@ -85,7 +88,7 @@ export default {
beforeMount() { beforeMount() {
this.fetchGoodsDetails() this.fetchGoodsDetails()
this.fetchShopDetails() this.fetchShopDetails()
if (this.isBackFormWxPay) { if (this.isBackFormWxH5Pay) {
Dialog.alert({ Dialog.alert({
title: '支付确认', title: '支付确认',
message: '确认已经完成微信支付', message: '确认已经完成微信支付',
...@@ -93,7 +96,11 @@ export default { ...@@ -93,7 +96,11 @@ export default {
}).then(() => { }).then(() => {
this.fetchCheckPayStatus() this.fetchCheckPayStatus()
}) })
window.sessionStorage.removeItem('isBackFormWxPay') window.sessionStorage.removeItem('isBackFormWxH5Pay')
}
if (!this.openId) {
const { code } = this.$route.query
if (code) this.fetchOpenId(code)
} }
}, },
methods: { methods: {
...@@ -109,9 +116,7 @@ export default { ...@@ -109,9 +116,7 @@ export default {
navShop(id) { navShop(id) {
this.$router.push({ path: '/shop', query: { shop_id: id } }) this.$router.push({ path: '/shop', query: { shop_id: id } })
}, },
async handlePlaceOrder(val) { async handleBuy() {
this.orderInfo = val
this.popupVisiable = false
const isLogin = store.state.isLogin || (await store.dispatch('checkLogin')) const isLogin = store.state.isLogin || (await store.dispatch('checkLogin'))
if (isLogin) { if (isLogin) {
this.handleHasLogin() this.handleHasLogin()
...@@ -119,14 +124,44 @@ export default { ...@@ -119,14 +124,44 @@ export default {
this.loginPopupVisiable = true this.loginPopupVisiable = true
} }
}, },
handleHasLogin() { handlePlaceOrder(val) {
const params = Object.assign({}, this.orderInfo) this.popupVisiable = false
const params = Object.assign({}, val)
params.customer_id = this.user.id params.customer_id = this.user.id
params.customer_phone = this.user.phone || '' params.customer_phone = this.user.phone || ''
params.buy_count = (params.buy_count).toString() params.buy_count = (params.buy_count).toString()
console.log(params) params.payment_method = this.payment_method
if (this.payment_method === '3') {
params.open_id = this.openId
}
this.fetchPlaceOrder(params) this.fetchPlaceOrder(params)
}, },
handleHasLogin() {
console.log(navigator.userAgent)
if (this.isWxBrowser) {
this.payment_method = '3'
this.getCode()
} else {
this.payment_method = '4'
this.popupVisiable = true
// this.fetchPlaceOrder(params)
}
},
getCode() {
const redirectURI = window.location.href
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx451c01d40d090d7a&redirect_uri=${redirectURI}&response_type=code&scope=snsapi_base#wechat_redirect`
},
// 获取微信openid
fetchOpenId(code) {
getOpenId({ code, identity: 'ezijing' }).then(response => {
if (response.code === 0) {
this.openId = response.openid
window.localStorage.setItem('open_id', this.openId)
} else {
this.getCode()
}
})
},
fetchGoodsDetails() { fetchGoodsDetails() {
const params = { const params = {
shop_id: this.shop_id, shop_id: this.shop_id,
...@@ -159,12 +194,21 @@ export default { ...@@ -159,12 +194,21 @@ export default {
} }
}) })
}, },
placeOrderParams() {
const params = Object.assign({ payment_method: this.payment_method }, this.order_params)
if (this.payment_method === '3') {
params.open_id = this.openId
}
return params
},
fetchPlaceOrder(params) { fetchPlaceOrder(params) {
createOrder(params).then(res => { createOrder(params).then(res => {
if (res.code === 0 && res.payment_url) { if (res.code === 0 && res.msg === '成功') {
window.sessionStorage.setItem('isBackFormWxPay', 1) window.sessionStorage.setItem('isBackFormWxH5Pay', 1)
window.sessionStorage.setItem('payment_order_id', res.payment_order_id) window.sessionStorage.setItem('payment_order_id', res.payment_order_id)
window.location.href = res.payment_url window.location.href = res.payment_url
} else {
Toast.fail(res.msg || '购买下单失败')
} }
}) })
}, },
......
const getters = { const getters = {
user: state => state.user.user user: state => state.user.user,
isWxBrowser: state => state.user.isWxBrowser
} }
export default getters export default getters
...@@ -3,7 +3,7 @@ const user = { ...@@ -3,7 +3,7 @@ const user = {
state: { state: {
user: {}, user: {},
isLogin: false, isLogin: false,
isWxBrowser: /micromessenger/.test(navigator.userAgent) isWxBrowser: /micromessenger/i.test(navigator.userAgent) && /android|iphone|ipad|ipod/i.test(navigator.userAgent)
}, },
mutations: { mutations: {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论