home.js 9.8 KB

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