index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. var device_use_menus = this.data.device_use_menus
  93. device_use_menus[0].hidden = !(role && role.rights && role.rights.applyCreate)
  94. this.setData({
  95. device_rent_menus,
  96. device_use_menus
  97. })
  98. },
  99. navigate: function(e) {
  100. var url = e.currentTarget.dataset.url
  101. var id = this.data.id
  102. if(url == '/pages/device-inner/index?id=' + id) {
  103. app.resetFilter();
  104. }
  105. wx.navigateTo({
  106. url: url,
  107. })
  108. },
  109. getProject() {
  110. var that = this
  111. http({
  112. url: 'projects/detail',
  113. data: {
  114. id: this.data.id
  115. },
  116. success: function(res) {
  117. if(res.code == 0) {
  118. that.setData({
  119. project: res.data
  120. })
  121. wx.setNavigationBarTitle({
  122. title: res.data.name,
  123. })
  124. }
  125. }
  126. })
  127. },
  128. /**
  129. * 生命周期函数--监听页面初次渲染完成
  130. */
  131. onReady: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面显示
  135. */
  136. onShow: function () {
  137. this.getProject()
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh: function () {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom: function () {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {
  163. }
  164. })