Commit a0e1e3c5944f9786e8a4c2cb5933a8a38f13e05b

Authored by vking
1 parent ac2fcd2e

boost

... ... @@ -26,6 +26,13 @@ Component({
this.setData({
displayType:0,
})
util.elog(null,'点击关闭了红包弹窗')
},
enter(){
this.setData({
displayType:0,
})
util.elog(null,'点击红包进入活动主页')
},
hasActivity(e){//有通知就可以参加活动
console.log('hasActivity.enter',e)
... ...
... ... @@ -19,7 +19,7 @@
<view class="money-dw">元</view>
</view>
<navigator url="/pack-activity/pages/index?id={{activity.id}}"
bindtap="close"
bindtap="enter"
hover-class="navigator-hover">
<view class="money-button flex-cc">开心收下</view>
</navigator>
... ...
var util = require('../../../utils/util.js')
var uri=require('../../../utils/uri.js')
var bookOrder=require('../../../utils/bookCommon.js')
const {regeneratorRuntime} = global
Page({
data:{
grand:[
{
sex:1,
grand_title:'先生',
isselect:true
},
{
sex:2,
grand_title:'女士',
isselect:false
}
],
name:'',
sex:1,
phone:'',
remark:'',
buttonhide:true,
pnum:'6'
},
onLoad:function(opt){
wx.removeStorage({
key:'tableid',
})
wx.removeStorage({
key:'tabletype',
})
util.setBarTitle('录入订座信息');
var selectmonth=opt.date.split('-')[0][0]=='0' ? opt.date.split('-')[0][1] : opt.date.split('-')[0];
var selectday=opt.date.split('-')[1][0]=='0' ? opt.date.split('-')[1][1] : opt.date.split('-')[1];
console.log(opt)
var stringTime =opt.year+'-'+opt.date+' ' +opt.time+':00';
console.log(stringTime)
var time=bookOrder.gettimestamp(stringTime);
console.log(time)
this.setData({
thisyear:opt.year,
selectdate:selectmonth+'月'+selectday+'日',
time_dur:opt.time,
sellerid:util.cache('sellerid'),
time:time,
pnum:util.cache('order_pnum') ? util.cache('order_pnum') : this.data.pnum,
})
this.getdesklist();
},
onShow:function(){
var that=this;
if(util.cache('tableid')){
var tables=util.cache('tableid');
var templist=this.data.templist;
var showdesk=[];
for(var i=0;i<tables.length;i++){
templist.forEach(function(r,n){
if(tables[i]==r.id){
r.isselect=true;
if(r.tid==2){
r.name=r.name.length>4 ? r.name.slice(0,3)+'...' : r.name;
showdesk.unshift(r);
}else {
r.name=r.name.length>4 ? r.name.slice(0,3)+'...' : r.name;
showdesk.push(r);
}
}
})
}
this.setData({
showdesk:showdesk.slice(0,2)
})
}
if(util.cache('tableid') && util.cache('tableid').length>0){
if(this.data.name!='' && this.data.phone!='' && !this.data.reminder){
this.setData({
buttonhide:false
})
}
}
util.postSuccessFun=function(json,uri_code){
switch (uri_code) {
case uri.CGI_USER_SETRESERVEINFO__CODE:
wx.hideLoading()
if(json.ret==200){
wx.reLaunch({
url:util.http_build_query(json.data,'b_detail')
})
}
break;
case uri.CGI_USER_GETTABLELIST__CODE:
console.log('xxxx',json.data);
var list=json.data;
var templist=[];
for(var key in list){
if(key!='typex' && key!='typey'){
list[key].list.forEach(function(v,i){
templist.push(v)
})
}
}
var tempsan=[];
var tempbao=[];
var showdesk=[];
var temp={};
templist.forEach(function(v,i){
v.name=v.name.length>4 ? v.name.slice(0,3)+'...' : v.name;
if(!v.r_status){
if(v.tid==2){
tempbao.push(v);
v.isselect=false;
showdesk.unshift(v);
}else{
tempsan.push(v);
v.isselect=false;
showdesk.push(v);
}
}
if(v.tid==2){
if(!temp.hasOwnProperty("tabletype_2")){
temp['tabletype_2']=true
}
}else{
if(!temp.hasOwnProperty("tabletype_1")){
temp['tabletype_1']=true
}
}
})
util.cache('tabletype',temp);
console.log(showdesk)
that.setData({
sancount:list.typex, //typex散台
baocount:list.typey, //typey包间
showdesk:showdesk.slice(0,2),
templist:templist
})
break;
}
}
},
changetime:function(){
wx.navigateBack()
},
selectgrand:function(e){
var sex=e.currentTarget.dataset.sex;
console.log(sex)
var grandlist=this.data.grand;
grandlist.forEach(function(v,i){
v.isselect=false;
if(v.sex==sex){
v.isselect=true;
}
})
this.setData({
grand:grandlist,
sex:sex
})
},
condition:function(e){
var name=this.data.name;
var phone=e.detail.value;
var regExp = /^(86)?((13\d{9})|(15[0,1,2,3,5,6,7,8,9]\d{8})|(18[0,5,6,7,8,9]\d{8}))$/
if(!(regExp.test(phone))){
this.setData({
reminder:'手机格式不正确'
})
}else{
this.setData({
reminder:null
})
}
if(name!='' && !this.data.reminder && phone!='' && util.cache('tableid')){
this.setData({
buttonhide:false
})
}
},
changename:function(e){
this.setData({
name:e.detail.value
})
},
changephone:function(e){
this.setData({
phone:e.detail.value
})
},
changeremark:function(e){
this.setData({
remark:e.detail.value
})
},
ifAll:function(){
var name=this.data.name;
var phone=this.data.phone;
if(name!='' && !this.data.reminder && phone!='' && util.cache('tableid')){
this.setData({
buttonhide:false
})
}
},
formsubmit:async function(){
wx.showLoading({
title:'正在预订',
mask:true
});
console.log(this.data.time)
var formData={
sid:this.data.sellerid,
tid:util.cache('tableid').toString(),
rname:this.data.name, //姓名
phone:this.data.phone, //手机号
sex:this.data.sex, //性别
pnum:this.data.pnum, //人数
rdate:this.data.time, //时间
cusdem:this.data.remark //备注
}
try{
let enter_params=util.cache('enter_params');
let manager_id=enter_params.manager_id;
if(manager_id){
let sc=(await App.Reserve.SellerInfo(enter_params)).data
let managers=sc.manager;
managers.forEach(man=>{
if(manager_id==man.id){
formData.cusman_id=man.id;
formData.cusman=man.user_name;
formData.cusman_phone=man.user_phone?man.user_phone:'';
formData.cusman_account=man.user_wechat?man.user_wechat:'';
}
})
}
let man=managers[mansIndex];
if(man){
App.Reserve.SetReserveCusman({
rid:this.data.bookInfo.id,
cusman_id:man.id,
cusman:man.user_name,
cusman_phone:man.user_phone?man.user_phone:'158777556369',
cusman_account:man.user_wechat?man.user_wechat:'',
});
}
}catch (e){}
console.log(formData)
util.post(uri.CGI_USER_SETRESERVEINFO,formData,uri.CGI_USER_SETRESERVEINFO__CODE)
},
changepnum:function(e){
console.log(e)
this.setData({
pnum:e.detail
})
this.getdesklist();
},
selectdesk:function(){
wx.navigateTo({
url:'b_desk?pnum='+this.data.pnum+'&year='+this.data.thisyear+'&date='+this.data.selectdate+'&time_dur='+this.data.time_dur
})
},
getdesklist:function(){
util.post(uri.CGI_USER_GETTABLELIST,{sid:this.data.sellerid,pnum:parseInt(this.data.pnum),rdate:this.data.time},uri.CGI_USER_GETTABLELIST__CODE)
},
binddesk:function(e){
var id=e.currentTarget.dataset.id;
var tables=util.cache('tableid') ? util.cache('tableid') : [];
var showdesk=this.data.showdesk;
showdesk.forEach(function(v,i){
if(v.id==id){
if(v.isselect==true){
var thisindex=tables.indexOf(id);
tables.splice(thisindex,1)
}else{
tables.push(id)
}
v.isselect=!v.isselect
}
})
util.cache('tableid',tables);
this.setData({
showdesk:showdesk
})
var name=this.data.name;
var phone=this.data.phone;
if(name!='' && !this.data.reminder && phone!='' && util.cache('tableid')){
this.setData({
buttonhide:false
})
}
}
})
\ No newline at end of file
{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle":"black",
"usingComponents": {
"selectPeople":"../../components/book/people/people",
"step":"../../components/book/step/step",
"nav":"/components/nav/nav"
}
}
\ No newline at end of file
<nav>点餐商户端</nav>
<step step="1"></step>
<view class="other-info flex-lr">
<view class="selected-time flex-vc" bindtap="changetime">
<view class="font30r black-font">时间</view>
<view class="actual-time green-font font34r">{{selectdate}} {{time_dur}}</view>
</view>
<selectPeople bind:changepnum="changepnum" pnum="{{pnum}}"></selectPeople>
</view>
<view class="border-line"></view>
<view class="advice-desk flex-lr">
<view class="black-font font30r">桌位</view>
<view>
<view class="font26r gray-deep-font flex-rr">(包间余{{baocount}}个,散台余{{sancount}}个)</view>
<view class="advice-desk-detail flex-rr">
<block wx:for="{{showdesk}}">
<block wx:if="{{item.tid==2}}">
<view class="order-desk-info {{item.isselect==true ? 'desk-active' : ''}}" bindtap="binddesk" data-id="{{item.id}}" data-type="{{item.tid}}">
<view class="flex-vc order-desk-detail">
<view class="font28r black-font smooth">{{item.name}}</view>
<view class="font26r black-font" style="margin-top:6rpx;">{{item.table_pnum}}人</view>
</view>
<view class="order-desk-type flex-cc white-font font20r">包间</view>
</view>
</block>
<block wx:else>
<view class="order-desk-info {{item.isselect==true ? 'desk-active' : ''}}" bindtap="binddesk" data-id="{{item.id}}" data-type="{{item.tid}}">
<view class="flex-vc order-desk-detail" style="height:100%;">
<view class="font28r black-font smooth">{{item.name}}</view>
<view class="font26r black-font" style="margin-top:6rpx;">6人</view>
</view>
</view>
</block>
</block>
<view class="flex-rr advice-more" bindtap="selectdesk">
<view style="padding-right:30rpx;" class="gray-deep-font font26r">更多</view>
<image src="http://nosqn.colorcun.com/custom/lite-yd/image/click.png" class="icon12-22"></image>
</view>
</view>
</view>
</view>
<view class="cut"></view>
<view class="book-info" style="margin-bottom: 205rpx;">
<view class="book-info-single flex-lr" style="align-items:flex-start;">
<input placeholder="请输入预订人姓名(必填)" placeholder-class="gray-font font34r" class="black-font font34r" maxlength="5" style="width:450rpx;" value="{{name}}" bindinput="changename" bindblur="ifAll"/>
<view class="book-info-grand flex-rr font28r gray-deep-font">
<block wx:for="{{grand}}">
<view class="book-grand flex-cc {{index==0 ? 'book-grand-border' : ''}} {{item.isselect==true ? 'book-grand-active white-font' : ''}}" bindtap="selectgrand" data-sex="{{item.sex}}">{{item.grand_title}}</view>
</block>
</view>
</view>
<view class="book-info-single flex-lr" style="align-items:flex-start;">
<input placeholder="请输入预订人手机号码(必填)" placeholder-class="gray-font font34r" class="black-font font34r" type="number" maxlength="11" bindblur="condition" bindinput="changephone" value="{{phone}}" style="color:{{reminder ? '#E14553' : '#353535'}};width:{{reminder ? 400 : 680}}rpx;"/>
<block wx:if="{{reminder}}">
<view class="flex-rr" style="height:100rpx;">
<view style="color:#E14553;" class="font28r">{{reminder}}</view>
<image src="http://nosqn.colorcun.com/custom/lite-yd/image/name-have.png" class="phone-reminder"></image>
</view>
</block>
</view>
<view class="book-info-single">
<input placeholder="请输入顾客要求(25字以内,选填)" placeholder-class="gray-font font34r" class="black-font font34r" maxlength="25" value="{{remark}}" bindinput="changeremark"/>
</view>
</view>
<view class="zhanwei">
<view class="confirm-button white-font flex-vc font34r {{buttonhide==false ? 'confirm-button-active' : ''}}" bindtap="{{buttonhide==false ? 'formsubmit' : ''}}">确定</view>
</view>
\ No newline at end of file
view{
line-height:1.2;
}
.other-info{
width:100%;
height:220rpx;
padding:20rpx 0;
box-sizing:border-box;
}
.selected-time{
width:375rpx;
height:100%;
border-right:1px solid #efeef3;
box-sizing:border-box;
}
.actual-time{
margin-top:30rpx;
}
.border-line{
width:680rpx;
height:1px;
background:#efeef3;
margin:0 auto;
}
.advice-desk{
width:680rpx;
height:auto;
padding:40rpx 0;
margin:0 auto;
}
.advice-desk-detail{
margin-top:30rpx;
}
.order-desk-info{
width:120rpx;
height:120rpx;
background:#EBF8F8;
border:1px solid #199095;
border-radius:10rpx;
position:relative;
overflow:hidden;
margin-right:40rpx;
}
.desk-active{
background:#A9E3E6;
}
.order-desk-detail{
width:100%;
height:90rpx;
}
.order-desk-type{
width:100%;
height:30rpx;
background:#199095;
position:absolute;
left:0;
bottom:0;
}
.advice-more{
padding:20rpx 0;
padding-left:30rpx;
}
.cut{
width:100%;
height:4px;
background:#efeef3;
}
.book-info{
width:680rpx;
padding-top:20rpx;
margin:0 auto;
}
.book-info-single{
width:100%;
height:120rpx;
padding-top:80rpx;
border-bottom:1px solid #efeef3;
}
.book-info-single>input{
width:100%;
height:100rpx;
}
.book-info-grand{
height:50rpx;
border:1px solid #199095;
margin-top:20rpx;
}
.book-grand{
width:90rpx;
height:100%;
box-sizing:border-box;
}
.book-grand-active{
background:rgba(25,153,149,.8);
}
.book-grand-border{
border-right:1px solid #199095;
}
.phone-reminder{
width:32rpx;
height:32rpx;
margin-left:20rpx;
}
.zhanwei{
width:100%;
height:170rpx;
background:#efeef3;
position:fixed;
left:0;
right:0;
bottom:0;
z-index: 99;
}
.confirm-button{
width:680rpx;
height:85rpx;
background:#199095;
margin:42rpx auto 0;
border-radius:10rpx;
opacity:.6;
}
.confirm-button-active{
opacity:1;
}
\ No newline at end of file
... ... @@ -147,7 +147,7 @@ Page({
/**
* 生命周期函数--监听页面显示
*/
onShow: async function () {
onShow: async function (e) {
console.log({
'this.hasGetLocation':this.hasGetLocation,
'this.hasOnLoad':this.hasOnLoad,
... ... @@ -199,7 +199,8 @@ Page({
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
onHide: function (e) {
util.elog(null,'离开地图页')
},
/**
... ... @@ -386,6 +387,10 @@ Page({
m.callout.display='ALWAYS';
}
hasCurrent=false
if("markertap"==e.type){
util.elog({id:m.seller.id,sellername:m.seller.sellername},'点击地图区域的店铺标记')
}
}
if(m.display!='none' && hasCurrent){
current++
... ... @@ -707,6 +712,7 @@ Page({
wx.navigateTo({
url:'/pages/reserve/detail?id='+util.attr(e,'sid')
})
util.elog({sid:util.attr(e,'sid')},'点击橱窗中的商家,进入店铺详情')
},
IsSetActivity(){
let cmap=this.data.map;
... ... @@ -910,8 +916,7 @@ Page({
})
},
boostEvent(e){
console.log('boostEvent',e)
//wx.aldstat.sendEvent( '强提醒', {...e.detail,time:parseInt(new Date()/1000)})
util.elog(e.detail,'强提醒')
if(e.detail.act=='hide'){
this.setData({
hasGetPos:true,
... ... @@ -919,4 +924,7 @@ Page({
this.selectComponent('#getpos').getPos();
}
},
elog(e){
util.elog({attr:util.attr(e),detail:e.detail},util.attr(e,'ename')||'点击')
}
})
\ No newline at end of file
... ...
... ... @@ -16,8 +16,8 @@
subkey="SDEBZ-I74W4-QLGUX-XXYXU-HIR23-3QFBJ"
layer-style="2"
style="width: 100%; height: {{map.height+60}}px;"></map>
<formids url="/pages/reserve/search" style="position: fixed;">
<view
<formids url="/pages/reserve/search" style="position: fixed;" >
<view bindtap="elog" data-ename="点击搜索框"
class="flex-ll"
style="position:fixed;top:{{statusBarHeight}}px;left:0;height: {{titleBarHeight}}px; line-height: {{titleBarHeight}}px;">
<view class="searchList flex-ll" catchtap="listShow">
... ...
... ... @@ -54,7 +54,7 @@
"list": []
},
"miniprogram": {
"current": 0,
"current": -1,
"list": [
{
"id": 0,
... ... @@ -127,13 +127,6 @@
},
{
"id": 11,
"name": "录入订座信息 b_info",
"pathName": "pack-book/pages/book/b_info",
"query": "year=2018&date=08-23&time=18:30",
"scene": "1001"
},
{
"id": 11,
"name": "pages/customer/remind",
"pathName": "pages/customer/remind",
"query": "id=21&rdate=153745200",
... ... @@ -197,11 +190,11 @@
"scene": 1001
},
{
"id": -1,
"id": 17,
"name": "pages/reserve/index 在线订座",
"pathName": "pages/reserve/index",
"query": "",
"scene": "1044",
"query": "a=b&c=d",
"scene": 1044,
"shareInfo": {
"groupName": "测试模拟群1",
"shareName": "8DEbIRpK4pa9mH_QY2vU4ZUKYPuI97WoQ4BQoFej-Q8@cr4dev",
... ...
var util = require('util.js')
var uri=require('uri.js')
module.exports = {
onShareAppMessage:function() {
var token=util.cache(uri.CACHE__TOKEN);
if(!token) {
wx.navigateTo({
url:"/pages/login/index"
});
}else{
console.log("this.data.share_xcx_url",this.data.share_xcx_url)
this.sharecallback();
return {
title: this.data.share_xcx_name?this.data.share_xcx_name:(this.data.share_xcx_title?this.data.share_xcx_title:'纳极,最懂你的店铺管家'),
desc: this.data.share_xcx_desc?this.data.share_xcx_desc:'',
path: this.data.share_xcx_url?this.data.share_xcx_url:'/pages/index/index',
}
}
},
sharecallback:function(){
util.post(uri.CGI__ASYN_TOURIST_OPRRATION,{provider_id:this.data.provider_id,type:this.data.sharetype},uri.CGI__ASYN_TOURIST_OPRRATION__CODE);
},
onRefresh:function(){
this.setData({
refreshpage:true
})
var pageinfo=getCurrentPages();
var pagelength=pageinfo.length;
var n_pageinfo=pageinfo[pagelength-1];
var turnpage='/'+n_pageinfo.route;
if(JSON.stringify(n_pageinfo.options)!='{}'){
turnpage+='?';
for(var opt in n_pageinfo.options){
turnpage+=opt+'='+n_pageinfo.options[opt]+'&';
}
}
wx.redirectTo({
url: turnpage,
})
},
restartLogin:function(){
console.log('hahah');
var pages = getCurrentPages();
var num = pages.length;
console.log('hahah');
wx.openSetting({
success: (res) => {
console.log('openSetting',res);
res.authSetting = {
"scope.userInfo": true,
"scope.userLocation": true
}
/*wx.redirectTo({
url:'/pages/index/s_index',
})*/
wx.redirectTo({
url:'../index/s_index',
})
},
fail:(res) => {
console.log('failsetting');
wx.redirectTo({
url:'../me/s_index',
})
}
})
},
};
\ No newline at end of file
var uri=require('uri.js')
var uri = require('uri.js')
function formatTime(date,type,connect) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
function formatTime(date, type, connect) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()
if(type==1){
if(connect){
return [year, month, day].map(formatNumber).join(connect)
}else{
return [year, month, day].map(formatNumber).join('/')
}
}else if(type==2){
return [month, day].map(formatNumber).join('/')
}else{
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()
if (type == 1) {
if (connect) {
return [year, month, day].map(formatNumber).join(connect)
} else {
return [year, month, day].map(formatNumber).join('/')
}
} else if (type == 2) {
return [month, day].map(formatNumber).join('/')
} else {
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
n = n.toString()
return n[1] ? n : '0' + n
}
//时间戳转为时间
function unixtoTime(ns,format='') {
var result;
var time = new Date(ns*1000);
//result=format || 'YYYY年MM月DD日 HH时II分SS秒 WW';
result=format || 'YYYY年MM月DD日 HH时II分SS秒';
//console.log(format);
result=result.toUpperCase();
result=result.replace('YYYY',time.getFullYear());
var m=time.getMonth()+1;
result=result.replace('MM',m>9?m:"0"+m);
var d=time.getDate();
result=result.replace('DD',d>9?d:'0'+d);
var hh=time.getHours();
result=result.replace('HH',hh>9?hh:'0'+hh);
var ii=time.getMinutes();
result=result.replace('II',ii>9?ii:'0'+ii);
var ss=time.getSeconds();
result=result.replace('SS',ss>9?ss:'0'+ss);
var week;
switch (time.getDay()) {
case 0:week="日";break
case 1:week="一";break
case 2:week="二";break
case 3:week="三";break
case 4:week="四";break
case 5:week="五";break
case 6:week="六";break
}
result=result.replace('WW',week);
if(format.indexOf('DAY')>0){
// 获取当天 0 点的时间戳
var timeStamp = new Date(new Date().setHours(0, 0, 0, 0)) / 1000;
function unixtoTime(ns, format = '') {
var result;
var time = new Date(ns * 1000);
//result=format || 'YYYY年MM月DD日 HH时II分SS秒 WW';
result = format || 'YYYY年MM月DD日 HH时II分SS秒';
//console.log(format);
result = result.toUpperCase();
result = result.replace('YYYY', time.getFullYear());
var m = time.getMonth() + 1;
result = result.replace('MM', m > 9 ? m : "0" + m);
var d = time.getDate();
result = result.replace('DD', d > 9 ? d : '0' + d);
var hh = time.getHours();
result = result.replace('HH', hh > 9 ? hh : '0' + hh);
var ii = time.getMinutes();
result = result.replace('II', ii > 9 ? ii : '0' + ii);
var ss = time.getSeconds();
result = result.replace('SS', ss > 9 ? ss : '0' + ss);
var week;
switch (time.getDay()) {
case 0:
week = "日";
break
case 1:
week = "一";
break
case 2:
week = "二";
break
case 3:
week = "三";
break
case 4:
week = "四";
break
case 5:
week = "五";
break
case 6:
week = "六";
break
}
result = result.replace('WW', week);
if (format.indexOf('DAY') > 0) {
// 获取当天 0 点的时间戳
var timeStamp = new Date(new Date().setHours(0, 0, 0, 0)) / 1000;
var day1 = timeStamp+86400//今天结束
var day2 = day1+86400//明天结束
var day1 = timeStamp + 86400//今天结束
var day2 = day1 + 86400//明天结束
//console.log('ns<day.getTime()',timeStamp,ns,day1,day2)
//console.log('ns<day.getTime()',timeStamp,ns,day1,day2)
if(ns>=timeStamp && ns<day1){
result=result.replace('DAY','今天');
}else{
if(ns>=day1 && ns<day2){
result=result.replace('DAY','明天');
}else{
result=result.replace('DAY','');
}
}
}
if(format.indexOf('`')>-1){
result=result.replace(/`(.*)\/(.*)`/ig,function($0,$1,$2){
return $1||$2;
});
if (ns >= timeStamp && ns < day1) {
result = result.replace('DAY', '今天');
} else {
if (ns >= day1 && ns < day2) {
result = result.replace('DAY', '明天');
} else {
result = result.replace('DAY', '');
}
}
return result;
}
if (format.indexOf('`') > -1) {
result = result.replace(/`(.*)\/(.*)`/ig, function ($0, $1, $2) {
return $1 || $2;
});
}
return result;
}
//时间转为时间戳
function timetouUnix(dasr,connect)
{
if(connect){
var newstr = dasr.replace(/-/g,connect);
}else{
var newstr = dasr.replace(/-/g,'/');
}
function timetouUnix(dasr, connect) {
if (connect) {
var newstr = dasr.replace(/-/g, connect);
} else {
var newstr = dasr.replace(/-/g, '/');
}
var date = new Date(newstr);
var time_str = date.getTime().toString();
return time_str.substr(0, 10);
var date = new Date(newstr);
var time_str = date.getTime().toString();
return time_str.substr(0, 10);
}
//支付
function orderPay(charge){
var that=this;
console.log(charge);
var obj = JSON.parse(charge)
console.log('obj:',obj);
wx.requestPayment({
'timeStamp': obj.timeStamp,
'nonceStr': obj.nonceStr,
'package': obj.package,
'signType': 'MD5',
'paySign': obj.paySign,
'success':function(res){
console.log('success:',res);
},
'fail':function(res){
console.log('fail:',res);
module.exports = {
formatTime: formatTime,
unixtoTime: unixtoTime,
timetouUnix: timetouUnix,
cgi: function (act) {
return uri.HOST__LINE + act //正式
//return uri.HOST__TEST+act //测试
},
wxApiIsUse: function (api) {
if (wx.canIUse(api)) {
return true;
} else {
this.alert('当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。');
}
},
openXcx: function (data) {
if (this.wxApiIsUse('navigateToMiniProgram')) {
wx.navigateToMiniProgram({
appId: data.appId,
path: data.path,
extraData: {
foo: 'bar'
},
'complete':function(res){
envVersion: 'trial',
//envVersion: '',
success(res) {
// 打开成功
}
})
}
},
loading: function (flag) {
if (flag == 'clear' || flag == "clean") {
wx.hideNavigationBarLoading();
return;
}
wx.showNavigationBarLoading();
},
alert: function (msg, success, cancel, title) {
wx.showModal({
title: title ? title : "提示信息",
content: msg,
showCancel: typeof cancel == 'undefined' ? false : true,
success: function (res) {
if (res.confirm) {
if (success) success();
} else {
if (cancel) cancel();
}
}
});
},
toast: function (title, icon = 'success') {
wx.showToast({
title: title,
icon: icon
})
},
showLoading: function (title) {
wx.showLoading({
title: '加载中',
})
}
module.exports = {
formatTime: formatTime,
unixtoTime:unixtoTime,
timetouUnix:timetouUnix,
orderPay:orderPay,
cgi:function(act){
return uri.HOST__LINE+act //正式
//return uri.HOST__TEST+act //测试
},
wxApiIsUse:function(api){
if(wx.canIUse(api)){
return true;
}else{
this.alert('当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。');
}
},
openXcx:function(data){
if(this.wxApiIsUse('navigateToMiniProgram')){
wx.navigateToMiniProgram({
appId: data.appId,
path: data.path,
extraData: {
foo: 'bar'
},
envVersion: 'trial',
//envVersion: '',
success(res) {
// 打开成功
}
})
}
},
loading:function(flag){
if(flag=='clear' || flag=="clean"){
wx.hideNavigationBarLoading();
return;
}
wx.showNavigationBarLoading();
},
postSuccessFun:function(json,uri_code){
console.log("APP::postSuccessFun",uri_code,json);
},
postFailFun:function(json,uri_code){
console.log(json,uri_code);
},
getToken:function(n_function){
var token=this.cache(uri.CACHE__TOKEN);
console.log("token:",token);
if(!token) {
this.loginStart(n_function);
return;
}
return token;
},
asyn:function(act,data,uri_code,n_function){//静默方式,不带loading
data=data||{};
var that=this;
data.token=that.cache(uri.CACHE__TOKEN);
wx.request({
url: that.cgi(act),
method:'POST',
data: data,
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function(res) {
console.log('request==>',that.http_build_query(data,that.cgi(act))+'\nrequest.success',res.data);
that.loading('clear');
if(n_function){
that.loginStart(n_function);
}
/*if(typeof res.data!='string'){
if(res.data.code!=200&&res.data.code!=1000){
console.log(res.data.code==-1,res.data.code);
if(res.data.code==-1) {
that.loginStart(n_function);
return;
}else{
that.alert(res.data.message);
return;
}
}
}*/
that.postSuccessFun(res.data,uri_code);
},
fail: function(res) {
console.log('request==>',that.http_build_query(data,that.cgi(act))+'\nrequest.fail',res);
that.loading('clear');
that.toast(res.errMsg);
that.postFailFun(res.data,uri_code);
}
})
},
post:function(act,data,uri_code,is_load,n_function,header={'Content-Type': 'application/x-www-form-urlencoded'}){
console.log('act:',act)
if(is_load!='0'){
this.loading();
}
this.asyn(act,data,uri_code,n_function,header);
},
upload:function(filePath,fileIndex,uri_code,sellerid,type,file){
var that=this;
this.loading();
if(this.wxApiIsUse('uploadFile')){
wx.uploadFile({
url: that.cgi('Seller/Index/UploadImages'),
filePath: filePath,
name: 'file',
formData:{
sellerid:sellerid,
type:type
},
success: function(res){
that.loading('clear');
that.postSuccessFun(res.data,uri_code,fileIndex);
},
fail: function(res) {
that.loading('clear');
that.toast("上传失败,请重试");
that.postFailFun(res.data,uri_code,fileIndex);
}
});
}
},
uploading:function(filePath,fileIndex,dir,uri_code,file){
var that=this;
this.loading();
console.log(filePath,fileIndex,dir,uri_code);
if(this.wxApiIsUse('uploadFile')){
wx.uploadFile({
url: 'https://xt05.colorcun.com/?s=App.Cookbook.UpLoadFile',
filePath: filePath,
name: 'file',
formData:{
dir:dir
},
success: function(res){
console.log('上传成功')
console.log(res)
that.loading('clear');
that.postSuccessFun(res.data,uri_code,fileIndex);
},
fail: function(res) {
that.toast("上传失败,请重试");
that.postFailFun(res.data,uri_code,fileIndex);
}
});
}
},
uploadImg:function(filePath,fileIndex,uri_code){
var that=this;
if(this.wxApiIsUse('uploadFile')){
wx.uploadFile({
url: that.cgi('bargainimage'),
filePath: filePath,
name: 'path',
formData:{
'token': that.getToken()
},
success: function(res){
console.log(res);
res.data=JSON.parse(res.data);
if(res.data.code!=200){
if(res.data.code==-1) {
wx.navigateTo({url:'/pages/login/index'});
return;
}else{
that.alert(res.data.message);
}
}
console.log("res-code-data",uri_code,res.data);
that.postSuccessFun(res.data,uri_code,fileIndex);
},
fail:function(res){
console.log(res);
}
});
}
},
download:function(id,uri_code,width){
var that=this;
this.loading();
if(this.wxApiIsUse('downloadFile')){
wx.downloadFile({
url: that.cgi('download'),
success: function(res) {
console.log("res-code-data",uri_code,res);
wx.playVoice({
filePath: res.tempFilePath
})
that.postSuccessFun(id,uri_code,width,res.data);
}
});
}
},
alert:function(msg,success,cancel,title){
wx.showModal({
title:title?title:"提示信息",
content:msg,
showCancel:typeof cancel=='undefined'?false:true,
success:function(res){
if(res.confirm){
if(success) success();
}else{
if(cancel) cancel();
}
}
});
},
toast:function(title,icon='success'){
wx.showToast({
title:title,
icon:icon
})
},
showLoading:function(title){
wx.showLoading({
title: '加载中',
})
},
getCommonType:function(key){
var that=this;
var common = that.cache(uri.CACHE__COMMON) || {time:0};
var time=Date.now();
if(common.time<time-600000){
wx.request({
url: that.cgi('commontype'),
header: {
'Content-Type': 'application/json'
},
success: function(res) {
if(res.data.code==200){
common={data:res.data.data,time:time};
//wx.setStorageSync(uri.CACHE__COMMON,common);
that.cache(uri.CACHE__COMMON,common)
}
}
})
}
if(!key) return common.data;
common = that.cache(uri.CACHE__COMMON) || {time:0};
return common.data[key];
},
getCommonTag:function(key,v_id){
var that=this;
var tagsdata=this.cache(uri.CACHE__COMMONTAG);
if(!tagsdata){
wx.request({
url: that.cgi(uri.CGI__USER_TCOMMONTAG),
data:{
'token': that.getToken()
},
header: {
'Content-Type': 'application/json'
},
success: function(res) {
if(res.data.code==200){
that.cache(uri.CACHE__COMMONTAG,res.data.data);
}
}
})
}
tagsdata=this.cache(uri.CACHE__COMMONTAG);
var result;
if(v_id){
tagsdata[key].map(function(v){
if(v.id==v_id){
result=v.tag_name;
}
})
}else{
result=tagsdata[key];
}
return result;
},
cache:function(key,value){
if(value){
wx.setStorageSync(key,value);
}
return wx.getStorageSync(key);
},
remove:function(key){
if(key){
wx.removeStorage({key: key})
}
},
image:function(id,width=""){
var url=this.cgi(uri.CGI__DOWNLOAD+'/id/'+id);
if(width){
url+='/width/'+width;
}
return url;
},
avatar:function(id,t='pu'){
return this.cgi(uri.CGI__AVATAR +'/'+t+'/'+id);
},
trim:function(str){
return str.replace(/^([ ]+)/,"").replace(/([ ]+)$/,"");
},
clear:function(str){//去除html标签
return this.trim(str.replace(/<[^>]+>/ig,""));
},
clearHtml:function(html){//去除html中特殊字符
html=html.replace(/[\n\r\t]+/ig,'');
html=html.replace(/<html[^>]*>(.*)<body[^>]*>/ig,'');
html=html.replace(/<div[^>]*>(.*)<article[^>]*>/ig,'');
html=html.replace(/<\/article[^>]*>(.*)<\/div[^>]*>/ig,'');
html=html.replace(/<style[^>]*>(.*)<\/style>/ig,'');
html=html.replace(/<\/body.*/ig,'');
html=html.replace(/<!--[^>]+>/ig,'');
html=html.replace(/&quot;/ig,'');
return html;
},
val:function(e,key=''){
if(key!='') return e.detail.value[key]||'';
return e.detail.value;
},
attr:function(e,key=''){
if(!key){
return e.currentTarget.dataset
}
return e.currentTarget.dataset[key];
},
extend:function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
},
getToken:function(n_function){
var token=this.cache(uri.CACHE__TOKEN);
console.log("token:",token);
if(!token) {
this.loginStart(n_function);
return;
}
return token;
},
loginStart:function(n_function){
console.log("n_function:",n_function,1111);
var that=this;
wx.login({
success: function(login_res) {
if (login_res.code) {
console.log('success');
console.log('wx.login.res' , login_res);
that.cache(uri.CACHE__LOGINCODE,login_res.code);
wx.getUserInfo({
success: function(res) {
res.code=login_res.code;
console.log('wx.getProviderInfo.res' , res);
var data={
code:login_res.code,
encryptData:res.encryptData,
encryptedData:res.encryptedData,
iv:res.iv,
rawData:res.rawData,
signature:res.signature,
appid:'wxc359908817c7bdd9',
secret:'a14a8415a501ade9542968d8a6504820',
}
wx.request({
url: that.cgi(uri.CGI__USER_XCXLOGIN),
data: data,
header: {
'content-type': 'application/json'
},
success: function(res) {
that.cache('setting','success');
that.cache(uri.CACHE__LOGINCODE,login_res.code);
/*if(n_function){
var pagelength=getCurrentPages().length;
console.log("pagelength:",pagelength);
console.log("getCurrentPages:",getCurrentPages());
if(typeof getCurrentPages()[pagelength-1][n_function]()!='undefined'){
getCurrentPages()[pagelength-1][n_function]();
}
}*/
return;
}
})
},
fail:function(){
that.cache('loginfail','fail');
if(n_function){
var pagelength=getCurrentPages().length;
console.log('hahahah');
getCurrentPages()[pagelength-1].onShow();
}
}
});
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
});
},
//重新调起授权
userInfoHandler:function(etarget){
if(this.wxApiIsUse('button.open-type.getUserInfo')){
if(etarget.detail&& etarget.detail.errMsg=='getUserInfo:ok'){
return true
//this.dc_loginStart()
}
}
},
getAccess_token: function (a, s, n_tempmessage) {
var that = this;
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + a + '&secret=' + s, //仅为示例,并非真实的接口地址
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log('access_token!!!!console:', res)
console.log('access_token:', res.data.access_token)
that.sendMessage(res.data.access_token, n_tempmessage);
}
})
},
//模板消息
sendMessage: function (a_t, dd) {
var that = this;
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=' + a_t, //仅为示例,并非真实的接口地址
data: dd,
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log('发送模板消息:',res)
//that.sendMessuc(res);
}
})
},
//获取当前网络状态
getNetwork:function(){
var that=this;
if(this.wxApiIsUse('getNetworkType')){
wx.getNetworkType({
success: function(res) {
that.getNetworkSuccess(res.networkType);
},
fail:function(res){
that.toast('获取网络状况失败!');
}
})
}
},
getNetworkSuccess:function(network){
return network;
},
compare:function(property){
return function(a,b){
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
}
},
getJsonLength:function(jsonData){
var jsonLength = 0;
for(var item in jsonData){
jsonLength++;
}
return jsonLength;
},
testPhone:function(phone){
if(!/^1[3-9][0-9]{9}$/.test(phone)){
this.alert("请输入正确的电话号码");
return false;
}
},
//加入卡包
addInCard:function(sellerid){
var that = this;
wx.request({
url: that.cgi(uri.CGI__USER_GETSIGNOPENCARD),
method:'GET',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data:{
sellerid:1,
},
success: function(res) {
console.log(res)
var cardExtstr = res.data.data.cardExt
var cardId = res.data.data.cardid
console.log('cardExtstr:',cardExtstr);
wx.addCard({
cardList: [
{
cardId: cardId,
cardExt: cardExtstr,
}
],
success: function(res) {
console.log('success:',res)
that.cache('cardList',res.cardList);
},
fail:function(res) {
console.log('fail:',res)
},
})
}
})
},
//保存图片
saveImage: function(url){
var that = this;
wx.downloadFile({
url:url,
success:function(res){
var path = res.tempFilePath
wx.saveImageToPhotosAlbum({
filePath: path,
success(res) {
},
//保存图片重新授权
fail(res) {
wx.openSetting({
success: (res) => {
res.authSetting = {
"scope.writePhotosAlbum": true
}
}
})
},
})
},
fail:function(res){
}
})
},
//根据source判断会员卡1 或优惠券2
sourceFrom:function(){
var source = this.cache('source')
console.log('source:',source)
var title = ''
if(source==1){
title = '会员卡'
}else{
title = '优惠券'
}
wx.setNavigationBarTitle({
title:title
})
return source
},
//返回会员卡 优惠券的开通进度
stepSetting:function(stepnum){
var source = this.cache('source')
var step = {
content:['会员卡开通','会员卡设置','发放确认','发放完成'],
step:[{id:'0'},{id:'1'},{id:'2'},{id:'3'}],
stepnum:stepnum
}
if(step&&source==2){
step.content[0] = '优惠券开通'
step.content[1] = '优惠券设置'
}
return step
},
setBarTitle:function(title){
wx.setNavigationBarTitle({
title:title
})
},
//小数规则:小数只能存在一个小数点并且至多保留两位小数 数字首位可以为0 第二位不能为0
limitDigit:function(value,firsezero){
if(value.length==1&value=='.'){
value = '0'+'.'
}
if(value=='00'){
value = '0'
}
value = value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
value = value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
//firsezero存在 首位不能为0
if(firsezero){
if(value.indexOf(".")< 0 && value !=""){//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
value= parseFloat(value);
}
}
return value
},
},
cache: function (key, value) {
if (value) {
wx.setStorageSync(key, value);
}
return wx.getStorageSync(key);
},
remove: function (key) {
if (key) {
wx.removeStorage({key: key})
}
},
image: function (id, width = "") {
var url = this.cgi(uri.CGI__DOWNLOAD + '/id/' + id);
if (width) {
url += '/width/' + width;
}
return url;
},
//
isEOne : function(arr,value){
for(var i = 0,vlen = arr.length; i < vlen; i++){
if(arr[i] == value){
return i;
}
}
return -1;
},
linkTo:function(url,sellerid,code){
var path='pages/menu/'+url;
if(code!=''){
path+='?sellerid='+sellerid+'&code='+code
}
if(sellerid!=''){
path+='?sellerid='+sellerid
}
avatar: function (id, t = 'pu') {
return this.cgi(uri.CGI__AVATAR + '/' + t + '/' + id);
},
trim: function (str) {
return str.replace(/^([ ]+)/, "").replace(/([ ]+)$/, "");
},
clear: function (str) {//去除html标签
return this.trim(str.replace(/<[^>]+>/ig, ""));
},
val: function (e, key = '') {
if (key != '') return e.detail.value[key] || '';
return e.detail.value;
},
attr: function (e, key = '') {
if (!key) {
return e.currentTarget.dataset
}
return e.currentTarget.dataset[key];
},
extend: function (destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
},
compare: function (property) {
return function (a, b) {
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
}
},
getJsonLength: function (jsonData) {
var jsonLength = 0;
for (var item in jsonData) {
jsonLength++;
}
return jsonLength;
},
testPhone: function (phone) {
if (!/^1[3-9][0-9]{9}$/.test(phone)) {
this.alert("请输入正确的电话号码");
return false;
}
},
setBarTitle: function (title) {
wx.setNavigationBarTitle({
title: title
})
},
//
isEOne: function (arr, value) {
for (var i = 0, vlen = arr.length; i < vlen; i++) {
if (arr[i] == value) {
return i;
}
}
return -1;
},
linkTo: function (url, sellerid, code) {
var path = 'pages/menu/' + url;
if (code != '') {
path += '?sellerid=' + sellerid + '&code=' + code
}
if (sellerid != '') {
path += '?sellerid=' + sellerid
}
console.log(path)
wx.navigateToMiniProgram({
appId: 'wx52646daaa3f42a4f',
path: path,
envVersion: 'release',
success: function (res) {
console.log(path)
wx.navigateToMiniProgram({
appId: 'wx52646daaa3f42a4f',
path: path,
envVersion: 'release',
success:function(res) {
console.log(path)
}
})
},
setting:function(){
if(wx.canIUse('openSetting')==true){
wx.openSetting({
success:function(res){
console.log(res.authSetting)
return res.authSetting
}
})
}
},
//获取设备信息
getsystem:function(){
try {
var res = wx.getSystemInfoSync()
return res;
} catch (e) {
return false
}
},
http_build_query(obj,url=''){
let ps=[]
for(let i in obj){
if(typeof obj[i]=='undefined' || obj[i]==null || obj[i]===false) continue;
ps.push(i+'='+obj[i].toString())
}
ps=ps.join('&');
if(!url){
return ps;
}
url+=(url.indexOf('?')>-1?'&':'?')+ps;
return url;
}
})
},
setting: function () {
if (wx.canIUse('openSetting') == true) {
wx.openSetting({
success: function (res) {
console.log(res.authSetting)
return res.authSetting
}
})
}
},
//获取设备信息
getsystem: function () {
try {
var res = wx.getSystemInfoSync()
return res;
} catch (e) {
return false
}
},
http_build_query(obj, url = '') {
let ps = []
for (let i in obj) {
if (typeof obj[i] == 'undefined' || obj[i] == null || obj[i] === false) continue;
ps.push(i + '=' + obj[i].toString())
}
ps = ps.join('&');
if (!url) {
return ps;
}
if(ps){
url += (url.indexOf('?') > -1 ? '&' : '?') + ps;
}
return url;
},
/**
* @param edata is object: ename,edata
*/
elog(edata,ename='EVENT_NAME') {
let key='EVENT_LOG_CACHE'
let ps=getCurrentPages();
console.log(ps)
let page=ps[ps.length-1]
edata=edata?edata:{}
edata.curPage={
path:page.route,
options:page.options,
}
let eobj={
ename:ename,
edata:edata,
page:this.http_build_query(page.options,page.route),
time:parseInt(new Date()/1000),
}
wx.getStorage({
key:key,
success:res=>{
let data=res.data||[]
data.push(eobj)
wx.setStorage({
key:key,
data:data,
})
},
fail:res=>{
let data=[eobj]
wx.setStorage({
key:key,
data:data,
})
},
})
},
}
... ...