123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609 |
- const util = require('../../../utils/util.js');
- const app = getApp();
- Page({
- data: {
- num: 0,//套餐数量
- agreement: false,//同意合同
- pay: true,//同意微信支付
- qptype: 0,
- recommender: '', //推荐人
- recommenderStatus: '',
- street: '', //街道社区
- streetStatus: '',
- atype: 0,//0活动1电商
- recommenderShow: false,
- recommenderShowText: '',
- datas: {},//payinfo数据
- imgPath: util.config.imgPath,
- userInfo: app.globalData.userInfo,
- formData: {
- aid: '',
- sid: '',
- vid: '',
- cid: '',
- useCoin: 0,
- useBalance: 0,
- useUserCoin: 0,
- meals: ''
- },
- total: {
- coin: '0.00', //钱包
- coupons: '0.00', //现金券
- ldiscount: '0.00', //早鸟优惠价格
- mdiscount: '0.00', //会员折扣价
- price: '0.00', //总价
- sumBalance: '0.00', //账户余额
- ableBalance: '0.00', //账户余额可用
- },
- idcards: {},
- textarea: '',//备注
- phoneNum: '',//手机号码
- mailAddress: '',//邮寄地址
- shipAddress: '',//收货地址
- email: '',//邮箱
- familyCommittee: '',//家委会
- travelDates: '',//出行日期
- groupid: '',//拼团号
- shareId: '',//分享id
- paying: false,//支付中
- percent: 0,
- alone: 0, //0单独报名,1拼团
- initialSku: {},
- sku: {
- quantity: 0,//购买数量
- sessions: {},
- meals: {},
- quota: 999,//限购
- presellDeduction: 0.00
- },
- show: {
- address: false,
- vouche: false,
- integral: false
- },
- voucheConfig: {},
- maskShow: false,
- presellOpen: 0,
- optionsData: {
- aid: '',
- otype: '',
- orderid: '',
- presellstatus: '',
- campsex: '',
- military: ''
- },
- },
- onLoad(options) {
- console.log(options)
- // wx.removeStorageSync('idcards');
- this.setData({ optionsData: options })
- this.data.formData.aid = options.aid;
- // this.setData({
- // formData: this.data.formData,
- // qptype: options.qptype || '',
- // groupid: options.groupid || '',
- // recommenderStatus:options.recommender,
- // streetStatus:options.street,
- // alone: options.createGroup != undefined ? options.createGroup : 0,
- // initialSku: { sessionsIndex: parseInt(options.sessionsIndex), mealsIndex: parseInt(options.mealsIndex), quantity: parseInt(options.quantity)},
- // atype: parseInt(options.atype),
- // presellOpen:options.presellOpen
- // });
- this.payinfo();
- },
- onShow() {
- let idcards = wx.getStorageSync('idcards');
- this.data.formData.cid = !util.isObjEmpty(idcards) ? idcards.ids.join(",") : '';
- this.setData({ idcards, formData: this.data.formData });
- this.setData({ userInfo: app.globalData.userInfo });
- if (!util.isObjEmpty(this.data.sku.meals)) this.safe();
- },
- onUnload() {
- wx.removeStorageSync('idcards');
- },
- payinfo() {
- let that = this, userInfo = app.globalData.userInfo;
- let data = {};
- data.aid = that.data.formData.aid;
- data.qptype = that.data.qptype ? that.data.qptype : 0;
- if (that.data.optionsData.orderid) {
- data.orderid = that.data.optionsData.orderid // 参数有orderinfo返回数据场次只有一条
- }
- util.ajax({
- func: "article/payinfo",
- data: data
- }, function (res) {
- if (res.code == 0) {
- let idcards = {
- ids: [],
- names: [],
- idCards: [],
- parentNames: []
- };
- res.data.attendants.forEach(el => {
- idcards.ids.push(el.id)
- idcards.names.push(el.name)
- idcards.idCards.push(el.idcard)
- if (el.parent) {
- idcards.parentNames.push(el.parent.name)
- } else {
- idcards.parentNames.push('( 无 )')
- }
- });
- wx.setStorageSync("idcards", idcards);
- that.setData({
- datas: res.data,
- userInfo,
- formData: that.data.formData,
- phoneNum: res.data.buyInfo.contactPhone || '',
- mailAddress: res.data.buyInfo.mailAddress ? res.data.buyInfo.mailAddress : '',
- email: res.data.buyInfo.email || '',
- 'sku.quantity': parseInt(res.data.num),
- 'sku.presellDeduction': res.data.presellDiscount,
- idcards,
- streetStatus: res.data.street,
- street: res.data.buyInfo.street || '',
- travelDates: res.data.travelDates,
- recommender: res.data.recommenderName,
- textarea: res.data.orderRemark || ''
- });
- wx.reportAnalytics('enter_enlist', {
- aid: that.data.formData.aid,
- title: res.data.title
- });
- that.getSku();
- that.safe();
- that.shipInfo();
- that.RecommenderMsg()
- } else if (res.code == 3003) {
- wx.showModal({
- title: '提示',
- content: res.reason,
- showCancel: false,
- success: function (data) {
- if (data.confirm) {
- wx.navigateBack();
- }
- }
- })
- } else {
- util.showTips(res.reason);
- }
- })
- },
- // 设定推荐人表单资料
- RecommenderMsg() {
- let info = this.data.datas;
- if (info.recommender == "0" || util.isEmpty(info.recommender)) {
- this.setData({
- recommenderShow: false
- })
- } else if (info.recommender == "1") {
- this.setData({
- recommenderShow: true,
- recommenderShowText: '请填写推荐人,没有填无'
- })
- } else if (info.recommender == "2") {
- this.setData({
- recommenderShow: true,
- recommenderShowText: '非必填,若有请填写'
- })
- }
- },
- getSku() {//sku
- let sku = this.data.sku, info = this.data.datas, initialSku = this.data.initialSku, that = this;
- info.sessions.forEach(item => {
- if (item.sid == info.sid) {
- sku.sessions = item;
- item.alipays.forEach(el => {
- if (el.pid == info.pid) {
- sku.meals = el;
- }
- });
- }
- });
- this.data.formData.sid = sku.sessions.sid;
- sku.meals.originalPrice = util.toMoney(sku.meals.originalPrice)
- sku.meals.price = util.toMoney(sku.meals.price)
- sku.quota = info.attendants.length;
- // sku.quota = parseInt(sku.meals.actNum) < sku.meals.maxT ? parseInt(sku.meals.actNum) : sku.meals.maxT;
- this.setData({ sku, formData: this.data.formData })
- console.log(this.data.sku)
- },
- // 购买数量加
- numAdd() {
- let sku = this.data.sku;
- if (sku.quantity >= sku.quota) {
- util.showTips("超出预付人数");
- } else {
- console.log(sku.quantity, this.data.idcards)
- sku.quantity = parseInt(sku.quantity) + 1;
- this.setData({ sku });
- this.safe();
- }
- },
- // 购买数量减
- numReduce() {
- let sku = this.data.sku;
- if (sku.quantity <= 1) {
- util.showTips("至少选择1件");
- } else {
- sku.quantity = parseInt(sku.quantity) - 1;
- console.log(sku.quantity, this.data.idcards)
- if (sku.quantity == this.data.idcards.idCards.length - 1) {
- this.data.idcards.idCards.pop();
- this.data.idcards.ids.pop();
- this.data.idcards.names.pop();
- this.data.idcards.parentNames.pop();
- }
- this.setData({ sku, idcards: this.data.idcards });
- wx.setStorageSync("idcards", this.data.idcards);
- this.safe();
- }
- },
- // 设置订单量
- numChange(e) {
- let sku = this.data.sku;
- if (parseInt(e.detail.value) > sku.quota) {
- util.showTips("库存不足");
- sku.quantity = sku.quota;
- } else if (parseInt(e.detail.value) <= 0 || util.isEmpty(e.detail.value)) {
- util.showTips("至少选择1件");
- sku.quantitym = 1;
- } else {
- sku.quantity = e.detail.value;
- }
- this.setData({ sku });
- this.safe();
- },
- openQuestion() {
- this.setData({ maskShow: true })
- },
- maskClose() {
- this.setData({ maskShow: false })
- },
- agree() {
- this.setData({
- agreement: !this.data.agreement
- })
- },
- choosePay() {
- this.setData({
- pay: !this.data.pay
- })
- },
- // 选择出行人信息
- chooseCard() {
- var quantity = this.data.sku.quantity;
- if (quantity > 0) {
- console.log(this.data.optionsData)
- wx.navigateTo({
- url: '/pages/account/cards/index?quantity=' + quantity + '&mage=' + this.data.datas.mage + '&lage=' + this.data.datas.lage + '&sparent=' + this.data.datas.sparent + '&adultMinAge=' + this.data.datas.adultMinAge + '&adultMaxAge=' + this.data.datas.adultMaxAge + '&military=' + this.data.optionsData.military + '&campSex=' + this.data.optionsData.campsex + '&sid=' + this.data.datas.sid + '&ageLimit=' + this.data.datas.ages
- })
- } else {
- util.showTips('请选择场次或者套餐数量');
- }
- },
- safe() {
- let that = this;
- that.data.formData.meals = that.data.sku.meals.pid + '|' + that.data.sku.quantity;
- that.data.formData.btype = that.data.optionsData.presellstatus == 1 ? 2 : 0; //购买类型: 0(默认)-普通购买 1-预付 2-付尾款
- util.ajax({
- func: "voucher/pay_mvoucher",//会员折扣,现金券,钱包
- data: that.data.formData,
- load: false
- }, function (res) {
- if (res.code == 0 && res.data != "") {
- let data = res.data;
- that.data.total.coin = util.toMoney(data.coin, ',');
- that.data.total.coupons = util.toMoney(data.price, ',');
- that.data.total.ldiscount = util.toMoney(data.ldiscount, ',');
- that.data.total.mdiscount = util.toMoney(data.mdiscount, ',');
- that.data.total.price = util.toMoney(data.totalFee, ',');
- that.data.total.sumBalance = util.toMoney(data.sumBalance, ',');
- that.data.total.sumBalanceNum = data.sumBalance;
- that.data.total.sumUserCoin = data.sumUserCoin || 0;
- that.data.total.userCoin = data.userCoin || 0;
- that.data.total.ableBalance = util.toMoney(data.ableBalance, ',');
- that.data.formData.vid = data.id || '';
- that.data.sku.presellDeduction = util.toMoney(data.presellDiscount, ',');
- that.setData({
- sku: that.data.sku,
- total: that.data.total,
- formData: that.data.formData,
- });
- } else {
- // that.clearSafe();
- }
- })
- },
- getPackId() {
- return (this.data.sku.meals.pid || '') + '|' + this.data.sku.quantity;
- },
- goCoupon() {
- var packIds = this.getPackId();
- if (this.data.datas.needIdcard != 'no' && util.isObjEmpty(this.data.idcards)) {
- util.showTips('请先选择购买儿童的身份信息。');
- return false;
- }
- this.data.show = { address: false, vouche: true, integral: false };
- let voucheConfig = {
- packIds: packIds,
- aid: this.data.formData.aid,
- sid: this.data.formData.sid,
- vid: this.data.formData.vid,
- cid: this.data.formData.cid
- }
- this.setData({ voucheConfig, show: this.data.show })
- },
- goPay() {
- var packIds = this.getPackId(),
- phoneNum = this.data.phoneNum,
- idcards = this.data.idcards,
- num = this.data.sku.quantity,
- datas = this.data.datas,
- userInfo = app.globalData.userInfo,
- email = this.data.email;
- if (util.isObjEmpty(this.data.sku.meals)) {
- util.showTips('请先选择场次套餐,再付款。');
- return false;
- }
- if (datas.needIdcard != 'no' && this.data.atype == 0) {
- if (idcards.ids) {
- if (idcards.ids.length == 0) {
- util.showTips('请先选择出行人的身份信息。');
- return false;
- } else if (idcards.ids.length != num) {
- util.showTips('请设置' + num + '人的身份信息。');
- return false;
- }
- } else {
- util.showTips('请先选择出行人的身份信息。');
- return false;
- }
- }
- if (datas.sphone == 'yes' && util.isPhone(phoneNum)) {
- util.showTips('请填写正确的用户联系手机号码。');
- return false;
- }
- if (datas.smailAddress == 'yes' && !this.data.mailAddress) {
- util.showTips('请填写邮寄信息。');
- return false;
- }
- var myreg = /^([a-zA-Z0-9]+[_|\_|\.|-]+)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|-]+)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
- console.log(email)
- if (datas.needEmail == 'yes' && !email) {
- util.showTips('请填写电子邮箱。');
- return false;
- }
- if (datas.needEmail == 'yes' && !myreg.test(email)) {
- util.showTips('请正确填写电子邮箱。');
- return false;
- }
- if (datas.familyCommittee == '1' && this.data.familyCommittee == '') {
- util.showTips('请填写是否为家委会');
- return false;
- }
- if (this.data.streetStatus == '1' && this.data.street == '') {
- util.showTips('请填写街道社区,没有填无');
- return false;
- }
- if (this.data.recommenderStatus == '1' && this.data.recommender == '') {
- util.showTips('请填写推荐人,没有填无');
- return false;
- }
- if (this.data.recommenderStatus == '1' && this.data.recommender.length > 10) {
- util.showTips('请正确填写推荐人');
- return false;
- }
- if (datas.travelDates == 'yes' && !this.data.travelDates && this.data.atype == 0) {
- util.showTips('请选择出行日期。');
- return false;
- }
- if (this.data.atype == 0 && datas.sremark == 'yes' && this.data.textarea == '') {
- util.showTips('请填写家长叮嘱等备注信息。');
- return false;
- }
- if (datas.agreement && !this.data.agreement && this.data.atype == 0) {
- util.showTips('请认真阅读相关协议条款,并认可同意。');
- return false;
- }
- if (!this.data.paying) {
- this.setData({ paying: true });
- this.WeChatPay();
- }
- },
- WeChatPay() {
- var data = {}, getPackId = this.getPackId(), userInfo = app.globalData.userInfo, that = this;
- data['meals'] = getPackId;//支付套餐字符串 如:pid|num,pid|num
- data['aid'] = this.data.formData.aid;//活动唯一标识
- data['sid'] = this.data.formData.sid;//场次id
- data['orderTitle'] = this.data.datas.title;//商品名
- data['phone'] = userInfo.phoneNum;//用户联系电话
- data['vid'] = this.data.formData.vid == -1 ? "" : this.data.formData.vid;//现金券id
- data['idcards'] = this.data.idcards.ids != undefined ? this.data.idcards.ids.join(",") : "";//身份证信息 ,字符串多个","隔开 如: id1,id2 remark
- data['remark'] = this.data.textarea;//备注
- data['contactPhone'] = this.data.phoneNum;//联系手机号
- data['recommender'] = this.data.recommender;//推荐人
- data['street'] = this.data.street;//街道社区
- data['travelDates'] = this.data.travelDates;//出行日期
- data['mailAddress'] = this.data.mailAddress;//邮寄地址
- data['openid'] = userInfo.socialUid;//微信用户的openid
- data['email'] = this.data.email;//邮件地址
- data['wallet'] = this.data.formData.useCoin;
- data['useBalance'] = this.data.formData.useBalance;
- data.useUserCoin = this.data.formData.useUserCoin;
- data['groupid'] = this.data.groupid;//拼团号
- data['shareId'] = this.data.shareId;//分享id
- data['product'] = 0;//产品: 0(默认)-活动 1-年卡
- data.createGroup = this.data.alone;
- data.orderid = this.data.optionsData.orderid;
- data.btype = 2; //付尾款
- util.WXPay(data, this.data.formData.aid, this.data.datas.title, that.data.alone, that.data.optionsData.presellstatus).then(function (res) {
- console.log(data.btype, res)
- wx.navigateTo({
- url: '/pages/order/success/index?orderid=' + res.orderid + '&alone=' + that.data.alone + '&presellStatus=' + that.data.optionsData.presellstatus + '&btype=' + data.btype + '&tradeChannelWeixin=' + res.tradeChannelWeixin
- });
- }, function (res) {
- util.showTips(res.reason)
- });
- that.setData({ paying: false });
- wx.reportAnalytics('gopay', {
- aid: that.data.aid,
- title: that.data.datas.title,
- });
- },
- coinChange(e) {
- this.data.formData.useUserCoin = Number(e.detail.value);
- this.setData({ formData: this.data.formData });
- this.safe();
- },
- switchChange(e) {
- this.data.formData.useCoin = Number(e.detail.value);
- this.setData({ formData: this.data.formData });
- this.safe();
- },
- balanceChange(e) {
- this.data.formData.useBalance = Number(e.detail.value);
- this.setData({ formData: this.data.formData });
- this.safe();
- },
- textarea(e) {
- this.setData({ textarea: e.detail.value });
- },
- phoneNum(e) {
- this.setData({ phoneNum: e.detail.value });
- },
- chooseAddress() {
- this.data.show = { address: true, vouche: false, integral: false };
- this.setData({ show: this.data.show });
- },
- weixinAddress() {
- let that = this;
- wx.chooseAddress({
- success(res) {
- let mailAddress = `${res.userName} ${res.telNumber} ${res.provinceName}/${res.cityName}/${res.countyName} ${res.detailInfo}`;
- that.setData({ mailAddress, shipAddress: res });
- }
- })
- },
- submitAddress(e) {
- let data = e.detail;
- this.setData({ mailAddress: data.name + ' ' + data.mobile + ' ' + data.provincial + ' ' + data.address });
- this.shipInfo();
- },
- shipInfo() {
- if (this.data.mailAddress) {
- let address = this.data.mailAddress.split(' ');
- let addressInfo = address[2].split('/');
- let shipAddress = {
- userName: address[0],
- telNumber: address[1],
- provinceName: addressInfo[0],
- cityName: addressInfo[1],
- countyName: addressInfo[2],
- detailInfo: address[3],
- }
- this.setData({ shipAddress });
- }
- },
- changeVouche(e) {
- this.data.formData.vid = e.detail;
- this.setData({ formData: this.data.formData });
- this.safe();
- },
- // 推荐人
- recommender(e) {
- this.setData({ recommender: util.trim(e.detail.value) });
- },
- // 街道社区
- streetInput(e) {
- this.setData({ street: util.trim(e.detail.value) });
- },
- // 邮箱
- email(e) {
- this.setData({ email: e.detail.value });
- console.log(this.data.email)
- let userInfo = app.globalData.userInfo;
- userInfo.email = e.detail.value;
- wx.setStorageSync('WXuserInfo', userInfo);
- },
- // 家委会
- familyCommittee(e) {
- this.setData({ familyCommittee: util.trim(e.detail.value) });
- },
- bindDateChange(e) {
- this.setData({
- travelDates: e.detail.value
- });
- },
- openDoc() {
- let datas = this.data.datas, url = '', that = this;
- switch (datas.agreement) {
- case 'default': //境内旅游合同
- url = util.config.imgUrl + '/doc/jingneihetong.pdf'
- break;
- case 'foreign': //境外旅游合同
- url = util.config.imgUrl + '/doc/jingwaihetong.pdf'
- break;
- case 'within': //沐童境内旅游合同
- url = util.config.imgUrl + '/doc/jingneimutong.pdf'
- break;
- case 'leave': //沐童境外旅游合同
- url = util.config.imgUrl + '/doc/jingwaimutong.pdf'
- break;
- case 'pay': //知识付费协议
- url = util.config.imgUrl + '/doc/knowledge.pdf'
- break;
- case 'bicycleDomestic': //沐童境内旅游合同(含骑行)
- url = util.config.imgUrl + '/doc/bicycleDomestic.pdf'
- break;
- case 'bicycleAbroad': //沐童出境旅游合同(含骑行)
- url = util.config.imgUrl + '/doc/bicycleAbroad.pdf'
- break;
- case 'within1': //境内旅游合同(沐童旅行社单日版)
- url = util.config.imgUrl + '/doc/singleDayContract.pdf'
- break;
- case 'within1_bicycle': //境内旅游合同(沐童旅行社单日骑行版)
- url = util.config.imgUrl + '/doc/singleDayBicycle.pdf'
- break;
- case 'within3': //境内旅游合同(沐童旅行社多日版)
- url = util.config.imgUrl + '/doc/manyDayContract.pdf'
- break;
- case 'within3_bicycle': //境内旅游合同(沐童旅行社多日骑行版)
- url = util.config.imgUrl + '/doc/manyDayBicycle.pdf'
- break;
- }
- const downloadTask = wx.downloadFile({
- url: url,
- success: function (res) {
- wx.openDocument({
- filePath: res.tempFilePath,
- fileType: "pdf"
- })
- }
- })
- downloadTask.onProgressUpdate((res) => {
- that.setData({ percent: res.progress })
- });
- },
- integral() {
- if (this.data.datas.needIdcard != 'no' && util.isObjEmpty(this.data.idcards)) {
- util.showTips('请先选择购买儿童的身份信息。');
- return false;
- }
- this.data.show = { address: false, vouche: false, integral: true };
- this.setData({ show: this.data.show, integralConfig: { idcards: this.data.idcards, sid: this.data.formData.sid, aid: this.data.formData.aid } });
- },
- close(e) {
- this.data.show[e.currentTarget.dataset.name] = false;
- this.setData({ show: this.data.show })
- },
- onShareAppMessage() {
- return {
- title: '分享自@宝贝走天下微信小程序',
- path: '/pages/home/index'
- }
- }
- })
|