index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const getUserInfo = require('../../utils/getUserInfo').default;
  4. const bgImg = require('../../static/images/bgImg')
  5. import {
  6. Router
  7. } from '../../utils/router.js'
  8. //获取应用实例
  9. Router({
  10. data: {
  11. currentBanner: 0,
  12. banners: [],
  13. showSearch: false,
  14. activeType: -1,
  15. header: [],
  16. noRecord: '',
  17. hideMask: false,
  18. keyword: '',
  19. url: 'https://www.4dkankan.com/eShopMobile.html?m=',
  20. totalPages: 1,
  21. currentPage: 1,
  22. size: 10,
  23. bgImg,
  24. loading: false,
  25. showClear: false,
  26. brandList: []
  27. },
  28. clearKeyword() {
  29. this.setData({
  30. keyword: ''
  31. })
  32. this.setData({showClear: false})
  33. this.search()
  34. },
  35. swiperChange(e) {
  36. this.setData({
  37. currentBanner: e.detail.current
  38. })
  39. },
  40. onShareAppMessage: function () {
  41. return {
  42. path: '/pages/index/index'
  43. }
  44. },
  45. getImgHeight() {
  46. const aw = 750
  47. const ah = 480
  48. this.setData({
  49. imgHeight: ah * wx.getSystemInfoSync().windowWidth / aw
  50. })
  51. this.navTop = this.data.imgHeight * 0.87
  52. this.bgTop = this.data.imgHeight * 0.6
  53. this.setData({
  54. navTop: this.bgTop
  55. })
  56. },
  57. onPageScroll(e) {
  58. if (e.scrollTop < 0) return;
  59. this.setData({
  60. bgTop: e.scrollTop > this.bgTop ? this.bgTop : e.scrollTop,
  61. bgIsTop: e.scrollTop > this.navTop,
  62. isFixed: e.scrollTop > this.data.navPosTop
  63. })
  64. },
  65. onPullDownRefresh() {
  66. this.setData({
  67. brandList: this.data.brandList.slice(0, 10),
  68. currentPage: 1
  69. });
  70. this.getBrandList(1, false, true);
  71. getApp().onPullDownRefresh()
  72. },
  73. onReachBottom() {
  74. if (!this.data.loading) {
  75. this.loadMore();
  76. console.log('reach down')
  77. }
  78. },
  79. clickSwiper() {
  80. wx.navigateTo({
  81. url: this.data.banners[this.data.currentBanner].redirectUrl,
  82. })
  83. },
  84. loadMore: function () {
  85. if (this.data.currentPage < this.data.totalPages) {
  86. console.log(this.data.currentPage + 1)
  87. this.getBrandList(this.data.currentPage + 1);
  88. } else {
  89. return;
  90. }
  91. },
  92. async getBrandList(page, isSearch = false, refresh = false) {
  93. this.setData({
  94. loading: true
  95. })
  96. let tempContent = this.data.brandList ?
  97. this.data.brandList : [];
  98. let {
  99. size,
  100. keyword,
  101. } = this.data
  102. console.log('gegeget')
  103. util.request(api.getFireList, {
  104. pageNum: page,
  105. projectSn: keyword,
  106. pageSize: size
  107. }, 'POST')
  108. .then(res => {
  109. if (isSearch) {
  110. wx.pageScrollTo({
  111. scrollTop: 0
  112. })
  113. this.setData({
  114. brandList: this.formBrandList(res.data.list),
  115. currentPage: res.data.curPage,
  116. totalPages: res.data.totalPageNum,
  117. loading: false,
  118. noRecord: false,
  119. showSearch: false
  120. });
  121. } else if (refresh) {
  122. this.setData({
  123. brandList: this.formBrandList(res.data.list),
  124. currentPage: res.data.curPage,
  125. totalPages: res.data.totalPageNum,
  126. loading: false
  127. });
  128. } else {
  129. this.setData({
  130. brandList: tempContent.concat(this.formBrandList(res.data.list)),
  131. currentPage: res.data.curPage,
  132. totalPages: res.data.totalPageNum,
  133. loading: false
  134. });
  135. }
  136. });
  137. },
  138. formBrandList(data) {
  139. return data.map(item => {
  140. let icon = ~item.projectSite.indexOf('非建构筑物') ? '/static/images/fire_other.png' :
  141. ~item.projectSite.indexOf('交通工具') ? '/static/images/fire_bus.png' :
  142. ~item.projectSite.indexOf('垃圾及废弃物') ? '/static/images/fire_recycle.png' : '/static/images/fire_building.png'
  143. return {
  144. ...item,
  145. icon,
  146. createTime: item.createTime.substr(0, 11)
  147. }
  148. })
  149. },
  150. inputChange: function (e) {
  151. let val = e.detail.value
  152. this.setData({
  153. keyword: val,
  154. noRecord: false
  155. })
  156. this.setData({showClear: !!val.length})
  157. this.search()
  158. },
  159. handleScroll(ev) {
  160. this.setData({
  161. isFixed: ev.detail.isFixed
  162. })
  163. },
  164. search: function () {
  165. let {
  166. keyword
  167. } = this.data
  168. this.getBrandList(1, true)
  169. // if (this.brandList.length <= 0) {
  170. // this.setData({
  171. // noRecord: true
  172. // })
  173. // }
  174. // else {
  175. // this.setData({
  176. // activeType: -1,
  177. // noRecord: false,
  178. // showSearch: false
  179. // })
  180. // }
  181. },
  182. inputFocus: function () {
  183. },
  184. gotoCateg() {
  185. wx.navigateTo({
  186. url: '/pages/ncategory/category?id=search',
  187. })
  188. },
  189. tapHeaderBar(e) {
  190. // let { id } = e.currentTarget.dataset
  191. // wx.navigateTo({
  192. // url: '/pages/ncategory/category?id=' + id,
  193. // })
  194. let {
  195. id
  196. } = e.currentTarget.dataset
  197. this.setData({
  198. activeType: id,
  199. showSearch: false,
  200. keyword: '',
  201. brandList: [],
  202. currentPage: 1
  203. })
  204. this.getBrandList(1)
  205. },
  206. tabShow() {
  207. this.setData({
  208. showSearch: true
  209. })
  210. },
  211. tabHide() {
  212. this.setData({
  213. showSearch: false,
  214. noRecord: false,
  215. keyword: ''
  216. })
  217. },
  218. getUserInfo,
  219. onLoad: async function (options) {
  220. this.setData({
  221. statusBarHeight: wx.getSystemInfoSync().statusBarHeight,
  222. isiOS: wx.getSystemInfoSync().system.indexOf('iOS') > -1,
  223. })
  224. let navHeight = 0
  225. if (!this.data.isiOS) {
  226. navHeight = 48;
  227. } else {
  228. navHeight = 44;
  229. }
  230. this.setData({
  231. navHeight: navHeight
  232. })
  233. getApp().checkNetStatu();
  234. // this.checkNetStatu()
  235. this.setData({
  236. imgServer: util.imgServer
  237. })
  238. this.onShow()
  239. // wx.setBackgroundColor({
  240. // backgroundColor: '#ff7701'
  241. // })
  242. },
  243. async getType() {
  244. let items = [{
  245. name: '全部',
  246. id: -1
  247. }]
  248. this.setData({
  249. header: items
  250. })
  251. },
  252. onReady: function () {
  253. // 页面渲染完成
  254. },
  255. onShow: function (options) {
  256. this.data.brandList = []
  257. if (global.type) {
  258. this.tapHeaderBar({
  259. currentTarget: {
  260. dataset: this.data.header[0]
  261. }
  262. })
  263. global.type = null
  264. }
  265. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  266. this.getTabBar().setData({
  267. selected: 0
  268. })
  269. }
  270. getApp().updateCardCount()
  271. // this.options.keyword && this.inputChange({detail: {value: this.options.keyword}})
  272. this.getBrandList(1)
  273. this.getType()
  274. this.getImgHeight()
  275. this.getUserInfo()
  276. // 页面显示
  277. },
  278. onHide: function () {
  279. // 页面隐藏
  280. },
  281. onUnload: function () {
  282. // 页面关闭
  283. },
  284. gotoWV: function (event) {
  285. let {
  286. id,
  287. scene
  288. } = event.currentTarget.dataset
  289. if (!scene) {
  290. return wx.showToast({
  291. icon: 'none',
  292. title: '暂无VR数据,无法查看',
  293. })
  294. }
  295. wx.navigateTo({
  296. url: `/pages/webview/index?id=${id}&scene=${scene}`,
  297. // url: `/pages/reserve/reserve?id=${id}`
  298. })
  299. },
  300. searchFocus() {
  301. wx.navigateTo({
  302. url: '/pages/search/search?keyword=' + this.data.keyword,
  303. })
  304. }
  305. })