Commit e799d829 authored by zhijie.xue's avatar zhijie.xue

代码整理

parent b2c2a087
This diff is collapsed.
dist/*
src/components/vant/*
weapp/*
static/*
\ No newline at end of file
module.exports = {
root: true,
globals: { wx: true },
globals: {
wx: true,
getCurrentPages: true
},
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
......@@ -17,7 +20,6 @@ module.exports = {
settings: {
'html/html-extensions': ['.html', '.wpy']
},
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
......
This diff is collapsed.
......@@ -11,8 +11,6 @@ import wepy from '@wepy/core';
import vuex from '@wepy/x';
import promisify from '@wepy/use-promisify';
import { login } from './common/api';
wepy.use(promisify);
wepy.use(vuex);
......
......@@ -33,7 +33,7 @@ module.exports = {
return http.post('/api/user/join/list');
},
getOneRaffle(params) {
return http.post('/api/user/join/info',params);
return http.post('/api/user/join/info', params);
},
getUserPhone() {
return http.post('/api/user/get/phone');
......@@ -44,7 +44,7 @@ module.exports = {
updateUserPhone(params) {
return http.post('/api/user/update/phone', params);
},
getPrize(params){
getPrize(params) {
return http.post('/api/user/prize/receive', params, { 'content-type': 'application/json' });
}
};
function getCommonDivisor(FirstNum,SecondNum) {
if (SecondNum == 0) return FirstNum;
function getCommonDivisor(firstNum, secondNum) {
if (secondNum === 0) return firstNum;
var remainder = parseInt(FirstNum % SecondNum) ;
var remainder = parseInt(firstNum % secondNum);
return getCommonDivisor(SecondNum, remainder);
return getCommonDivisor(secondNum, remainder);
}
function getProbability (quantity,coinQuantity) {
//如果用户克币数是0
if(quantity == 0) {
return '0/'+coinQuantity;
function getProbability (quantity, coinQuantity) {
// 如果用户克币数是0
if (quantity === 0) {
return '0/' + coinQuantity;
}
var divisor = getCommonDivisor(quantity,coinQuantity);
var value = quantity/divisor;
var value2 = coinQuantity/divisor;
//如果分子比分母大说明中奖概率是100%,那么返回中奖概率
if(value>=value2) {
return coinQuantity+"/"+coinQuantity
var divisor = getCommonDivisor(quantity, coinQuantity);
var value = quantity / divisor;
var value2 = coinQuantity / divisor;
// 如果分子比分母大说明中奖概率是100%,那么返回中奖概率
if (value >= value2) {
return coinQuantity + '/' + coinQuantity;
} else {
return value+"/"+value2
return value + '/' + value2;
}
}
module.exports = {
getProbability:getProbability
getProbability
};
"use strict";
'use strict';
var areaList = {
province_list: {
......
......@@ -151,7 +151,7 @@
_invalidDown: 0,
_videoContexts: [],
loading: false,
isFirstUp: true,
isFirstUp: true
},
watch: {
videoList () {
......
......@@ -79,15 +79,10 @@
},
methods: {
tomorehelp(){
wx.navigateTo({url: '/pages/morehelp'})
tomorehelp() {
wx.navigateTo({url: '/pages/morehelp'});
}
}
},
onLoad () {
},
});
</script>
<config>
......
......@@ -269,7 +269,8 @@
</template>
<script>
let touchDotX = 0, touchDotY = 0;
let touchDotX = 0;
let touchDotY = 0;
import store from '../store';
import { mapState, mapActions } from '@wepy/x';
import wepy from '@wepy/core';
......@@ -323,23 +324,12 @@
methods: {
...mapActions([ 'setIsConnected', 'setUserInfo' ]),
moveSwiper(e) {
if (e.$wx.detail.source == 'touch') {
if (e.$wx.detail.source === 'touch') {
let current = e.$wx.detail.current;
this.currentIndex = current;
}
},
swipermoveDone(e) {
if (e.$wx.detail.source == 'touch') {
let current = e.$wx.detail.current;
let totalPage = 3;
let nextlist = [
{value: 11, text: '白色条纹马克杯,马克吐温同款11', imgsrc: '/static/images/test1.jpg', price: '¥9.89', people: 2200, sku: '100004549235'},
{value: 12, text: '白色条纹马克杯,马克吐温同款12', imgsrc: '/static/images/test2.png', price: '¥19.20', people: '2200', sku: '100004549235'},
{value: 13, text: '白色条纹马克杯,马克吐温同款13', imgsrc: '/static/images/peo1.jpg', price: '¥39.08', people: 2200, sku: '100004549235'},
{value: 14, text: '白色条纹马克杯,马克吐温同款14', imgsrc: '/static/images/peo2.jpg', price: '¥599.20', people: 2200, sku: '100004549235'},
{value: 15, text: '白色条纹马克杯,马克吐温同款15', imgsrc: '/static/images/peo3.jpg', price: '¥2399.01', people: 2200, sku: '100004549235'}
];
let that = this;
function debounce(func, wait) {
let timeout;
return function () {
......@@ -351,6 +341,19 @@
if (callNow) func();
};
}
if (e.$wx.detail.source === 'touch') {
let current = e.$wx.detail.current;
let totalPage = 3;
let nextlist = [
{value: 11, text: '白色条纹马克杯,马克吐温同款11', imgsrc: '/static/images/test1.jpg', price: '¥9.89', people: 2200, sku: '100004549235'},
{value: 12, text: '白色条纹马克杯,马克吐温同款12', imgsrc: '/static/images/test2.png', price: '¥19.20', people: '2200', sku: '100004549235'},
{value: 13, text: '白色条纹马克杯,马克吐温同款13', imgsrc: '/static/images/peo1.jpg', price: '¥39.08', people: 2200, sku: '100004549235'},
{value: 14, text: '白色条纹马克杯,马克吐温同款14', imgsrc: '/static/images/peo2.jpg', price: '¥599.20', people: 2200, sku: '100004549235'},
{value: 15, text: '白色条纹马克杯,马克吐温同款15', imgsrc: '/static/images/peo3.jpg', price: '¥2399.01', people: 2200, sku: '100004549235'}
];
let that = this;
/* if(current <= 2) {
debounce(setTimeout(function(){
that.topPage +=1;
......@@ -370,7 +373,7 @@
that.circular = true;
return;
}
that.list = [ ...that.list, ...nextlist];
that.list = [...that.list, ...nextlist];
}, 1000), 500);
}
}
......@@ -459,11 +462,11 @@
// }
},
deleteAnimation (current) {
if (current && current.itemid != undefined) {
if (current && current.itemid !== undefined) {
let list = this.list;
list = list.map((item, index) => {
item.select = '';
if (index == current.itemid) {
if (index === +current.itemid) {
item.select = true;
}
return item;
......@@ -478,7 +481,7 @@
this.current = this.currentIndex - 1;
}
setTimeout(function() {
let newlist = that.list.filter((item, index) => index != current.itemid);
let newlist = that.list.filter((item, index) => index !== +current.itemid);
// 正常情况下,current.itemid都会比current大一个,因为current有个隐藏元素,当相等或小于的时候就有问题,要重新设置current,最小不能超过0
if (current.itemid <= that.current) {
that.current = Math.max(that.current - 1, 0);
......@@ -526,15 +529,15 @@
success (res) {
console.log('requestSubscribeMessage success', res);
if (res.errMsg === 'requestSubscribeMessage:ok') {
const rs = tmplIds.every(v => res[v] === 'accept');
// 兼容写法,有时响应中的模板id不是3个
const rs = tmplIds.every(v => res[v] === undefined || res[v] === 'accept');
if (rs) {
that.sign = true;
setTimeout(async () => {
const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = '/static/audio/supermarie.mp3';
innerAudioContext.onPlay(() => {
});
innerAudioContext.onPlay(() => {});
innerAudioContext.onError((res) => {
console.log(res.errMsg);
console.log(res.errCode);
......@@ -557,16 +560,14 @@
}
const openid = wx.getStorageSync('openId');
return {
title: `${this.$wepy.userInfo && this.$wepy.userInfo.nickName || '您的好朋友'}邀请您来抽奖啦~`,
title: `${(this.$wepy.userInfo && this.$wepy.userInfo.nickName) || '您的好朋友'}邀请您来抽奖啦~`,
path: `/pages/index?openid=${openid}`,
imageUrl: this.$wepy.awardsInfo.photoUrl,
success: function(res) {
let shareId = res.shareTickets[0];
console.log('shareId', shareId);
// 转发成功
},
fail: function(res) {
// 转发失败
console.log(res);
}
};
......@@ -574,11 +575,11 @@
getAwards: function() {
const { batchId, photoUrl, quantity, name, chance, progress } = this.awardsInfo;
if (!batchId || !this.mainInfo || !this.mainInfo.account) {
Notify({ message: '服务器异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true});
Notify({ message: '服务器异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true });
return;
}
if (this.mainInfo && this.mainInfo.account && this.mainInfo.account.quantity === 0) {
Notify({ message: '您的克币数为0, 无法参与抽奖', background: '#FF5D15', safeAreaInsetTop: true});
Notify({ message: '您的克币数为0, 无法参与抽奖', background: '#FF5D15', safeAreaInsetTop: true });
return;
}
wx.navigateTo({
......
......@@ -101,24 +101,24 @@
</template>
<script>
import wepy from '@wepy/core';
import { getRaffles } from '../common/api'
import { getRaffles } from '../common/api';
wepy.page({
data: {
list:[],
fonts:['','待开奖','未中奖','待领取','未发货','已发货'],
list: [],
fonts: ['', '待开奖', '未中奖', '待领取', '未发货', '已发货']
},
methods: {
goprize(event) {
let detail = event.$wx.currentTarget;
let id = detail.dataset.id || '';
wx.navigateTo({url:'/pages/prize?joinRecordId='+id});
wx.navigateTo({url: '/pages/prize?joinRecordId=' + id});
}
},
onLoad () {
getRaffles().then(res=>{
getRaffles().then(res => {
this.list = res || [];
});
},
}
});
</script>
<config>
......
......@@ -99,98 +99,98 @@
import wepy from '@wepy/core';
import Dialog from '../components/vant/dialog/dialog';
import Notify from '../components/vant/notify/notify';
import { getOneRaffle, getUserPhone, getPrize } from '../common/api'
import { getOneRaffle, getUserPhone, getPrize } from '../common/api';
var raffle = require('../common/raffleProbability');
var area = require('../components/custom/china.js');
wepy.page({
data: {
quantity:0,
prize:{},
name:'',
phone:'',
address:'',
province:'',
city:'',
county:'',
cityValue:'',
areaList:[],
showAddress:false,
joinRecordId:null,
chance:'',
btnfont:'领取',
idNumber:''
quantity: 0,
prize: {},
name: '',
phone: '',
address: '',
province: '',
city: '',
county: '',
cityValue: '',
areaList: [],
showAddress: false,
joinRecordId: null,
chance: '',
btnfont: '领取',
idNumber: ''
},
methods: {
goprize() {
if(!this.prize.cash) {
if(!this.name){
Notify({message: '请填写收货人', background:'#FF5D15'});
if (!this.prize.cash) {
if (!this.name) {
Notify({message: '请填写收货人', background: '#FF5D15'});
return;
}
let reg = /^1\d{10}$/
if(!this.phone){
Notify({message: '请填写手机号码', background:'#FF5D15'});
let reg = /^1\d{10}$/;
if (!this.phone) {
Notify({message: '请填写手机号码', background: '#FF5D15'});
return;
}
if(!reg.test(this.phone)) {
Notify({message: '请填写正确的手机号码', background:'#FF5D15'});
if (!reg.test(this.phone)) {
Notify({message: '请填写正确的手机号码', background: '#FF5D15'});
return;
}
if(!this.idNumber) {
Notify({message: '请填写身份证号', background:'#FF5D15'});
if (!this.idNumber) {
Notify({message: '请填写身份证号', background: '#FF5D15'});
return;
}
if(!this.city){
Notify({message: '请选择所在地区', background:'#FF5D15'});
if (!this.city) {
Notify({message: '请选择所在地区', background: '#FF5D15'});
return;
}
if(!this.address){
Notify({message: '请填写详细地址', background:'#FF5D15'});
if (!this.address) {
Notify({message: '请填写详细地址', background: '#FF5D15'});
return;
}
}
let params = {
joinRecordId:this.joinRecordId,
name:this.name,
phone:this.phone,
province:this.province,
city:this.city,
county:this.county,
address:this.address,
idNumber:this.idNumber,
joinRecordId: this.joinRecordId,
name: this.name,
phone: this.phone,
province: this.province,
city: this.city,
county: this.county,
address: this.address,
idNumber: this.idNumber
};
let message = '您所领取的奖品我们将在3到5个工作日内寄出,请您耐心等待,感谢您的参与!';
let cashmeg = '您所领取的奖品我们将会在几分钟内发出,请您耐心等待,感谢您的参与!';
let that = this;
if(this.btnfont!=='领取') return;
if (this.btnfont !== '领取') return;
this.btnfont = '...';
getPrize(params).then(()=>{
getPrize(params).then(() => {
this.btnfont = '领取';
Dialog.alert({
title: '领取成功',
message: that.prize.cash?cashmeg:message,
message: that.prize.cash ? cashmeg : message
}).then(() => {
wx.reLaunch({url:'/pages/index'})
wx.reLaunch({url: '/pages/index'});
});
}).catch(()=>{
}).catch(() => {
this.btnfont = '领取';
});
},
onClose() {
this.showAddress = !this.showAddress;
},
setValue(event){
setValue(event) {
let value = event.$wx.detail;
let form = event.$wx.currentTarget.dataset.form;
if(form) this[form] = value;
if (form) this[form] = value;
},
getaddress(event) {
let detail = event.$wx.detail.values;
this.province = detail[0].name;
this.city = detail[1].name;
this.county = detail[2].name;
this.cityValue = detail[0].name+detail[1].name+detail[2].name
this.onClose()
this.cityValue = detail[0].name + detail[1].name + detail[2].name;
this.onClose();
}
},
computed: {
......@@ -199,22 +199,23 @@
onLoad (query) {
let joinRecordId = query.joinRecordId || '';
this.joinRecordId = joinRecordId;
if(!joinRecordId) Notify({message: '缺少参数错误!', background:'#FF5D15'});
//请求接口得到数据
getOneRaffle({joinRecordId:joinRecordId}).then(data=>{
let dat = data|| {};
if (!joinRecordId) Notify({message: '缺少参数错误!', background: '#FF5D15'});
// 请求接口得到数据
getOneRaffle({joinRecordId: joinRecordId}).then(data => {
console.log(555, data);
let dat = data || {};
this.prize = dat.prize;
this.quantity = dat.quantity;
this.chance = raffle.getProbability(dat.quantity,dat.prize.coinQuantity);
this.chance = raffle.getProbability(+dat.quantity, +dat.prize.coinQuantity);
});
getUserPhone().then(data=>{
getUserPhone().then(data => {
this.phone = data.phone;
});
this.areaList = area.areaList;
/*this.prize = {cash:false,name:'Nintendo Switch任天堂游戏机Nintendo Switch任天堂游戏机',photoUrl:'/static/images/test2.png',coinQuantity:5000};
/* this.prize = {cash:false,name:'Nintendo Switch任天堂游戏机Nintendo Switch任天堂游戏机',photoUrl:'/static/images/test2.png',coinQuantity:5000};
this.quantity = 300;
this.chance = raffle.getProbability(this.quantity,this.prize.coinQuantity);*/
},
this.chance = raffle.getProbability(this.quantity,this.prize.coinQuantity); */
}
});
</script>
<config>
......
......@@ -139,7 +139,7 @@
import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify';
import Dialog from '../components/vant/dialog/dialog';
import { updateUserPhone, confirmRaffle, register,getUserPhone } from '../common/api'
import { updateUserPhone, confirmRaffle, register } from '../common/api';
import store from '../store';
wepy.page({
store,
......@@ -152,27 +152,27 @@
name: '',
chance: '',
photoUrl: '',
btnfont:'立即参与',
hasPhone:false,
btnfont: '立即参与',
hasPhone: false
},
methods: {
check() {
this.isCheck = !this.isCheck;
},
async getPhoneNumber(e) {
if(this.btnfont !== '立即参与') {return;}
if (this.btnfont !== '立即参与') { return; }
let that = this;
let detail = e.$wx.detail || {};
function goprize() {
updateUserPhone(detail).then(()=>{
updateUserPhone(detail).then(() => {
that.confirmRaff();
wx.setStorageSync('hasPhone',true);
wx.setStorageSync('hasPhone', true);
that.hasPhone = true;
}).catch(()=>{
}).catch(() => {
that.btnfont = '立即参与';
});
}
if(detail.encryptedData) {
if (detail.encryptedData) {
this.btnfont = '提交中...';
wx.checkSession({
success () {
......@@ -183,40 +183,40 @@
goprize();
}
});
}else {
Notify({message: '参与失败,请重新授权!',background:'#FF5D15'})
} else {
Notify({message: '参与失败,请重新授权!', background: '#FF5D15'});
}
},
async confirmRaff() {
let title = ['参与成功!','参与失败!','参与失败!'];
let message = ['参与成功,坐等开奖。','当前抽奖已结束。','当前奖品已经没有库存了。'];
//如果用户还未注册
let title = ['参与成功!', '参与失败!', '参与失败!'];
let message = ['参与成功,坐等开奖。', '当前抽奖已结束。', '当前奖品已经没有库存了。'];
// 如果用户还未注册
let isRegister = wx.getStorageSync('isRegister');
if(isRegister === false) {
if (isRegister === false) {
await register(store.state.userInfo);
wx.setStorageSync('isRegister', true);
}
this.btnfont = '提交中...';
confirmRaffle({batchId:this.batchId}).then(data=>{
confirmRaffle({batchId: this.batchId}).then(data => {
this.btnfont = '立即参与';
let code = data.joinCode;
if(code === undefined) code = 3;
if (code === undefined) code = 3;
Dialog.alert({
title: title[code],
message: message[code],
message: message[code]
}).then(() => {
wx.reLaunch({url:'/pages/index'})
wx.reLaunch({url: '/pages/index'});
});
}).catch(()=>{
}).catch(() => {
this.btnfont = '立即参与';
})
});
},
joinin() {
if(!this.isCheck) {
Notify({message: '勾选同意后才可以抽奖!', background:'#FF5D15'})
if (!this.isCheck) {
Notify({message: '勾选同意后才可以抽奖!', background: '#FF5D15'});
return;
}
if(this.hasPhone) {
if (this.hasPhone) {
this.confirmRaff();
}
}
......@@ -224,7 +224,7 @@
computed: {
imgsrc() {
let imgsrc = '/static/images/selected.png';
if(this.isCheck) {
if (this.isCheck) {
imgsrc = '/static/images/selected.png';
} else {
imgsrc = '/static/images/selectno.png';
......@@ -247,7 +247,7 @@
}
this.hasPhone = wx.getStorageSync('hasPhone');
this.batchId = batchId;
this.quantity = quantity||'';
this.quantity = quantity || '';
this.name = name;
this.chance = chance;
this.photoUrl = photoUrl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment