This commit is contained in:
zmj 2024-06-27 09:11:32 +08:00
commit 25517afb79
17 changed files with 2124 additions and 725 deletions

View File

@ -30,3 +30,7 @@ export const getMassageCode = (data) => {
export const setPayPassword = (data) => { export const setPayPassword = (data) => {
return request.post('/user/user/set_payPassword', data); return request.post('/user/user/set_payPassword', data);
} }
export const getFundList = (data) => {
return request.get('/user/user/fundList', data);
}

View File

@ -99,6 +99,10 @@ export const vipRechargeApi = (data) => {
return request.post('/store/store/recharge', data); return request.post('/store/store/recharge', data);
} }
export const reVipRechargeApi = (data) => {
return request.post('/store/store/again_recharge', data);
}
export const rechargeCountApi = (data) => { export const rechargeCountApi = (data) => {
return request.get('/store/store/recharge_count', data); return request.get('/store/store/recharge_count', data);
} }
@ -138,3 +142,7 @@ export const getCreateLists = (data) => {
export const getloginSms = (data) => { export const getloginSms = (data) => {
return request.post('/user/user/login_sms', data); return request.post('/user/user/login_sms', data);
} }
export const getReportingSms = (data) => {
return request.post('/user/user/reporting_sms', data);
}

View File

@ -8,13 +8,19 @@
<view>商品名称</view> <view>商品名称</view>
<view>{{ datas.name || datas.goods_name || datas.store_name }}</view> <view>{{ datas.name || datas.goods_name || datas.store_name }}</view>
</view> </view>
<view class="row" v-if="datas.store_info">
<view>商品规格</view>
<view>{{ datas.store_info}}</view>
</view>
<view class="row"> <view class="row">
<view>商品单位</view> <view>商品单位</view>
<view>{{ datas.unit_name }}</view> <view>{{ datas.unit_name }}</view>
</view> </view>
<view class="row"> <view class="row">
<view>商品价格</view> <view>商品价格</view>
<view>¥ {{ datas.price || datas.sell }} / {{ datas.unit_name }}</view> <view>¥ {{priceKey.off_activity==1? datas[priceKey.price]: datas[priceKey.op_price] }} /
{{ datas.unit_name }}
</view>
</view> </view>
<view class="row" v-if="datas.batch > 0"> <view class="row" v-if="datas.batch > 0">
<view>起批量</view> <view>起批量</view>
@ -28,22 +34,16 @@
</view> </view>
<view style="color: #F55726;" v-else>¥ {{ subtotal }}</view> <view style="color: #F55726;" v-else>¥ {{ subtotal }}</view>
</view> </view>
<view v-if="datas.is_bulk" class="row"> <view v-if="datas.is_bulk" class="row" style="height: 100rpx;">
<view>购买重量<text style="color: #F55726;">*</text></view> <view>购买重量<text style="color: #F55726;">*</text></view>
<view style="flex: 1;"> <view style="justify-content: end;">
<up-input v-model="datas.cart_num" :cursorSpacing='120' type="digit" border="none" <up-number-box v-model="datas.cart_num"></up-number-box>
placeholder="请输入购买重量" inputAlign="right"></up-input>
</view> </view>
</view> </view>
<view v-else class="row"> <view v-else class="row" style="height: 100rpx;">
<view>购买数量<text style="color: #F55726;">*</text></view> <view>购买数量<text style="color: #F55726;">*</text></view>
<view style="flex: 1;"> <view style="justify-content: end;">
<up-input ref='foucs1' v-model="datas.cart_num" :cursorSpacing='120' type="digit" border="none" <up-number-box v-model="datas.cart_num"></up-number-box>
placeholder="请输入购买数量" inputAlign="right">
<template #suffix>
<span style="color: #20b128;">{{ datas.unit_name }}</span>
</template>
</up-input>
</view> </view>
</view> </view>
<view class="row" style="padding-top: 30px;padding-bottom: 30rpx;"> <view class="row" style="padding-top: 30px;padding-bottom: 30rpx;">
@ -80,13 +80,22 @@
}, },
}) })
let priceKey = ref({})
if (uni.getStorageSync('PRICE_KEY')) {
priceKey.value = JSON.parse(uni.getStorageSync('PRICE_KEY'));
} else {
priceKey.value = {};
}
const datas = ref({ const datas = ref({
cart_num: '' cart_num: ''
}); });
const setData = (e) => { const setData = (e) => {
datas.value = e; datas.value = e;
if (Number(e.batch) > 0) datas.value.cart_num = e.batch; if (Number(e.batch) > 0) datas.value.cart_num = e.batch;
else datas.value.cart_num = ''; else datas.value.cart_num = 1;
} }
@ -107,13 +116,16 @@
} }
const subtotal = computed(() => { const subtotal = computed(() => {
let num = +datas.value.cart_num || 0; let num = +datas.value.cart_num || 1;
let sell = +datas.value.sell || +datas.value.price; let sell = +datas.value[priceKey.value.off_activity == 1 ? priceKey.value.price : priceKey.value.op_price];
return Number(num * sell * 100 / 100).toFixed(2) return Number(num * sell * 100 / 100).toFixed(2)
}) })
defineExpose({ defineExpose({
setData, setData,
// founcsFn // founcsFn

View File

@ -1,4 +1,5 @@
let BASE_URL let BASE_URL
let WSS_URL
import store from "@/store/user.js" import store from "@/store/user.js"
// 环境 // 环境
// let env = "dev" // let env = "dev"
@ -7,13 +8,18 @@ let env = "prod"
switch (env) { switch (env) {
case 'dev': case 'dev':
BASE_URL = 'https://test-multi-store.lihaink.cn'; // BASE_URL = 'https://test-multi-store.lihaink.cn';
// WSS_URL = 'wss://test-multi-store.lihaink.cn/pull'
BASE_URL = 'https://ceshi-multi-store.lihaink.cn';
WSS_URL = 'wss://ceshi-multi-store.lihaink.cn/pull'
break; break;
case 'liu': case 'liu':
BASE_URL = 'http://192.168.1.201:8545'; BASE_URL = 'https://ceshi-multi-store.lihaink.cn';
WSS_URL = 'wss://ceshi-multi-store.lihaink.cn/pull'
break; break;
default: default:
BASE_URL = 'https://multi-store.lihaink.cn'; BASE_URL = 'https://multi-store.lihaink.cn';
WSS_URL = 'wss://multi-store.lihaink.cn/pull'
} }
let HTTP_REQUEST_URL let HTTP_REQUEST_URL
@ -21,6 +27,7 @@ let HEADER
let config = { let config = {
HTTP_REQUEST_URL: BASE_URL, HTTP_REQUEST_URL: BASE_URL,
WSS_URL: WSS_URL,
HEADER: { HEADER: {
'content-type': 'application/json', 'content-type': 'application/json',
//#ifdef MP //#ifdef MP

View File

@ -0,0 +1,135 @@
<template>
<up-sticky bgColor="#fff">
<up-tabs :list="tabsLst" :itemStyle="{width:'33vw',paddingBottom:'20rpx'}" lineColor='#50C758' :current='mark'
@change="tabsChange"></up-tabs>
</up-sticky>
<block v-if="lists.length>0">
<view class="content" v-if='type==1||type==2'>
<view class="li" v-for="(item,index) in lists" :key="index">
<view class="li-top">
<text>{{item.title}}</text>
<text style="font-weight: bold;" :style="{color:item.type=='in'?'#50C758':'red'
}">{{ item.type=='in'?'+':'-' }}{{item.amount}}</text>
</view>
<view class="li-top" style="margin-bottom: 0;">
<text style="font-size: 24rpx;color: grey;">{{item.create_time}}</text>
<text style="font-size: 24rpx;color: grey;">余额 {{item.before_balance}}</text>
</view>
</view>
</view>
<view class="content" v-if='type==3'>
<view class="li" v-for="(item,index) in lists" :key="index">
<view class="li-top">
<text>{{item.title}}</text>
<text style="font-weight: bold;" :style="{color:!item.financial_pm?'#50C758':'red'
}">{{ !item.financial_pm?'+':'-' }}{{item.number}}</text>
</view>
<view class="li-top" style="margin-bottom: 0;">
<text style="font-size: 24rpx;color: grey;">{{item.create_time}}</text>
</view>
</view>
</view>
<view class="content" v-if='type==4'>
<view class="li" v-for="(item,index) in lists" :key="index">
<view class="li-top">
<text>{{item.order_sn}}</text>
<text style="font-weight: bold;" :style="{color:!item.status?'#50C758':'red'
}">{{ !item.status?'+':'-' }}{{item.number}}</text>
</view>
<view class="li-top" style="margin-bottom: 0;">
<text style="font-size: 24rpx;color: grey;">{{item.create_time}}</text>
</view>
</view>
</view>
</block>
<up-empty v-else mode="history" style="margin-top: 20vh;" text='没有更多内容了'>
</up-empty>
<view style="height: 50rpx;">
</view>
</template>
<script setup>
import {
ref,
reactive
} from "vue"
import {
onLoad,
onPullDownRefresh
} from "@dcloudio/uni-app"
import {
getFundList
} from "@/api/address.js"
const navLists = ['', '采购款明细', '余额明细', '礼品券明细', '返还金明细']
const tabsLst = reactive([{
name: '全部'
},
{
name: '收入'
},
{
name: '支出'
},
]);
const mark = ref(0)
const tabsChange = (e) => {
mark.value = e.index
getLists()
}
const lists = ref([])
let type = ref('')
const getLists = async (isPullDown = false) => {
let res = await getFundList({
type: type.value,
mark: mark.value || ''
})
lists.value = res.data.lists
if (isPullDown) uni.stopPullDownRefresh()
}
onLoad((opt) => {
type.value = opt.type
uni.setNavigationBarTitle({
title: navLists[type.value]
})
getLists()
})
onPullDownRefresh(() => {
getLists(true)
})
</script>
<style lang="scss">
.content {
background-color: white;
width: 690rpx;
padding: 20rpx;
margin: 0 auto;
box-sizing: border-box;
margin: 0 auto;
margin-top: 30rpx;
border-radius: 20rpx;
margin-bottom: 100rpx;
.li {
margin-top: 20rpx;
border-bottom: 1px solid #EDF2FA;
padding-bottom: 20rpx;
.li-top {
display: flex;
justify-content: space-between;
margin-bottom: 20rpx;
}
}
}
</style>

View File

@ -28,38 +28,52 @@
{{ Role == 1 ? '行业会员' : '商户' }}开通报备 {{ Role == 1 ? '行业会员' : '商户' }}开通报备
</view> </view>
<up-form labelPosition="left" :model="formData" :borderBottom='false'> <up-form labelPosition="left" :model="formData" :borderBottom='false'>
<up-form-item label="" prop="userInfo.name"> <up-form-item label="">
<up-input v-model="formData.real_name" border="none" prefixIcon="account" placeholder="请输入真实姓名" <up-input v-model="formData.real_name" border="none" prefixIcon="account" placeholder="请输入真实姓名"
:customStyle="{ background: '#F3F3F3', padding: '20rpx', 'border-radius': '30rpx' }" :customStyle="{ background: '#F3F3F3', padding: '20rpx', 'border-radius': '30rpx' }"
:placeholderStyle="{color:'#444444'}" :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }"></up-input>
:prefixIconStyle="{'margin-right':'40rpx'}"></up-input>
</up-form-item> </up-form-item>
<up-form-item label="" prop="userInfo.name"> <up-form-item label="">
<up-input v-model="formData.mobile" border="none" prefixIcon="phone" placeholder="请输入电话号码" <up-input v-model="formData.mobile" border="none" prefixIcon="phone" placeholder="请输入电话号码"
:customStyle="{ background: '#F3F3F3', padding: '20rpx', 'border-radius': '30rpx' }" :customStyle="{ background: '#F3F3F3', padding: '20rpx', 'border-radius': '30rpx' }"
:placeholderStyle="{color:'#444444'}" :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }"></up-input>
:prefixIconStyle="{'margin-right':'40rpx'}"></up-input>
</up-form-item> </up-form-item>
<up-form-item label="" prop="userInfo.name"> <up-form-item label="">
<view @click="showPop = true" style="width: 100%;"> <view @click="showPop = true" style="width: 100%;">
<up-input style="pointer-events: none" v-model="formData.address" border="none" <up-input style="pointer-events: none" v-model="formData.address" border="none" prefixIcon="map"
prefixIcon="map" readonly placeholder="点击选择地址" :customStyle="{background:'#F3F3F3',padding:'20rpx', readonly placeholder="点击选择地址" :customStyle="{
background: '#F3F3F3', padding: '20rpx',
'border-radius': '30rpx' 'border-radius': '30rpx'
}" :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }" }" :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }"
suffixIcon='arrow-down'></up-input> suffixIcon='arrow-down'></up-input>
</view> </view>
</up-form-item> </up-form-item>
<up-form-item label="" prop="userInfo.name" v-if='Role==1'> <up-form-item label="" v-if='Role == 1'>
<view @click="showPop1 = true" style="width: 100%;"> <view @click="showPop1 = true" style="width: 100%;">
<up-input style="pointer-events: none" v-model="formData.label_name" border="none" <up-input style="pointer-events: none" v-model="formData.label_name" border="none"
prefixIcon="man-add" readonly placeholder="点击选择用户身份" :customStyle="{background:'#F3F3F3',padding:'20rpx', prefixIcon="man-add" readonly placeholder="点击选择用户身份" :customStyle="{
background: '#F3F3F3', padding: '20rpx',
'border-radius': '30rpx' 'border-radius': '30rpx'
}" :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }" }" :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }"
suffixIcon='arrow-down'></up-input> suffixIcon='arrow-down'></up-input>
</view> </view>
</up-form-item> </up-form-item>
<up-form-item label="">
<view style="width: 100%;display: flex;align-items: center;justify-content: space-between;">
<view class="">
<up-input v-model="formData.code" border="none" prefixIcon="tags" placeholder="请输入验证码"
:customStyle="{
background: '#F3F3F3', padding: '20rpx',
'border-radius': '30rpx'
}" :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }"></up-input>
</view>
<text class='btn-text' style="color: grey;" v-if='cutDown'>重新获取({{ cutDown }})</text>
<text @click="getCode" class='btn-text' v-else> {{ flag ? '获取验证码' : '重新获取' }} </text>
</view>
</up-form-item>
</up-form> </up-form>
<view class="store-info"> <view class="store-info">
@ -67,8 +81,6 @@
</view> </view>
</view> </view>
<view class="submit-btn" @click="submit"> <view class="submit-btn" @click="submit">
<!-- <up-button text="完成并收款" size='large' :customStyle="{height:'100rpx',fontSize:'50rpx'}" @click="submit"
shape="circle" color="#50C758"></up-button> -->
<view <view
style='width: 710rpx;height: 100rpx;text-align: center;line-height: 100rpx;text-align: center;color: white;background-color: #33B83A;border-radius: 50rpx;font-size:40rpx ;'> style='width: 710rpx;height: 100rpx;text-align: center;line-height: 100rpx;text-align: center;color: white;background-color: #33B83A;border-radius: 50rpx;font-size:40rpx ;'>
{{ Role == 1 ? '完成并收款' : '完成' }} {{ Role == 1 ? '完成并收款' : '完成' }}
@ -107,15 +119,21 @@
<uni-td style="font-size: 20rpx;" align="center" v-if='Role == 1'>{{ item.label_name }}</uni-td> <uni-td style="font-size: 20rpx;" align="center" v-if='Role == 1'>{{ item.label_name }}</uni-td>
<uni-td style="font-size: 20rpx;" align="center"> <uni-td style="font-size: 20rpx;" align="center">
<view v-if="item.paid == 1 || Role == 4">已开通</view> <view v-if="item.paid == 1 || Role == 4">已开通</view>
<view v-else @click="upadtaStatus(item)" style="color:#33B83A ;">未开通,查询</view> <view v-else style="color:#33B83A ;">
<view @click="upadtaStatus(item)">
未开通,查询
</view>
<view @click="rePay(item)">
重新支付
</view>
</view>
</uni-td> </uni-td>
</uni-tr> </uni-tr>
</uni-table> </uni-table>
</view> </view>
</block> </block>
</view> </view>
<view style="height: 50rpx;" />
<!-- 地址选择器 --> <!-- 地址选择器 -->
<up-popup :show="showPop" @close="showPop = false" @open="showPop = true" :round="10"> <up-popup :show="showPop" @close="showPop = false" @open="showPop = true" :round="10">
@ -160,15 +178,15 @@
</view> </view>
</view> </view>
</up-popup> </up-popup>
<up-picker :show="showPop1" :columns="columns" @confirm='conformRole' @cancel='showPop1=false' <up-picker :show="showPop1" :columns="columns" @confirm='conformRole' @cancel='showPop1 = false' @close="showPop1 = false"
@close="showPop1=false" @open="showPop1=true" keyName='label_name' confirmColor='#33B83A'></up-picker> @open="showPop1 = true" keyName='label_name' confirmColor='#33B83A'></up-picker>
</template> </template>
<script setup> <script setup>
import { import {
reactive, reactive,
ref ref
} from 'vue'; } from 'vue';
import useUserStore from "@/store/user";
import { import {
provinceListApi, provinceListApi,
cityListApi, cityListApi,
@ -180,18 +198,23 @@
import { import {
vipRechargeApi, vipRechargeApi,
rechargeCountApi, rechargeCountApi,
reVipRechargeApi,
rechargeListsApi, rechargeListsApi,
updataOrderApi, updataOrderApi,
getStoreByPhone, getStoreByPhone,
getUserLabel, getUserLabel,
getUserShip, getUserShip,
getCreateLists getCreateLists,
getReportingSms
} from "@/api/user.js" } from "@/api/user.js"
import Push from "@/utils/push.js"
import { import {
onPullDownRefresh, onPullDownRefresh,
onLoad onLoad
} from "@dcloudio/uni-app" } from "@dcloudio/uni-app"
import {
config
} from "@/config/app.js"
const showPop1 = ref(false) const showPop1 = ref(false)
const Role = ref('') const Role = ref('')
@ -210,15 +233,14 @@
}).catch(err => { }).catch(err => {
uni.$u.toast('未查到店铺信息,请检查手机号码') uni.$u.toast('未查到店铺信息,请检查手机号码')
}) })
} }
// //
let STORE_INFO = reactive({ let STORE_INFO = reactive({
id: "" id: ""
}) })
//
const setPhoneOneDay = () => { const setPhoneOneDay = () => {
if (uni.getStorageSync('VIP_PHONE')) return; if (uni.getStorageSync('VIP_PHONE')) return;
const currentDate = new Date(); const currentDate = new Date();
@ -229,7 +251,6 @@
phone: storePhone.value phone: storePhone.value
})); }));
} }
const getPhoneOneDay = () => { const getPhoneOneDay = () => {
if (uni.getStorageSync('VIP_PHONE')) { if (uni.getStorageSync('VIP_PHONE')) {
let data = JSON.parse(uni.getStorageSync('VIP_PHONE')) let data = JSON.parse(uni.getStorageSync('VIP_PHONE'))
@ -240,8 +261,30 @@
} }
} }
} }
//
//
const cutDown = ref(0)
const flag = ref(true)
const code = ref('')
const checkPhone = (phone) => {
const regex = /^1[3-9]\d{9}$/;
return regex.test(formData.mobile) ? true : false
}
const getCode = async () => {
if (!checkPhone(formData.mobile)) return uni.$u.toast('请输入正确的手机号')
await getReportingSms({
account: formData.mobile
})
flag.value = false
cutDown.value = 60
let timer = setInterval(() => {
cutDown.value--
if (cutDown.value <= 0) clearInterval(timer)
}, 1000)
}
//
const currentTab = ref(1) const currentTab = ref(1)
const formData = reactive({ const formData = reactive({
@ -252,13 +295,28 @@
area: "", area: "",
street: "", street: "",
village: "", village: "",
brigade: "",
real_name: "", real_name: "",
auth_code: "", auth_code: "",
address: "", address: "",
label_name: "", label_name: "",
label_id: "", label_id: "",
user_ship: '' user_ship: '',
code: '',
// store_id: STORE_INFO.id,
// mobile: "19130550023",
// province: 510000,
// city: '510500',
// area: "510503",
// street: "510503102",
// village: "510503102201",
// real_name: "",
// auth_code: "131197337173621549",
// address: "",
// label_name: "",
// label_id: "4",
// user_ship: '1',
// code: ''
}) })
const conformRole = (e) => { const conformRole = (e) => {
@ -281,7 +339,6 @@
const addressTbasChange = (e) => { const addressTbasChange = (e) => {
currentAddressIndex.value = e.index currentAddressIndex.value = e.index
} }
const addressList = reactive({ const addressList = reactive({
city: [], city: [],
area: [], area: [],
@ -289,7 +346,6 @@
village: [], village: [],
brigade: [] brigade: []
}) })
const addressLiClick = async (i, item) => { const addressLiClick = async (i, item) => {
if (i == 0) { if (i == 0) {
formData.city = item.city_code formData.city = item.city_code
@ -336,7 +392,6 @@
.name .name
return currentAddressIndex.value++ return currentAddressIndex.value++
} }
const getCityList = async () => { const getCityList = async () => {
let res = await cityListApi({ let res = await cityListApi({
province_code: formData.province province_code: formData.province
@ -366,34 +421,51 @@
}, },
]); ]);
//
// scoket
let timerInvol = null
const userInfo = useUserStore().userInfo;
const connection = new Push({
url: config.WSS_URL, // websocket
app_key: '2ce3ce22329517213caa7dad261f5695',
});
// user-1
const user_channel = connection.subscribe(`wechat_mmp_${userInfo.id}`);
user_channel.on('message', function (data) {
try {
clearTimeout(timerInvol);
paySuccessToTabs2()
} catch (error) { }
});
const submit = async () => { const submit = async () => {
if (!formData.real_name) return uni.$u.toast('请填写真实姓名'); if (!formData.real_name) return uni.$u.toast('请填写真实姓名');
if (!formData.mobile) return uni.$u.toast('请填写电话号码'); if (!formData.mobile) return uni.$u.toast('请填写电话号码');
if (!formData.code) return uni.$u.toast('请输入短信验证码');
if (!formData.label_id) return uni.$u.toast('请选择用户身份');
if (!formData.address) return uni.$u.toast('请选择地址');
formData.store_id = STORE_INFO.id formData.store_id = STORE_INFO.id
if (Role.value == 1) { if (Role.value == 1) {
// formData.recharge_type = 'INDUSTRYMEMBERS'
// formData.user_ship = 1
// vipRechargeApi(formData).then(res => {})
// return
uni.scanCode({ uni.scanCode({
success: function (res) { success: function (res) {
if (String(res.result.length) != 18) return uni.$u.toast('二维码未扫描完整');
uni.showLoading({
title: '支付中...'
});
formData.auth_code = res.result formData.auth_code = res.result
formData.recharge_type = 'INDUSTRYMEMBERS' formData.recharge_type = 'INDUSTRYMEMBERS'
formData.user_ship = 1 formData.user_ship = 1
vipRechargeApi(formData).then(res => { vipRechargeApi(formData).then(res => {
uni.$u.toast('操作成功'); timerInvol = setTimeout(() => {
currentTab.value = 2 uni.hideLoading();
formData.real_name = '' uni.$u.toast('支付超时');
formData.mobile = '' }, 30000)
formData.address = ''
formData.label_name = ''
formData.city = ''
formData.area = ''
formData.street = ''
formData.village = ''
formData.brigade = ''
currentAddressIndex.value = 0
tabsList.forEach(item => {
item.name = '请选择'
})
getCount()
getLists()
}) })
} }
@ -414,7 +486,9 @@
formData.street = '' formData.street = ''
formData.village = '' formData.village = ''
formData.brigade = '' formData.brigade = ''
formData.code = ''
currentAddressIndex.value = 0 currentAddressIndex.value = 0
cutDown.value = 0
tabsList.forEach(item => { tabsList.forEach(item => {
item.name = '请选择' item.name = '请选择'
}) })
@ -422,7 +496,57 @@
getCount() getCount()
}) })
} }
}
const rePay = (item) => {
uni.scanCode({
success: function (res) {
if (String(res.result.length) != 18) return uni.$u.toast('二维码未扫描完整');
uni.showLoading({
title: '支付中...'
});
reVipRechargeApi({
id: item.id,
auth_code: res.result
}).then(res => {
timerInvol = setTimeout(() => {
uni.hideLoading();
uni.$u.toast('支付超时');
}, 30000)
})
}
});
}
// formDatatabs2
const paySuccessToTabs2 = () => {
uni.hideLoading()
uni.showToast({
title: '支付成功',
duration: 2000,
success() {
currentTab.value = 2
formData.real_name = ''
formData.mobile = ''
formData.address = ''
formData.label_name = ''
formData.city = ''
formData.area = ''
formData.street = ''
formData.village = ''
formData.brigade = ''
formData.code = ''
currentAddressIndex.value = 0
cutDown.value = 0
tabsList.forEach(item => {
item.name = '请选择'
})
setTimeout(() => {
getLists()
getCount()
}, 500); // 1
}
});
} }
// //
@ -450,7 +574,6 @@
}) })
lists.value = res.data.lists lists.value = res.data.lists
count.value = res.data.count count.value = res.data.count
} }
} }
@ -463,13 +586,15 @@
updataOrderApi({ updataOrderApi({
order_no: item.order_id, order_no: item.order_id,
recharge: 1 recharge: 1
}).then(res => {
getCount()
getLists()
}) })
} }
onLoad(() => { onLoad(() => {
getUserShip().then(res => { getUserShip().then(res => {
console.log(res)
range.value = res.data.lists.map(item => { range.value = res.data.lists.map(item => {
return { return {
value: item.id, value: item.id,
@ -621,4 +746,13 @@
.slot-content { .slot-content {
padding-bottom: 50rpx; padding-bottom: 50rpx;
} }
.code-btn {
display: flex;
align-items: center;
}
.btn-text {
color: #20B128;
}
</style> </style>

View File

@ -52,8 +52,8 @@
"path": "pages/my/my", "path": "pages/my/my",
"style": { "style": {
"navigationBarTitleText": "个人中心", "navigationBarTitleText": "个人中心",
"enablePullDownRefresh": false, "enablePullDownRefresh": true,
"navigationStyle": "custom" "navigationBarBackgroundColor": "#D3FDCA"
} }
}, { }, {
"path": "pages/charge/charge_record", "path": "pages/charge/charge_record",
@ -234,9 +234,14 @@
"navigationBarTitleText": "会员报备", "navigationBarTitleText": "会员报备",
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }
},
{
"path": "balanceDetail/index",
"style": {
"navigationBarTitleText": "余额明细",
"enablePullDownRefresh": true
}
} }
] ]
} }
], ],

View File

@ -34,9 +34,12 @@
<view class="title"> <view class="title">
<view class="name u-line-2">{{item.goods_name}}</view> <view class="name u-line-2">{{item.goods_name}}</view>
<view class="tip u-line-1">{{item.unit_name}}</view> <view class="tip u-line-1">{{item.unit_name}}</view>
<view v-if="priceKey.off_activity==1" class="tip u-line-1">原价<text
style="text-decoration: line-through;">{{item[priceKey.op_price]}}</text>
</view>
</view> </view>
<view class="price-btn"> <view class="price-btn">
<view class="price">{{item.sell}}</view> <view class="price">{{item[priceKey.price]}}</view>
<view class="btn"> <view class="btn">
<view class="num">{{item.cart_num}}</view> <view class="num">{{item.cart_num}}</view>
<u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon> <u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon>
@ -109,14 +112,11 @@
</view> </view>
</view> </view>
<view style="width: 200rpx;"> <view style="width: 200rpx;">
<up-button color="#20b128" shape="circle" :disabled="!checkAll || c_price0<500 " <up-button color="#20b128" shape="circle" @click="settleAccounts">
@click="settleAccounts"> <view class="">
<view class="" v-if='c_price0>=500'>
去结算<text v-if="checkAll">({{checkAll}})</text> 去结算<text v-if="checkAll">({{checkAll}})</text>
</view> </view>
<view class="" v-else>
¥500起订
</view>
</up-button> </up-button>
</view> </view>
</view> </view>
@ -132,7 +132,8 @@
<script setup> <script setup>
import { import {
onShow onShow,
onLoad
} from "@dcloudio/uni-app" } from "@dcloudio/uni-app"
import { import {
computed, computed,
@ -260,8 +261,12 @@
cartList.value = res.data.lists; cartList.value = res.data.lists;
cartInfo.value = { cartInfo.value = {
total_price: res.data?.extend.total_price || '0.00', total_price: res.data?.extend.total_price || '0.00',
pay_price: res.data?.extend.pay_price || '0.00',
count: res.data?.count || 0 count: res.data?.count || 0
} }
console.log(cartInfo.value)
setTimeout(() => { setTimeout(() => {
triggered.value = false; triggered.value = false;
}, 300) }, 300)
@ -269,11 +274,11 @@
} }
const c_price0 = computed(() => { const c_price0 = computed(() => {
let price = cartInfo.value.total_price + ''; let price = cartInfo.value.pay_price + '';
return price.split('.')[0] || '0'; return price.split('.')[0] || '0';
}) })
const c_price1 = computed(() => { const c_price1 = computed(() => {
let price = cartInfo.value.total_price + ''; let price = cartInfo.value.pay_price + '';
return price.split('.')[1] || '00'; return price.split('.')[1] || '00';
}) })
@ -281,15 +286,18 @@
let checkAll = ref(0) let checkAll = ref(0)
const checkItem = (item, type) => { const checkItem = (item, type) => {
item.check = type; item.check = type;
let price = Number(cartInfo.value.total_price); let price = Number(cartInfo.value.pay_price);
if (type) { if (type) {
price += item.sell * item.cart_num; price += (priceKey.value.off_activity == 1 ? item[priceKey.value.price] : item[priceKey.value.op_price]) *
item
.cart_num;
checkAll.value++; checkAll.value++;
} else { } else {
price -= item.sell * item.cart_num; price -= (priceKey.value.off_activity == 1 ? item[priceKey.value.price] : item[priceKey.value.op_price]) *
item.cart_num;
checkAll.value--; checkAll.value--;
} }
cartInfo.value.total_price = price.toFixed(2); cartInfo.value.pay_price = price.toFixed(2);
} }
const changeAll = (flag = false) => { const changeAll = (flag = false) => {
let count = 0; let count = 0;
@ -332,6 +340,15 @@
onShow(() => { onShow(() => {
getcartList(); getcartList();
}) })
let priceKey = ref({})
onLoad(() => {
if (uni.getStorageSync('PRICE_KEY')) {
priceKey.value = JSON.parse(uni.getStorageSync('PRICE_KEY'));
} else {
priceKey.value = {};
}
})
</script> </script>
<style lang="scss"> <style lang="scss">
@ -406,8 +423,8 @@
} }
.shop-img { .shop-img {
height: 120rpx; height: 164rpx;
width: 120rpx; width: 164rpx;
margin-right: 20rpx; margin-right: 20rpx;
border-radius: 14rpx; border-radius: 14rpx;
} }

View File

@ -39,13 +39,12 @@
:style="{ height: btns.height + 'px', top: btns.top + 'px', left: (btns.left - 40) + 'px' }"> :style="{ height: btns.height + 'px', top: btns.top + 'px', left: (btns.left - 40) + 'px' }">
<up-button icon="share-square" openType="share" plain size="large" loadingSize="100" /> <up-button icon="share-square" openType="share" plain size="large" loadingSize="100" />
</view> </view>
<view class="navbar"> <view class="navbar">
<view style="width: 400rpx;"> <view style="width: 400rpx;">
<up-search placeholder="请输入商品" @search="searchKeyword" @clear="searchKeyword" v-model="keyword" <up-search placeholder="请输入商品" @search="searchKeyword" @clear="searchKeyword" v-model="keyword"
:showAction="false"></up-search> :showAction="false"></up-search>
</view> </view>
<view class="nav-item" @click="navTo('/pages/cart/cart')"> <view class="nav-item" @click="navTo(`/pages/cart/cart`)">
<image src="@/static/tab/ba.png"></image> <image src="@/static/tab/ba.png"></image>
<text>购物车</text> <text>购物车</text>
</view> </view>
@ -117,8 +116,17 @@
<view class="order-by"> <view class="order-by">
<view class="item" :class="{ 'order-active': where.order == '' }" @click="changeOrder('')">综合 <view class="item" :class="{ 'order-active': where.order == '' }" @click="changeOrder('')">综合
</view> </view>
<view class="item" :class="{ 'order-active': where.order == 'desc' || where.order == 'asc' }" <view class="item" style="display: flex;align-items: center;"
@click="changeOrder(where.order == 'asc' ? 'desc' : 'asc')">价格</view> :class="{ 'order-active': where.order == 'desc' || where.order == 'asc' }"
@click="changeOrder(where.order == 'asc' ? 'desc' : 'asc')">
价格
<view style="color: black;">
<up-icon name="arrow-up-fill" :color="where.order=='asc'?'#20b128':'' "
size="8"></up-icon>
<up-icon name="arrow-down-fill" :color="where.order=='desc'?'#20b128':'' "
size="8"></up-icon>
</view>
</view>
<view class="item" :class="{ 'order-active': where.order == 'sales' }" <view class="item" :class="{ 'order-active': where.order == 'sales' }"
@click="changeOrder('sales')">销量 @click="changeOrder('sales')">销量
</view> </view>
@ -145,33 +153,54 @@
<view class="shop-img" <view class="shop-img"
:style="{ backgroundImage: `url(${item.image}?x-oss-process=image/format,webp)` }"> :style="{ backgroundImage: `url(${item.image}?x-oss-process=image/format,webp)` }">
</view> </view>
<view class="shop-content"> <view class="shop-content">
<view class="title"> <view class="goods-name" style="font-size: 28rpx;color: #060606;">
<view class="name u-line-2">{{ item.store_name }}</view> {{ item.store_name }}
<view class="tip u-line-1"> </view>
<text>{{ item.spec }}</text> <view class="shop-content-li" v-if="priceKey.off_activity==1">
<view class="shop-content-li-l" style="color: #FC452F;">
活动价
</view>
<view class="shop-content-li-r" style="color:#FC452F ;"><text
style="font-size: 30rpx;">{{item[priceKey.price]}}</text>/{{ item.unit_name }}
</view>
<view class="tag">
<view class="icon" />
赠10%品牌礼品
</view> </view>
</view> </view>
<view style="display: flex;" v-if='item.batch > 0'> <view class="shop-content-li" style="color: #999999;" v-if="priceKey.off_activity==1">
<view style="color: red;">起批量: {{ item.batch }}{{ item.unit_name }}起卖</view> <view class="shop-content-li-l">原价</view>
<view class="shop-content-li-r line-through">{{item[priceKey.op_price]}}</view>
</view> </view>
<!-- <view style="display: flex;align-items: center;" v-if='userStore?.userInfo?.user_ship == 1'>
<text class='price' style="font-size: 24rpx;">会员价</text> <view class="shop-content-li" v-else>
<text class="price" style="margin-right: 10rpx;">{{ item.vip_price }} <view class="shop-content-li-l">售价</view>
</text> <view class="shop-content-li-r" style="color:#FC452F ;"><text
<text class='price' style="font-size: 24rpx;">/{{ item.unit_name }}</text> style="font-size: 28rpx;">{{item[priceKey.op_price]}}</text>
</view> -->
<view class="price-btn">
<!-- <view class="price" style="font-size: 24rpx;"
v-if='userStore?.userInfo?.user_ship == 1'>
{{ item.price }}/{{ item.unit_name }}
</view> -->
<view class="price">
{{ item.price }}/{{ item.unit_name }}
</view> </view>
<view class="btn"> </view>
<view class="shop-content-li" style="justify-content: space-between;"
v-if="item.store_info">
<view style="display: flex;">
<view class="shop-content-li-l">规格</view>
<view class="shop-content-li-r">{{ item.store_info }}</view>
</view>
</view>
<view class="shop-content-li" style="justify-content: space-between;" v-if="item.batch">
<view style="display: flex;">
<view class="shop-content-li-l">起批量</view>
<view class="shop-content-li-r">{{ item.batch }}{{ item.unit_name }}起卖</view>
</view>
<!-- <view class="btn">
<u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon> <u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon>
</view> -->
</view> </view>
<view class="shopconetent-btn">
<u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon>
</view> </view>
</view> </view>
</view> </view>
@ -184,28 +213,44 @@
<view class="row"> <view class="row">
<view>合计</view> <view>合计</view>
<view class="price" v-if='cartInfo.pay_price<=0||userStore?.userInfo?.user_ship !=4'>¥<text <view class="price" v-if='cartInfo.pay_price<=0||userStore?.userInfo?.user_ship !=4'>¥<text
style="font-size: 36rpx;">{{ cartInfo.total_price }}</text></view> style="font-size: 36rpx;">{{ cartInfo.pay_price }}</text></view>
<view class="price" v-else>¥<text style="font-size: 30rpx;">{{ cartInfo.total_price }}</text></view> </view>
<view class="price" v-if="cartInfo.pay_price>0 &&userStore?.userInfo?.user_ship == 4"><text <view style="font-size: 22rpx;text-indent: 3em;color: #F55726;"
style="font-size: 36rpx;">优惠后 v-if="cartInfo.msg&&cartInfo.total_price>0 ">
{{ cartInfo.pay_price }}</text></view> {{cartInfo.msg }}
</view> </view>
<!-- <view class="row">
<view style="color: #777;">原价 ¥50.00</view>
<view class="price">优惠 ¥0.00</view>
</view> -->
</view> </view>
<view class="btn"> <view class="btn">
<up-button color="#20b128" :disabled="cartInfo.total_price < 500" @click="settleAccounts"> <up-button color="#20b128" :disabled="cartInfo.pay_price<=0" @click="settleAccounts"> 结算</up-button>
{{ cartInfo.total_price < 500 ? "¥500起订" : "结算" }} </up-button>
</view> </view>
<view class="cart" @click="navTo('/pages/cart/cart')"> <view class="cart" @click="navTo(`/pages/cart/cart`)">
<image src="@/static/icon/cart.png"></image> <image src="@/static/icon/cart.png"></image>
<view class="badge">{{ cartInfo.count }}</view> <view class="badge">{{ cartInfo.count }}</view>
</view> </view>
</view> </view>
<goodPopup ref="goodRef" :show="showGoodPopup" @close="showGoodPopup = false" @change="changeGood" /> <goodPopup ref="goodRef" :show="showGoodPopup" @close="showGoodPopup = false" @change="changeGood" />
<u-overlay :show="showOverlay" @click="showOverlay = false">
<view class="warp">
<view class="rect" @tap.stop>
<view class="rect-tit">
温馨提示
</view>
<view class="rect-contetn">
只需再购买 {{500- cartInfo.pay_price}} 就能拥有10%的品牌礼品券若错过此次机会则无礼品券
</view>
<view class="rect-btn">
<view style="width: 236rpx;">
<up-button @click="abandActive">放弃优惠</up-button>
</view>
<view style="width: 236rpx;">
<up-button color="#20b128" @click="showOverlay=false">继续采购</up-button>
</view>
</view>
</view>
</view>
</u-overlay>
</view> </view>
</template> </template>
@ -232,7 +277,8 @@
import { import {
productLogApi, productLogApi,
userInfoApi, userInfoApi,
getStoreInfo getStoreInfo,
loginUpdateUserApi
} from "@/api/user.js"; } from "@/api/user.js";
import viewPopup from "@/components/viewPopup.vue" import viewPopup from "@/components/viewPopup.vue"
import goodPopup from "@/components/goodPopup.vue" import goodPopup from "@/components/goodPopup.vue"
@ -247,8 +293,16 @@
import useUserStore from "@/store/user"; import useUserStore from "@/store/user";
const userStore = useUserStore(); const userStore = useUserStore();
const STORE_INFO = reactive({ const STORE_INFO = reactive({
id: 23, id: '',
store_name: "农(特)产品直营店" store_name: ""
})
const priceKey = reactive({
off_activity: "",
op_price: "",
price: ""
}) })
const getStoreInfoFn = () => { const getStoreInfoFn = () => {
@ -264,9 +318,11 @@
for (let key in data) { for (let key in data) {
STORE_INFO[key] = data[key] STORE_INFO[key] = data[key]
} }
getgoodClassList(0);
getGoodList();
}) })
} }
getStoreInfoFn()
// //
@ -360,6 +416,19 @@
} }
const changeOrder = (order) => { const changeOrder = (order) => {
switch (order) {
case 'asc':
where.value.field = 'price'
break;
case 'desc':
where.value.field = 'price'
break;
case 'sales':
where.value.field = 'sales'
break;
default:
where.value.field = ''
}
where.value.order = order; where.value.order = order;
getGoodList(); getGoodList();
} }
@ -370,13 +439,14 @@
name: '', name: '',
order: '', order: '',
store_name: '', store_name: '',
// store_id: 23 store_id: '',
store_id: 4 field: "",
}) })
const loading = ref(true); const loading = ref(true);
const goodList = ref([]); const goodList = ref([]);
const getGoodList = (loadmore = false) => { const getGoodList = (loadmore = false) => {
where.value.store_id = STORE_INFO.id; // id
loading.value = true; loading.value = true;
let class_id = rightActive.value || leftActive.value || topActive.value || ''; let class_id = rightActive.value || leftActive.value || topActive.value || '';
let class_all = ''; let class_all = '';
@ -387,21 +457,19 @@
if (class_all) class_id = ""; // if (class_all) class_id = ""; //
if (loadmore) where.value.page_no++; if (loadmore) where.value.page_no++;
else where.value.page_no = 1; else where.value.page_no = 1;
// where.value.store_id = 23
where.value.store_id = 4
goodListApi({ goodListApi({
...where.value, ...where.value,
class_all: class_all, class_all: class_all,
class: class_id, class: class_id,
cate_id: class_id, cate_id: class_id,
}).then(res => { }).then(res => {
for (let key in res.data.extend) {
priceKey[key] = res.data.extend[key]
}
uni.setStorageSync("PRICE_KEY", JSON.stringify(priceKey))
console.log(priceKey)
if (loadmore) goodList.value.push(...res.data.lists); if (loadmore) goodList.value.push(...res.data.lists);
else goodList.value = res.data.lists; else goodList.value = res.data.lists;
//
// if (!STORE_INFO.store_name || !STORE_INFO.detailed_address) {
// STORE_INFO.store_name = res.data.store.name;
// STORE_INFO.value.detailed_address = res.data.store.detailed_address;
// }
}) })
} }
@ -423,9 +491,7 @@
page_no: page_no, page_no: page_no,
page_size: 30, page_size: 30,
level: three, level: three,
// store_id: STORE_INFO.id // id store_id: STORE_INFO.id // id
// store_id: 23 // id
store_id: 4 // id
}).then(res => { }).then(res => {
if (pid == 0) { // if (pid == 0) { //
if (!res.data?.lists?.length) return; if (!res.data?.lists?.length) return;
@ -527,10 +593,7 @@
const openGoodPopup = (item) => { // / const openGoodPopup = (item) => { // /
goodData.value = item; goodData.value = item;
goodRef.value.setData(item); goodRef.value.setData(item);
// goodRef.value.founcsFn();
showGoodPopup.value = true; showGoodPopup.value = true;
//访 //访
productLogApi({ productLogApi({
product_id: item.product_id, product_id: item.product_id,
@ -558,8 +621,21 @@
addCart(data.product_id, data.cart_num); addCart(data.product_id, data.cart_num);
} }
// //
const showOverlay = ref(false); //
const abandActive = () => {
showOverlay.value = false
uni.navigateTo({
url: '/pagesOrder/settle/settle'
})
}
const settleAccounts = () => { const settleAccounts = () => {
if (+cartInfo.value.pay_price < 500) return showOverlay.value = true;
uni.navigateTo({ uni.navigateTo({
url: '/pagesOrder/settle/settle' url: '/pagesOrder/settle/settle'
}) })
@ -569,7 +645,8 @@
const cartInfo = ref({ const cartInfo = ref({
total_price: '0.00', total_price: '0.00',
pay_price: 0, pay_price: 0,
count: 0 count: 0,
msg: ''
}) })
const getCartList = (res) => { const getCartList = (res) => {
cartListApi({ cartListApi({
@ -579,6 +656,7 @@
cartInfo.value = { cartInfo.value = {
total_price: res.data?.extend?.total_price || '0.00', total_price: res.data?.extend?.total_price || '0.00',
pay_price: res.data?.extend?.pay_price || '0.00', pay_price: res.data?.extend?.pay_price || '0.00',
msg: res.data?.extend?.msg || '',
count: res.data?.count || 0 count: res.data?.count || 0
} }
cartStore.setCartList(res.data?.lists.map(item => item.id)) cartStore.setCartList(res.data?.lists.map(item => item.id))
@ -609,13 +687,17 @@
getShareInfo() getShareInfo()
onLoad(async (opt) => { onLoad(async (opt) => {
where.value.store_id = opt.id || STORE_INFO.id;
// id
if (opt.id) { if (opt.id) {
where.value.store_id = (opt.id == 'undefined' ? STORE_INFO.id : opt.id);
} else {
where.value.store_id = STORE_INFO.id
}
// id
if (opt.id && opt.id != 'undefined') {
console.log(opt.id, opt.id != 'undefined', "进来了这里")
where.value.store_id = opt.id; where.value.store_id = opt.id;
const info = await shopDetailApi({ const info = await shopDetailApi({
store_id: 4 store_id: where.value.store_id
// store_id: 23
}); });
// //
if (opt.spread_uid) { if (opt.spread_uid) {
@ -625,8 +707,9 @@
uni.setStorageSync('SHARE_INFO', shareInfo.value); uni.setStorageSync('SHARE_INFO', shareInfo.value);
} }
} }
getgoodClassList(0);
getGoodList(); getStoreInfoFn()
// #ifndef H5 // #ifndef H5
// //
btns.value = uni.getMenuButtonBoundingClientRect(); btns.value = uni.getMenuButtonBoundingClientRect();
@ -639,6 +722,10 @@
userInfoApi().then(res => { userInfoApi().then(res => {
const user = res.data; const user = res.data;
userStore.setUserInfo(user); userStore.setUserInfo(user);
if (!user.openid) loginUpdateUserApi({
mobile: user.mobile
})
if (user.is_staff == 1) { if (user.is_staff == 1) {
uni.reLaunch({ uni.reLaunch({
url: "/multipleShop/verificationOrder/index" url: "/multipleShop/verificationOrder/index"
@ -702,11 +789,13 @@
.badge { .badge {
position: absolute; position: absolute;
top: -10rpx; top: -10rpx;
right: 0; right: 10rpx;
background-color: #FF0000; background-color: #FF0000;
color: #FFFFFF; color: #FFFFFF;
padding: 0 8rpx; text-align: center;
border-radius: 50rpx; width: 30rpx;
height: 30rpx;
border-radius: 30rpx;
font-size: 18rpx; font-size: 18rpx;
} }
@ -984,8 +1073,8 @@
display: flex; display: flex;
.shop-img { .shop-img {
height: 120rpx; height: 164rpx;
width: 120rpx; width: 164rpx;
margin-right: 20rpx; margin-right: 20rpx;
border-radius: 14rpx; border-radius: 14rpx;
overflow: hidden; overflow: hidden;
@ -997,40 +1086,54 @@
width: 380rpx; width: 380rpx;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-around;
position: relative;
.title { .shop-content-li {
.name { font-size: 22rpx;
font-size: 28rpx; color: #333333;
}
.tip {
color: #999;
font-size: 24rpx;
margin: 2rpx 0;
}
}
.price {
font-size: 30rpx;
font-weight: bold;
color: #F55726;
}
.price-btn {
display: flex; display: flex;
justify-content: space-between; align-items: center;
vertical-align: middle;
.btn { .line-through {
text-decoration: line-through;
}
.shop-content-li-l {
font-size: 22rpx;
width: 70rpx;
text-align-last: justify;
margin-right: 6rpx;
}
}
.tag {
font-size: 16rpx;
color: #A17C3A;
background-color: #F3E7C0;
padding: 8rpx 4rpx;
margin-left: 4rpx;
display: flex; display: flex;
align-items: center; align-items: center;
.num {
width: 60rpx;
text-align: center;
}
} }
.shopconetent-btn {
position: absolute;
bottom: 0;
right: 0;
} }
// .icon {
// background-image: url('https://lihai001.oss-cn-chengdu.aliyuncs.com/attach/3b653202406260957228679.png');
// width: 17rpx;
// height: 14rpx;
// background-size: 100% 100%;
// margin: 5rpx;
// }
} }
} }
} }
@ -1102,4 +1205,41 @@
margin: 0 0 20rpx 20rpx; margin: 0 0 20rpx 20rpx;
margin-top: 20rpx; margin-top: 20rpx;
} }
.warp {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.rect {
width: 630rpx;
height: 440rpx;
background-image: url('https://lihai001.oss-cn-chengdu.aliyuncs.com/attach/9c70c202406261048431851.png');
background-size: 100% 100%;
box-sizing: border-box;
text-align: center;
// padding: 30rpx;
padding: 50rpx 32rpx;
.rect-tit {
text-align: center;
font-size: 32rpx;
color: #333333;
margin-bottom: 60rpx;
}
.rect-contetn {
font-size: 30rpx;
color: #333333;
}
.rect-btn {
display: flex;
margin-top: 50rpx;
justify-content: space-around;
}
}
</style> </style>

View File

@ -120,6 +120,9 @@
// //
const officialCode = () => { const officialCode = () => {
console.log("jinfas")
return
uni.navigateTo({ uni.navigateTo({
url: `/pages/code/code?id=${userStore.userInfo.id}`, url: `/pages/code/code?id=${userStore.userInfo.id}`,
success: () => { success: () => {
@ -168,7 +171,6 @@
} else { } else {
userStore.setUserInfo(res.data); userStore.setUserInfo(res.data);
// //
// //
if (res.data.is_staff == 1) { if (res.data.is_staff == 1) {
userStore.setUserInfo(res.data); userStore.setUserInfo(res.data);
@ -209,6 +211,7 @@
}).then(res => { }).then(res => {
// token // token
userStore.setUserInfo(res.data); userStore.setUserInfo(res.data);
userStore.setToken(res.data.token);
// //
if (res.is_staff == 1) { if (res.is_staff == 1) {
userStore.setUserInfo(res.data); userStore.setUserInfo(res.data);

View File

@ -39,7 +39,8 @@
userLoginApi, userLoginApi,
userInfoApi, userInfoApi,
getStoreInfo, getStoreInfo,
getloginSms getloginSms,
loginUpdateUserApi
} from "@/api/user.js"; } from "@/api/user.js";
import { import {
ref, ref,
@ -94,10 +95,12 @@
}) })
uni.setStorageSync('token', res.data.token); uni.setStorageSync('token', res.data.token);
userStore.setToken(res.data.token); userStore.setToken(res.data.token);
console.log(res.data.token)
userInfoApi().then(res => { userInfoApi().then(res => {
const user = res.data; const user = res.data;
userStore.setUserInfo(user); userStore.setUserInfo(user);
if (!user.openid) loginUpdateUserApi({
mobile: user.mobile
})
uni.reLaunch({ uni.reLaunch({
url: '/pages/index/index' url: '/pages/index/index'
}) // token }) // token

View File

@ -1,7 +1,7 @@
<style lang="scss"> <style lang="scss">
.rest { .rest {
display: flex; display: flex;
justify-content: space-around; justify-content: space-between;
margin: 20rpx; margin: 20rpx;
.rest-item { .rest-item {
@ -23,8 +23,8 @@
</style> </style>
<template> <template>
<view> <view>
<up-navbar title="我的" :autoBack="true" bgColor="transparent" :fixed="true"> <!-- <up-navbar title="我的" :autoBack="true" bgColor="transparent" :fixed="true">
</up-navbar> </up-navbar> -->
<view class="user-info"> <view class="user-info">
<image class="bg" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/e3a7b202404261113002322.webp" <image class="bg" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/e3a7b202404261113002322.webp"
mode="widthFix"></image> mode="widthFix"></image>
@ -40,36 +40,36 @@
会员报备 会员报备
</view> </view>
</view> </view>
</view> </view>
<view class="rest"> <view class="rest">
<view class="rest-item"> <view class="rest-item" @click="navgo('/pageQuota/balanceDetail/index?type=2')">
<view class="rest-item-num">{{userInfo.now_money||"0.00"}}</view> <view class="rest-item-num">{{userInfo.now_money||"0.00"}}</view>
<view class="rest-item-txt">余额</view> <view class="rest-item-txt">余额</view>
</view> </view>
<view class="rest-item"> <view class="rest-item" @click="navgo('/pageQuota/balanceDetail/index?type=1')">
<view class="rest-item-num">{{userInfo.purchase_funds||'0.00'}}</view> <view class="rest-item-num">{{userInfo.purchase_funds||'0.00'}}</view>
<view class="rest-item-txt">采购款</view> <view class="rest-item-txt">采购款</view>
</view> </view>
<view class="rest-item"> <view class="rest-item">
<view class="rest-item-num">{{userInfo.return_money||'0.00'}}</view> <view class="rest-item-num">{{userInfo.return_money||'0.00'}}</view>
<!-- <view class="rest-item-num">{{"10000.00"}}</view> -->
<view class="rest-item-txt">返还金</view> <view class="rest-item-txt">返还金</view>
</view> </view>
<!-- <view class="rest-item" @click="navgo('/pageQuota/balanceDetail/index?type=3')"> -->
<view class="rest-item"> <view class="rest-item">
<view class="rest-item-num">{{userInfo.integral ||"0.00"}}</view> <view class="rest-item-num">{{userInfo.number ||"0.00"}}</view>
<view class="rest-item-txt">礼品券</view> <view class="rest-item-txt">冻结礼品券</view>
</view>
<!-- <view class="rest-item" @click="navgo('/pageQuota/balanceDetail/index?type=3')"> -->
<view class="rest-item">
<view class="rest-item-num">{{userInfo.GetNumber ||"0.00"}}</view>
<view class="rest-item-txt">可用礼品券</view>
</view> </view>
</view> </view>
<!-- <view class="gift">
<view style="font-weight: bold;">
供销经营礼包
</view>
<view class='gift-buy' @click="navgo('/pages/gift/index')">
立即购买
</view>
</view> -->
<view class="order-info-box"> <view class="order-info-box">
<view class="order-info"> <view class="order-info">
<view class="info-head">我的订单</view> <view class="info-head">我的订单</view>
@ -131,13 +131,17 @@
orderCountApi orderCountApi
} from "@/api/order.js"; } from "@/api/order.js";
import { import {
onShow onShow,
onPullDownRefresh
} from "@dcloudio/uni-app" } from "@dcloudio/uni-app"
import {
userInfoApi
} from "@/api/user.js"
const userStore = useUserStore(); const userStore = useUserStore();
const userInfo = ref({}); const userInfo = ref({});
const orderCount = ref({ const orderCount = ref({
no_pay: 0, no_pay: 0,
receiving: 0, receiving: 0,
@ -185,9 +189,18 @@
} }
onShow(() => { onShow(() => {
userInfo.value = userStore.userInfo; userInfoApi().then(res => {
userInfo.value = res.data;
})
getOrderCount(); getOrderCount();
}) })
onPullDownRefresh(() => {
userInfoApi().then(res => {
userInfo.value = res.data;
uni.stopPullDownRefresh()
})
})
</script> </script>
<style lang="scss"> <style lang="scss">
@ -195,7 +208,7 @@
overflow: hidden; overflow: hidden;
position: relative; position: relative;
width: 750rpx; width: 750rpx;
height: 350rpx; height: 250rpx;
.bg { .bg {
width: 100%; width: 100%;
@ -209,7 +222,7 @@
box-sizing: border-box; box-sizing: border-box;
padding: 50rpx 0 50rpx 50rpx; padding: 50rpx 0 50rpx 50rpx;
position: absolute; position: absolute;
top: 150rpx; top: 50rpx;
left: 0; left: 0;
z-index: 2; z-index: 2;
display: flex; display: flex;

View File

@ -44,7 +44,7 @@
<up-icon name="arrow-right-double" color="#20B128"></up-icon> <up-icon name="arrow-right-double" color="#20B128"></up-icon>
</view> --> </view> -->
</view> </view>
<view class="all"> {{datas.goods_count}} 件商品, 总金额 <text>¥{{datas.total_price}}</text> </view> <view class="all"> {{datas.goods_count}} 件商品, 总金额 <text>¥{{datas.pay_price}}</text> </view>
</view> </view>
<view v-if="datas.paid==0" class="item-btn"> <view v-if="datas.paid==0" class="item-btn">
<view style="width: 80px;"><up-button size="small" plain color="#989898" shape="circle" <view style="width: 80px;"><up-button size="small" plain color="#989898" shape="circle"

View File

@ -81,14 +81,17 @@
const type = ref(1) // 1 2 const type = ref(1) // 1 2
const onKetDown = (e) => { const onKetDown = (e) => {
uni.vibrateShort();
if (type.value == 1) { if (type.value == 1) {
form.password.length < 6 ? form.password.length < 6 ?
form.password += e : form.password += e :
showKeyBorad.value = false showKeyBorad.value = false
if (form.password.length == 6) showKeyBorad.value = false;
} else { } else {
form.rePassword.length < 6 ? form.rePassword.length < 6 ?
form.rePassword += e : form.rePassword += e :
showKeyBorad.value = false showKeyBorad.value = false
if (form.rePassword.length == 6) showKeyBorad.value = false;
} }
} }
@ -102,10 +105,9 @@
// //
const submit = async () => { const submit = async () => {
if (!form.code) return uni.$u.toast('请输入验证码'); if (!form.code) return uni.$u.toast('请输入验证码');
if (form.password.length < 6) return uni.$u.toast('请输入6位数密码');
if (form.password !== form.rePassword) return uni.$u.toast('两次密码不一致'); if (form.password !== form.rePassword) return uni.$u.toast('两次密码不一致');
await setPayPassword({ await setPayPassword({
...form ...form

View File

@ -57,7 +57,7 @@
<view class="row"> <view class="row">
<view>商品总价 <text>共计{{ cartList.length }}款商品</text></view> <view>商品总价 <text>共计{{ cartList.length }}款商品</text></view>
<view> <view>
<text>¥</text>{{ c_price(orderInfo.total_price, 0) }}<text>.{{ c_price(orderInfo.total_price, 1) }}</text> <text>¥</text>{{ c_price(orderInfo.pay_price, 0) }}<text>.{{ c_price(orderInfo.pay_price, 1) }}</text>
</view> </view>
</view> </view>
<view class="row"> <view class="row">
@ -71,13 +71,25 @@
</view> </view>
</view> </view>
<view class="row" v-if="userInfo.user_ship==1 "> <view class="row" v-if="userInfo.user_ship==1 ">
<view>消费返利</view> <view>优惠返还</view>
<view> <view>
<text>¥</text>{{ c_price(orderInfo.activity_price, 0) }}<text>.{{ c_price(orderInfo.activity_price, 1) }}</text> <text>¥</text>{{ c_price(orderInfo.activity_price, 0) }}<text>.{{ c_price(orderInfo.activity_price, 1) }}</text>
</view> </view>
</view> </view>
</view> </view>
<view class="m-card good-info">
<view class="m-card order-remark">
<view class="head-title">
<text>订单备注</text>
<text>0/200</text>
</view>
<up-textarea style="background-color: #F6F6F6;" v-model="formData.remark" placeholder="暂无备注内容"
:height="40"></up-textarea>
</view>
<view style="width: 100%;height: 500rpx;"></view>
<view class="fiexd-bottom" style="z-index: 999;">
<view class="pay-type-bottom">
<view class=" good-info">
<view class="head-title">支付方式</view> <view class="head-title">支付方式</view>
<view class="row"> <view class="row">
<view class="icon-text"> <view class="icon-text">
@ -97,7 +109,8 @@
<view class="icon-text"> <view class="icon-text">
<image src="@/static/icon/YEZF.png" style="width:40rpx;height: 40rpx;" /> <image src="@/static/icon/YEZF.png" style="width:40rpx;height: 40rpx;" />
<text style="margin-left: 20rpx;font-size: 26rpx;">余额支付</text> <text style="margin-left: 20rpx;font-size: 26rpx;">余额支付</text>
<text style="margin-left: 20rpx;font-size: 22rpx;color: #FFB76D;">( 可用¥{{userInfo.now_money}} <text style="margin-left: 20rpx;font-size: 22rpx;color: #FFB76D;">(
可用¥{{userInfo.now_money}}
)</text> )</text>
</view> </view>
<view class="icon" @click="onChoosePaytype(3)"> <view class="icon" @click="onChoosePaytype(3)">
@ -111,7 +124,8 @@
<view class="icon-text"> <view class="icon-text">
<image src="@/static/icon/cgkzf.png" style="width:40rpx;height: 40rpx;" /> <image src="@/static/icon/cgkzf.png" style="width:40rpx;height: 40rpx;" />
<text style="margin-left: 20rpx;font-size: 26rpx;">采购款支付</text> <text style="margin-left: 20rpx;font-size: 26rpx;">采购款支付</text>
<text style="margin-left: 20rpx;font-size: 22rpx;color: #1296DB;">( 可用¥{{userInfo.purchase_funds}} <text style="margin-left: 20rpx;font-size: 22rpx;color: #1296DB;">(
可用¥{{userInfo.purchase_funds}}
)</text> )</text>
</view> </view>
<view class="icon" @click="onChoosePaytype(18)"> <view class="icon" @click="onChoosePaytype(18)">
@ -121,33 +135,30 @@
</view> </view>
</view> </view>
</view> </view>
</view>
<view class="m-card order-remark">
<view class="head-title"> <view class="submit-row">
<text>订单备注</text>
<text>0/200</text>
</view>
<up-textarea style="background-color: #F6F6F6;" v-model="formData.remark" placeholder="暂无备注内容"
:height="40"></up-textarea>
</view>
<view style="width: 100%;height: 200rpx;"></view>
<view class="fiexd-btn-box" style="z-index: 999;">
<view class="tips"> <view class="tips">
<view style="margin-right: 20rpx;"> {{ cartList.length }} </view> <view style="margin-right: 20rpx;"> {{ cartList.length }} </view>
<view class="all"> <view class="all">
<text style="color: #000;">合计: </text> <text style="color: #000;">合计: </text>
<text></text> <text></text>
<block v-if="orderInfo.total_price"> <block v-if="orderInfo.total_price">
<text style="font-size: 32rpx;font-weight: bold;">{{ c_price(orderInfo.pay_price, 0) }}</text> <text
style="font-size: 32rpx;font-weight: bold;">{{ c_price(orderInfo.pay_price, 0) }}</text>
<text>.{{ c_price(orderInfo.pay_price, 1) }}</text> <text>.{{ c_price(orderInfo.pay_price, 1) }}</text>
</block> </block>
</view> </view>
</view> </view>
<view style="width: 200rpx;"> <view style="width: 200rpx;">
<up-button color="#20B128" shape="circle" @click="submitOrder" :throttleTime="1000">预付款提交</up-button> <up-button color="#20B128" shape="circle" @click="submitOrder"
:throttleTime="1000">预付款提交</up-button>
</view> </view>
</view> </view>
</view>
<addressPopup ref="addressRef" :show="showAddress" :list="addressList" @close="showAddress = false" <addressPopup ref="addressRef" :show="showAddress" :list="addressList" @close="showAddress = false"
@change="changeAddress" /> @change="changeAddress" />
<shopListPopupVue ref="shopRef" :show="shopListShow" :list="merchantList" @close="shopListShow = false" <shopListPopupVue ref="shopRef" :show="shopListShow" :list="merchantList" @close="shopListShow = false"
@ -360,6 +371,11 @@
const passwordBoardProps = { const passwordBoardProps = {
title: '输入支付密码', title: '输入支付密码',
onComplete(value) { onComplete(value) {
// uni.vibrateShort({
// success: function() {
// console.log('success');
// }
// });
password.value = value password.value = value
passwordBoardVisible.value = false passwordBoardVisible.value = false
payFn() payFn()
@ -641,4 +657,32 @@
color: white; color: white;
} }
} }
.fiexd-bottom {
position: fixed;
bottom: 0;
left: 0;
// height: calc(constant(safe-area-inset-bottom) + 120rpx);
/* 适用于iOS设备 */
// height: calc(env(safe-area-inset-bottom) + 120rpx);
/* 适用于Android设备 */
width: 100%;
box-sizing: border-box;
background-color: #fff;
padding: 20rpx;
padding-bottom: calc(constant(safe-area-inset-bottom) + 20rpx);
/* 适用于iOS设备 */
padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
/* 适用于Android设备 */
.submit-row {
display: flex;
justify-content: space-between;
align-items: center;
}
.pay-type-bottom {
margin-bottom: 50rpx;
}
}
</style> </style>

View File

@ -43,6 +43,7 @@
} }
break; break;
} }
uni.vibrateShort();
if (refValue.value.length === props.num) { if (refValue.value.length === props.num) {
emits('complete', refValue.value.join('')); emits('complete', refValue.value.join(''));
} }

871
utils/push.js Normal file
View File

@ -0,0 +1,871 @@
function Push(options) {
this.doNotConnect = 0;
options = options || {};
options.heartbeat = options.heartbeat || 25000;
options.pingTimeout = options.pingTimeout || 10000;
this.config = options;
this.uid = 0;
this.channels = {};
this.connection = null;
this.pingTimeoutTimer = 0;
Push.instances.push(this);
this.createConnection();
}
Push.prototype.checkoutPing = function() {
var _this = this;
_this.checkoutPingTimer && clearTimeout(_this.checkoutPingTimer);
_this.checkoutPingTimer = setTimeout(function() {
_this.checkoutPingTimer = 0;
if (_this.connection.state === 'connected') {
_this.connection.send('{"event":"pusher:ping","data":{}}');
if (_this.pingTimeoutTimer) {
clearTimeout(_this.pingTimeoutTimer);
_this.pingTimeoutTimer = 0;
}
_this.pingTimeoutTimer = setTimeout(function() {
_this.connection.closeAndClean();
if (!_this.connection.doNotConnect) {
_this.connection.waitReconnect();
}
}, _this.config.pingTimeout);
}
}, this.config.heartbeat);
};
Push.prototype.channel = function(name) {
return this.channels.find(name);
};
Push.prototype.allChannels = function() {
return this.channels.all();
};
Push.prototype.createConnection = function() {
if (this.connection) {
throw Error('Connection already exist');
}
var _this = this;
var url = this.config.url;
function updateSubscribed() {
for (var i in _this.channels) {
_this.channels[i].subscribed = false;
}
}
this.connection = new Connection({
url: url,
app_key: this.config.app_key,
onOpen: function() {
_this.connection.state = 'connecting';
_this.checkoutPing();
},
onMessage: function(params) {
if (_this.pingTimeoutTimer) {
clearTimeout(_this.pingTimeoutTimer);
_this.pingTimeoutTimer = 0;
}
params = JSON.parse(params.data);
var event = params.event;
var channel_name = params.channel;
if (event === 'pusher:pong') {
_this.checkoutPing();
return;
}
if (event === 'pusher:error') {
throw Error(params.data.message);
}
var data = JSON.parse(params.data),
channel;
if (event === 'pusher_internal:subscription_succeeded') {
channel = _this.channels[channel_name];
channel.subscribed = true;
channel.processQueue();
channel.emit('pusher:subscription_succeeded');
return;
}
if (event === 'pusher:connection_established') {
_this.connection.socket_id = data.socket_id;
_this.connection.updateNetworkState('connected');
_this.subscribeAll();
}
if (event.indexOf('pusher_internal') !== -1) {
console.log("Event '" + event + "' not implement");
return;
}
channel = _this.channels[channel_name];
if (channel) {
channel.emit(event, data);
}
},
onClose: function() {
updateSubscribed();
},
onError: function() {
updateSubscribed();
}
});
};
Push.prototype.disconnect = function() {
this.connection.doNotConnect = 1;
this.connection.close();
};
Push.prototype.subscribeAll = function() {
if (this.connection.state !== 'connected') {
return;
}
for (var channel_name in this.channels) {
//this.connection.send(JSON.stringify({event:"pusher:subscribe", data:{channel:channel_name}}));
this.channels[channel_name].processSubscribe();
}
};
Push.prototype.unsubscribe = function(channel_name) {
if (this.channels[channel_name]) {
delete this.channels[channel_name];
if (this.connection.state === 'connected') {
this.connection.send(JSON.stringify({
event: "pusher:unsubscribe",
data: {
channel: channel_name
}
}));
}
}
};
Push.prototype.unsubscribeAll = function() {
var channels = Object.keys(this.channels);
if (channels.length) {
if (this.connection.state === 'connected') {
for (var channel_name in this.channels) {
this.unsubscribe(channel_name);
}
}
}
this.channels = {};
};
Push.prototype.subscribe = function(channel_name) {
if (this.channels[channel_name]) {
return this.channels[channel_name];
}
if (channel_name.indexOf('private-') === 0) {
return createPrivateChannel(channel_name, this);
}
if (channel_name.indexOf('presence-') === 0) {
return createPresenceChannel(channel_name, this);
}
return createChannel(channel_name, this);
};
Push.instances = [];
function createChannel(channel_name, push) {
var channel = new Channel(push.connection, channel_name);
push.channels[channel_name] = channel;
channel.subscribeCb = function() {
push.connection.send(JSON.stringify({
event: "pusher:subscribe",
data: {
channel: channel_name
}
}));
}
channel.processSubscribe();
return channel;
}
function createPrivateChannel(channel_name, push) {
var channel = new Channel(push.connection, channel_name);
push.channels[channel_name] = channel;
channel.subscribeCb = function() {
__ajax({
url: push.config.auth,
type: 'POST',
data: {
channel_name: channel_name,
socket_id: push.connection.socket_id
},
success: function(data) {
data = JSON.parse(data);
data.channel = channel_name;
push.connection.send(JSON.stringify({
event: "pusher:subscribe",
data: data
}));
},
error: function(e) {
throw Error(e);
}
});
};
channel.processSubscribe();
return channel;
}
function createPresenceChannel(channel_name, push) {
return createPrivateChannel(channel_name, push);
}
uni.onNetworkStatusChange(function(res) {
if (res.isConnected) {
for (var i in Push.instances) {
con = Push.instances[i].connection;
con.reconnectInterval = 1;
if (con.state === 'connecting') {
con.connect();
}
}
}
});
function Connection(options) {
this.dispatcher = new Dispatcher();
__extends(this, this.dispatcher);
var properies = ['on', 'off', 'emit'];
for (var i in properies) {
this[properies[i]] = this.dispatcher[properies[i]];
}
this.options = options;
this.state = 'initialized'; //initialized connecting connected disconnected
this.doNotConnect = 0;
this.reconnectInterval = 1;
this.connection = null;
this.reconnectTimer = 0;
this.connect();
}
Connection.prototype.updateNetworkState = function(state) {
var old_state = this.state;
this.state = state;
if (old_state !== state) {
this.emit('state_change', {
previous: old_state,
current: state
});
}
};
Connection.prototype.connect = function() {
this.doNotConnect = 0;
if (this.networkState == 'connecting' || this.networkState == 'established') {
console.log('networkState is ' + this.networkState + ' and do not need connect');
return;
}
if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer);
this.reconnectTimer = 0;
}
this.closeAndClean();
var options = this.options;
var _this = this;
_this.updateNetworkState('connecting');
var cb = function() {
uni.onSocketOpen(function(res) {
_this.reconnectInterval = 1;
if (_this.doNotConnect) {
_this.updateNetworkState('closing');
uni.closeSocket();
return;
}
_this.updateNetworkState('established');
if (options.onOpen) {
options.onOpen(res);
}
});
if (options.onMessage) {
uni.onSocketMessage(options.onMessage);
}
uni.onSocketClose(function(res) {
_this.updateNetworkState('disconnected');
if (!_this.doNotConnect) {
_this.waitReconnect();
}
if (options.onClose) {
options.onClose(res);
}
});
uni.onSocketError(function(res) {
_this.close();
if (!_this.doNotConnect) {
_this.waitReconnect();
}
if (options.onError) {
options.onError(res);
}
});
};
uni.connectSocket({
url: options.url,
fail: function(res) {
console.log('uni.connectSocket fail');
console.log(res);
_this.updateNetworkState('disconnected');
_this.waitReconnect();
},
success: function() {
}
});
cb();
}
Connection.prototype.connect = function() {
this.doNotConnect = 0;
if (this.state === 'connected') {
console.log('networkState is "' + this.state + '" and do not need connect');
return;
}
if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer);
this.reconnectTimer = 0;
}
this.closeAndClean();
var options = this.options;
this.updateNetworkState('connecting');
var _this = this;
var cb = function() {
uni.onSocketOpen(function(res) {
_this.reconnectInterval = 1;
if (_this.doNotConnect) {
_this.updateNetworkState('disconnected');
uni.closeSocket();
return;
}
if (options.onOpen) {
options.onOpen(res);
}
});
if (options.onMessage) {
uni.onSocketMessage(options.onMessage);
}
uni.onSocketClose(function(res) {
_this.updateNetworkState('disconnected');
if (!_this.doNotConnect) {
_this.waitReconnect();
}
if (options.onClose) {
options.onClose(res);
}
});
uni.onSocketError(function(res) {
_this.close();
if (!_this.doNotConnect) {
_this.waitReconnect();
}
if (options.onError) {
options.onError(res);
}
});
};
uni.connectSocket({
url: options.url + '/app/' + options.app_key,
fail: function(res) {
console.log('uni.connectSocket fail');
console.log(res);
_this.updateNetworkState('disconnected');
_this.waitReconnect();
},
success: function() {
}
});
cb();
}
Connection.prototype.closeAndClean = function() {
if (this.state === 'connected') {
uni.closeSocket();
}
this.updateNetworkState('disconnected');
};
Connection.prototype.waitReconnect = function() {
if (this.state === 'connected' || this.state === 'connecting') {
return;
}
if (!this.doNotConnect) {
this.updateNetworkState('connecting');
var _this = this;
if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer);
}
this.reconnectTimer = setTimeout(function() {
_this.connect();
}, this.reconnectInterval);
if (this.reconnectInterval < 1000) {
this.reconnectInterval = 1000;
} else {
// 每次重连间隔增大一倍
this.reconnectInterval = this.reconnectInterval * 2;
}
// 有网络的状态下重连间隔最大2秒
if (this.reconnectInterval > 2000 && navigator.onLine) {
_this.reconnectInterval = 2000;
}
}
}
Connection.prototype.send = function(data) {
if (this.state !== 'connected') {
console.trace('networkState is "' + this.state + '", can not send ' + data);
return;
}
uni.sendSocketMessage({
data: data
});
}
Connection.prototype.close = function() {
this.updateNetworkState('disconnected');
uni.closeSocket();
}
var __extends = (this && this.__extends) || function(d, b) {
for (var p in b)
if (b.hasOwnProperty(p)) {
d[p] = b[p];
}
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
function Channel(connection, channel_name) {
this.subscribed = false;
this.dispatcher = new Dispatcher();
this.connection = connection;
this.channelName = channel_name;
this.subscribeCb = null;
this.queue = [];
__extends(this, this.dispatcher);
var properies = ['on', 'off', 'emit'];
for (var i in properies) {
this[properies[i]] = this.dispatcher[properies[i]];
}
}
Channel.prototype.processSubscribe = function() {
if (this.connection.state !== 'connected') {
return;
}
this.subscribeCb();
};
Channel.prototype.processQueue = function() {
if (this.connection.state !== 'connected' || !this.subscribed) {
return;
}
for (var i in this.queue) {
this.queue[i]();
}
this.queue = [];
};
Channel.prototype.trigger = function(event, data) {
if (event.indexOf('client-') !== 0) {
throw new Error("Event '" + event + "' should start with 'client-'");
}
var _this = this;
this.queue.push(function() {
_this.connection.send(JSON.stringify({
event: event,
data: data,
channel: _this.channelName
}));
});
this.processQueue();
};
////////////////
var Collections = (function() {
var exports = {};
function extend(target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
for (var i = 0; i < sources.length; i++) {
var extensions = sources[i];
for (var property in extensions) {
if (extensions[property] && extensions[property].constructor &&
extensions[property].constructor === Object) {
target[property] = extend(target[property] || {}, extensions[property]);
} else {
target[property] = extensions[property];
}
}
}
return target;
}
exports.extend = extend;
function stringify() {
var m = ["Push"];
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === "string") {
m.push(arguments[i]);
} else {
m.push(safeJSONStringify(arguments[i]));
}
}
return m.join(" : ");
}
exports.stringify = stringify;
function arrayIndexOf(array, item) {
var nativeIndexOf = Array.prototype.indexOf;
if (array === null) {
return -1;
}
if (nativeIndexOf && array.indexOf === nativeIndexOf) {
return array.indexOf(item);
}
for (var i = 0, l = array.length; i < l; i++) {
if (array[i] === item) {
return i;
}
}
return -1;
}
exports.arrayIndexOf = arrayIndexOf;
function objectApply(object, f) {
for (var key in object) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
f(object[key], key, object);
}
}
}
exports.objectApply = objectApply;
function keys(object) {
var keys = [];
objectApply(object, function(_, key) {
keys.push(key);
});
return keys;
}
exports.keys = keys;
function values(object) {
var values = [];
objectApply(object, function(value) {
values.push(value);
});
return values;
}
exports.values = values;
function apply(array, f, context) {
for (var i = 0; i < array.length; i++) {
f.call(context || (window), array[i], i, array);
}
}
exports.apply = apply;
function map(array, f) {
var result = [];
for (var i = 0; i < array.length; i++) {
result.push(f(array[i], i, array, result));
}
return result;
}
exports.map = map;
function mapObject(object, f) {
var result = {};
objectApply(object, function(value, key) {
result[key] = f(value);
});
return result;
}
exports.mapObject = mapObject;
function filter(array, test) {
test = test || function(value) {
return !!value;
};
var result = [];
for (var i = 0; i < array.length; i++) {
if (test(array[i], i, array, result)) {
result.push(array[i]);
}
}
return result;
}
exports.filter = filter;
function filterObject(object, test) {
var result = {};
objectApply(object, function(value, key) {
if ((test && test(value, key, object, result)) || Boolean(value)) {
result[key] = value;
}
});
return result;
}
exports.filterObject = filterObject;
function flatten(object) {
var result = [];
objectApply(object, function(value, key) {
result.push([key, value]);
});
return result;
}
exports.flatten = flatten;
function any(array, test) {
for (var i = 0; i < array.length; i++) {
if (test(array[i], i, array)) {
return true;
}
}
return false;
}
exports.any = any;
function all(array, test) {
for (var i = 0; i < array.length; i++) {
if (!test(array[i], i, array)) {
return false;
}
}
return true;
}
exports.all = all;
function encodeParamsObject(data) {
return mapObject(data, function(value) {
if (typeof value === "object") {
value = safeJSONStringify(value);
}
return encodeURIComponent(base64_1["default"](value.toString()));
});
}
exports.encodeParamsObject = encodeParamsObject;
function buildQueryString(data) {
var params = filterObject(data, function(value) {
return value !== undefined;
});
return map(flatten(encodeParamsObject(params)), util_1["default"].method("join", "=")).join("&");
}
exports.buildQueryString = buildQueryString;
function decycleObject(object) {
var objects = [],
paths = [];
return (function derez(value, path) {
var i, name, nu;
switch (typeof value) {
case 'object':
if (!value) {
return null;
}
for (i = 0; i < objects.length; i += 1) {
if (objects[i] === value) {
return {
$ref: paths[i]
};
}
}
objects.push(value);
paths.push(path);
if (Object.prototype.toString.apply(value) === '[object Array]') {
nu = [];
for (i = 0; i < value.length; i += 1) {
nu[i] = derez(value[i], path + '[' + i + ']');
}
} else {
nu = {};
for (name in value) {
if (Object.prototype.hasOwnProperty.call(value, name)) {
nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']');
}
}
}
return nu;
case 'number':
case 'string':
case 'boolean':
return value;
}
}(object, '$'));
}
exports.decycleObject = decycleObject;
function safeJSONStringify(source) {
try {
return JSON.stringify(source);
} catch (e) {
return JSON.stringify(decycleObject(source));
}
}
exports.safeJSONStringify = safeJSONStringify;
return exports;
})();
var Dispatcher = (function() {
function Dispatcher(failThrough) {
this.callbacks = new CallbackRegistry();
this.global_callbacks = [];
this.failThrough = failThrough;
}
Dispatcher.prototype.on = function(eventName, callback, context) {
this.callbacks.add(eventName, callback, context);
return this;
};
Dispatcher.prototype.on_global = function(callback) {
this.global_callbacks.push(callback);
return this;
};
Dispatcher.prototype.off = function(eventName, callback, context) {
this.callbacks.remove(eventName, callback, context);
return this;
};
Dispatcher.prototype.emit = function(eventName, data) {
var i;
for (i = 0; i < this.global_callbacks.length; i++) {
this.global_callbacks[i](eventName, data);
}
var callbacks = this.callbacks.get(eventName);
if (callbacks && callbacks.length > 0) {
for (i = 0; i < callbacks.length; i++) {
callbacks[i].fn.call(callbacks[i].context || (window), data);
}
} else if (this.failThrough) {
this.failThrough(eventName, data);
}
return this;
};
return Dispatcher;
}());
var CallbackRegistry = (function() {
function CallbackRegistry() {
this._callbacks = {};
}
CallbackRegistry.prototype.get = function(name) {
return this._callbacks[prefix(name)];
};
CallbackRegistry.prototype.add = function(name, callback, context) {
var prefixedEventName = prefix(name);
this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || [];
this._callbacks[prefixedEventName].push({
fn: callback,
context: context
});
};
CallbackRegistry.prototype.remove = function(name, callback, context) {
if (!name && !callback && !context) {
this._callbacks = {};
return;
}
var names = name ? [prefix(name)] : Collections.keys(this._callbacks);
if (callback || context) {
this.removeCallback(names, callback, context);
} else {
this.removeAllCallbacks(names);
}
};
CallbackRegistry.prototype.removeCallback = function(names, callback, context) {
Collections.apply(names, function(name) {
this._callbacks[name] = Collections.filter(this._callbacks[name] || [], function(
oning) {
return (callback && callback !== oning.fn) ||
(context && context !== oning.context);
});
if (this._callbacks[name].length === 0) {
delete this._callbacks[name];
}
}, this);
};
CallbackRegistry.prototype.removeAllCallbacks = function(names) {
Collections.apply(names, function(name) {
delete this._callbacks[name];
}, this);
};
return CallbackRegistry;
}());
function prefix(name) {
return "_" + name;
}
function __ajax(options) {
options = options || {};
options.type = (options.type || 'GET').toUpperCase();
options.dataType = options.dataType || 'json';
var params = formatParams(options.data);
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = ActiveXObject('Microsoft.XMLHTTP');
}
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var status = xhr.status;
if (status >= 200 && status < 300) {
options.success && options.success(xhr.responseText, xhr.responseXML);
} else {
options.error && options.error(status);
}
}
}
if (options.type === 'GET') {
xhr.open('GET', options.url + '?' + params, true);
xhr.send(null);
} else if (options.type === 'POST') {
xhr.open('POST', options.url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(params);
}
}
function formatParams(data) {
var arr = [];
for (var name in data) {
arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name]));
}
return arr.join('&');
}
export default Push