Commit a55d33d9d81b933035b77a8e8ecf219b3658f83b

Authored by vking
1 parent d5fff0b7

master-rewrite-addnew

  1 +// pack-book/components/book/time/add-time-dur.js
  2 +var util = require('../../../../utils/util.js')
  3 +import App from '../../../../utils/api';
  4 +const timeSort=['morning', 'noon', 'night'];
  5 +const timeConfig= {
  6 + 'morning':{
  7 + name:'早市',
  8 + defTime:'',
  9 + },
  10 + 'noon':{
  11 + name:'午市',
  12 + defTime:'12:00',
  13 + },
  14 + 'night': {
  15 + name: '晚市',
  16 + defTime: '18:30'
  17 + },
  18 +}
  19 +Component({
  20 + /**
  21 + * 组件的属性列表
  22 + */
  23 + properties: {
  24 + solt:{//ddate_solt,时段,修改或从桌位过来使用
  25 + type:Number,
  26 + value:-1,
  27 + },
  28 + date:{//0今天,1明天,2其它
  29 + type:Number,
  30 + value:-1,
  31 + },
  32 + ddate:{//到店时间
  33 + type:Number,
  34 + value:-1,
  35 + }
  36 + },
  37 + lifetimes: {
  38 + attached: function () {
  39 + //console.log('add-time-dur.attached')
  40 + },
  41 + moved: function () { },
  42 + detached: function () { },
  43 + },
  44 + observers:{
  45 + "solt,date":async function(solt,date){
  46 + if(solt<0) return;
  47 + console.log('add-time-dur.observers',arguments)
  48 + this.config=null
  49 + this.ddate_solt=-1
  50 + this.initSolt()//初始化solt
  51 + }
  52 + },
  53 + /**
  54 + * 组件的初始数据
  55 + */
  56 + data: {
  57 + ddate_solt:-1,
  58 + config:[],
  59 + },
  60 +
  61 + /**
  62 + * 组件的方法列表
  63 + */
  64 + methods: {
  65 + async initSolt(){//初始化solt
  66 + if(this.initSoltIng) return false
  67 + this.initSoltIng=true
  68 + await this.getConfig();//时段配置
  69 + this.initSoltIng=false
  70 + },
  71 + async getConfig(){//时段配置
  72 + let res = await App.Reserve.SellerInfo(util.cache('enter_params'));
  73 + let daily = res.data.daily;
  74 + console.log('add-time-dur.daily',daily)
  75 + this.initUserTime(daily)
  76 + if(this.data.solt>-1){
  77 + this.initSoltTime()
  78 + }
  79 + this.trigger();
  80 + },
  81 + initUserTime(daily){
  82 + let config=[]
  83 + let time=parseInt(new Date()/1000);
  84 + let HHII=util.unixtoTime(time,"HH:II")
  85 + timeSort.forEach((en_name,ti)=>{
  86 + let dur=daily[en_name];
  87 + let min='',max='',hasShow=false,hasDisabled=false,hasChecked=false
  88 + if(dur){
  89 + hasShow=true
  90 + dur=dur.split('-');
  91 + min=dur[0];
  92 + max=dur[1];
  93 + if(HHII>=min && HHII<=max){
  94 + hasChecked=true
  95 + this.ddate_solt=ti
  96 + }
  97 + if(HHII>max && this.data.date==0){
  98 + hasDisabled=true
  99 + }
  100 + }
  101 + config.push({
  102 + name:timeConfig[en_name].name,
  103 + en_name:en_name,
  104 + hasShow:hasShow,
  105 + min:min,
  106 + max:max,
  107 + hasDisabled:hasDisabled,
  108 + hasChecked:hasChecked,
  109 + defTime:timeConfig[en_name].defTime
  110 + });
  111 + })
  112 + this.config=config;
  113 + this.setData({
  114 + config:this.config,
  115 + ddate_solt:this.ddate_solt,
  116 + })
  117 + },
  118 + initSoltTime(){//修改或快速预订
  119 + this.ddate_solt=this.data.solt
  120 + this.config.forEach((t,ti)=>{
  121 + t.hasDisabled=false
  122 + t.hasChecked=ti==this.ddate_solt
  123 + })
  124 + this.setData({
  125 + config:this.config,
  126 + ddate_solt:this.ddate_solt,
  127 + })
  128 + },
  129 + selectedValue(e){
  130 + console.log('add-time-dur.selectedValue',e)
  131 + this.ddate_solt=util.attr(e,'value')
  132 + this.config.forEach((t,ti)=>{
  133 + t.hasDisabled=false
  134 + t.hasChecked=ti==this.ddate_solt
  135 + })
  136 + this.setData({
  137 + config:this.config,
  138 + ddate_solt:this.ddate_solt,
  139 + })
  140 + this.trigger();
  141 + },
  142 + initTimeSpaceIndex(){//对选中时段进行展开
  143 + if(this.ddate_solt<0) return;
  144 + console.log('add-time-dur.tindex',this.ddate_solt,this.config[this.ddate_solt])
  145 + let min=this.config[this.ddate_solt].min
  146 + let max=this.config[this.ddate_solt].max
  147 + let defTime=this.config[this.ddate_solt].defTime
  148 + let time
  149 + if(this.data.ddate>0){
  150 + time=parseInt(this.data.ddate);
  151 + }else{
  152 + time=parseInt(new Date()/1000);
  153 + }
  154 + min=util.timetouUnix(util.unixtoTime(time,"YYYY-MM-DD "+min+":00"))
  155 + max=util.timetouUnix(util.unixtoTime(time,"YYYY-MM-DD "+max+":00"))
  156 + if(defTime && !this.data.ddate){//非修改时,优先默认时间
  157 + defTime=util.timetouUnix(util.unixtoTime(time,"YYYY-MM-DD "+defTime+":00"))
  158 + if(defTime>time){
  159 + time=defTime
  160 + }
  161 + }
  162 + let dur,timeCheckedIndex=0,list=[];
  163 + for(dur=parseInt(min);dur<=max;dur+=1800){
  164 + let t={
  165 + hasChecked:time<=dur,
  166 + time:dur,
  167 + //timeStr:util.unixtoTime(dur,"YYYY-MM-DD HH:II:SS")
  168 + }
  169 + list.push(t)
  170 + if(dur<=time){
  171 + timeCheckedIndex++
  172 + }
  173 + }
  174 + console.log('add-time-dur.tindex',timeCheckedIndex,list)
  175 + return {list:list,listIndex:timeCheckedIndex}
  176 + },
  177 + trigger(){
  178 + let timeList=this.initTimeSpaceIndex()
  179 + this.triggerEvent('event',{
  180 + ddate_solt:this.ddate_solt,
  181 + ...timeList,
  182 + })
  183 + }
  184 + }
  185 +})
  1 +{
  2 + "component": true,
  3 + "usingComponents": {}
  4 +}
  1 +<!--pack-book/components/book/time/add-time-dur.wxml-->
  2 +<view class="tab flex-ll">
  3 + <block wx:for="{{config}}" wx:key="config-key">
  4 + <view class="item {{item.hasChecked?'checked':''}} {{item.hasDisabled?'disabled':''}}"
  5 + wx:if="{{item.hasShow}}"
  6 + bindtap="{{item.hasDisabled?'':'selectedValue'}}" data-value="{{index}}">
  7 + <view class="picker">{{item.name}}</view>
  8 + </view>
  9 + </block>
  10 +</view>
  1 +/* pack-book/components/book/time/add-time-dur.wxss */
  2 +@import "../../../app.wxss";
  3 +.tab{
  4 + font-size: 34rpx;
  5 + color: #199095;
  6 +}
  7 +.tab .item{
  8 + height: 50rpx;
  9 + line-height: 49rpx;
  10 + width: 210rpx !important;
  11 + min-width: 210rpx !important;
  12 + border-radius: 10rpx;
  13 + border: 2rpx solid #199095;
  14 + margin-right: 20rpx;
  15 + text-align: center;
  16 +}
  17 +.tab .item .item-text,.section .tab .item .picker{
  18 + height: 46rpx;
  19 + line-height: 46rpx;
  20 +}
  21 +.tab .item .picker{
  22 + width:210rpx;
  23 + text-align: center;
  24 +}
  25 +.tab .item-pnum{
  26 + height: 50rpx;
  27 + line-height: 50rpx;
  28 + width: 60rpx !important;
  29 + min-width: 60rpx !important;
  30 + border-radius: 10rpx;
  31 + border: 2rpx solid #199095;
  32 + margin-right: 32rpx;
  33 + text-align: center;
  34 +}
  35 +.tab .item-pnum .pnum,.tab .item .pnum input{
  36 + height: 46rpx;
  37 + line-height: 46rpx;
  38 + font-size: 34rpx;
  39 +}
  40 +.tab .item:last-child{
  41 + margin-right: 0;
  42 +}
  43 +.tab .item-pnum:last-child{
  44 + margin-right: 0;
  45 +}
  46 +.tab .checked{
  47 + background-color:#199095;
  48 + color: #FEFEFE;
  49 + border: 2rpx solid #199095;
  50 +}
  51 +.tab .disabled{
  52 + background-color:#999999;
  53 + color: #efefef;
  54 + border: 2rpx solid #999999;
  55 +}
