select-sensitive-data.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. const Constants = require('@/utils/Constants.js');
  2. const util = require('@/utils/util.js')
  3. const mixins = require('@/mixins/index.js')
  4. Page({
  5. mixins: [mixins],
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. routeObjName: 'roleSensitive',
  11. tableData: [],
  12. formMode: Constants.formMode.detail,
  13. },
  14. /**
  15. * @desc : 列表交换器选择事件全选
  16. * @date : 2024/2/1 15:49
  17. * @author : 于继渤
  18. */
  19. onChangeSwitch(e) {
  20. console.log(e)
  21. let formData = this.data.formData
  22. let tableData = this.data.tableData
  23. formData.checked = e.detail
  24. if (tableData && tableData.length > 0) {
  25. tableData.forEach(res => {
  26. res.checked = e.detail
  27. if (res.children && res.children.length > 0) {
  28. res.children.forEach(it => {
  29. it.checked = e.detail
  30. })
  31. }
  32. })
  33. }
  34. this.setData({
  35. formData: formData,
  36. tableData: tableData
  37. })
  38. },
  39. /**
  40. * @desc : 列表交换器选择事件父级
  41. * @date : 2024/2/1 15:49
  42. * @author : 于继渤
  43. */
  44. onCheckedItem(e) {
  45. console.log(e)
  46. let _that = this
  47. let index = e.currentTarget.dataset.index
  48. let tableData = _that.data.tableData
  49. tableData[index].checked = !tableData[index].checked
  50. if (tableData[index].children && tableData[index].children.length > 0) {
  51. console.log('list[index].children', tableData[index].children)
  52. tableData[index].children.forEach(res => {
  53. res.checked = tableData[index].checked
  54. })
  55. }
  56. _that.setData({
  57. tableData: tableData
  58. })
  59. },
  60. /**
  61. * @desc : 列表交换器选择事件子级
  62. * @date : 2024/2/1 15:49
  63. * @author : 于继渤
  64. */
  65. onCheckedItem_(e) {
  66. let index = e.currentTarget.dataset.index
  67. let index_ = e.currentTarget.dataset.index_
  68. let tableData = this.data.tableData
  69. tableData[index].children[index_].checked = !tableData[index].children[index_].checked
  70. if (tableData[index].children.filter(res => {
  71. res.checked
  72. }).length == tableData[index].children.length) {
  73. tableData[index].checked = true
  74. } else {
  75. tableData[index].checked = false
  76. }
  77. this.setData({
  78. tableData: tableData
  79. })
  80. },
  81. /**
  82. * @desc : 设置保存参数
  83. * @date : 2024/2/1 15:49
  84. * @author : 于继渤
  85. */
  86. setParams() {
  87. let params = {}
  88. // 修改之后的 值
  89. if (this.data.formData && this.data.formData.roleId) {
  90. params.roleId = this.data.formData.roleId
  91. }
  92. params.pageSize = this.data.pageInfo.pageSize;
  93. params.currentPage = this.data.pageInfo.currentPage;
  94. return params
  95. },
  96. /**
  97. * @desc : 处理接口返回数据
  98. * @date : 2024/2/1 15:49
  99. * @author : 于继渤
  100. */
  101. handleData(tableData) {
  102. this.setData({
  103. tableData: util.convertToChildren(tableData, 'parentCode', 'itemCode')
  104. })
  105. },
  106. /**
  107. * @desc : 加载数据
  108. * @date : 2024/2/1 15:49
  109. * @author : 于继渤
  110. */
  111. getData(params) {
  112. if (this.data.formData && this.data.formData.roleId) {
  113. params.roleId = this.data.formData.roleId
  114. }
  115. return this.excute(this.data.service, this.data.service.getRoleSensitive, params).then(res => {
  116. //处理数据
  117. if (res.data.code == 200) {
  118. this.handleData(res.data.data.list)
  119. }
  120. })
  121. },
  122. /**
  123. * @desc : 折叠面板多选框事件
  124. * @date : 2024/2/1 15:49
  125. * @author : 于继渤
  126. */
  127. obtainList(e) {
  128. this.setData({
  129. tableData: e.detail.list
  130. })
  131. },
  132. toAdd() {
  133. let tableData = this.data.tableData
  134. //格式化数据
  135. let tableDataTemp = []
  136. tableData.forEach(res => {
  137. if (res.checked) {
  138. tableDataTemp.push({
  139. senItemCode: res.itemCode,
  140. flgShow: res.checked
  141. })
  142. }
  143. if (res.children && res.children.length > 0) {
  144. res.children.forEach(it => {
  145. if (it.checked) {
  146. tableDataTemp.push({
  147. senItemCode: it.itemCode,
  148. flgShow: it.checked
  149. })
  150. }
  151. })
  152. }
  153. })
  154. //铭感信息跳转编辑
  155. if (this.data.formType == Constants.formMode.edit) {
  156. //调用接口修改权限
  157. let formData = this.data.formData
  158. formData.roleSensitiveList = tableDataTemp
  159. this.setData({
  160. formData: JSON.stringify(this.data.formData)
  161. })
  162. let params = []
  163. this.save(params)
  164. } else {
  165. // 给父页面传递数据
  166. const eventChannel = this.getOpenerEventChannel();
  167. eventChannel.emit('bindData', {
  168. showFlag: 'selectSensitiveData',
  169. list: tableDataTemp
  170. })
  171. wx.navigateBack({
  172. delta: 1
  173. })
  174. }
  175. },
  176. /**
  177. * @desc : 批量修改敏感信息接口
  178. * @date : 2024/2/1 15:49
  179. * @author : 于继渤
  180. */
  181. saveData(params) {
  182. return this.excute(this.data.service, this.data.service.updateBatch, params);
  183. },
  184. /**
  185. * 生命周期函数--监听页面加载
  186. */
  187. onLoad(options) {
  188. //接收父页面传递的参数
  189. let that = this
  190. const eventChannel = this.getOpenerEventChannel()
  191. eventChannel.on('editParams', function (data) {
  192. console.log('editParams', data)
  193. that.setData({
  194. formData: JSON.parse(data.data.formData),
  195. formMode: data.data.formMode,
  196. id: data.data.id,
  197. formType: data.data.formType
  198. })
  199. })
  200. },
  201. /**
  202. * 生命周期函数--监听页面初次渲染完成
  203. */
  204. onReady() {
  205. },
  206. /**
  207. * 生命周期函数--监听页面显示
  208. */
  209. onShow() {
  210. },
  211. /**
  212. * 生命周期函数--监听页面隐藏
  213. */
  214. onHide() {
  215. },
  216. /**
  217. * 生命周期函数--监听页面卸载
  218. */
  219. onUnload() {
  220. },
  221. /**
  222. * 页面相关事件处理函数--监听用户下拉动作
  223. */
  224. onPullDownRefresh() {
  225. },
  226. /**
  227. * 页面上拉触底事件的处理函数
  228. */
  229. onReachBottom() {
  230. },
  231. /**
  232. * 用户点击右上角分享
  233. */
  234. onShareAppMessage() {
  235. }
  236. })