Commit bf04ed01 by 汪睦雄

完善小程序

parent dcebc76b
......@@ -4,7 +4,7 @@
<view class='container'>
<image class='logo' mode='aspectFit' src='/images/icon_logo.png' mode='aspectFit'></image>
<view class='slogan'>
<view>行者亲子游</view>
<view>行者亲子游</view>
<view>美好的教育,行走在路上</view>
</view>
<view class='action-wrapper'>
......
......@@ -22,6 +22,8 @@ Page({
currentPage: 1,
loading: true,
hasMore: true,
show_kf: false
},
/**
......@@ -133,7 +135,16 @@ Page({
})
},
// 获取评论数据
getCommentData: function() {
// 商家详情没有评论
if(this.data.detail.type=='2'){
this.setData({
hasMore: false,
loading: false
})
return
}
const p = this.data.currentPage
api.project.comments({
pid: this.data.id,
......@@ -176,9 +187,25 @@ Page({
},
handleCollect: function() {
let that = this
api.project.collect({
pid: this.data.id
}).then(res => {
// 收藏改变
if(res.code==0){
let detail = that.data.detail
detail.is_collect = !detail.is_collect
if( res.collect == 'add' ){
// 添加收藏
detail.collect_num = parseInt(detail.collect_num) + 1
}else{
// 移除收藏
detail.collect_num = parseInt(detail.collect_num) - 1
}
that.setData({
detail: detail
})
}
$Toast({
content: res.msg,
type: !res.code ? 'success' : 'error'
......@@ -195,9 +222,60 @@ Page({
},
// 立即报名
enrollClick: function(){
wx.navigateTo({
url: '/pages/detail/enroll/index?id=' + this.data.id,
enrollClick: function() {
let status = this.data.detail.status
// 0-立即报名;1-预约下次;2-已售罄
if(status==0){
wx.navigateTo({
url: '/pages/detail/enroll/index?id=' + this.data.id,
})
} else if (status == 1){
wx.navigateTo({
url: '/pages/detail/appoint/index?id=' + this.data.id,
})
}else{
$Toast({
content: "活动已售罄",
type: 'error'
});
}
},
// 商家详情 - 咨询客服下单
kfClick: function() {
this.setData({
show_kf: true
})
},
// 客户弹框按钮点击
handleKfClose: function(event){
let that = this
if(event.type=='ok'){
// 保存二维码
wx.downloadFile({
url: that.data.detail.kf_qrcode,
success: function(res){
if (res.statusCode === 200){
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function (res) {
wx.showToast({
title: '图片保存成功',
})
},
fail: function (res) {
wx.showToast({
title: '图片保存失败',
})
}
})
}
}
})
}
// 关闭弹框
that.setData({
show_kf: false
})
}
})
\ No newline at end of file
......@@ -6,6 +6,7 @@
"i-toast": "/iview/toast/index",
"i-cell-group": "/iview/cell-group/index",
"i-cell": "/iview/cell/index",
"more": "/components/more/index"
"more": "/components/more/index",
"i-modal": "/iview/modal/index"
}
}
\ No newline at end of file
......@@ -7,29 +7,31 @@
<view class="attributes-wrapper">
<view class='header'>
<view class='title'>{{detail.title}}</view>
<view class='intro'>{{detail.tags}}</view>
<view class='intro'>
{{detail.type=='2'?'可预约':'限'+detail.sign_limits+'组报名'}} 收藏{{detail.collect_num}}次
</view>
</view>
<i-cell-group>
<i-cell>
<i-cell wx-if="{{detail.type=='1'}}">
<image slot="icon" src='/images/icon_tag.png' mode='scaleToFill' class='icon'></image>
<view>{{detail.created_at}}</view>
<view>活动时间:{{detail.time_period}}</view>
</i-cell>
<i-cell>
<i-cell wx-if="{{detail.type=='1'}}">
<image slot="icon" src='/images/icon_clock.png' mode='scaleToFill' class='icon'></image>
<view>报名截止:{{detail.time_period}}</view>
<view>报名截止:{{detail.sign_endtime}}</view>
</i-cell>
<i-cell>
<image slot="icon" src='/images/icon_location.png' mode='scaleToFill' class='icon'></image>
<view>{{detail.location}}</view>
<view catchtap='handleMap'>{{detail.location}}</view>
<view slot="footer">
<image src='/images/icon_map.png' class='icon-map' catchtap='handleMap'></image>
</view>
</i-cell>
<i-cell>
<i-cell wx-if="{{detail.type=='1'}}">
<image slot="icon" src='/images/icon_rmb.png' mode='scaleToFill' class='icon'></image>
<view class='text-red'>
<text>¥ {{detail.price}}</text>
<text class='margin-left-20'>会员价: ¥ {{detail.vip_price}}</text>
<text>¥{{detail.price}}</text>
<text class='margin-left-10'>Vip: ¥{{detail.vip_price}}</text>
</view>
<view slot="footer">
<button class='btn-pay-vip' catchtap='handleVip'>购买会员卡</button>
......@@ -39,16 +41,15 @@
</view>
<view class='desc-wrapper'>
<view class='title'>活动详情</view>
<view class='title'>{{detail.type=='1'?'活动':'商家'}}详情</view>
<view class='content'>
<template is="wxParse" data="{{wxParseData:description.nodes}}" />
</view>
</view>
<view class='comments-wrapper'>
<view wx-if="{{detail.type=='1'}}" class='comments-wrapper'>
<view class='title'>活动评价({{comments.length > 0 ? comments.lenght : 0}})</view>
<view class='content-wrapper'>
</view>
</view>
......@@ -62,7 +63,7 @@
<text class='title'>首页</text>
</view>
<view class='op-wrapper' catchtap='handleCollect'>
<image src='/images/icon_star.png' class='icon'></image>
<image src='/images/icon_star{{detail.is_collect==1?"_active":""}}.png' class='icon'></image>
<text class='title'>收藏</text>
</view>
<button open-type='share' class='form-button op-wrapper' catchtap='handleShare'>
......@@ -70,8 +71,19 @@
<text class='title'>分享</text>
</button>
</view>
<view class='actions-section btn-wrapper' catchtap='enrollClick'>立即报名</view>
<view wx-if="{{detail.type=='1'}}" class="actions-section btn-wrapper {{detail.status==1?'btn-overdate':''}} {{detail.status==2?'btn-soldout':''}}" catchtap='enrollClick'>{{detail.status_text}}</view>
<view wx-if="{{detail.type=='2'}}" class='actions-section btn-wrapper' catchtap='kfClick'>咨询客服下单</view>
</view>
</view>
<i-toast id="toast" />
<i-modal title="咨询客服" visible="{{show_kf}}" bind:ok="handleKfClose" bind:cancel="handleKfClose" ok-text="保存图片">
<view class="qrcode">
<image style='width:150rpx;height:150rpx;border-radius:4rpx;' src='{{detail.kf_qrcode}}'></image>
<text style='width:100%;text-align:center;height:24px;line-height:24px;font-size:24rpx;'>
保存图片后,扫码添加客服咨询
</text>
</view>
</i-modal>
</view>
\ No newline at end of file
......@@ -132,3 +132,9 @@
color: #fff;
justify-content: center;
}
.actions-section.btn-overdate {
background-color: #26CD84;
}
.actions-section.btn-soldout {
background-color: #CFCFCF;
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ Page({
user: {},
nickname: '',
genders: ["", "男", "女"],
genders: ["男", "女"],
gender: 0,
phone: ''
},
......@@ -24,9 +24,9 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
......@@ -81,10 +81,11 @@ Page({
handleGenderChange: function(event) {
this.setData({
gender: event.detail.value
gender: parseInt(event.detail.value) + 1
})
},
// 保存资料
handleSubmit: function() {
api.me.update({
nickname: this.data.nickname,
......@@ -95,6 +96,40 @@ Page({
content: res.msg,
type: !res.code ? 'success' : 'error'
});
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1200)
})
},
/**
* 选择头像控件触发事件
*/
chooseAvatar: function() {
let that = this;
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function(res) {
api.me.uploadAvatar("avatar", res.tempFilePaths[0]).then(res => {
// 这里为什么需要自己转JSON呢???
res = JSON.parse( res )
$Toast({
content: res.msg,
type: 'success'
})
if (!res.code) {
let user = that.data.user
user.avatar = res.avatar_url
that.setData({
user: user
})
}
})
}
})
}
})
\ No newline at end of file
......@@ -2,14 +2,16 @@
<view class='page-wrapper'>
<i-cell-group i-class='plane'>
<i-cell title="头像" i-class="cell-class">
<image slot="footer" class='avatar-image' src='{{user.avatar}}'></image>
<image catchtap='chooseAvatar' slot="footer" class='avatar-image' src='{{user.avatar}}'></image>
</i-cell>
<i-cell title="姓名" is-link i-class="cell-class">
<i-cell title="姓名" i-class="cell-class">
<input slot="footer" class='input' type='text' placeholder='请输入您的昵称' bindinput='handleNickname' value='{{user.nickname}}'></input>
</i-cell>
<i-cell title="性别" is-link i-class="cell-class">
<picker slot="footer" class='input' range="{{genders}}" value="{{user.gender}}" bindchange="handleGenderChange" class="picker">
<view class='picker-text'>{{genders[gender]}}</view>
<picker slot="footer" class='input' range="{{genders}}" value="{{user.gender-1}}" bindchange="handleGenderChange" class="picker">
<view class='picker-text'>{{genders[gender-1]}}</view>
</picker>
</i-cell>
</i-cell-group>
......
// pages/me/vip/index.js
import api from '../../../utils/Api.js'
const app = getApp()
Page({
/**
......@@ -10,7 +12,9 @@ Page({
is_vip: 0,
vip_endtime: null,
vip_price: 49.9
vip_price: 49.9,
order: {}
},
handleChange1({ detail }) {
......@@ -29,8 +33,9 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let is_vip = options.is_vip
let vip_endtime = options.vip_endtime
let userInfo = app.globalData.userInfo
let is_vip = userInfo.is_vip
let vip_endtime = userInfo.vip_endtime
this.setData({
is_vip: is_vip,
vip_endtime: vip_endtime
......@@ -99,5 +104,55 @@ Page({
*/
onShareAppMessage: function () {
},
/**
* 立即购买/续费
*/
handleClick: function (){
let that = this
let year = this.data.value1
let params = {
year: year
}
// 获取支付参数
api.me.vipOrder(params).then(res => {
if (res.code == 0) {
console.log("获取支付参数", res)
that.setData({
order: res.data
})
// 发起微信支付
wx.requestPayment({
timeStamp: '' + res.result.timeStamp,
nonceStr: '' + res.result.nonceStr,
package: '' + res.result.package,
signType: '' + res.result.signType,
paySign: '' + res.result.paySign,
success: function (ret) {
that.setOrderPaid(that.data.order.order_id, function (res) {
// 支付同步回调结果
console.log(res)
})
}
})
}else{
wx.showToast({
title: res.msg,
})
}
})
},
/**
* 同步支付结果回调:重置订单状态
*/
setOrderPaid(id, callback) {
let that = this
let params = {
order_id: id
}
api.me.vipOrderPaied(params).then(res => {
typeof callback == "function" && callback()
})
}
})
\ No newline at end of file
......@@ -9,9 +9,9 @@
<view class='calculation-box'>
<i-row class='height'>
<i-col span="6" offset='1' i-class="col-class">{{is_vip==1?'续费':'购买'}}会员</i-col>
<i-col span="6" i-class="col-class color-orange">¥ {{vip_price}}</i-col>
<i-col span="9" offset='1' i-class="col-class">
<i-input-number value="{{ value1 }}" min="1" max="10" bindchange="handleChange1" />
<i-col span="4" i-class="col-class color-orange">¥ {{vip_price}}</i-col>
<i-col span="12" offset='1' i-class="col-class">
<i-input-number i-class="vip_num_input" value="{{ value1 }}" min="1" max="10" bindchange="handleChange1" />
</i-col>
</i-row>
</view>
......
......@@ -28,6 +28,7 @@ page {
margin: auto;
background-color: #fff;
margin-bottom: 30rpx;
padding-bottom: 8rpx;
}
.vip_intro {
......@@ -45,7 +46,11 @@ page {
color: #969696;
font-size: 30rpx;
}
.vip_num_input{
text-align: right;
padding-right: 20rpx;
box-sizing: border-box;
}
.color-orange {
color: #ff4200;
}
......@@ -37,7 +37,7 @@
"list": []
},
"miniprogram": {
"current": 3,
"current": 8,
"list": [
{
"id": 0,
......@@ -88,40 +88,10 @@
"query": ""
},
{
"id": -1,
"name": "详情",
"id": 8,
"name": "活动/商家详情",
"pathName": "pages/detail/index",
"query": "id=1"
},
{
"id": -1,
"name": "报名",
"pathName": "pages/detail/enroll/index",
"query": ""
},
{
"id": -1,
"name": "报名",
"pathName": "pages/detail/enroll/index",
"query": ""
},
{
"id": -1,
"name": "报名",
"pathName": "pages/detail/enroll/index",
"query": ""
},
{
"id": -1,
"name": "报名",
"pathName": "pages/detail/enroll/index",
"query": ""
},
{
"id": -1,
"name": "报名",
"pathName": "pages/detail/enroll/index",
"query": ""
"query": "id=12"
},
{
"id": -1,
......
......@@ -60,6 +60,12 @@ export const me = {
},
vipOrder: params => {
return req.post('order/vipOrder', params).then(res => res.data)
},
vipOrderPaied: params => {
return req.post('order/vipOrderPaied', params).then(res => res.data)
},
uploadAvatar: (name, filePath, params) => {
return req.upload('User/uploadAvatar', name, filePath, params).then(res => res.data)
}
}
......
......@@ -49,6 +49,28 @@ class Request {
})
}
uploadFile({
url,
name,
filePath,
data
}) {
return new Promise((resolve, reject) => {
wx.uploadFile({
url: (this._baseUrl || '') + url,
filePath: filePath,
name: name || 'file',
formData: data ? data : {},
header: {
...this._header,
"Content-Type": "application/x-www-form-urlencoded"
},
success: res => this.intercept(res) && resolve(res),
fail: reject
})
})
}
get(url, data, header) {
return this.request({
url,
......@@ -68,6 +90,17 @@ class Request {
})
})
}
upload(url, name, filePath, data) {
return this.uploadFile({
url,
name,
filePath,
data: Util.sign({
...data,
token: wx.getStorageSync('token')
})
})
}
put(url, data, header) {
return this.request({
url,
......
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