addRole.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /* 查询应用列表 */
  48. query_appselect() {
  49. _Http.basic({
  50. "classname": "sale.role.role",
  51. "method": "query_appselect",
  52. "content": {
  53. "roleid": this.data.roleid
  54. }
  55. }).then(res => {
  56. console.log("应用列表", res)
  57. if (res.msg != '成功') return wx.showToast({
  58. title: res.msg,
  59. icon: "none"
  60. })
  61. this.setData({
  62. roleid: this.data.roleid == -1 ? 0 : this.data.roleid,
  63. appList: res.data
  64. })
  65. /* this.setData({
  66. roleid: this.data.roleid == -1 ? 0 : this.data.roleid,
  67. appList: wx.getStorageSync('userauth')
  68. }) */
  69. })
  70. },
  71. /* 提交数据 */
  72. submitRole() {
  73. if (this.data.disabled || this.data.loading) return;
  74. this.setData({
  75. loading: true
  76. })
  77. let {
  78. isReturn,
  79. returnData
  80. } = this.selectComponent("#form").getData();
  81. _Http.basic({
  82. "classname": "sale.role.role",
  83. "method": "insertormodify_role",
  84. "content": {
  85. "roleid": this.data.roleid,
  86. ...returnData
  87. }
  88. }).then(res => {
  89. console.log("新建角色", res)
  90. this.setData({
  91. loading: false
  92. })
  93. if (res.msg != '成功') return wx.showToast({
  94. title: res.msg,
  95. icon: "none"
  96. })
  97. this.setData({
  98. disabled: true
  99. })
  100. let systemapps = this.selectComponent("#myCateg").backData();
  101. if (systemapps.length > 0) _Http.basic({
  102. "classname": "sale.role.role",
  103. "method": "add_appauth",
  104. "content": {
  105. "roleid": res.data.roleid,
  106. systemapps
  107. }
  108. }).then(res => {
  109. console.log("绑定授权", res)
  110. })
  111. this.navBack();
  112. })
  113. },
  114. deleteRole() {
  115. const that = this;
  116. wx.showModal({
  117. title: "提示",
  118. content: "是否确认删除该角色?",
  119. success: (s) => {
  120. if (s.confirm) {
  121. console.log('删除')
  122. _Http.basic({
  123. "classname": "sale.role.role",
  124. "method": "delete_role",
  125. "content": {
  126. "roleid": this.data.roleid
  127. }
  128. }).then(res => {
  129. if (res.msg != '成功') return wx.showToast({
  130. title: res.msg,
  131. });
  132. that.navBack('删除成功');
  133. })
  134. }
  135. }
  136. })
  137. },
  138. navBack(tips = '保存成功') {
  139. let pages = getCurrentPages(),
  140. prevPage = pages[pages.length - 2];
  141. prevPage.getList(true);
  142. setTimeout(() => {
  143. wx.navigateBack({
  144. delta: 0
  145. })
  146. wx.showToast({
  147. title: tips,
  148. })
  149. }, 300)
  150. },
  151. onReady() {
  152. getHeight.getHeight('.module-navigation', this).then(res => {
  153. this.setData({
  154. height: res - 130
  155. })
  156. })
  157. },
  158. /* 表单是否完成 */
  159. formCompletedOrNot({
  160. detail
  161. }) {
  162. this.setData({
  163. disabled: !detail
  164. })
  165. },
  166. })