index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. const _Http = getApp().globalData.http;
  2. const getHeight = require("../../utils/getRheRemainingHeight"),
  3. currency = require("../../utils/currency");
  4. Page({
  5. data: {
  6. tabShow: true,
  7. auth: {}, //权限
  8. listHeight: 0,
  9. butText: "", //按钮类型
  10. content: {
  11. nocache: true,
  12. "pageNumber": 1,
  13. "pageSize": 20,
  14. "pageTotal": 1,
  15. "where": {
  16. "condition": ""
  17. }
  18. }
  19. },
  20. onLoad(options) {
  21. let auth = options.auth ? JSON.parse(options.auth) : getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心'])[0].apps[0].meta.auth,
  22. tabList = [],
  23. authList = auth.map(v => {
  24. if (v.option == 'account') {
  25. tabList[0] = {
  26. title: "账号列表",
  27. butText: "新建账号",
  28. classname: "sale.team.team",
  29. method: "query_teamList",
  30. url: '/pages/teams/addUsers'
  31. }
  32. } else if (v.option == 'role') {
  33. tabList[1] = {
  34. title: "角色列表",
  35. butText: "新建角色",
  36. classname: "sale.role.role",
  37. method: "query_roleList",
  38. url: '/pages/teams/addRole'
  39. }
  40. } else if (v.option == 'paidOrder') {
  41. tabList[2] = {
  42. title: "付费订单",
  43. butText: wx.getStorageSync('siteP').sys_payswitch ? "新建付费订单" : "",
  44. classname: "system.payorder.payorder",
  45. method: "list",
  46. url: "/pages/teams/addOrder"
  47. }
  48. }
  49. return v.option
  50. });
  51. tabList = tabList.filter(v => v);
  52. this.setData({
  53. authList,
  54. tabList,
  55. active: tabList[options.title ? tabList.findIndex(v => v.title == options.title) || 0 : 0]
  56. })
  57. /* if (options.title) setTimeout(() => {
  58. this.setData({
  59. active: this.data.active
  60. })
  61. }, 300) */
  62. this.getList();
  63. },
  64. /* tab切换 */
  65. tabChange(e) {
  66. this.setData({
  67. active: this.data.tabList[e.detail.index],
  68. list: [],
  69. })
  70. this.getList(true);
  71. },
  72. /* 获取列表 */
  73. getList(init = false) {
  74. if (init.detail != undefined) init = init.detail;
  75. if (init) this.setData({
  76. ['content.pageNumber']: 1
  77. })
  78. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  79. let active = this.data.active;
  80. _Http.basic({
  81. classname: active.classname || '',
  82. method: active.method || '',
  83. id: active.id || '',
  84. content: this.data.content
  85. }).then(res => {
  86. this.selectComponent('#ListBox').RefreshToComplete();
  87. if (res.msg != '成功') return wx.showToast({
  88. title: res.msg,
  89. icon: "none"
  90. })
  91. if (active.butText == '新建账号') {
  92. for (let i = 0; i < res.data.length; i++) {
  93. res.data[i].attinfos = res.data[i].attinfos.filter(v => v.usetype == 'headportrait');
  94. }
  95. } else if (active.butText == '新建付费订单') {
  96. res.data = res.data.map(v => {
  97. switch (v.ispaid) {
  98. case 0:
  99. v.color = "#FF3B30";
  100. v.status = '未付费';
  101. break;
  102. case 1:
  103. v.color = '#52C41A';
  104. v.status = '已付费';
  105. break;
  106. case 2:
  107. v.color = '#ddd';
  108. v.status = "新建";
  109. break;
  110. case 3:
  111. v.color = '#ddd';
  112. v.status = "已取消";
  113. break;
  114. case 4:
  115. v.color = '#ddd';
  116. v.status = "已退费";
  117. break;
  118. };
  119. v.amount = currency(v.amount, {
  120. symbol: "¥",
  121. precision: 2
  122. }).format();
  123. return v
  124. })
  125. }
  126. this.setData({
  127. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  128. ['content.pageNumber']: res.pageNumber + 1,
  129. ['content.pageTotal']: res.pageTotal
  130. })
  131. })
  132. },
  133. /* 新建账号/角色 */
  134. newItem() {
  135. let url = this.data.active.url;
  136. if (!url) return;
  137. if (url == '/pages/teams/addOrder') {
  138. _Http.basic({
  139. "classname": "system.payorder.payorder",
  140. "method": "createOrder",
  141. "content": {},
  142. }).then(res => {
  143. console.log("新建订单", res)
  144. if (res.msg != '成功') return wx.showToast({
  145. title: res.msg,
  146. icon: "none",
  147. mask: true
  148. });
  149. wx.navigateTo({
  150. url: url + '?sys_payorderid=' + res.data.sys_payorderid
  151. })
  152. })
  153. } else {
  154. wx.navigateTo({
  155. url
  156. })
  157. }
  158. },
  159. /* 修改角色 */
  160. changeRole(e) {
  161. let {
  162. item
  163. } = e.currentTarget.dataset;
  164. wx.navigateTo({
  165. url: `./addRole?item=${JSON.stringify(item)}&update=${this.data.authList.includes("角色修改")}&userDelete=${this.data.authList.includes("角色删除")}`
  166. })
  167. },
  168. /* 修改账号 */
  169. changeUser(e) {
  170. let {
  171. item
  172. } = e.currentTarget.dataset;
  173. delete(item.attinfos);
  174. wx.navigateTo({
  175. url: `./addUsers?item=${JSON.stringify(item)}&update=${this.data.authList.includes("账号修改")}`
  176. })
  177. },
  178. onReady() {
  179. getHeight.getHeight('.tabs', this).then(res => {
  180. this.setData({
  181. listHeight: res
  182. })
  183. });
  184. },
  185. })