Files
aishangjia-uniapp/pages/checkout/checkout.vue

788 lines
18 KiB
Vue

<template>
<view class="user-index">
<view class="page-bg"></view>
<view class="header" :style="'margin-top: ' + statusBarHeight + 'px'"></view>
<view class="main-header">
<image class="bg-image" :src="bgImage" mode="scaleToFill"></image>
<!-- 用户信息 -->
</view>
<view class="main">
<!-- 表单信息 -->
<u--form :model="form" ref="uForm">
<view class="buy-user">
<!-- 表单组件 -->
<view class="form-wrapper">
<u-cell-group :border="false">
<u-cell title="姓名" :isLink="true">
<input slot="value" class="w-input" placeholder="请填写姓名" v-model="form.realName" />
</u-cell>
<u-cell title="手机号" :isLink="true">
<input slot="value" class="w-input" placeholder="请填写手机号码" v-model="form.phone" />
</u-cell>
<u-cell title="所属区域" :isLink="true" @click="onArea">
<input slot="value" class="w-input" :disabled="true" placeholder="请选择所属区域" v-model="form.area" />
</u-cell>
<u-cell title="服务门店" :border="false" :isLink="true" @click="onMerchant">
<input slot="value" class="w-input" :disabled="true" placeholder="请选择服务门店" v-model="form.merchantName" />
</u-cell>
</u-cell-group>
</view>
</view>
<u-gap height="3"></u-gap>
<!-- 会员套餐 -->
<view class="buy-user">
<u-cell :title="form.roleName"></u-cell>
<view class="price-box">
<view class="info">
<image :src="form.icon"
mode="aspectFill"></image>
<view class="content">
{{ form.comments }}
</view>
</view>
<view class="price" v-for="(item,index) in form.price" :key="index" v-if="priceId == item.id">
<text class="reb">{{ item.price }}</text>
<text class="num">x1</text>
</view>
</view>
</view>
<view class="xieyi">
<u-icon name="checkbox-mark"></u-icon>
购买代表同意爱尚家网
<text @click="$push('pages/article/detail/detail?id=116')">人工牵线协议</text>
</view>
</u--form>
</view>
<view class="cart">
<view class="cart-info" @click="navTo('pages/menu/menu')">
<!-- <view style="position: relative;"> -->
<!-- <u-badge class="badge" size="mini" type="error" :is-center="true" :count="totalNum"></u-badge> -->
<!-- <image class="cart-logo" src="../../static/icon/cart4.png"></image> -->
<!-- </view> -->
<view class="total-price">{{ totalPrice }}</view>
<!-- <view class="clear-cart" @click="onClearCart">清空购物车</view> -->
<view class="buy">
<u-button text="立即下单" shape="circle" type="error" class="custom-style" :disabled="disabled"
@click="onBuy">
</u-button>
</view>
</view>
</view>
<!-- 地址选择器 -->
<liu-customize-sel ref="area" @change="chooseSuccess"></liu-customize-sel>
<!-- 选择店铺 -->
<u-picker :show="showMerchant" :columns="merchantList" keyName="label" @confirm="confirmMerchant"
@cancel="showMerchant = false"></u-picker>
</view>
</template>
<script>
import store from '@/store/index.js'
import storage from '@/utils/storage'
import * as UserPlanApi from '@/api/love-user-plan.js'
import * as UserPlanLogApi from '@/api/love-user-plan-log.js'
import * as MerchantApi from '@/api/merchant.js'
import {
getUser,
updateUser
} from '@/api/user.js'
import {
username
} from '@/config.js';
import {
getMobile
} from '@/utils/util.js'
import http from '@/api'
const userId = uni.getStorageSync('userId')
export default {
data() {
return {
merchantList: [],
bgImage: 'data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%221%22%20x1%3D%220%22%20x2%3D%221%22%20y1%3D%220%22%20y2%3D%220%22%20gradientTransform%3D%22matrix(6.123233995736766e-17%2C%201%2C%20-0.36308349769888226%2C%206.123233995736766e-17%2C%200.5%2C%200)%22%3E%3Cstop%20stop-color%3D%22%23101010%22%20stop-opacity%3D%221%22%20offset%3D%220.24%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23160028%22%20stop-opacity%3D%221%22%20offset%3D%221%22%3E%3C%2Fstop%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22url(%231)%22%3E%3C%2Frect%3E%3C%2Fsvg%3E',
statusBarHeight: 25,
// 是否已登录
isLogin: false,
disabled: false,
showMerchant: false,
// 系统设置
form: {
planId: 0,
priceId: 0,
area: '',
merchantName: ''
},
priceId: 0,
totalPrice: 0.00,
dealerId: 0
}
},
onLoad(options) {
this.form.planId = Number(options.planId)
this.priceId = Number(options.priceId)
this.totalPrice = options.price
this.getUserInfo()
this.getOrderInfo()
// 设置navbar标题、颜色options
uni.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#101010'
})
},
onShow() {},
watch: {
dealerId(val,old) {
console.log("侦听根级属性侦听根级属性侦听根级属性侦听根级属性44: ",val);
this.getDealerMerchant(val)
}
},
methods: {
// 跳转页面
navTo(url) {
this.$navTo(url)
},
getUserInfo() {
const {
form
} = this
const app = this
uni.getSystemInfo({
success(data) {
if (data) {
app.statusBarHeight = data.statusBarHeight + 50
}
}
})
getUser().then(res => {
if (res.code == 0 && res.data.username != 'www') {
if(res.data){
console.log("res.data.phone: ",res.data.phone);
app.form.realName = res.data.nickname
app.form.phone = res.data.phone
app.dealerId = res.data.dealerId
// app.getDealerMerchant(res.data.dealerId)
}
app.isLogin = true
} else {
app.isLogin = false
app.$push('pages/login/index')
}
})
},
getOrderInfo(){
const app = this
const { planId } = this.form
UserPlanApi.getUserPlan(planId).then(result => {
console.log("result: ",result);
app.form = result.data
result.data.price.map(d => {
if(d.id == app.priceId){
app.form.priceId = d.id
app.totalPrice = d.price.toFixed(2)
}
})
})
},
getMerchant(){
const app = this
const form = {
region: app.form.region
}
console.log("app.planId: ",app.planId);
if(app.form.planId == 18){
form.gradeId = 18
}
MerchantApi.listMerchant(form).then(result => {
let arr = []
app.merchantList = []
result.data.map(d => {
console.log(d);
// 只收集线下门店
if(d.gradeId >= 10){
arr.push({
label: `${d.merchantName} (${d.gradeName})`,
id: d.merchantId,
code: d.merchantCode,
address: d.address
})
}
})
app.merchantList.push(arr)
})
},
// 获取推荐人的店铺信息
getDealerMerchant(dealerId){
console.log("获取推荐人的店铺信息: ",'获取推荐人的店铺信息');
const app = this
MerchantApi.pageMerchant({userId: dealerId}).then(result => {
console.log("result23123123123: ",result);
if(result.data.count > 0){
const data = result.data.list
const merchantName = data[0].merchantName
console.log("merchantName333333: ",merchantName);
const area = `${data[0].province} ${data[0].city} ${data[0].region}`
var newObj = {
...app.form
}
newObj.merchantName = merchantName
newObj.area = area
newObj.province = data[0].province
newObj.city = data[0].city
newObj.region = data[0].region
newObj.merchantId = data[0].merchantId
app.form = newObj
// app.form = ...{area,merchantName}
// app.area = region
// app.merchantName = merchantName
// app.form.merchantName = merchantName
// app.form.province = data[0].province
// app.form.city = data[0].city
// app.form.region = data[0].region
}
})
},
onArea() {
this.$refs.area.open()
},
onMerchant(){
this.showMerchant = true
},
confirmMerchant(e){
console.log("eeeeee2222: ",e);
this.form.merchantId = e.value[0].id
this.form.merchantCode = e.value[0].code
this.form.merchantName = e.value[0].label
this.form.address = e.value[0].address
this.showMerchant = false
},
//地址选择成功
chooseSuccess(e) {
const app = this
const data = e.value
if(data){
app.form.area = `${data[0].label} ${data[1].label} ${data[2].label}`
app.form.province = data[0].label
app.form.city = data[1].label
app.form.region = data[2].label
app.getMerchant()
}
},
// 跳转到服务页面
handleService({
url
}) {
if (url.slice(0, 4) == 'http') {
wx.openCustomerServiceChat({
extInfo: {
url: 'https://work.weixin.qq.com/kfid/kfc1693a8d29b84bc5e'
},
corpId: 'ww1c3f872ba0a39228',
success(res) {}
})
return;
}
if (!this.isLogin) {
return false;
}
console.log("url: ", url);
this.$navTo(url)
},
// 显示toast信息
showToast(title, duration = 2000) {
this.$refs.uToast.show({
title,
duration
})
},
handleLogout() {
// http.setConfig((config) => {
// config.header = {};
// config.header = {
// AppId: appId,
// tenantId: tenantId
// };
// return config
// })
// uni.clearStorage()
// uni.clearStorageSync()
uni.redirectTo({
url: '/pages/login/index'
})
},
onBuy() {
const app = this
const {
form
} = this
console.log("form: ",form);
if(form.realName == ''){
this.$error('请填写姓名')
return false
}
if(form.phone == ''){
this.$error('请填写手机号码')
return false
}
if(form.area == ''){
this.$error('请选择所属区域')
return false
}
if(!form.merchantId){
this.$error('请选择服务门店')
return false
}
app.disabled = true
UserPlanLogApi.addUserPlanLog({
planId: form.planId,
priceId: form.priceId,
province: form.province,
city: form.province,
region: form.region,
area: form.area,
realName: form.realName,
phone: form.phone,
merchantId: form.merchantId,
merchantCode: form.merchantCode,
merchantName: form.merchantName,
address: form.address
}).then(res => {
const orderInfo = res.data
// 调起微信支付
uni.requestPayment({
provider: orderInfo.provider, // 服务提供商
timeStamp: orderInfo.timeStamp, // 时间戳
nonceStr: orderInfo.nonceStr, // 随机字符串
package: orderInfo.package,
signType: orderInfo.signType, // 签名算法
paySign: orderInfo.paySign, // 签名
success: function(res) {
// 业务逻辑。。。
app.$success('支付成功')
setTimeout(function() {
app.showEdit = false
app.disabled = false
app.$navTo('pages/order/index')
}, 1500);
},
fail: function(err) {
console.log('支付失败', err);
app.disabled = false
}
});
}).catch(err => {
app.disabled = false
})
},
onApply() {
if (!this.isLogin) {
return false;
}
this.$navTo('pages/wallet/balance/log')
}
}
}
</script>
<style lang="scss" scoped>
.user-index {
background-color: #f3f3f3;
height: 100vh;
}
.container {
padding-bottom: 60rpx;
}
.page-bg {
width: 750rpx;
height: calc(100rpx + var(--status-bar-height));
display: block;
background-color: #101010;
position: absolute;
left: 0;
top: 0;
z-index: -100;
}
// 页面头部
.main-header {
// background-color: #FBF7EF;
position: fixed;
top: 0;
width: 100%;
height: 360rpx;
background-size: 100% 100%;
overflow: hidden;
display: flex;
align-items: center;
display: flex;
justify-content: space-between;
.bg-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
}
.star {
position: absolute;
opacity: 0.1;
color: #fff;
}
.star1 {
width: 100rpx;
height: 100rpx;
right: 80rpx;
top: 34rpx;
}
.star2 {
width: 100rpx;
height: 100rpx;
left: 40rpx;
top: 10rpx;
}
.star3 {
width: 70rpx;
height: 70rpx;
left: 130rpx;
top: 70rpx;
}
.user-info {
display: flex;
height: 120rpx;
padding-left: 30rpx;
z-index: 1;
.user-content {
display: flex;
flex-direction: column;
justify-content: center;
margin-left: 30rpx;
color: #ffffff;
.nick-name {
font-size: 30rpx;
font-weight: bold;
max-width: 270rpx;
display: flex;
flex-direction: row;
image {
margin-left: 10rpx;
width: 36rpx;
height: 36rpx;
}
}
.user-id {
font-weight: 300;
color: #efefef;
font-size: 24rpx;
}
.mobile {
margin-top: 15rpx;
font-size: 28rpx;
}
.user-grade {
align-self: baseline;
display: flex;
align-items: center;
background: #3c3c3c;
margin-top: 12rpx;
border-radius: 10rpx;
padding: 4rpx 12rpx;
.user-grade_icon .image {
display: block;
width: 32rpx;
height: 32rpx;
}
.user-grade_name {
margin-left: 5rpx;
font-size: 26rpx;
color: #EEE0C3;
}
}
.roles-box {
display: flex;
.login-tips {
margin-top: 12rpx;
margin-right: 6rpx;
font-size: 30rpx;
display: flex;
}
}
}
}
.switch {
display: flex;
color: #ffffff;
flex-direction: column;
justify-content: center;
align-items: center;
padding-right: 50rpx;
z-index: 999;
image {
width: 45rpx;
height: 45rpx;
}
.switch-text {
z-index: 9999;
color: #681752;
}
}
.setting {
color: #cecece;
position: absolute;
right: 2vh;
top: 1vh;
image {
width: 45rpx;
height: 45rpx;
}
}
}
.main {
position: fixed;
top: 80rpx;
left: 25rpx;
z-index: 999;
// 开通会员
.buy-user {
display: flex;
flex-direction: column;
margin: 22rpx auto 22rpx auto;
padding: 22rpx 0;
width: 700rpx;
box-shadow: 0 1rpx 5rpx 0px #eaebec;
border-radius: 24rpx;
background: #fff;
.desc {
padding-top: 5rpx;
padding-left: 32rpx;
font-size: 28rpx;
color: #545454;
}
.asset-right {
width: 170rpx;
border-left: 1rpx solid #eee;
}
.asset-right-item {
text-align: center;
color: #545454;
.item-icon {
font-size: 44rpx;
}
.item-name {
margin-top: 14rpx;
font-size: 28rpx;
}
}
.asset-left-item {
text-align: center;
padding-left: 28rpx;
display: flex;
.item-value {
font-size: 34rpx;
// color: #febd45;
}
.item-name {
color: #545454;
margin-top: 14rpx;
font-size: 24rpx;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin: 30rpx 25rpx 20rpx 0;
}
.buy-user-icon {
width: 40rpx;
margin-bottom: 8rpx;
}
}
}
}
// 退出登录
.my-logout {
display: flex;
justify-content: center;
margin-top: 50rpx;
.logout-btn {
width: 400rpx;
margin: 0 auto;
font-size: 28rpx;
color: #616161;
border-radius: 20rpx;
border: 1px solid #dcdcdc;
padding: 16rpx 0;
text-align: center;
}
}
.price-box {
padding: 30rpx;
display: flex;
justify-content: space-between;
.info {
display: flex;
image {
width: 120rpx;
height: 120rpx;
border-radius: 20rpx;
}
.content {
width: 280rpx;
padding-left: 30rpx;
font-size: 28rpx;
color: #666666;
}
}
.price {
display: flex;
flex-direction: column;
align-items: flex-end;
padding: 0 20rpx;
.reb {
color: #ff0000;
}
.num {
color: #999999;
}
}
}
.xieyi {
width: 600rpx;
font-size: 26rpx;
text-align: center;
display: flex;
justify-content: center;
margin: 50rpx auto;
color: #999999;
text {
color: #681752;
}
}
.cart {
position: fixed;
bottom: 25rpx;
z-index: 888;
width: 750rpx;
height: 80rpx;
line-height: 80rpx;
.cart-info {
background: linear-gradient(to bottom, $main-bg, $main-bg2);
width: 700rpx;
margin: auto;
display: flex;
border-radius: 100rpx;
justify-content: space-between;
position: relative;
.cart-logo {
position: absolute;
width: 90rpx;
height: 90rpx;
margin-left: 20rpx;
bottom: 10rpx;
}
.total-price {
padding-left: 30rpx;
font-size: 34rpx;
font-weight: bold;
color: #ffffff;
}
.clear-cart {
color: #ff0000;
}
.buy {
margin-right: 0;
display: flex;
flex-direction: column;
justify-content: center;
.custom-style {
padding: 0 50rpx;
color: #ffffff;
background-color: #ff0000;
// background: linear-gradient(to bottom, $main-bg, $main-bg2);
// background-color: #8b004c;
border: none;
width: 330rpx;
height: 66rpx;
font-size: 28rpx;
}
}
}
}
.w-input{
width: 400rpx;
text-align: right;
font-size: 25rpx;
color: #606266;
}
</style>