123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- const app = getApp();
- let PreselectionIndex = null; // 记录选中的频道
- const {
- deviceWakeList,
- deviceWakeadd,
- deviceWakedetail,
- listByDevice,
- pageByDevice,
- radioList
- } = require('../../utils/apiUtil.js');
- 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: [],
- },
- onLoad(options) {
- var that = this;
- that.data.clientType = options.clientType;
- that.data.deviceMac = options.deviceMac;
- that.init();
- },
- init() {
- var that = this;
- deviceWakeList({
- clientType: that.data.clientType,
- deviceMac: that.data.deviceMac,
- }).then((res) => {
- listByDevice({
- clientType: that.data.clientType
- }).then((item) => {
- const listData = [...res, ...item];
- that.setData({
- list: listData
- })
- deviceWakedetail({
- clientType: that.data.clientType,
- deviceMac: that.data.deviceMac,
- }).then((data) => {
- if (data && data.length === 0) {
- return;
- };
- that.setData({
- deviceWake: data,
- });
- listData.map((v, index) => {
- if (v.wakeId === data[0].wakeId || v.channelId === data[0].channelId) {
- that.setData({
- actionIndex: index
- })
- }
- })
- })
- })
- })
- },
- actionWakeDetail(e) {
- var that = this;
- that.setData({
- actionWakeIndex: e.currentTarget.dataset.index,
- })
- },
- setWake() {
- var that = this;
- var index = that.data.actionWakeIndex;
- if (index === null) {
- wx.showToast({
- title: '请选择唤醒音',
- icon: "none",
- duration: 1500
- })
- return
- };
- if (that.data.deviceWake.length > 0 && (that.data.deviceWake[0].audioId === that.data.detailList[index].audioId)) {
- wx.showToast({
- title: '请不要重复设置哦!',
- icon: "none",
- duration: 1500
- });
- return;
- }
- let repData = {}
- if (that.data.detailList[index].channelId) {
- repData = {
- clientType: that.data.clientType,
- deviceMac: that.data.deviceMac,
- type: 1,
- audioId: that.data.detailList[index].audioId,
- audioType: that.data.detailList[index].audioType,
- channelId: that.data.detailList[index].channelId,
- }
- } else {
- repData = {
- wakeAudioId: that.data.detailList[index].wakeAudioId,
- clientType: that.data.clientType,
- deviceMac: that.data.deviceMac,
- type: 0,
- }
- }
- deviceWakeadd(repData).then(() => {
- that.setData({
- actionWakeIndex: null,
- isShowWakeDetail: false,
- actionWakeDetail: null,
- actionWakeIndex: PreselectionIndex
- });
- // 刷新页面
- that.init();
- getCurrentPages().map((v) => {
- if (v.route === "pages/deviceWake/deviceWake") {
- v.setdeviceWakedetail();
- };
- })
- });
- },
- clone() {
- var that = this;
- that.setData({
- isShowWakeDetail: false,
- actionWakeIndex: null
- })
- },
- actionWake(e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- if (that.data.list[index].channelId) {
- // 选择1-12频道
- pageByDevice({
- channelId: that.data.list[index].channelId,
- pageNum: 1,
- pageSize: 300
- }).then((res) => {
- if (that.data.deviceWake.length > 0) {
- res.records.map((v, index) => {
- if (v.audioId === that.data.deviceWake[0].audioId) {
- that.setData({
- actionWakeIndex: index
- })
- }
- });
- };
- that.setData({
- isShowWakeDetail: true,
- detailList: res.records
- })
- })
- } else {
- // 官方频道
- radioList({
- wakeId: that.data.list[index].wakeId,
- pageNum: 1,
- pageSize: 300
- }).then((res) => {
- if (that.data.deviceWake.length > 0) {
- res.records.map((v, index) => {
- if (v.audioId === that.data.deviceWake[0].audioId) {
- that.setData({
- actionWakeIndex: index
- })
- }
- });
- };
- that.setData({
- isShowWakeDetail: true,
- detailList: res.records
- })
- })
- };
- PreselectionIndex = e.currentTarget.dataset.index;
- },
- })
|