@@ -909,5 +909,11 @@ Page({ @@ -909,5 +909,11 @@ Page({
909 this.setData({ 909 this.setData({
910 CustomRemarkMoreMask:!this.data.CustomRemarkMoreMask 910 CustomRemarkMoreMask:!this.data.CustomRemarkMoreMask
911 }) 911 })
912 - } 912 + },
  913 + addTimeDurEvent(e){
  914 + console.log('add-time-dur.event',e);
  915 + this.setData({
  916 + [`form.time`]:e.detail.ddate_solt,
  917 + })
  918 + },
913 }) 919 })
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 "searchList":"/components/searchlist/searchlist", 9 "searchList":"/components/searchlist/searchlist",
10 "calendar": "plugin://bmCalendar/calendar", 10 "calendar": "plugin://bmCalendar/calendar",
11 "board":"../../components/book/board/board", 11 "board":"../../components/book/board/board",
12 - "formids":"/components/formids/formids" 12 + "formids":"/components/formids/formids",
  13 + "add-time-dur":"../../components/book/time/add-time-dur"
13 } 14 }
14 } 15 }
@@ -40,6 +40,9 @@ @@ -40,6 +40,9 @@
40 </view> 40 </view>
41 </view> 41 </view>
42 </view> 42 </view>
  43 + <view class="section">
  44 + <add-time-dur date="{{form.date}}" solt="{{detail.time.kk}}" bindevent="addTimeDurEvent"></add-time-dur>
  45 + </view>
