addRole.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. const _Http = getApp().globalData.http;
  2. const getHeight = require("../../utils/getRheRemainingHeight.js");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. height: 0,
  9. roleid: -1, //角色id
  10. appList: [], //应用列表
  11. fromList: [{
  12. label: "角色名称",
  13. error: false,
  14. errMsg: "",
  15. type: "text",
  16. value: "",
  17. placeholder: "请填写",
  18. valueName: "rolename", //绑定的字段名称
  19. required: true, //必填
  20. }, {
  21. label: "角色描述",
  22. error: false,
  23. errMsg: "",
  24. type: "text",
  25. value: "",
  26. placeholder: "请填写",
  27. valueName: "remarks", //绑定的字段名称
  28. required: true, //必填
  29. }],
  30. disabled: true, //按钮禁用
  31. loading: false, //按钮加载
  32. },
  33. onLoad(options) {
  34. console.log(options)
  35. if (options.item) {
  36. let item = JSON.parse(options.item)
  37. this.setData({
  38. roleid: item.roleid,
  39. ['fromList[0].value']: item.rolename,
  40. ['fromList[1].value']: item.remarks,
  41. disabled: false,
  42. });
  43. };
  44. this.query_appselect();
  45. },
  46. /* 查询应用列表 */
  47. query_appselect() {
  48. _Http.basic({
  49. "classname": "sale.role.role",
  50. "method": "query_appselect",
  51. "content": {
  52. "roleid": this.data.roleid
  53. }
  54. }).then(res => {
  55. console.log("应用列表", res)
  56. if (res.msg != '成功') return wx.showToast({
  57. title: res.msg,
  58. icon: "none"
  59. })
  60. this.setData({
  61. roleid: this.data.roleid == -1 ? 0 : this.data.roleid,
  62. appList: res.data
  63. })
  64. })
  65. },
  66. /* 提交数据 */
  67. submitRole() {
  68. if (this.data.disabled || this.data.loading) return;
  69. this.setData({
  70. loading: true
  71. })
  72. let {
  73. isReturn,
  74. returnData
  75. } = this.selectComponent("#form").getData();
  76. _Http.basic({
  77. "classname": "sale.role.role",
  78. "method": "insertormodify_role",
  79. "content": {
  80. "roleid": this.data.roleid,
  81. ...returnData
  82. }
  83. }).then(res => {
  84. console.log("新建角色", res)
  85. this.setData({
  86. loading: false
  87. })
  88. if (res.msg != '成功') return wx.showToast({
  89. title: res.msg,
  90. icon: "none"
  91. })
  92. this.setData({
  93. disabled: true
  94. })
  95. let systemapps = this.selectComponent("#myCateg").backData();
  96. if (systemapps.length > 0) _Http.basic({
  97. "classname": "sale.role.role",
  98. "method": "add_appauth",
  99. "content": {
  100. "roleid": res.data.roleid,
  101. systemapps
  102. }
  103. }).then(res => {
  104. console.log("绑定授权", res)
  105. })
  106. this.navBack();
  107. })
  108. },
  109. deleteRole() {
  110. const that = this;
  111. wx.showModal({
  112. title: "提示",
  113. content: "是否确认删除该角色?",
  114. success: (s) => {
  115. if (s.confirm) {
  116. console.log('删除')
  117. _Http.basic({
  118. "classname": "sale.role.role",
  119. "method": "delete_role",
  120. "content": {
  121. "roleid": this.data.roleid
  122. }
  123. }).then(res => {
  124. if (res.msg != '成功') return wx.showToast({
  125. title: res.msg,
  126. });
  127. that.navBack('删除成功');
  128. })
  129. }
  130. }
  131. })
  132. },
  133. navBack(tips = '保存成功') {
  134. let pages = getCurrentPages(),
  135. prevPage = pages[pages.length - 2];
  136. prevPage.getList(true);
  137. setTimeout(() => {
  138. wx.navigateBack({
  139. delta: 0
  140. })
  141. wx.showToast({
  142. title: tips,
  143. })
  144. }, 300)
  145. },
  146. onReady() {
  147. getHeight.getHeight('.module-navigation', this).then(res => {
  148. this.setData({
  149. height: res - 130
  150. })
  151. })
  152. },
  153. /* 表单是否完成 */
  154. formCompletedOrNot({
  155. detail
  156. }) {
  157. this.setData({
  158. disabled: !detail
  159. })
  160. },
  161. })