123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- // pages/wakeList/wakeList.js
- const { deviceWakeList, deviceWakeadd, deviceWakedetail, listByDevice, pageByDevice, radioList }=require('./../../utils/api.js');
- let PreselectionIndex = null; // 记录选中的频道
- let _this = null;
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- navBarHeight: app.globalData.navBarHeight,
- MenuButtonTop: app.globalData.MenuButtonTop,
- nvabarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '设置唤醒音', //导航栏 中间的标题
- },
- list: [],
- actionIndex: null,
- clientType: "",
- deviceMac: "",
- detailList: [],
- isShowWakeDetail: false,
- actionWakeIndex: null,
- deviceWake: [],
- },
- actionWakeDetail(e){
- this.setData({
- actionWakeIndex: e.currentTarget.dataset.index,
- })
- },
- setWake() {
- const index = this.data.actionWakeIndex;
- if(_this.data.deviceWake.length > 0 && (_this.data.deviceWake[0].audioId === this.data.detailList[index].audioId)) {
- wx.showToast({
- title: '请不要重复设置哦!',
- icon: "none",
- duration: 1500
- })
- return;
- }
- if(index === null) {
- wx.showToast({
- title: '请选择唤醒音',
- icon: "none",
- duration: 1500
- })
- return
- };
- let repData = {}
- if(this.data.detailList[index].channelId) {
- repData={
- clientType: this.data.clientType,
- deviceMac: this.data.deviceMac,
- type: 1,
- audioId: this.data.detailList[index].audioId,
- audioType: this.data.detailList[index].audioType,
- channelId: this.data.detailList[index].channelId,
- }
- } else {
- repData = {
- wakeAudioId: this.data.detailList[index].wakeAudioId,
- clientType: this.data.clientType,
- deviceMac: this.data.deviceMac,
- type: 0,
- }
- }
- deviceWakeadd(repData).then(()=> {
- _this.setData({
- actionWakeIndex: null,
- isShowWakeDetail: false,
- actionWakeDetail: null,
- actionWakeIndex: PreselectionIndex
- });
- // 刷新页面
- _this.init();
- getCurrentPages().map((v)=> {
- if(v.route === "pages/deviceWake/deviceWake") {
- v.setdeviceWakedetail();
- };
- })
- })
- },
- clone() {
- this.setData({
- isShowWakeDetail: false,
- actionWakeIndex: null
- })
- },
- actionWake(e) {
-
- const index = e.currentTarget.dataset.index;
- if(this.data.list[index].channelId) {
- // 选择1-12频道
- pageByDevice({
- channelId: this.data.list[index].channelId,
- pageNum: 1,
- pageSize: 300
- }).then((res)=> {
- if(_this.data.deviceWake.length > 0) {
- res.records.map((v, index)=> {
- if(v.audioId === _this.data.deviceWake[0].audioId) {
- _this.setData({
- actionWakeIndex: index
- })
- }
- });
- };
- _this.setData({
- isShowWakeDetail: true,
- detailList: res.records
- })
- })
- } else {
- // 官方频道
- radioList({
- wakeId: this.data.list[index].wakeId,
- pageNum: 1,
- pageSize: 300
- }).then((res)=> {
- if(_this.data.deviceWake.length > 0) {
- res.records.map((v, index)=> {
- if(v.audioId === _this.data.deviceWake[0].audioId) {
- _this.setData({
- actionWakeIndex: index
- })
- }
- });
- };
- _this.setData({
- isShowWakeDetail: true,
- detailList: res.records
- })
- })
- };
- PreselectionIndex = e.currentTarget.dataset.index;
-
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- _this = this;
- this.data.clientType = options.clientType;
- this.data.deviceMac = options.deviceMac;
-
- this.init();
- },
- init() {
- deviceWakeList({
- clientType: this.data.clientType,
- deviceMac: this.data.deviceMac,
- }).then((res)=> {
- listByDevice({clientType: this.data.clientType}).then((item)=> {
- const listData = [...res, ...item];
- _this.setData({
- list: listData
- })
- deviceWakedetail({
- clientType: this.data.clientType,
- deviceMac: this.data.deviceMac,
- }).then((data)=> {
- if(data && data.length === 0) {
- return;
- };
- _this.setData({
- deviceWake: data,
- });
- listData.map((v, index)=> {
- if(v.wakeId === data[0].wakeId || v.channelId === data[0].channelId) {
- this.setData({
- actionIndex: index
- })
- }
- })
- })
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|