messagePush.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="padding-sm messagePush">
  3. <form action="">
  4. <checkbox-group class="block" @change="CheckboxChange">
  5. <view class="margin-top ">
  6. <view class="flex align-center checkItems" v-for="(item,index) in checkbox">
  7. <checkbox class="blue" :class="item.checked==1?'checked':''"
  8. :checked="item.checked==1?true:false" :value="item.value"></checkbox>
  9. <view class="title">{{item.title}}</view>
  10. </view>
  11. </view>
  12. </checkbox-group>
  13. <view class="btn-area submitBottomBtn padding-lr-sm">
  14. <button class="bg-blue round margin-top" @click="$noMultipleClicks(btnSubmit)">提 交 </button>
  15. </view>
  16. </form>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. noClick: true,
  24. flag: false,
  25. getData: {},
  26. checkedValue: [],
  27. checkbox: [{
  28. value: 'm1',
  29. checked: false,
  30. title: '火警报警'
  31. },
  32. {
  33. value: 'm2',
  34. checked: false,
  35. title: '火警故障'
  36. },
  37. {
  38. value: 'm3',
  39. checked: false,
  40. title: '水压越线'
  41. },
  42. {
  43. value: 'm4',
  44. checked: false,
  45. title: '开关变化'
  46. },
  47. {
  48. value: 'm5',
  49. checked: false,
  50. title: '设备离线'
  51. },
  52. {
  53. value: 'm6',
  54. checked: false,
  55. title: '烟感报警'
  56. },
  57. {
  58. value: 'm7',
  59. checked: false,
  60. title: '电气火灾'
  61. },
  62. {
  63. value: 'm8',
  64. checked: false,
  65. title: '视频报警'
  66. },
  67. {
  68. value: 'm9',
  69. checked: false,
  70. title: '电梯监测'
  71. },
  72. {
  73. value: 'm10',
  74. checked: false,
  75. title: '井盖监测'
  76. }
  77. ],
  78. }
  79. },
  80. onLoad: function(option) {
  81. this.getCheckList();
  82. },
  83. methods: {
  84. CheckboxChange(e) {
  85. this.flag = true;
  86. var items = this.checkbox,
  87. values = e.detail.value;
  88. this.checkedValue = values;
  89. // console.log(values)
  90. // console.log('点击复选框时this.checkedValue')
  91. // console.log(this.checkedValue)
  92. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  93. items[i].checked = false;
  94. for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
  95. if (items[i].value == values[j]) {
  96. items[i].checked = true;
  97. break
  98. }
  99. }
  100. }
  101. },
  102. // 回显数据请求
  103. async getCheckList(params = {}) {
  104. const res = await this.$myRequest({
  105. url: 'PushSettings/setperm',
  106. data: params,
  107. showLoading: true
  108. })
  109. this.getData = res.data.data[0];
  110. // 遍历checkbox数组对象
  111. for (let i = 0; i < this.checkbox.length; i++) {
  112. //判断value是否存在于返回对象中.存在的话checked重新赋值
  113. if (this.getData.hasOwnProperty(this.checkbox[i].value)) {
  114. // console.log(this.checkbox[i].value)
  115. this.checkbox[i].checked = true
  116. }
  117. }
  118. },
  119. //提交
  120. async btnSubmit() {
  121. // 提交验证
  122. // alert(this.aa);
  123. // alert(this.checkedValue)
  124. // if (!this.aa.length) {
  125. // uni.showToast({
  126. // title: "请选择推送选项",
  127. // icon: "none"
  128. // });
  129. // return
  130. // }
  131. let mingParams = {};
  132. if (!this.flag) {
  133. //不点击默认传参
  134. var obgj = this.getData;
  135. console.log('不点击默认传参obgj')
  136. console.log(obgj);
  137. var arr = [];
  138. for (var key in obgj) {
  139. console.log(key)
  140. console.log(obgj[key])
  141. arr.push([key][0])
  142. }
  143. arr.map((e) => {
  144. mingParams[e] = true;
  145. });
  146. } else {
  147. //点击复选框后传参
  148. var arr = this.checkedValue;
  149. console.log('自由选中复选框后传参arr')
  150. console.log(arr)
  151. arr.map((e) => {
  152. mingParams[e] = true;
  153. });
  154. console.log('mingParams')
  155. console.log(mingParams)
  156. }
  157. let res = await this.PushSettings(mingParams);
  158. // let res = await this.PushSettings({'m1':true,"m2":true,"m6":true});
  159. if (!res.data.flag) {
  160. uni.showToast({
  161. title: "添加失败",
  162. icon: "none"
  163. });
  164. } else {
  165. uni.showToast({
  166. title: "添加成功",
  167. });
  168. setTimeout(() => {
  169. uni.switchTab({
  170. url: '/pages/setting/setting',
  171. });
  172. }, 1000);
  173. }
  174. },
  175. PushSettings(params = {}) {
  176. return this.$myRequest({
  177. url: 'PushSettings/setperm',
  178. data: params
  179. })
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. .checkItems {
  186. width: 50%;
  187. display: inline-block;
  188. text-align: center;
  189. margin-bottom: 40rpx;
  190. .title {
  191. display: inline-block;
  192. margin-left: 10rpx;
  193. }
  194. }
  195. </style>