wakeList.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // pages/wakeList/wakeList.js
  2. const { deviceWakeList, deviceWakeadd, deviceWakedetail, listByDevice, pageByDevice, radioList }=require('./../../utils/api.js');
  3. let PreselectionIndex = null; // 记录选中的频道
  4. let _this = null;
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. navBarHeight: app.globalData.navBarHeight,
  12. MenuButtonTop: app.globalData.MenuButtonTop,
  13. nvabarData: {
  14. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  15. title: '设置唤醒音', //导航栏 中间的标题
  16. },
  17. list: [],
  18. actionIndex: null,
  19. clientType: "",
  20. deviceMac: "",
  21. detailList: [],
  22. isShowWakeDetail: false,
  23. actionWakeIndex: null,
  24. deviceWake: [],
  25. },
  26. actionWakeDetail(e){
  27. this.setData({
  28. actionWakeIndex: e.currentTarget.dataset.index,
  29. })
  30. },
  31. setWake() {
  32. const index = this.data.actionWakeIndex;
  33. if(_this.data.deviceWake.length > 0 && (_this.data.deviceWake[0].audioId === this.data.detailList[index].audioId)) {
  34. wx.showToast({
  35. title: '请不要重复设置哦!',
  36. icon: "none",
  37. duration: 1500
  38. })
  39. return;
  40. }
  41. if(index === null) {
  42. wx.showToast({
  43. title: '请选择唤醒音',
  44. icon: "none",
  45. duration: 1500
  46. })
  47. return
  48. };
  49. let repData = {}
  50. if(this.data.detailList[index].channelId) {
  51. repData={
  52. clientType: this.data.clientType,
  53. deviceMac: this.data.deviceMac,
  54. type: 1,
  55. audioId: this.data.detailList[index].audioId,
  56. audioType: this.data.detailList[index].audioType,
  57. channelId: this.data.detailList[index].channelId,
  58. }
  59. } else {
  60. repData = {
  61. wakeAudioId: this.data.detailList[index].wakeAudioId,
  62. clientType: this.data.clientType,
  63. deviceMac: this.data.deviceMac,
  64. type: 0,
  65. }
  66. }
  67. deviceWakeadd(repData).then(()=> {
  68. _this.setData({
  69. actionWakeIndex: null,
  70. isShowWakeDetail: false,
  71. actionWakeDetail: null,
  72. actionWakeIndex: PreselectionIndex
  73. });
  74. // 刷新页面
  75. _this.init();
  76. getCurrentPages().map((v)=> {
  77. if(v.route === "pages/deviceWake/deviceWake") {
  78. v.setdeviceWakedetail();
  79. };
  80. })
  81. })
  82. },
  83. clone() {
  84. this.setData({
  85. isShowWakeDetail: false,
  86. actionWakeIndex: null
  87. })
  88. },
  89. actionWake(e) {
  90. const index = e.currentTarget.dataset.index;
  91. if(this.data.list[index].channelId) {
  92. // 选择1-12频道
  93. pageByDevice({
  94. channelId: this.data.list[index].channelId,
  95. pageNum: 1,
  96. pageSize: 300
  97. }).then((res)=> {
  98. if(_this.data.deviceWake.length > 0) {
  99. res.records.map((v, index)=> {
  100. if(v.audioId === _this.data.deviceWake[0].audioId) {
  101. _this.setData({
  102. actionWakeIndex: index
  103. })
  104. }
  105. });
  106. };
  107. _this.setData({
  108. isShowWakeDetail: true,
  109. detailList: res.records
  110. })
  111. })
  112. } else {
  113. // 官方频道
  114. radioList({
  115. wakeId: this.data.list[index].wakeId,
  116. pageNum: 1,
  117. pageSize: 300
  118. }).then((res)=> {
  119. if(_this.data.deviceWake.length > 0) {
  120. res.records.map((v, index)=> {
  121. if(v.audioId === _this.data.deviceWake[0].audioId) {
  122. _this.setData({
  123. actionWakeIndex: index
  124. })
  125. }
  126. });
  127. };
  128. _this.setData({
  129. isShowWakeDetail: true,
  130. detailList: res.records
  131. })
  132. })
  133. };
  134. PreselectionIndex = e.currentTarget.dataset.index;
  135. },
  136. /**
  137. * 生命周期函数--监听页面加载
  138. */
  139. onLoad(options) {
  140. _this = this;
  141. this.data.clientType = options.clientType;
  142. this.data.deviceMac = options.deviceMac;
  143. this.init();
  144. },
  145. init() {
  146. deviceWakeList({
  147. clientType: this.data.clientType,
  148. deviceMac: this.data.deviceMac,
  149. }).then((res)=> {
  150. listByDevice({clientType: this.data.clientType}).then((item)=> {
  151. const listData = [...res, ...item];
  152. _this.setData({
  153. list: listData
  154. })
  155. deviceWakedetail({
  156. clientType: this.data.clientType,
  157. deviceMac: this.data.deviceMac,
  158. }).then((data)=> {
  159. if(data && data.length === 0) {
  160. return;
  161. };
  162. _this.setData({
  163. deviceWake: data,
  164. });
  165. listData.map((v, index)=> {
  166. if(v.wakeId === data[0].wakeId || v.channelId === data[0].channelId) {
  167. this.setData({
  168. actionIndex: index
  169. })
  170. }
  171. })
  172. })
  173. })
  174. })
  175. },
  176. /**
  177. * 生命周期函数--监听页面初次渲染完成
  178. */
  179. onReady() {
  180. },
  181. /**
  182. * 生命周期函数--监听页面显示
  183. */
  184. onShow() {
  185. },
  186. /**
  187. * 生命周期函数--监听页面隐藏
  188. */
  189. onHide() {
  190. },
  191. /**
  192. * 生命周期函数--监听页面卸载
  193. */
  194. onUnload() {
  195. },
  196. /**
  197. * 页面相关事件处理函数--监听用户下拉动作
  198. */
  199. onPullDownRefresh() {
  200. },
  201. /**
  202. * 页面上拉触底事件的处理函数
  203. */
  204. onReachBottom() {
  205. },
  206. /**
  207. * 用户点击右上角分享
  208. */
  209. onShareAppMessage() {
  210. }
  211. })