patternList.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. // pages/patternList/patternList.js
  2. var navlist = [
  3. { id: " ", title: "综合", icon: "../../images/search_list_zh_pre.png" },
  4. { id: "price", title: "价格", icon: "../../images/search_list_zh_n.png" }
  5. ];
  6. // 热销新品
  7. var contentList = [
  8. ];
  9. Page({
  10. data: {
  11. pageNo: 1,
  12. activeIndex: 0,
  13. navList: navlist,
  14. contentList: contentList,
  15. navId: 0,
  16. systemInfo: [],
  17. loadingHidden: false,
  18. list: [],
  19. num: 1,
  20. limt: 20,
  21. tab: '',
  22. pre0: "../../images/search_list_zh_pre.png",
  23. n0: "../../images/search_list_zh_n.png",
  24. pre: "../../images/search_list_zh_pre.png",
  25. n: "../../images/search_list_zh_n.png",
  26. noActPrice: '/images/search_jt_price_up.png',
  27. dataVal: "0",
  28. hidden: false,
  29. page: 0,
  30. size: 20,
  31. hasMore: true,
  32. hasRefesh: false,
  33. commodity_name: '',
  34. host: '',
  35. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  36. callbackcount: 10, //返回数据的个数
  37. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  38. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  39. tab: '',
  40. tabVal: '',
  41. activeId1 : '商务选礼',
  42. activeId2: '',
  43. activeId3: '',
  44. posYes : false, //当前滚动条位置是否是
  45. screenH : '', //屏幕高度
  46. scrollTop : 0, //滚动高度
  47. scrollTopFlag: 0,//滚动高度标志位
  48. showMsg: true, //显示切换模式提示
  49. showChangeModel: false, //显示切换模式确认弹窗
  50. collectState : false , //商品是否收藏
  51. scrollFlag : false,
  52. scrollId : ''
  53. },
  54. onLoad: function (options) {
  55. var that = this;
  56. var host = getApp().globalData.servsers;
  57. var un_id = getApp().globalData.un_id;
  58. wx.getSystemInfo({
  59. success: function (res) {
  60. that.setData({
  61. screenH: res.windowHeight
  62. })
  63. }
  64. })
  65. var activeId1 = options.activeId1;
  66. var activeId2 = options.activeId2;
  67. var activeId3 = options.activeId3;
  68. var activeName1 = options.activeName1;
  69. var activeName2 = options.activeName2;
  70. var activeName3 = options.activeName3;
  71. that.setData({
  72. activeId1: activeId1,
  73. activeId2: activeId2,
  74. activeId3: activeId3,
  75. activeName1: activeName1,
  76. activeName2: activeName2,
  77. activeName3: activeName3
  78. })
  79. //检索商品列表
  80. wx.request({
  81. url: host + "commodityapi/findCommodityByPrms",
  82. data: {
  83. purposeId: activeId1,
  84. objectId: activeId2,
  85. priceType: activeId3,
  86. sortType :1,
  87. offset: 0,
  88. limit: 10
  89. },
  90. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  91. header: {
  92. 'Accept': 'application/json'
  93. },
  94. success: function (res) {
  95. that.setData({
  96. contentList: res.data.rows,
  97. searchPageNum: 0, //第一次加载,设置1
  98. searchSongList: [], //放置返回数据的数组,设为空
  99. isFromSearch: true, //第一次加载,设置true
  100. searchLoading: true, //把"上拉加载"的变量设为true,显示
  101. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  102. });
  103. if (res.data.rows.length < 10) {
  104. that.setData({
  105. searchPageNum: 0, //第一次加载,设置1
  106. searchSongList: [], //放置返回数据的数组,设为空
  107. isFromSearch: true, //第一次加载,设置true
  108. searchLoading: false, //把"上拉加载"的变量设为true,显示
  109. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  110. });
  111. }
  112. if (res == null || res.data == null) {
  113. console.error('网络请求失败');
  114. return;
  115. }
  116. }
  117. });
  118. },
  119. //切换TAB
  120. tagChoose: function (options) {
  121. var that = this
  122. var id = options.currentTarget.dataset.id;
  123. var index = e.currentTarget.dataset.index;
  124. var type = e.currentTarget.dataset.dataType;
  125. if (id == "price" && type == '1') {//价格
  126. that.setData({
  127. activeIndex: index,
  128. pageNo: 1,
  129. pre: "../../images/search_list_zh_n.png"
  130. })
  131. } else {//综合
  132. //设置当前样式
  133. if (type == '0') {//选择综合
  134. that.setData({
  135. noActPrice: '/images/search_jt_price_up.png'
  136. })
  137. }
  138. that.setData({
  139. activeIndex: index,
  140. pageNo: 1
  141. })
  142. }
  143. },
  144. onTapTag: function (e) {
  145. var that = this;
  146. var host = getApp().globalData.servsers;
  147. var tab = e.currentTarget.id;
  148. var index = e.currentTarget.dataset.index;
  149. var tabType = e.currentTarget.dataset.type;
  150. var tabVal = e.currentTarget.dataset.val;//标志是否是一个tab点击多次(价格)
  151. that.setData({
  152. tab: tab,
  153. tabVal: tabVal,
  154. searchPageNum: 0
  155. })
  156. if (tab == "price" && tabVal == '0') {//切换数据 为 从低到高 (箭头朝上)
  157. wx.request({
  158. url: host + "commodityapi/findCommodityByPrms",
  159. data: {
  160. purposeId: that.data.activeId1,
  161. objectId: that.data.activeId2,
  162. priceType: that.data.activeId3,
  163. sortType : 2,
  164. offset: 0,
  165. limit: 10
  166. },
  167. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  168. header: {
  169. 'Accept': 'application/json'
  170. },
  171. success: function (res) {
  172. that.setData({
  173. contentList: res.data.rows,
  174. activeIndex: index,
  175. tab: tab,
  176. scrollTop: 0, //回到顶部
  177. pageNo: 1,
  178. dataVal: "1",
  179. pre: "../../images/search_list_zh_n.png",
  180. searchPageNum: 0, //第一次加载,设置1
  181. searchSongList: [], //放置返回数据的数组,设为空
  182. isFromSearch: true, //第一次加载,设置true
  183. searchLoading: true, //把"上拉加载"的变量设为true,显示
  184. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  185. });
  186. if (res.data.rows.length < 10) {
  187. that.setData({
  188. searchPageNum: 0, //第一次加载,设置1
  189. searchSongList: [], //放置返回数据的数组,设为空
  190. isFromSearch: true, //第一次加载,设置true
  191. searchLoading: false, //把"上拉加载"的变量设为true,显示
  192. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  193. });
  194. }
  195. if (res == null || res.data == null) {
  196. console.error('网络请求失败');
  197. return;
  198. }
  199. }
  200. });
  201. } else if (tab == "price" && tabVal == '1') {//切换数据 为 从高到低 (箭头朝下)
  202. wx.request({
  203. url: host + "commodityapi/findCommodityByPrms",
  204. data: {
  205. purposeId: that.data.activeId1,
  206. objectId: that.data.activeId2,
  207. priceType: that.data.activeId3,
  208. sortType: 3,
  209. offset: 0,
  210. limit: 10
  211. },
  212. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  213. header: {
  214. 'Accept': 'application/json'
  215. },
  216. success: function (res) {
  217. that.setData({
  218. contentList: res.data.rows,
  219. activeIndex: index,
  220. tab: tab,
  221. scrollTop: 0, //回到顶部
  222. pageNo: 1,
  223. dataVal: "0",
  224. pre: "../../images/search_list_zh_pre.png",
  225. searchPageNum: 0, //第一次加载,设置1
  226. searchSongList: [], //放置返回数据的数组,设为空
  227. isFromSearch: true, //第一次加载,设置true
  228. searchLoading: true, //把"上拉加载"的变量设为true,显示
  229. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  230. });
  231. if (res.data.rows.length < 10) {
  232. that.setData({
  233. searchPageNum: 0, //第一次加载,设置1
  234. searchSongList: [], //放置返回数据的数组,设为空
  235. isFromSearch: true, //第一次加载,设置true
  236. searchLoading: false, //把"上拉加载"的变量设为true,显示
  237. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  238. });
  239. }
  240. if (res == null || res.data == null) {
  241. console.error('网络请求失败');
  242. return;
  243. }
  244. }
  245. });
  246. } else {
  247. //检索商品列表
  248. wx.request({
  249. url: host + "commodityapi/findCommodityByPrms",
  250. data: {
  251. purposeId: that.data.activeId1,
  252. objectId: that.data.activeId2,
  253. priceType: that.data.activeId3,
  254. sortType: 1,
  255. offset: 0,
  256. limit: 10
  257. },
  258. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  259. header: {
  260. 'Accept': 'application/json'
  261. },
  262. success: function (res) {
  263. that.setData({
  264. contentList: res.data.rows,
  265. scrollTop: 0, //回到顶部
  266. host: host, searchPageNum: 0, //第一次加载,设置1
  267. searchSongList: [], //放置返回数据的数组,设为空
  268. isFromSearch: true, //第一次加载,设置true
  269. searchLoading: true, //把"上拉加载"的变量设为true,显示
  270. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  271. });
  272. if (res.data.rows.length < 10) {
  273. that.setData({
  274. searchPageNum: 0, //第一次加载,设置1
  275. searchSongList: [], //放置返回数据的数组,设为空
  276. isFromSearch: true, //第一次加载,设置true
  277. searchLoading: false, //把"上拉加载"的变量设为true,显示
  278. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  279. });
  280. }
  281. if (res == null || res.data == null) {
  282. console.error('网络请求失败');
  283. return;
  284. }
  285. }
  286. });
  287. that.setData({
  288. activeIndex: index,
  289. tab: tab,
  290. pageNo: 1,
  291. pre: "../../images/search_list_zh_pre.png"
  292. })
  293. }
  294. },
  295. fetchSearchList: function () {//加载更多
  296. var that = this;
  297. var host = getApp().globalData.servsers;
  298. var forid = that.data.forid;
  299. var tab = that.data.tab;
  300. var tabVal = that.data.tabVal;
  301. if (tab == "price" && tabVal == '0') {//切换数据 为 从低到高 (箭头朝上)
  302. wx.request({
  303. url: host + "commodityapi/findCommodityByPrms",
  304. data: {
  305. purposeId: that.data.activeId1,
  306. objectId: that.data.activeId2,
  307. priceType: that.data.activeId3,
  308. sortType: 2,
  309. offset: parseInt(that.data.searchPageNum),
  310. limit: 10
  311. },
  312. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  313. header: {
  314. 'Accept': 'application/json'
  315. },
  316. success: function (res) {
  317. if (res.data.rows.length != 0) {
  318. let contentList = [];
  319. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  320. that.data.isFromSearch ? contentList = res.data.rows : contentList = that.data.contentList.concat(res.data.rows)
  321. that.setData({
  322. contentList: contentList, //获取数据数组
  323. searchLoading: true //把"上拉加载"的变量设为false,显示
  324. });
  325. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  326. } else {
  327. that.setData({
  328. searchLoadingComplete: true, //把“没有数据”设为true,显示
  329. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  330. });
  331. }
  332. if (res == null || res.data == null) {
  333. console.error('网络请求失败');
  334. return;
  335. }
  336. wx.hideNavigationBarLoading(
  337. that.setData({
  338. hidden: 'hidden'
  339. })
  340. )
  341. }
  342. });
  343. } else if (tab == "price" && tabVal == '1') {//切换数据 为 从高到低 (箭头朝下)
  344. wx.request({
  345. url: host + "commodityapi/findCommodityByPrms",
  346. data: {
  347. purposeId: that.data.activeId1,
  348. objectId: that.data.activeId2,
  349. priceType: that.data.activeId3,
  350. sortType: 3,
  351. offset: parseInt(that.data.searchPageNum),
  352. limit: 10
  353. },
  354. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  355. header: {
  356. 'Accept': 'application/json'
  357. },
  358. success: function (res) {
  359. if (res.data.rows.length != 0) {
  360. let contentList = [];
  361. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  362. that.data.isFromSearch ? contentList = res.data.rows : contentList = that.data.contentList.concat(res.data.rows)
  363. that.setData({
  364. contentList: contentList, //获取数据数组
  365. searchLoading: true //把"上拉加载"的变量设为false,显示
  366. });
  367. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  368. } else {
  369. that.setData({
  370. searchLoadingComplete: true, //把“没有数据”设为true,显示
  371. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  372. });
  373. }
  374. if (res == null || res.data == null) {
  375. console.error('网络请求失败');
  376. return;
  377. }
  378. wx.hideNavigationBarLoading(
  379. that.setData({
  380. hidden: 'hidden'
  381. })
  382. )
  383. }
  384. });
  385. } else {
  386. //检索商品列表
  387. wx.request({
  388. url: host + "commodityapi/findCommodityByPrms",
  389. data: {
  390. purposeId: that.data.activeId1,
  391. objectId: that.data.activeId2,
  392. priceType: that.data.activeId3,
  393. sortType: 1,
  394. offset: parseInt(that.data.searchPageNum),
  395. limit: 10
  396. },
  397. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  398. header: {
  399. 'Accept': 'application/json'
  400. },
  401. success: function (res) {
  402. if (res.data.rows.length != 0) {
  403. let contentList = [];
  404. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  405. that.data.isFromSearch ? contentList = res.data.rows : contentList = that.data.contentList.concat(res.data.rows)
  406. that.setData({
  407. contentList: contentList, //获取数据数组
  408. searchLoading: true //把"上拉加载"的变量设为false,显示
  409. });
  410. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  411. } else {
  412. that.setData({
  413. searchLoadingComplete: true, //把“没有数据”设为true,显示
  414. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  415. });
  416. }
  417. if (res == null || res.data == null) {
  418. console.error('网络请求失败');
  419. return;
  420. }
  421. wx.hideNavigationBarLoading(
  422. that.setData({
  423. hidden: 'hidden'
  424. })
  425. )
  426. }
  427. });
  428. }
  429. },
  430. // //滚动到底部触发事件
  431. // searchScrollLower: function () {
  432. // var that = this;
  433. // if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  434. // that.setData({
  435. // searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  436. // isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  437. // });
  438. // that.fetchSearchList();
  439. // }
  440. // },
  441. //下拉
  442. onReachBottom:function(){
  443. var that = this;
  444. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  445. that.setData({
  446. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  447. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  448. });
  449. that.fetchSearchList();
  450. }
  451. },
  452. //重新选择
  453. returnChoose:function(e){
  454. wx.navigateTo({
  455. url: '/pages/patternMenu/patternMenu'
  456. })
  457. },
  458. //购物车
  459. goCar:function(e){
  460. wx.navigateTo({
  461. url: '/pages/carInsert/carInsert'
  462. })
  463. },
  464. //监测滚动位置,当滚动位置达到2.5p时,显示“回到顶部”按钮
  465. onPageScroll:function(e){
  466. var that = this;
  467. var screenH = that.data.screenH;
  468. screenH = screenH * 2.5;
  469. that.setData({
  470. scrollTopFlag: e.scrollTop,
  471. scrollFlag : true
  472. })
  473. if (e.scrollTop >= screenH){
  474. that.setData({
  475. posYes : true
  476. })
  477. }else{
  478. that.setData({
  479. posYes: false
  480. })
  481. }
  482. },
  483. //回到顶部
  484. goTop:function(e){
  485. var that = this;
  486. that.setData({
  487. posYes: false
  488. })
  489. wx.pageScrollTo({
  490. scrollTop: 0,
  491. duration: 300
  492. })
  493. },
  494. //关闭切换模式提示
  495. closeMsg: function (e) {
  496. var that = this;
  497. that.setData({
  498. showMsg: false
  499. })
  500. },
  501. //打开切换提示
  502. openChangeModel: function (e) {
  503. var that = this;
  504. that.setData({
  505. showMsg: false,
  506. showChangeModel: true
  507. })
  508. },
  509. //跳转至一键选礼
  510. goChooseGift: function (e) {
  511. var that = this;
  512. that.setData({
  513. showChangeModel: false
  514. })
  515. wx.switchTab({
  516. url: '/pages/index/index'
  517. })
  518. },
  519. //关闭切换模式确认弹窗
  520. closeChangeModel: function (e) {
  521. var that = this;
  522. that.setData({
  523. showChangeModel: false
  524. })
  525. },
  526. //收藏
  527. collect: function (e) {
  528. var that = this;
  529. var dataState = e.currentTarget.dataset.state;
  530. var id = e.currentTarget.dataset.id;
  531. var comid = e.currentTarget.dataset.comid;
  532. var host = getApp().globalData.servsers;
  533. var un_id = getApp().globalData.un_id;
  534. var contentList = that.data.contentList;
  535. if (un_id != undefined && un_id != '' && un_id != null){
  536. console.log(dataState);
  537. if (!dataState) {
  538. //后台增加收藏用户收藏数据
  539. wx.request({
  540. url: host + "collectionapi/insertcollection",
  541. data: {
  542. user_id: un_id,
  543. collection_clas: 2,
  544. collection_name: comid
  545. },
  546. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  547. header: {
  548. 'Accept': 'application/json'
  549. },
  550. success: function (res) {
  551. that.setData({
  552. collectState: true
  553. })
  554. if (res == null || res.data == null) {
  555. console.error('网络请求失败');
  556. return;
  557. }
  558. }
  559. })
  560. contentList[id].collectState = true;
  561. that.setData({
  562. contentList: contentList
  563. })
  564. } else {
  565. wx.request({
  566. url: host + "collectionapi / deleteforxcx",
  567. data: {
  568. user_id: un_id,
  569. collection_clas: 2,
  570. collection_name: comid,
  571. },
  572. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  573. header: {
  574. 'Accept': 'application/json'
  575. },
  576. success: function (res) {
  577. that.setData({
  578. collectState: false
  579. })
  580. if (res == null || res.data == null) {
  581. console.error('网络请求失败');
  582. return;
  583. }
  584. }
  585. })
  586. contentList[id].collectState = false;
  587. that.setData({
  588. contentList: contentList
  589. })
  590. }
  591. }
  592. },
  593. })
  594. var that;
  595. var Util = require('../../utils/util.js');