index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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://rt2.swdz.com/mini/create-order.png',
  15. title: '创建订单',
  16. desc: '创建外部设备租赁订单',
  17. url: '/pages/create-order/index',
  18. hidden: true
  19. }, {
  20. img: 'http://rt2.swdz.com/mini/rent-check.png',
  21. title: '租赁审核',
  22. desc: '设备租赁订单审核',
  23. url: '/pages/order/index?type=check'
  24. }, {
  25. img: 'http://rt2.swdz.com/mini/error-handle.png',
  26. title: '异常处理',
  27. desc: '订单流程变更审核处理',
  28. url: '/pages/order/index?index=4&type=abnormal'
  29. }, {
  30. img: 'http://rt2.swdz.com/mini/all-order.png',
  31. title: '所有订单',
  32. desc: '查看全部设备租赁订单',
  33. url: '/pages/order/index'
  34. }],
  35. device_use_menus: [{
  36. img: 'http://rt2.swdz.com/mini/use-apply.png',
  37. title: '调用申请',
  38. desc: '机电负责人调用设备',
  39. url: '/pages/create-order-inner/index',
  40. hidden: true
  41. }, {
  42. img: 'http://rt2.swdz.com/mini/rent-check.png',
  43. title: '调用审核',
  44. desc: '设备调用订单审核',
  45. url: '/pages/order-inner/index?type=check'
  46. }, {
  47. img: 'http://rt2.swdz.com/mini/error-handle.png',
  48. title: '异常处理',
  49. desc: '订单流程变更审核处理',
  50. url: '/pages/order-inner/index?index=4&type=abnormal'
  51. }, {
  52. img: 'http://rt2.swdz.com/mini/all-order.png',
  53. title: '所有订单',
  54. desc: '查看全部设备调用订单',
  55. url: '/pages/order-inner/index'
  56. }],
  57. device_depot_menus: [{
  58. img: 'http://rt2.swdz.com/mini/all-order.png',
  59. title: '所有设备',
  60. desc: '查看仓库所有设备',
  61. url: '/pages/device-inner/index'
  62. }, {
  63. img: 'http://rt2.swdz.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. if (url == '/pages/device-inner/index?id=' + id) {
  122. app.resetFilter();
  123. }
  124. // if (url == '/pages/order/index?type=check') {
  125. // url = url + "&id=" + id
  126. // }
  127. // if (url == '/pages/order/index?index=4&type=abnormal') {
  128. // url = url + "&id=" + id
  129. // }
  130. // if (url == '/pages/order-inner/index?type=check') {
  131. // url = url + "&id=" + id
  132. // }
  133. // if (url == '/pages/order-inner/index?index=4&type=abnormal') {
  134. // url = url + "&id=" + id
  135. // }
  136. console.log(url)
  137. switch (url) {
  138. case '/pages/order/index?type=check':
  139. url = url + "&id=" + id
  140. break;
  141. case '/pages/order/index?index=4&type=abnormal':
  142. url = url + "&id=" + id
  143. break;
  144. case '/pages/order-inner/index?type=check':
  145. url = url + "&id=" + id
  146. break;
  147. case '/pages/order-inner/index?index=4&type=abnormal':
  148. url = url + "&id=" + id
  149. break;
  150. default:
  151. url = url + "?id=" + id
  152. break;
  153. }
  154. wx.navigateTo({
  155. url: url,
  156. })
  157. },
  158. getProject() {
  159. var that = this
  160. http({
  161. url: 'projects/detail',
  162. data: {
  163. id: this.data.id
  164. },
  165. success: function (res) {
  166. if (res.code == 0) {
  167. that.setData({
  168. project: res.data
  169. })
  170. wx.setNavigationBarTitle({
  171. title: res.data.name,
  172. })
  173. }
  174. }
  175. })
  176. },
  177. /**
  178. * 生命周期函数--监听页面初次渲染完成
  179. */
  180. onReady: function () {
  181. },
  182. /**
  183. * 生命周期函数--监听页面显示
  184. */
  185. onShow: function () {
  186. this.getProject()
  187. },
  188. /**
  189. * 生命周期函数--监听页面隐藏
  190. */
  191. onHide: function () {
  192. },
  193. /**
  194. * 生命周期函数--监听页面卸载
  195. */
  196. onUnload: function () {
  197. },
  198. /**
  199. * 页面相关事件处理函数--监听用户下拉动作
  200. */
  201. onPullDownRefresh: function () {
  202. },
  203. /**
  204. * 页面上拉触底事件的处理函数
  205. */
  206. onReachBottom: function () {
  207. },
  208. /**
  209. * 用户点击右上角分享
  210. */
  211. onShareAppMessage: function () {
  212. }
  213. })