43 <view class="section "> 46 <view class="section ">
44 <view class="tab flex-ll"> 47 <view class="tab flex-ll">
45 <formids class="item {{form.time==0?'checked':''}} {{timeOpt[0]}}" 48 <formids class="item {{form.time==0?'checked':''}} {{timeOpt[0]}}"
@@ -5,11 +5,14 @@ @@ -5,11 +5,14 @@
5 "es6": true, 5 "es6": true,
6 "enhance": true, 6 "enhance": true,
7 "postcss": true, 7 "postcss": true,
  8 + "preloadBackgroundData": false,
8 "minified": true, 9 "minified": true,
9 "newFeature": true, 10 "newFeature": true,
10 "coverView": true, 11 "coverView": true,
11 "nodeModules": true, 12 "nodeModules": true,
12 "autoAudits": false, 13 "autoAudits": false,
  14 + "showShadowRootInWxmlPanel": true,
  15 + "scopeDataCheck": false,
13 "uglifyFileName": false, 16 "uglifyFileName": false,
14 "checkInvalidKey": true, 17 "checkInvalidKey": true,
15 "checkSiteMap": true, 18 "checkSiteMap": true,
@@ -527,7 +530,7 @@ @@ -527,7 +530,7 @@
527 "id": 64, 530 "id": 64,
528 "name": "pack-book/pages/book/b_addnew 桌位进入", 531 "name": "pack-book/pages/book/b_addnew 桌位进入",
529 "pathName": "pack-book/pages/book/b_addnew", 532 "pathName": "pack-book/pages/book/b_addnew",
530 - "query": "id=43844", 533 + "query": "",
531 "scene": null 534 "scene": null
532 }, 535 },
533 { 536 {