Sanakey
2021-04-30 8724a444c8a1d09dc8f9efd005e8443aad8df1ab
提交 | 用户 | age
8724a4 1 type CheckField = 'wechatName'|'wechatNumber'|'subAnchorWechat';
f9ad6c 2 // 获取应用实例
S 3 // import appModule from '../../modules/app';
4 Page({
5   data: {
8724a4 6     liveRoomData: {} as any,
S 7     imagesUrl:[] as any,
8     doccode:'',
9     roomid:'',
10     liveStatus: {
11       101: "直播中",
12       102: "未开始",
13       103: "回放",
14       104: "禁播",
15       105: "暂停中",
16       106: "异常",
17       107: "已过期",
18     },
19     showDialog:false,
20     isShowSubAnchorDialog:false,
21     wechatName:'',
22     wechatNumber:'',
23     subAnchorWechat:'',
f9ad6c 24   },
S 25
8724a4 26   getImagesUrl(){
S 27     let {liveRoomData} = this.data;
28     let imagesUrl =  [
29       {
30         url:liveRoomData.ShareImgUnidUrl,
31         name:'分享卡片封面',
32       },
33       {
34         url:liveRoomData.FeedsImgUnidUrl,
35         name:'购物直播频道封面',
36       },
37       {
38         url:liveRoomData.CoverImgUnidUrl,
39         name:'直播间背景墙',
40       }
41     ];
f9ad6c 42     this.setData({
8724a4 43       imagesUrl
S 44     })
f9ad6c 45   },
S 46
8724a4 47   async onLoad(options) {
S 48     let {doccode,roomid} = options;
49     this.setData({
50       doccode,
51       roomid,
52     })
53     this.getLiveRoomDetail();
54
f9ad6c 55   },
8724a4 56   onShow() {
S 57     this.getGoodsListInRoom();
58     this.getAssistantList();
59   },
60   async getLiveRoomDetail(){
61     let {doccode} = this.data;
f9ad6c 62     let [error, result] = await wx.$utils.to(
S 63       wx.$http.request({
8724a4 64         url:`/shopping/panicBuyingLive/getLiveRoomDetailByDocCode.do`,
S 65         data:{
66           doccode,
67         }
f9ad6c 68       })
S 69     )
70     if (error){
71       console.log(error);
72       return;
73     }
74     console.log(result);
75     this.setData({
8724a4 76       liveRoomData:result.list[0],
S 77       subAnchorWechat:result.list[0].SubAnchorWechat
78     })
79     this.getImagesUrl();
80   },
81
82   // 主播副号相关
83   closeSubAnchorDialog(){
84     this.setData({
85       isShowSubAnchorDialog:false,
86     })
87   },
88   showSubAnchorDialog(){
89     this.setData({
90       isShowSubAnchorDialog:true
91     })
92   },
93   checkSubAnchorWechat(event:any){
94     console.log(event);
95     let value = event.detail.value.trim();
96     this.setData({subAnchorWechat:value})
97     this.checkFieldValue('subAnchorWechat','请输入主播副微信号');
98   },
99   async saveSubAnchorWechat(){
100     if(!this.checkFieldValue('subAnchorWechat','请输入主播副微信号')) return;
101     let {roomid,subAnchorWechat} = this.data
102     let [error, result] = await wx.$utils.to(
103       wx.$http.request({
104         url:`/shopping/live/addSubAnchor.do`,
105         data:{
106           roomid,
107           userName:subAnchorWechat
108         }
109       })
110     )
111     if (error){
112       console.log(error);
113       return;
114     }
115     console.log(result);
116     if (result.qrcodeImg){
117       let authentication =this.selectComponent('#my-anchor-authentication');
118       authentication.showQrCodeDialog();
119       return;
120     }
121     if (result.state=='success'){
122       this.closeSubAnchorDialog()
123       this.setData({
124         [`liveRoomData.SubAnchorWechat`]:subAnchorWechat
125       })
126     }
127   },
128   async deleteSubAnchorWechat(){
129     wx.pro.showModal({
130       title: '提示',
131       content: '确定要删除主播副号吗?',
132     }).then((res:any) => {
133       // on close
134       console.log(res);
135       if (res.confirm){
136         console.log('确认');
137         this.deleteSubAnchorWechatRequest();
138       }
139     });
140
141   },
142   async deleteSubAnchorWechatRequest(){
143     let {roomid} = this.data
144     let [error, result] = await wx.$utils.to(
145       wx.$http.request({
146         url:`/shopping/live/deleteSubAnchor.do`,
147         data:{
148           roomid,
149         }
150       })
151     )
152     if (error){
153       console.log(error);
154       return;
155     }
156     console.log(result);
157     if (result.state=='success'){
158       this.closeSubAnchorDialog()
159       this.setData({
160         subAnchorWechat:'',
161         [`liveRoomData.SubAnchorWechat`]:''
162       })
163     }
164   },
165
166   // 海报相关
167   async createPoster(){
168     // let {roomid} = this.data;
169     // await this.getSharedCode();
170     let poster =this.selectComponent('#my-poster-creator');
171     poster.drawPic();
172   },
173
174   // 直播间商品相关
175   async getGoodsListInRoom(){
176     let {roomid} = this.data;
177     let [error, result] = await wx.$utils.to(
178       wx.$http.request({
179         url:`/shopping/panicBuyingLive/goodsListInRoom.do`,
180         data:{
181           roomid,
182         }
183       })
184     )
185     if (error){
186       console.log(error);
187       return;
188     }
189     console.log(result);
190     this.setData({
191       goodsList:result.list
192     })
193   },
194
195   async pushGoodsInLive(event:any){
196     let {roomid} = this.data;
197     let {goodsid} = event.currentTarget.dataset;
198     let [error, result] = await wx.$utils.to(
199       wx.$http.request({
200         url:`/shopping/live/goodsPushInRoom.do`,
201         data:{
202           roomid,
203           goodsid
204         }
205       })
206     )
207     if (error){
208       console.log(error);
209       return;
210     }
211     console.log(result);
212     if (result.state=='success'){
213       wx.showToast({title:'推送成功'})
214     }
215   },
216
217   // 开关相关
218   async onChangeFeedsPublic({detail}:any){
219     console.log('是否开启官方收录:',detail);
220     // this.setData({ isFeedsPublic: detail });
221     this.sendChangesSwitchRequest('/shopping/live/updateFeedPublic.do',['isFeedsPublic',detail]);
222   },
223   onChangeCloseReplay({detail}:any){
224     console.log('是否关闭回放:',detail);
225     // this.setData({ isFeedsPublic: detail });
226     this.sendChangesSwitchRequest('/shopping/live/updateReplay.do',['isCloseReplay',!detail]);
227   },
228   // onChangeCloseKf({detail}:any){
229   //   console.log('是否关闭客服:',detail);
230   //   // this.setData({ isFeedsPublic: detail });
231   //   this.sendChangesSwitchRequest('/shopping/live/updateKf.do',['isCloseKf',detail]);
232   // },
233   onChangeCloseComment({detail}:any){
234     console.log('是否关闭禁言',detail);
235     // this.setData({ isFeedsPublic: detail });
236     this.sendChangesSwitchRequest('/shopping/live/updateComment.do',['isCloseComment',detail]);
237   },
238   // onChangeCloseGoods({detail}:any){
239   //   console.log('是否关闭商品货架:',detail);
240   //   // this.setData({ isFeedsPublic: detail });
241   //   this.sendChangesSwitchRequest('/shopping/live/updateGoodsToOnSaleInRoom.do',['isFeedsPublic',detail]);
242   // },
243
244   async sendChangesSwitchRequest(url:string,value:any){
245     let {roomid} = this.data;
246     let [error, result] = await wx.$utils.to(
247       wx.$http.request({
248         url,
249         data:{
250           roomid,
251           [value[0]]:value[1]?'1':'0',
252         }
253       })
254     )
255     if (error){
256       console.log(error);
257       return false;
258     }
259     console.log(result);
260     if (result.state=='success'){
261       console.log('请求成功',[value[0]],value[1]);
262       this.setData({
263         [`liveRoomData.${value[0]}`]:value[1],
264       })
265       return true;
266     }
267     return false;
268   },
269
270
271   //直播小助手相关
272   async getAssistantList(){
273     let {roomid} = this.data;
274     let [error, result] = await wx.$utils.to(
275       wx.$http.request({
276         url:`/shopping/live/getAssistantList.do`,
277         data:{
278           roomid,
279         }
280       })
281     )
282     if (error){
283       console.log(error);
284       return;
285     }
286     console.log(result);
287     this.setData({
288       assistantList:result.list,
289       maxAssistantCount: result.maxCount,
290       currentAssistantCount: result.count,
291     })
292   },
293   deleteAssistant(event:any){
294     let {alias} = event.currentTarget.dataset;
295     wx.pro.showModal({
296       title: '提示',
297       content: '确定要移除该助手吗?',
298     }).then((res:any) => {
299       // on close
300       console.log(res);
301       if (res.confirm){
302         console.log('确认');
303         this.deleteAssistantRequest(alias)
304       }
305     });
306   },
307   async deleteAssistantRequest(data:string){
308     let {roomid} = this.data;
309     let [error, result] = await wx.$utils.to(
310       wx.$http.request({
311         url:`/shopping/live/removeAssistant.do`,
312         data:{
313           roomid,
314           userName:data
315         }
316       })
317     )
318     if (error){
319       console.log(error);
320       return;
321     }
322     console.log(result);
323     if (result.state=='success'){
324       this.getAssistantList()
325     }
326   },
327   checkWechatName(event:any){
328     let value = event.detail.value.trim();
329     this.setData({wechatName:value})
330     this.checkFieldValue('wechatName','请输入微信昵称');
331   },
332   checkWechatNumber(event:any){
333     console.log(event);
334     let value = event.detail.value.trim();
335     this.setData({wechatNumber:value})
336     this.checkFieldValue('wechatNumber','请输入微信号');
337   },
338   async handleSaveAssistant(){
339     if(!this.checkFieldValue('wechatName','请输入微信昵称')) return;
340     if(!this.checkFieldValue('wechatNumber','请输入微信号')) return;
341     let {roomid,wechatName,wechatNumber} = this.data
342     let [error, result] = await wx.$utils.to(
343       wx.$http.request({
344         url:`/shopping/live/addAssistant.do`,
345         data:{
346           roomid,
347           nickName:wechatName,
348           userName:wechatNumber
349         }
350       })
351     )
352     if (error){
353       console.log(error);
354       return;
355     }
356     console.log(result);
357     if (result.state=='success'){
358       this.closeDialog()
359       this.setData({
360         wechatName:'',
361         wechatNumber:''
362       })
363       this.getAssistantList()
364     }
365   },
366   checkFieldValue(value:CheckField,msg:string){
367     if (!this.data[value]) {
368       this.setData({
369         [value + "Error"]: msg,
370       });
371       return false;
372     }
373     this.setData({
374       [value + "Error"]: "",
375     });
376     return true;
377   },
378   closeDialog(){
379     this.setData({
380       showDialog:false,
381     })
382   },
383   showAssistantDialog(){
384     this.setData({
385       showDialog:true
f9ad6c 386     })
S 387   }
388 })