Sanakey
2021-05-22 f46177f2ce3a33218e4d018b410d6eb978764d20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import * as dayjs from "dayjs";
type timeType = 'startTime'|'endTime';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isShowStartDatePopup:false,
    isShowEndDatePopup:false,
    minStartDate: new Date().getTime() + 1000 * 60 * 15,
    maxStartDate: new Date().getTime() + 1000 * 60 * 60 * 24 * 180,
    startDate: new Date().getTime() + 1000 * 60 * 60, //new Date().getTime(),
    startTime: '',
    startDateAndTime: [] as any,
    minEndDate: new Date().getTime() + 1000 * 60 * 45,
    maxEndDate: new Date().getTime() + 1000 * 60 * 60 * 24 * 180,
    endDate: new Date().getTime() + 1000 * 60 * 240, //new Date().getTime(),
    endTime: '',
    endDateAndTime: [] as any,
    formatter(type:string, value:string) {
      // console.log(type,value)
      if (type === "year") {
        return `${value}年`;
      } else if (type === "month") {
        return `${value}月`;
      } else if (type === "day") {
        return `${value}日`;
      }
      return value;
    },
    doccode:'',
    qrCodeUrl:"", //https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr
  },
 
 
  /**
   * 检查
   */
 
  async onSubmit() {
    let data = {
      docCode:this.data.doccode,
      startTime:`${this.data.startTime}:00`,
      endTime:`${this.data.endTime}:00`,
    };
    let checkStartTime = this.checkTime("startTime", "请选择计划开始时间");
    let checkEndTime = this.checkTime("endTime", "请选择计划结束时间");
    console.log('待提交数据',data);
    if (!checkStartTime||!checkEndTime){
      return;
    }
    let [error, result] = await wx.$utils.to(
      wx.$http.request({
        url:`/shopping/panicBuyingLive/saveRoomStep3.do`,
        data,
        method: 'POST'
      })
    )
    if (error){
      console.log(error);
      return;
    }
    console.log("新建房间--第三步",result);
    if (result.qrcodeUrl){
      let authentication =this.selectComponent('#my-anchor-authentication');
      authentication.showQrCodeDialog(result.qrcodeUrl);
      return;
    }
    if (result.state=='success'){
      wx.navigateBack({
        delta: 3
      })
    }
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let doccode = options.doccode || '';
    let currentLiveRoomData = wx.globalData.currentLiveRoomData;
    console.log('正在编辑的直播间数据',currentLiveRoomData);
    if (currentLiveRoomData&&JSON.stringify(currentLiveRoomData) != '{}'){
      let startDate = this.data.startDate;
      let endDate = this.data.endDate;
      let lives = {
        startTime: currentLiveRoomData.StartTime,
        endTime: currentLiveRoomData.EndTime,
        startDate: currentLiveRoomData.StartTime?new Date(currentLiveRoomData.StartTime).getTime():startDate,
        endDate: currentLiveRoomData.EndTime?new Date(currentLiveRoomData.EndTime).getTime():endDate,
      };
      // if (currentLiveRoomData.StartTime){
      //   startDate =  new Date(currentLiveRoomData.StartTime).getTime()
      // }
      // if (currentLiveRoomData.EndTime){
      //   endDate = new Date(currentLiveRoomData.EndTime).getTime()
      // }
      console.log('已有时间',lives);
      this.setData({
        ...lives,
      })
    }
    this.handleDateAndTime()
    this.setData({
      doccode,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},
  formatTime(time: any) {
    // const date:any = dayjs(time);
    // console.log();
    // return `${date.$y}-${date.$M + 1}-${date.$D} ${date.$H}:${date.$m}`;
    return dayjs(time).format('YYYY-MM-DD HH:mm');
  },
  handleDateAndTime(){
    let waitHandle = this.data;
    let startTime = waitHandle.startTime|| this.formatTime(new Date().getTime() + 1000 * 60 * 60);
    let endTime =waitHandle.endTime|| this.formatTime(new Date().getTime() + 1000 * 60 * 240);
    this.setData({
      startTime,
      endTime,
      startDateAndTime: startTime.split(' '),
      endDateAndTime: endTime.split(' '),
    })
 
  },
  showStartDatePopup(){
    this.setData({
      isShowStartDatePopup: true
    })
  },
  onStartDatePopupClose(){
    this.setData({
      isShowStartDatePopup: false
    })
  },
  onEnterStartDate(event: { detail: any; }) {
    let detail = event.detail;
    const dateTime:any = this.formatTime(event.detail);
    console.log("选择开播时间", dateTime,detail);
    this.setData({
      startDate: detail,
      startTime: dateTime,
      minEndDate: detail + 1000 * 60 * 30,
    });
    this.handleDateAndTime();
    this.onStartDatePopupClose();
    this.checkTime("startTime", "请选择计划开始时间");
  },
  showEndDatePopup(){
    this.setData({
      isShowEndDatePopup: true
    })
  },
  onEndDatePopupClose(){
    this.setData({
      isShowEndDatePopup: false
    })
  },
  onEnterEndDate(event: { detail: any; }) {
    const date:any = this.formatTime(event.detail);
    console.log("选择下播时间", date,event.detail);
    this.setData({
      endTime: date,
      endDate: event.detail,
    });
    // this.triggerEvent('selectedEndTime',{
    //   endTime: date
    // });
    this.handleDateAndTime();
    this.onEndDatePopupClose();
    this.checkTime("endTime", "请选择计划结束时间");
  },
  checkTime(time:timeType, msg:string) {
    if (this.data[time] == '') {
      this.setData({
        [time + "Error"]: msg,
      });
      console.log(this.data.startTime);
      return false;
    }
    let startDate = this.data.startDate;
    let endDate = this.data.endDate;
    console.log(this.data);
    if (time==='startTime'){
      if (startDate&&endDate&&(startDate - endDate > 0)) {
        this.setData({
          ["startTimeError"]: "开始时间需小于结束时间",
        });
        return false;
      }
    }
    if (time==='endTime'){
      if (startDate&&endDate&&(endDate - startDate < 0)) {
        this.setData({
          ["endTimeError"]: "结束时间需大于开始时间",
        });
        return false;
      }
    }
    if (startDate&&endDate&&(Math.abs(startDate - endDate)<1000*60*30)){
      this.setData({
        [time + "Error"]: "所选时间范围间隔不得短于30分钟",
      });
      return false;
    }
    if (startDate&&endDate&&(Math.abs(startDate - endDate)>1000*60*60*24)){
      this.setData({
        [time + "Error"]: "所选时间范围必须在24小时以内",
      });
      return false;
    }
    this.setData({
      ["startTimeError"]: "",
      ["endTimeError"]: "",
    });
    return true;
    // this.handleLiveTime()
  },
});
 
export {}