wakeList.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. const app = getApp();
  2. let PreselectionIndex = null; // 记录选中的频道
  3. const {
  4. deviceWakeList,
  5. deviceWakeadd,
  6. deviceWakedetail,
  7. listByDevice,
  8. pageByDevice,
  9. radioList
  10. } = require('../../utils/apiUtil.js');
  11. Page({
  12. data: {
  13. navBarHeight: app.globalData.navBarHeight,
  14. MenuButtonTop: app.globalData.MenuButtonTop,
  15. nvabarData: {
  16. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  17. title: '设置唤醒音', //导航栏 中间的标题
  18. },
  19. list: [],
  20. actionIndex: null,
  21. clientType: "",
  22. deviceMac: "",
  23. detailList: [],
  24. isShowWakeDetail: false,
  25. actionWakeIndex: null,
  26. deviceWake: [],
  27. },
  28. onLoad(options) {
  29. var that = this;
  30. that.data.clientType = options.clientType;
  31. that.data.deviceMac = options.deviceMac;
  32. that.init();
  33. },
  34. init() {
  35. var that = this;
  36. deviceWakeList({
  37. clientType: that.data.clientType,
  38. deviceMac: that.data.deviceMac,
  39. }).then((res) => {
  40. listByDevice({
  41. clientType: that.data.clientType
  42. }).then((item) => {
  43. const listData = [...res, ...item];
  44. that.setData({
  45. list: listData
  46. })
  47. deviceWakedetail({
  48. clientType: that.data.clientType,
  49. deviceMac: that.data.deviceMac,
  50. }).then((data) => {
  51. if (data && data.length === 0) {
  52. return;
  53. };
  54. that.setData({
  55. deviceWake: data,
  56. });
  57. listData.map((v, index) => {
  58. if (v.wakeId === data[0].wakeId || v.channelId === data[0].channelId) {
  59. that.setData({
  60. actionIndex: index
  61. })
  62. }
  63. })
  64. })
  65. })
  66. })
  67. },
  68. actionWakeDetail(e) {
  69. var that = this;
  70. that.setData({
  71. actionWakeIndex: e.currentTarget.dataset.index,
  72. })
  73. },
  74. setWake() {
  75. var that = this;
  76. var index = that.data.actionWakeIndex;
  77. if (index === null) {
  78. wx.showToast({
  79. title: '请选择唤醒音',
  80. icon: "none",
  81. duration: 1500
  82. })
  83. return
  84. };
  85. if (that.data.deviceWake.length > 0 && (that.data.deviceWake[0].audioId === that.data.detailList[index].audioId)) {
  86. wx.showToast({
  87. title: '请不要重复设置哦!',
  88. icon: "none",
  89. duration: 1500
  90. });
  91. return;
  92. }
  93. let repData = {}
  94. if (that.data.detailList[index].channelId) {
  95. repData = {
  96. clientType: that.data.clientType,
  97. deviceMac: that.data.deviceMac,
  98. type: 1,
  99. audioId: that.data.detailList[index].audioId,
  100. audioType: that.data.detailList[index].audioType,
  101. channelId: that.data.detailList[index].channelId,
  102. }
  103. } else {
  104. repData = {
  105. wakeAudioId: that.data.detailList[index].wakeAudioId,
  106. clientType: that.data.clientType,
  107. deviceMac: that.data.deviceMac,
  108. type: 0,
  109. }
  110. }
  111. deviceWakeadd(repData).then(() => {
  112. that.setData({
  113. actionWakeIndex: null,
  114. isShowWakeDetail: false,
  115. actionWakeDetail: null,
  116. actionWakeIndex: PreselectionIndex
  117. });
  118. // 刷新页面
  119. that.init();
  120. getCurrentPages().map((v) => {
  121. if (v.route === "pages/deviceWake/deviceWake") {
  122. v.setdeviceWakedetail();
  123. };
  124. })
  125. });
  126. },
  127. clone() {
  128. var that = this;
  129. that.setData({
  130. isShowWakeDetail: false,
  131. actionWakeIndex: null
  132. })
  133. },
  134. actionWake(e) {
  135. var that = this;
  136. var index = e.currentTarget.dataset.index;
  137. if (that.data.list[index].channelId) {
  138. // 选择1-12频道
  139. pageByDevice({
  140. channelId: that.data.list[index].channelId,
  141. pageNum: 1,
  142. pageSize: 300
  143. }).then((res) => {
  144. if (that.data.deviceWake.length > 0) {
  145. res.records.map((v, index) => {
  146. if (v.audioId === that.data.deviceWake[0].audioId) {
  147. that.setData({
  148. actionWakeIndex: index
  149. })
  150. }
  151. });
  152. };
  153. that.setData({
  154. isShowWakeDetail: true,
  155. detailList: res.records
  156. })
  157. })
  158. } else {
  159. // 官方频道
  160. radioList({
  161. wakeId: that.data.list[index].wakeId,
  162. pageNum: 1,
  163. pageSize: 300
  164. }).then((res) => {
  165. if (that.data.deviceWake.length > 0) {
  166. res.records.map((v, index) => {
  167. if (v.audioId === that.data.deviceWake[0].audioId) {
  168. that.setData({
  169. actionWakeIndex: index
  170. })
  171. }
  172. });
  173. };
  174. that.setData({
  175. isShowWakeDetail: true,
  176. detailList: res.records
  177. })
  178. })
  179. };
  180. PreselectionIndex = e.currentTarget.dataset.index;
  181. },
  182. })