wakeList.js 4.7 KB

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