index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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&type=abnormal'
  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&type=abnormal'
  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. showAuth: false
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: function (options) {
  75. var id = options.id ? options.id : 1
  76. this.setData({
  77. id: id,
  78. userInfo: app.globalData.userInfo
  79. })
  80. api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
  81. app.updateUserInfo(res);
  82. });
  83. var that = this;
  84. api.getByName(this, 'project-roles/getRoleAndRights', 'role', {id: id}, function() {
  85. that.updateMenuItemShow()
  86. });
  87. wx.setStorageSync('sg-added-devices', [])
  88. },
  89. requestAuth(e) {
  90. wx.requestSubscribeMessage({
  91. tmplIds: ['UxFg6zf47Gmha84hNzbdTJ3K0UHzcXNMPUbJQj-ivA8'],
  92. success (res) {
  93. console.log(res)
  94. }
  95. })
  96. },
  97. switchShow(e) {
  98. var name = e.currentTarget.dataset.name
  99. this.setData({
  100. [name]: !this.data[name]
  101. })
  102. },
  103. updateMenuItemShow() {
  104. var role = this.data.role
  105. var device_rent_menus = this.data.device_rent_menus
  106. device_rent_menus[0].hidden = !(role && role.rights && role.rights.rentCreate)
  107. if(['sub', 'admin'].indexOf(role.key) != -1) {
  108. device_rent_menus[1].hidden = true;
  109. device_rent_menus[2].hidden = true;
  110. }
  111. var device_use_menus = this.data.device_use_menus
  112. device_use_menus[0].hidden = !(role && role.rights && role.rights.applyCreate)
  113. this.setData({
  114. device_rent_menus,
  115. device_use_menus
  116. })
  117. },
  118. navigate: function(e) {
  119. var url = e.currentTarget.dataset.url
  120. var id = this.data.id
  121. console.log(url)
  122. if(url == '/pages/device-inner/index?id=' + id) {
  123. app.resetFilter();
  124. }
  125. wx.navigateTo({
  126. url: url,
  127. })
  128. },
  129. getProject() {
  130. var that = this
  131. http({
  132. url: 'projects/detail',
  133. data: {
  134. id: this.data.id
  135. },
  136. success: function(res) {
  137. if(res.code == 0) {
  138. that.setData({
  139. project: res.data
  140. })
  141. wx.setNavigationBarTitle({
  142. title: res.data.name,
  143. })
  144. }
  145. }
  146. })
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function () {
  157. this.getProject()
  158. },
  159. /**
  160. * 生命周期函数--监听页面隐藏
  161. */
  162. onHide: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面卸载
  166. */
  167. onUnload: function () {
  168. },
  169. /**
  170. * 页面相关事件处理函数--监听用户下拉动作
  171. */
  172. onPullDownRefresh: function () {
  173. },
  174. /**
  175. * 页面上拉触底事件的处理函数
  176. */
  177. onReachBottom: function () {
  178. },
  179. /**
  180. * 用户点击右上角分享
  181. */
  182. onShareAppMessage: function () {
  183. }
  184. })