home.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // parents/pages/home/home.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, getWxLocationSetting } from '../../../utils/util.js'
  3. import { GetLibrary, GetParentHome, GetBorrowBookNum, ScanningBooks, GoodIndex, ScanningBackBooks,IndexBarList} from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isFirst: 0,
  14. latitude: '',
  15. longitude: '',
  16. isLoaded: 0,
  17. pageNo: 1,
  18. pageSize: 10,
  19. vipId:'ea4e93ee-8b22-41bd-bb09-ec36e88eab78',
  20. carouselList: ['../../../assets/main_banner1.png', '../../../assets/banner1.png'],
  21. // 签到签离
  22. sign: [
  23. {
  24. icon: '../../../assets/sign_in.png',
  25. text: '签到',
  26. url: 'president/pages/sign_leave_in/sign_leave_in?isSignin=1',
  27. zindex: 3,
  28. },
  29. {
  30. icon: '../../../assets/sign_leave.png',
  31. text: '签离',
  32. url: 'president/pages/sign_leave_in/sign_leave_in?isSignin=0',
  33. zindex: 3,
  34. },
  35. {
  36. icon: '../../../assets/data_ansyc.png',
  37. text: '数据统计',
  38. url: 'president/pages/data_statistics/data_statistics',
  39. zindex: 3,
  40. },
  41. ],
  42. // 图书借阅
  43. library: [
  44. {
  45. icon: '../../../assets/replace_record.png',
  46. text: '代办借阅',
  47. url: 'president/pages/borrow_books/borrow_books',
  48. zindex: 3,
  49. },
  50. {
  51. icon: '../../../assets/returnBook.png',
  52. text: '还书',
  53. url: 'president/pages/Return_book_car/Return_book_car',
  54. zindex: 3,
  55. },
  56. {
  57. icon: '../../../assets/reding_booksbank.png',
  58. text: '馆内阅读排行榜',
  59. url: 'president/pages/ranking/ranking',
  60. zindex: 3,
  61. },
  62. ],
  63. // 书籍调配
  64. Books: [
  65. {
  66. icon: '../../../assets/library_books.png',
  67. text: '在馆书籍',
  68. url: 'president/pages/library_books/library_books',
  69. zindex: 3,
  70. },
  71. {
  72. icon: '../../../assets/goodboos_icon.png',
  73. text: '好书推荐',
  74. url: 'president/pages/good_books_new/good_books_new',
  75. zindex: 3,
  76. },
  77. {
  78. icon: '../../../assets/allot_lists.png',
  79. text: '调书清单',
  80. url: 'president/pages/book_inventory/book_inventory',
  81. zindex: 3,
  82. },
  83. ],
  84. topList: [],
  85. list: [],
  86. footerData: {
  87. actIndex: 0,
  88. list: [
  89. {
  90. text: '日常事务',
  91. icon: '../../../assets/lock_gary.png',
  92. actIcon: '../../../assets/lock_blue.png',
  93. url: 'president/pages/home/home',
  94. zindex: 3,
  95. },
  96. {
  97. text: '人员管理',
  98. icon: '../../../assets/people_manager_gary.png',
  99. actIcon: '../../../assets/people_manager_blue.png',
  100. url: 'president/pages/Personnel_management/Personnel_management',
  101. zindex: 3,
  102. },
  103. {
  104. text: '我的',
  105. icon: '../../../assets/me_gray.png',
  106. actIcon: '../../../assets/me_blue.png',
  107. url: 'president/pages/me/me',
  108. zindex: 3,
  109. }
  110. ]
  111. }
  112. },
  113. /**
  114. * 生命周期函数--监听页面加载
  115. */
  116. onLoad: function (options) {
  117. options.userId = getGlobalVal('userId')
  118. options.library = getGlobalVal('library')
  119. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  120. const returnbookList = getGlobalVal(`returnBook_${options.userId}_${options.libId}`) || []
  121. console.log(`returnBook_${options.userId}_${options.libId}`)
  122. console.log(returnbookList)
  123. this.setData({ options, isFirst: 1 })
  124. this.getIndexBarList()
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady: function () {
  130. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  131. for (const i in obj) {
  132. this[i] = obj[i]
  133. }
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. // this.getList(res => {
  155. // wx.stopPullDownRefresh()
  156. // })
  157. },
  158. /**
  159. * 页面上拉触底事件的处理函数
  160. */
  161. onReachBottom: function () {
  162. },
  163. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage: function () {
  167. if (isFn(sharePage)) return sharePage()
  168. },
  169. /**
  170. * 获取首页数据
  171. */
  172. getList: function (cb) {
  173. const continuousFn = { fn: this.getList, param: { ...arguments } }
  174. const libId = this.data.options.library.id || ''
  175. // hasLibraryService()
  176. if (!libId) {
  177. wx.showToast({
  178. title: '请先定位图书馆',
  179. icon: 'none'
  180. })
  181. return
  182. }
  183. GoodIndex({ data: { libId }, continuousFn }).then(res => {
  184. const { list } = res.data
  185. const listTemp = (res => {
  186. for (let i in res) {
  187. if (res[i].summary.length>30){
  188. res[i].summary = res[i].summary.slice(0, 30) + '...'
  189. }else{
  190. res[i].summary = res[i].summary
  191. }
  192. }
  193. return res
  194. })(list)
  195. // console.log(listTemp,list)
  196. this.setData({ list: listTemp })
  197. cb && cb(res)
  198. }).catch(res => {
  199. cb && cb(res)
  200. })
  201. },
  202. /**
  203. * 获取定位
  204. */
  205. getLocation: function (cb) {
  206. getWxLocationSetting(res => {
  207. this.setData({
  208. isShowPosition: false
  209. })
  210. wx.showLoading({
  211. title: '定位中'
  212. })
  213. wx.getLocation({
  214. type: 'wgs84',
  215. success: res => {
  216. const { latitude, longitude } = res
  217. this.setData({
  218. latitude,
  219. longitude
  220. })
  221. this.getLibrary(cb)
  222. },
  223. fail: res => {
  224. wx.showToast({
  225. title: '定位失败',
  226. icon: 'none'
  227. })
  228. },
  229. complete: res => {
  230. wx.hideLoading()
  231. }
  232. })
  233. })
  234. },
  235. /**
  236. * 获取图书馆
  237. */
  238. getLibrary: function (cb) {
  239. const continuousFn = { fn: this.getLibrary, param: { ...arguments } }
  240. const { options, latitude, longitude, pageNo, pageSize } = this.data
  241. const { vipId } = options
  242. GetLibrary({ data: { vipId, pageNo, pageSize, leagueLat: latitude, leagueLng: longitude }, continuousFn }).then(res => {
  243. const { list } = res.data
  244. if (list[0]['id']) {
  245. getApp().globalData.library = list[0]
  246. wx.setStorageSync('library', list[0])
  247. this.setData({ 'options.library': list[0] })
  248. this.getList(cb)
  249. }
  250. })
  251. },
  252. /**
  253. * 获取首页图片
  254. */
  255. getIndexBarList: function (cb) {
  256. const continuousFn = { fn: this.getIndexBarList, param: { ...arguments } }
  257. const { options, latitude, longitude, pageNo, pageSize } = this.data
  258. const { vipId } = options
  259. IndexBarList({ data: { vipId, pageNo, pageSize, leagueLat: latitude, leagueLng: longitude }, continuousFn }).then(res => {
  260. const { imgList } = res.data
  261. this.setData({ imgList, isLoaded: 1})
  262. })
  263. },
  264. /**
  265. * 签到签离选择跳转进入页
  266. */
  267. selectRouteCtl: function (e) {
  268. const { index } = e.currentTarget.dataset
  269. const { sign } = this.data
  270. const { url, zindex } = sign[index]
  271. // if(index==0){
  272. // this.scanCtl()
  273. // }else{
  274. // if (!hasVipService()) return
  275. navigateTo({ url, zindex })
  276. // }
  277. },
  278. /**
  279. * 图书借阅选择跳转进入页
  280. */
  281. selectRouteCtlBorrow: function (e) {
  282. const { index } = e.currentTarget.dataset
  283. const { library, options } = this.data
  284. const { url, zindex } = library[index]
  285. const returnbookList = getGlobalVal(`returnBook_${options.userId}_${options.libId}`) || []
  286. console.log(`returnBook_${options.userId}_${options.libId}`)
  287. console.log(returnbookList)
  288. if(index==1){
  289. if (returnbookList.length > 0) {
  290. navigateTo({ url: 'president/pages/Return_book_car/Return_book_car', paras: { } })
  291. return
  292. }
  293. if (returnbookList.length == 0) {
  294. this.scanFn()
  295. }
  296. }else{
  297. navigateTo({ url, zindex })
  298. }
  299. },
  300. /**
  301. * 书籍调配选择跳转进入页
  302. */
  303. selectRouteCtlBooks: function (e) {
  304. const { index } = e.currentTarget.dataset
  305. const { Books } = this.data
  306. const { url, zindex } = Books [index]
  307. // if(index==0){
  308. // this.scanCtl()
  309. // }else{
  310. // if (!hasVipService()) return
  311. navigateTo({ url, zindex })
  312. // }
  313. },
  314. /**
  315. * 调用微信扫一扫
  316. */
  317. scanFn: function () {
  318. wx.scanCode({
  319. success: res => {
  320. const url = res.result
  321. const detailsId = url.split('_')[1].split('.')[0]
  322. if (!detailsId) {
  323. wx.showToast({
  324. title: qrcodeInvalidToastText,
  325. icon: 'none'
  326. })
  327. return
  328. }
  329. this.scanningBooksFn(detailsId)
  330. }
  331. })
  332. },
  333. /**
  334. * 扫一扫借书
  335. */
  336. scanningBooksFn: function (detailsId) {
  337. const continuousFn = { fn: this.scanningBooksFn, param: { ...arguments } }
  338. const { libId } = this.data.options
  339. const { returnbookList } = this.data
  340. ScanningBackBooks({ data: { detailsId, libId }, continuousFn }).then(res => {
  341. const { detailsId } = res.data;
  342. for (var i in returnbookList) {
  343. if (detailsId == returnbookList[i].detailsId) {
  344. wx.showToast({
  345. title: '此二维码已经扫过',
  346. icon: 'none'
  347. })
  348. }
  349. }
  350. if (detailsId) {
  351. navigateTo({ url: 'president/pages/Return_book_car/Return_book_car', paras: { ...res.data } })
  352. }
  353. }).catch(res => {
  354. wx.showToast({
  355. title: res.msg,
  356. icon: 'none'
  357. })
  358. })
  359. }
  360. })