index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../services/user.js');
  4. import { Router } from '../../utils/router.js'
  5. let raw = [
  6. {
  7. name: "FURLA",
  8. link: "gu6HmTLKp",
  9. type: "fushi",
  10. img: "hf4",
  11. belong: "",
  12. qrcode: "furla"
  13. },
  14. {
  15. name: "Adidas",
  16. link: "wmgAlMV6w",
  17. type: "fushi",
  18. img: "hf1",
  19. belong: "",
  20. qrcode: "Adidas"
  21. },
  22. {
  23. name: "Clarks",
  24. link: "TSC1mTgLg",
  25. type: "fushi",
  26. img: "hf11",
  27. belong: "",
  28. qrcode: "Clarks"
  29. },
  30. {
  31. name: "润园四季",
  32. link: "8OBkdB5a8",
  33. type: "fushi",
  34. img: "hf13",
  35. belong: "",
  36. qrcode: "DAZZLE"
  37. },
  38. {
  39. name: "FILA",
  40. link: "dP6EECGrI",
  41. type: "fushi",
  42. img: "hf2",
  43. belong: "",
  44. qrcode: "FILA"
  45. },
  46. {
  47. name: "DAZZLE",
  48. link: "n1Pg6NjKW",
  49. type: "fushi",
  50. img: "hf3",
  51. belong: "",
  52. qrcode: "DAZZLE"
  53. },
  54. {
  55. name: "LANCOME",
  56. link: "kklFfbwet",
  57. type: "liren",
  58. img: "hf5",
  59. belong: "",
  60. qrcode: "FILA"
  61. },
  62. {
  63. name: "名表专柜",
  64. link: "qzInCQin1",
  65. type: "qita",
  66. img: "hf12",
  67. belong: "",
  68. qrcode: "FILA"
  69. },
  70. {
  71. name: "MJstyle",
  72. link: "UK5iVJ2yu",
  73. type: "fushi",
  74. img: "hf7",
  75. belong: "",
  76. qrcode: "MJstyle"
  77. },
  78. {
  79. name: "PANDORA",
  80. link: "teO9zu7cP",
  81. type: "fushi",
  82. img: "hf6",
  83. belong: "",
  84. qrcode: "FILA"
  85. },
  86. {
  87. name: "NOME",
  88. link: "bTpjhkgSh",
  89. type: "fushi",
  90. img: "hf8",
  91. belong: "",
  92. qrcode: "NOME"
  93. },
  94. {
  95. name: "探鱼",
  96. link: "lzNp1eYM3",
  97. type: "meishi",
  98. img: "hf9",
  99. belong: "",
  100. qrcode: "tanyu"
  101. },
  102. {
  103. name: "LOHAS",
  104. link: "ZNTxtgnlJ",
  105. type: "qita",
  106. img: "hf14",
  107. belong: "",
  108. qrcode: "LOHAS"
  109. }
  110. ]
  111. //获取应用实例
  112. const app = getApp()
  113. Router({
  114. data: {
  115. raw,
  116. data: raw,
  117. showSearch: false,
  118. activeType:-1,
  119. header:[
  120. {
  121. name:'全部',
  122. type:'all',
  123. id: -1
  124. },
  125. {
  126. name: '美食',
  127. id: 1,
  128. type: 'meishi'
  129. },
  130. {
  131. name: '服饰',
  132. id: 2,
  133. type: 'fushi'
  134. },
  135. {
  136. name: '丽人',
  137. id: 3,
  138. type: 'liren'
  139. },
  140. {
  141. name: '其他',
  142. id: 0,
  143. type: 'qita'
  144. },
  145. ],
  146. noRecord:'',
  147. hideMask: false,
  148. keyword:'',
  149. url:'https://www.4dkankan.com/eShopMobile.html?m=',
  150. totalPages: 1,
  151. currentPage: 1,
  152. size: 10,
  153. loading: false,
  154. brandList:[]
  155. },
  156. onShareAppMessage: function () {
  157. return {
  158. title: '看店4DKanKan:宅家中,云逛街,轻松买',
  159. desc: '看店4DKanKan:宅家中,云逛街,轻松买',
  160. path: '/pages/index/index'
  161. }
  162. },
  163. onPullDownRefresh(){
  164. this.setData({
  165. brandList: this.data.brandList.slice(0,10),
  166. currentPage: 1
  167. });
  168. this.getBrandList(1,false,true);
  169. },
  170. onReachBottom() {
  171. if (!this.data.loading) {
  172. this.loadMore();
  173. console.log('reach down')
  174. }
  175. },
  176. loadMore: function () {
  177. if (this.data.currentPage<this.data.totalPages) {
  178. console.log(this.data.currentPage + 1)
  179. this.getBrandList(this.data.currentPage + 1);
  180. } else {
  181. return;
  182. }
  183. },
  184. getBrandList(page,isSearch=false,refresh=false){
  185. this.setData({
  186. loading: true
  187. })
  188. let tempContent = this.data.brandList ?
  189. this.data.brandList :
  190. [];
  191. let { activeType, size, keyword,} = this.data
  192. util.request(api.IndexList, { type: activeType, page, name:keyword, size })
  193. .then(res=> {
  194. if (isSearch){
  195. if (res.data.data.length <= 0) {
  196. this.setData({
  197. noRecord: true
  198. });
  199. }
  200. else {
  201. wx.pageScrollTo({
  202. scrollTop: 0
  203. })
  204. this.setData({
  205. brandList: res.data.data,
  206. currentPage: res.data.currentPage,
  207. totalPages: res.data.totalPages,
  208. loading: false,
  209. noRecord: false,
  210. showSearch: false
  211. });
  212. }
  213. }
  214. else if(refresh){
  215. this.setData({
  216. brandList: res.data.data,
  217. currentPage: res.data.currentPage,
  218. totalPages: res.data.totalPages,
  219. loading: false
  220. });
  221. }
  222. else {
  223. this.setData({
  224. brandList: tempContent.concat(res.data.data),
  225. currentPage: res.data.currentPage,
  226. totalPages: res.data.totalPages,
  227. loading: false
  228. });
  229. }
  230. });
  231. },
  232. inputChange: function (e) {
  233. let val = e.detail.value
  234. this.setData({
  235. keyword:val,
  236. noRecord: false
  237. })
  238. },
  239. search:function(){
  240. let {keyword} = this.data
  241. this.getBrandList(1, true)
  242. // if (this.brandList.length <= 0) {
  243. // this.setData({
  244. // noRecord: true
  245. // })
  246. // }
  247. // else {
  248. // this.setData({
  249. // activeType: -1,
  250. // noRecord: false,
  251. // showSearch: false
  252. // })
  253. // }
  254. },
  255. inputFocus: function () {
  256. },
  257. tapHeaderBar(e){
  258. let { id } = e.currentTarget.dataset
  259. this.setData({
  260. activeType: id,
  261. showSearch: false,
  262. keyword: '',
  263. brandList: [],
  264. currentPage: 1
  265. })
  266. this.getBrandList(1)
  267. },
  268. tabShow(){
  269. this.setData({
  270. showSearch: true
  271. })
  272. },
  273. tabHide() {
  274. this.setData({
  275. showSearch: false,
  276. noRecord:false,
  277. keyword:''
  278. })
  279. },
  280. onLoad: function (options) {
  281. this.setData({
  282. imgServer: util.imgServer
  283. })
  284. this.getBrandList(1)
  285. },
  286. onReady: function () {
  287. // 页面渲染完成
  288. },
  289. onShow: function () {
  290. if(typeof this.getTabBar === 'function' && this.getTabBar()){
  291. this.getTabBar().setData({
  292. selected:0
  293. })
  294. }
  295. // 页面显示
  296. },
  297. onHide: function () {
  298. // 页面隐藏
  299. },
  300. onUnload: function () {
  301. // 页面关闭
  302. },
  303. gotoWV: function (event){
  304. let { id } = event.currentTarget.dataset
  305. wx.navigateTo({
  306. url: `/pages/webview/index?id=${id}`,
  307. })
  308. }
  309. })