index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // pages/project/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. import api from '../../utils/api'
  5. var app = getApp()
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. id: -1,
  12. userInfo: {},
  13. device_rent_menus: [{
  14. img: 'http://t18.9026.com/mini/create-order.png',
  15. title: '创建订单',
  16. desc: '创建外部设备租赁订单',
  17. url: '/pages/create-order/index',
  18. hidden: true
  19. }, {
  20. img: 'http://t18.9026.com/mini/rent-check.png',
  21. title: '租赁审核',
  22. desc: '设备租赁订单审核',
  23. url: '/pages/order/index?type=check'
  24. }, {
  25. img: 'http://t18.9026.com/mini/error-handle.png',
  26. title: '异常处理',
  27. desc: '订单流程变更审核处理',
  28. url: '/pages/order/index?index=4'
  29. }, {
  30. img: 'http://t18.9026.com/mini/all-order.png',
  31. title: '所有订单',
  32. desc: '查看全部设备租赁订单',
  33. url: '/pages/order/index'
  34. }],
  35. device_use_menus: [{
  36. img: 'http://t18.9026.com/mini/use-apply.png',
  37. title: '调用申请',
  38. desc: '机电负责人调用设备',
  39. url: '/pages/create-order-inner/index',
  40. hidden: true
  41. }, {
  42. img: 'http://t18.9026.com/mini/rent-check.png',
  43. title: '调用审核',
  44. desc: '设备调用订单审核',
  45. url: '/pages/order-inner/index?type=check'
  46. }, {
  47. img: 'http://t18.9026.com/mini/error-handle.png',
  48. title: '异常处理',
  49. desc: '订单流程变更审核处理',
  50. url: '/pages/order-inner/index?index=4'
  51. }, {
  52. img: 'http://t18.9026.com/mini/all-order.png',
  53. title: '所有订单',
  54. desc: '查看全部设备调用订单',
  55. url: '/pages/order-inner/index'
  56. }],
  57. device_depot_menus: [{
  58. img: 'http://t18.9026.com/mini/all-order.png',
  59. title: '所有设备',
  60. desc: '查看仓库所有设备',
  61. url: '/pages/device-inner/index'
  62. }, {
  63. img: 'http://t18.9026.com/mini/rent-check.png',
  64. title: '维修上报',
  65. desc: '设备维修上报',
  66. url: '/pages/repair/index'
  67. }],
  68. role: null
  69. },
  70. /**
  71. * 生命周期函数--监听页面加载
  72. */
  73. onLoad: function (options) {
  74. var id = options.id ? options.id : 1
  75. this.setData({
  76. id: id,
  77. userInfo: app.globalData.userInfo
  78. })
  79. api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
  80. app.updateUserInfo(res);
  81. });
  82. var that = this;
  83. api.getByName(this, 'project-roles/getRoleAndRights', 'role', {id: id}, function() {
  84. that.updateMenuItemShow()
  85. });
  86. wx.setStorageSync('sg-added-devices', [])
  87. },
  88. updateMenuItemShow() {
  89. var role = this.data.role
  90. var device_rent_menus = this.data.device_rent_menus
  91. device_rent_menus[0].hidden = !(role && role.rights && role.rights.rentCreate)
  92. if(['sub', 'admin'].indexOf(role.key) != -1) {
  93. device_rent_menus[1].hidden = true;
  94. device_rent_menus[2].hidden = true;
  95. }
  96. var device_use_menus = this.data.device_use_menus
  97. device_use_menus[0].hidden = !(role && role.rights && role.rights.applyCreate)
  98. this.setData({
  99. device_rent_menus,
  100. device_use_menus
  101. })
  102. },
  103. navigate: function(e) {
  104. var url = e.currentTarget.dataset.url
  105. var id = this.data.id
  106. if(url == '/pages/device-inner/index?id=' + id) {
  107. app.resetFilter();
  108. }
  109. wx.navigateTo({
  110. url: url,
  111. })
  112. },
  113. getProject() {
  114. var that = this
  115. http({
  116. url: 'projects/detail',
  117. data: {
  118. id: this.data.id
  119. },
  120. success: function(res) {
  121. if(res.code == 0) {
  122. that.setData({
  123. project: res.data
  124. })
  125. wx.setNavigationBarTitle({
  126. title: res.data.name,
  127. })
  128. }
  129. }
  130. })
  131. },
  132. /**
  133. * 生命周期函数--监听页面初次渲染完成
  134. */
  135. onReady: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面显示
  139. */
  140. onShow: function () {
  141. this.getProject()
  142. },
  143. /**
  144. * 生命周期函数--监听页面隐藏
  145. */
  146. onHide: function () {
  147. },
  148. /**
  149. * 生命周期函数--监听页面卸载
  150. */
  151. onUnload: function () {
  152. },
  153. /**
  154. * 页面相关事件处理函数--监听用户下拉动作
  155. */
  156. onPullDownRefresh: function () {
  157. },
  158. /**
  159. * 页面上拉触底事件的处理函数
  160. */
  161. onReachBottom: function () {
  162. },
  163. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage: function () {
  167. }
  168. })