Personnel_management.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // parents/pages/reservations/reservations.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { LibVipList, ManagerList } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, thumbnail,qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. thumbnail,
  14. isLoaded: 1,
  15. content: '',
  16. navIndex: 0,
  17. pageNo:1,
  18. pageSize:10,
  19. isAll:0,
  20. index: 0,
  21. isDown: false,
  22. list:[],
  23. managerList:[],
  24. isreturn:0,
  25. navList: [
  26. {
  27. text: '会员管理',
  28. list: [],
  29. nodataArray: {
  30. text: '暂没有预约书单',
  31. image: '../../../assets/nodata_3.png',
  32. hasNodataBtn: 1,
  33. btnText: '去书库看看'
  34. }
  35. },
  36. {
  37. text: '馆内人员管理',
  38. list: [],
  39. nodataArray: {
  40. text: '暂没有已预约书单',
  41. image: '../../../assets/nodata_2.png',
  42. hasNodataBtn: 1,
  43. btnText: '去书库看看'
  44. }
  45. }
  46. ],
  47. footerData: {
  48. actIndex: 1,
  49. list: [
  50. {
  51. text: '日常事务',
  52. icon: '../../../assets/lock_gary.png',
  53. actIcon: '../../../assets/lock_blue.png',
  54. url: 'president/pages/home/home',
  55. zindex: 3,
  56. },
  57. {
  58. text: '人员管理',
  59. icon: '../../../assets/people_manager_gary.png',
  60. actIcon: '../../../assets/people_manager_blue.png',
  61. url: 'president/pages/Personnel_management/Personnel_management',
  62. zindex: 3,
  63. },
  64. {
  65. text: '我的',
  66. icon: '../../../assets/me_gray.png',
  67. actIcon: '../../../assets/me_blue.png',
  68. url: 'president/pages/me/me',
  69. zindex: 3,
  70. }
  71. ]
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面加载
  76. */
  77. onLoad: function (options) {
  78. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  79. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  80. wx.setNavigationBarTitle({
  81. title: `人员管理`,
  82. })
  83. this.setData(options)
  84. this.getData(res => {
  85. this.setData({ isLoaded: 1 })
  86. })
  87. },
  88. /**
  89. * 生命周期函数--监听页面初次渲染完成
  90. */
  91. onReady: function () {
  92. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  93. for (const i in obj) {
  94. this[i] = obj[i]
  95. }
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. const { isAll, options } = this.data
  117. const { type = 1 } = options
  118. if (type == 1) return
  119. this.setData({ pageNo: 1 })
  120. this.getData(res => {
  121. wx.stopPullDownRefresh()
  122. })
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. const { isAll, isDown } = this.data
  129. if (isAll) {
  130. this.setData({ isDown: true })
  131. return
  132. } else {
  133. this.setData({ isLoad: true, isDown: false })
  134. this.getData(() => {
  135. this.setData({ isLoad: false })
  136. })
  137. }
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. if (isFn(sharePage)) return sharePage()
  144. },
  145. pickChange: function (e) {
  146. this.setData({
  147. index: e.detail.value
  148. });
  149. },
  150. /**
  151. * 会员管理获取数据
  152. */
  153. getData: function (cb) {
  154. const continuousFn = { fn: this.getData, param: { ...arguments } }
  155. // if (!hasVipService()) {
  156. // cb && cb()
  157. // return
  158. // }
  159. // if (!hasLibraryService()) {
  160. // cb && cb()
  161. // return
  162. // }
  163. const { navIndex, navList, options, pageSize, pageNo, libId } = this.data
  164. LibVipList({ data: { pageSize, pageNo, libId,}, continuousFn }).then(res => {
  165. const { list, pages, todayAdd } = res.data
  166. const oneTemp = (res => {
  167. for (let i in res) {
  168. for (let j in res[i].valueList){
  169. if (res[i].valueList[j].summary.length > 30) {
  170. res[i].valueList[j].summary = res[i].valueList[j].summary.slice(0, 30) + '...'
  171. } else {
  172. res[i].valueList[j].summary = res[i].valueList[j].summary
  173. }
  174. }
  175. }
  176. return res
  177. })(list)
  178. let listTemp = []
  179. if (pageNo == 1) {
  180. listTemp = [].concat(oneTemp)
  181. } else {
  182. listTemp = [].concat(that.data.list, oneTemp)
  183. }
  184. this.setData({
  185. list: listTemp,
  186. pageNo: list.length == pageSize ? pageNo + 1 : pageNo,
  187. isAll: list.length < pageSize ,
  188. pages: pages,
  189. todayAdd: todayAdd
  190. })
  191. cb && cb()
  192. }).catch(res => {
  193. cb && cb()
  194. })
  195. },
  196. /**
  197. * 馆内人员管理获取数据
  198. */
  199. getLibraryData: function (cb) {
  200. const continuousFn = { fn: this.getData, param: { ...arguments } }
  201. // if (!hasVipService()) {
  202. // cb && cb()
  203. // return
  204. // }
  205. // if (!hasLibraryService()) {
  206. // cb && cb()
  207. // return
  208. // }
  209. const { navIndex, navList, options, pageSize, pageNo, libId } = this.data
  210. ManagerList({ data: { pageSize, pageNo, libId, }, continuousFn }).then(res => {
  211. const { managerList, pages } = res.data
  212. // debugger
  213. const oneTemp = (res => {
  214. for (let i in res) {
  215. for (let j in res[i].valueList) {
  216. if (res[i].valueList[j].summary.length > 30) {
  217. res[i].valueList[j].summary = res[i].valueList[j].summary.slice(0, 30) + '...'
  218. } else {
  219. res[i].valueList[j].summary = res[i].valueList[j].summary
  220. }
  221. }
  222. }
  223. return res
  224. })(managerList)
  225. let listTemp = []
  226. if (pageNo == 1) {
  227. listTemp = [].concat(oneTemp)
  228. } else {
  229. listTemp = [].concat(that.data.managerList, oneTemp)
  230. }
  231. this.setData({
  232. managerList: listTemp,
  233. pageNo: managerList.length == pageSize ? pageNo + 1 : pageNo,
  234. isAll: managerList.length < pageSize,
  235. managerpages: pages,
  236. })
  237. cb && cb()
  238. }).catch(res => {
  239. cb && cb()
  240. })
  241. },
  242. /**
  243. * 选择导航栏
  244. */
  245. selectNavCtl: function (e) {
  246. const { index } = e.currentTarget.dataset
  247. const { navIndex, navList, isreturn } = this.data
  248. if (navIndex == index) return
  249. this.setData({ navIndex: index })
  250. if (index == 0) {
  251. this.setData({ isreturn: 0 })
  252. if (navList[index]['list'].length == 0) {
  253. this.getData()
  254. }
  255. } else if (index == 1) {
  256. this.setData({ isreturn: 1 })
  257. this.getLibraryData()
  258. }
  259. },
  260. })