goodsAllList.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. // goodsAllList.js
  2. //获取应用实例
  3. var app = getApp();
  4. // 列表
  5. var contentList = [];
  6. var conditionTab = [
  7. { id: 31, scene_name: 'For her' },
  8. { id: 32, scene_name: 'For him' },
  9. { id: -2, scene_name: 'New' },
  10. { id: -3, scene_name: 'SALE' }
  11. ];
  12. Page({
  13. data: {
  14. conditionTab: conditionTab,
  15. contentList: contentList,
  16. loadingHidden: false,
  17. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  18. limt: 10,
  19. callbackcount: 15, //返回数据的个数
  20. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  21. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  22. kindId: '', //当前页面 - 礼物盒ID
  23. selectId : -1,
  24. objectId : -1 , //默认送礼对象的id
  25. filtrateId : 0 , //默认筛选条件【价钱1-2、销量3-4、起订量5-6、定制周期7-8 的 由高到低 还是 由低到高】
  26. priceIcon: '/images/sort_icon_default.png', //价钱icon默认
  27. priceId: 0, //价钱默认id
  28. countIcon: '/images/sort_icon_default.png', //销量icon默认
  29. countId: 0, //销量默认id
  30. orderIcon: '/images/sort_icon_default.png', //起订量icon默认
  31. orderId: 0, //起订量默认id
  32. cycleIcon: '/images/sort_icon_default.png', //定制周期icon默认
  33. cycleId: 0, //定制周期默认id
  34. },
  35. onLoad: function (options) {
  36. var that = this;
  37. var host = getApp().globalData.servsers;
  38. //全部商品
  39. wx.request({
  40. url: host +"commodityapi/findAllforNewproduct",
  41. data: {
  42. offset: 0,
  43. limit: 10
  44. },
  45. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  46. header: {
  47. 'Accept': 'application/json'
  48. },
  49. success: function (res) {
  50. that.setData({
  51. contentList: res.data.rows,
  52. searchPageNum: 0, //第一次加载,设置1
  53. searchSongList: [], //放置返回数据的数组,设为空
  54. isFromSearch: true, //第一次加载,设置true
  55. searchLoading: true, //把"上拉加载"的变量设为true,显示
  56. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  57. });
  58. if (res.data.rows.length < 10) {
  59. that.setData({
  60. searchPageNum: 0, //第一次加载,设置1
  61. searchSongList: [], //放置返回数据的数组,设为空
  62. isFromSearch: true, //第一次加载,设置true
  63. searchLoading: false, //把"上拉加载"的变量设为true,显示
  64. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  65. });
  66. }
  67. if (res == null || res.data == null) {
  68. console.error('网络请求失败');
  69. return;
  70. }
  71. }
  72. });
  73. },
  74. fetchSearchList: function () {//加载更多
  75. var that = this;
  76. var host = getApp().globalData.servsers;
  77. var objectId = that.data.objectId;//筛选条件第一行选择
  78. var filtrateId = that.data.filtrateId;//筛选排序
  79. if (objectId>0){
  80. wx.request({
  81. url: host + "commodityapi/findAllforNewproduct",
  82. data: {
  83. commodity_object: objectId,
  84. sort_type: filtrateId,
  85. offset: parseInt(that.data.searchPageNum) * 10
  86. },
  87. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  88. header: {
  89. 'Accept': 'application/json'
  90. },
  91. success: function (res) {
  92. if (res.data.rows.length != 0) {
  93. let contentList = [];
  94. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  95. that.data.isFromSearch ? contentList = res.data.rows : contentList = that.data.contentList.concat(res.data.rows)
  96. that.setData({
  97. contentList: contentList, //获取数据数组
  98. searchLoading: true //把"上拉加载"的变量设为false,显示
  99. });
  100. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  101. } else {
  102. console.log(22);
  103. that.setData({
  104. searchLoadingComplete: true, //把“没有数据”设为true,显示
  105. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  106. });
  107. }
  108. if (res == null || res.data == null) {
  109. console.error('网络请求失败');
  110. return;
  111. }
  112. wx.hideNavigationBarLoading(
  113. that.setData({
  114. hidden: 'hidden'
  115. })
  116. )
  117. }
  118. });
  119. } else if (objectId == -2) {//点击的是推荐类型 - New[新品]
  120. wx.request({
  121. url: host + "commodityapi/findAllforNewproduct",
  122. data: {
  123. commodity_recommend: '1',
  124. sort_type: filtrateId,
  125. offset: parseInt(that.data.searchPageNum) * 10
  126. },
  127. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  128. header: {
  129. 'Accept': 'application/json'
  130. },
  131. success: function (res) {
  132. if (res.data.rows.length != 0) {
  133. let contentList = [];
  134. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  135. that.data.isFromSearch ? contentList = res.data.rows : contentList = that.data.contentList.concat(res.data.rows)
  136. that.setData({
  137. contentList: contentList, //获取数据数组
  138. searchLoading: true //把"上拉加载"的变量设为false,显示
  139. });
  140. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  141. } else {
  142. console.log(22);
  143. that.setData({
  144. searchLoadingComplete: true, //把“没有数据”设为true,显示
  145. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  146. });
  147. }
  148. if (res == null || res.data == null) {
  149. console.error('网络请求失败');
  150. return;
  151. }
  152. wx.hideNavigationBarLoading(
  153. that.setData({
  154. hidden: 'hidden'
  155. })
  156. )
  157. }
  158. });
  159. } else if (objectId == -3) {//点击的是推荐类型 - SALE[打折品]
  160. wx.request({
  161. url: host + "commodityapi/findAllforNewproduct",
  162. data: {
  163. commodity_recommend: '3',
  164. sort_type: filtrateId,
  165. offset: parseInt(that.data.searchPageNum) * 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. if (res.data.rows.length != 0) {
  173. let contentList = [];
  174. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  175. that.data.isFromSearch ? contentList = res.data.rows : contentList = that.data.contentList.concat(res.data.rows)
  176. that.setData({
  177. contentList: contentList, //获取数据数组
  178. searchLoading: true //把"上拉加载"的变量设为false,显示
  179. });
  180. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  181. } else {
  182. that.setData({
  183. searchLoadingComplete: true, //把“没有数据”设为true,显示
  184. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  185. });
  186. }
  187. if (res == null || res.data == null) {
  188. console.error('网络请求失败');
  189. return;
  190. }
  191. wx.hideNavigationBarLoading(
  192. that.setData({
  193. hidden: 'hidden'
  194. })
  195. )
  196. }
  197. });
  198. }
  199. },
  200. //滚动到底部触发事件
  201. searchScrollLower: function () {
  202. var that = this;
  203. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  204. that.setData({
  205. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  206. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  207. });
  208. that.fetchSearchList();
  209. }
  210. } ,
  211. //送礼对象 - 筛选
  212. objectType:function(e){
  213. var that = this;
  214. var host = getApp().globalData.servsers;
  215. var id = e.currentTarget.dataset.id;
  216. var objectId = e.currentTarget.dataset.flagid;//查询id
  217. var filtrateId = that.data.filtrateId;//筛选排序
  218. if (objectId > 0){//点击的是选礼对象
  219. wx.request({
  220. url: host + "commodityapi/findAllforNewproduct",
  221. data: {
  222. commodity_object: objectId,
  223. sort_type: filtrateId,
  224. offset: 0,
  225. limit: 10
  226. },
  227. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  228. header: {
  229. 'Accept': 'application/json'
  230. },
  231. success: function (res) {
  232. that.setData({
  233. contentList: res.data.rows,
  234. objectId: objectId,
  235. selectId : id,
  236. searchPageNum: 0, //第一次加载,设置1
  237. searchSongList: [], //放置返回数据的数组,设为空
  238. isFromSearch: true, //第一次加载,设置true
  239. searchLoading: true, //把"上拉加载"的变量设为true,显示
  240. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  241. });
  242. if (res.data.rows.length < 10) {
  243. that.setData({
  244. searchPageNum: 0, //第一次加载,设置1
  245. searchSongList: [], //放置返回数据的数组,设为空
  246. isFromSearch: true, //第一次加载,设置true
  247. searchLoading: false, //把"上拉加载"的变量设为true,显示
  248. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  249. });
  250. }
  251. if (res == null || res.data == null) {
  252. console.error('网络请求失败');
  253. return;
  254. }
  255. }
  256. });
  257. } else if (objectId == -2){//点击的是推荐类型 - New[新品]
  258. wx.request({
  259. url: host + "commodityapi/findAllforNewproduct",
  260. data: {
  261. commodity_recommend: '1',
  262. sort_type: filtrateId,
  263. offset: 0,
  264. limit: 10
  265. },
  266. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  267. header: {
  268. 'Accept': 'application/json'
  269. },
  270. success: function (res) {
  271. that.setData({
  272. contentList: res.data.rows,
  273. objectId: objectId,
  274. selectId: id,
  275. searchPageNum: 0, //第一次加载,设置1
  276. searchSongList: [], //放置返回数据的数组,设为空
  277. isFromSearch: true, //第一次加载,设置true
  278. searchLoading: true, //把"上拉加载"的变量设为true,显示
  279. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  280. });
  281. if (res.data.rows.length < 10) {
  282. that.setData({
  283. searchPageNum: 0, //第一次加载,设置1
  284. searchSongList: [], //放置返回数据的数组,设为空
  285. isFromSearch: true, //第一次加载,设置true
  286. searchLoading: false, //把"上拉加载"的变量设为true,显示
  287. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  288. });
  289. }
  290. if (res == null || res.data == null) {
  291. console.error('网络请求失败');
  292. return;
  293. }
  294. }
  295. });
  296. } else if (objectId == -3) {//点击的是推荐类型 - SALE[打折品]
  297. wx.request({
  298. url: host + "commodityapi/findAllforNewproduct",
  299. data: {
  300. commodity_recommend: '3',
  301. sort_type: filtrateId,
  302. offset: 0,
  303. limit: 10
  304. },
  305. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  306. header: {
  307. 'Accept': 'application/json'
  308. },
  309. success: function (res) {
  310. that.setData({
  311. contentList: res.data.rows,
  312. objectId: objectId,
  313. selectId: id,
  314. searchPageNum: 0, //第一次加载,设置1
  315. searchSongList: [], //放置返回数据的数组,设为空
  316. isFromSearch: true, //第一次加载,设置true
  317. searchLoading: true, //把"上拉加载"的变量设为true,显示
  318. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  319. });
  320. if (res.data.rows.length < 10) {
  321. that.setData({
  322. searchPageNum: 0, //第一次加载,设置1
  323. searchSongList: [], //放置返回数据的数组,设为空
  324. isFromSearch: true, //第一次加载,设置true
  325. searchLoading: false, //把"上拉加载"的变量设为true,显示
  326. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  327. });
  328. }
  329. if (res == null || res.data == null) {
  330. console.error('网络请求失败');
  331. return;
  332. }
  333. }
  334. });
  335. }
  336. },
  337. //排序 先升序[箭头向上],后降序[箭头向下]
  338. priceChange:function(e){
  339. var that = this;
  340. var host = getApp().globalData.servsers;
  341. var objectId = that.data.objectId;//查询id
  342. var flag = e.currentTarget.dataset.flag;//当前排序类型
  343. var priceIcon = that.data.priceIcon;
  344. var countIcon = that.data.countIcon;
  345. var orderIcon = that.data.orderIcon;
  346. var cycleIcon = that.data.cycleIcon;
  347. var filtrateId = that.data.filtrateId;//当前排序值
  348. if (flag == 1){//价格
  349. if (filtrateId == 2){
  350. filtrateId = 1;
  351. priceIcon = '/images/sort_icon_descending.png';
  352. } else{
  353. filtrateId = 2;
  354. priceIcon = '/images/sort_icon_ascending.png';
  355. }
  356. countIcon = '/images/sort_icon_default.png';
  357. orderIcon = '/images/sort_icon_default.png';
  358. cycleIcon = '/images/sort_icon_default.png';
  359. }
  360. else if (flag == 2){//综合
  361. if (filtrateId == 4) {
  362. filtrateId = 3;
  363. countIcon = '/images/sort_icon_descending.png';
  364. } else{
  365. filtrateId = 4;
  366. countIcon = '/images/sort_icon_ascending.png';
  367. }
  368. priceIcon = '/images/sort_icon_default.png';
  369. orderIcon = '/images/sort_icon_default.png';
  370. cycleIcon = '/images/sort_icon_default.png';
  371. }
  372. else if (flag == 3) {//起订量
  373. if(filtrateId == 6) {
  374. filtrateId = 5;
  375. orderIcon = '/images/sort_icon_descending.png';
  376. } else {
  377. filtrateId = 6;
  378. orderIcon = '/images/sort_icon_ascending.png';
  379. }
  380. priceIcon = '/images/sort_icon_default.png';
  381. countIcon = '/images/sort_icon_default.png';
  382. cycleIcon = '/images/sort_icon_default.png';
  383. }
  384. else if (flag == 4) {//定制周期
  385. if (filtrateId == 8) {
  386. filtrateId = 7;
  387. cycleIcon = '/images/sort_icon_descending.png';
  388. } else{
  389. filtrateId = 8;
  390. cycleIcon = '/images/sort_icon_ascending.png';
  391. }
  392. priceIcon = '/images/sort_icon_default.png';
  393. countIcon = '/images/sort_icon_default.png';
  394. orderIcon = '/images/sort_icon_default.png';
  395. }
  396. if (objectId > 0) {//点击的是选礼对象
  397. wx.request({
  398. url: host + "commodityapi/findAllforNewproduct",
  399. data: {
  400. commodity_object: objectId,
  401. sort_type: filtrateId,
  402. offset: 0,
  403. limit: 10
  404. },
  405. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  406. header: {
  407. 'Accept': 'application/json'
  408. },
  409. success: function (res) {
  410. that.setData({
  411. contentList: res.data.rows,
  412. filtrateId: filtrateId,
  413. priceIcon: priceIcon,
  414. countIcon: countIcon,
  415. orderIcon: orderIcon,
  416. cycleIcon: cycleIcon,
  417. searchPageNum: 0, //第一次加载,设置1
  418. searchSongList: [], //放置返回数据的数组,设为空
  419. isFromSearch: true, //第一次加载,设置true
  420. searchLoading: true, //把"上拉加载"的变量设为true,显示
  421. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  422. });
  423. if (res.data.rows.length < 10) {
  424. that.setData({
  425. searchPageNum: 0, //第一次加载,设置1
  426. searchSongList: [], //放置返回数据的数组,设为空
  427. isFromSearch: true, //第一次加载,设置true
  428. searchLoading: false, //把"上拉加载"的变量设为true,显示
  429. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  430. });
  431. }
  432. if (res == null || res.data == null) {
  433. console.error('网络请求失败');
  434. return;
  435. }
  436. }
  437. });
  438. } else if (objectId == -2) {//点击的是推荐类型 - New[新品]
  439. wx.request({
  440. url: host + "commodityapi/findAllforNewproduct",
  441. data: {
  442. commodity_recommend: '1',
  443. sort_type: filtrateId,
  444. offset: 0,
  445. limit: 10
  446. },
  447. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  448. header: {
  449. 'Accept': 'application/json'
  450. },
  451. success: function (res) {
  452. that.setData({
  453. contentList: res.data.rows,
  454. filtrateId: filtrateId,
  455. priceIcon: priceIcon,
  456. countIcon: countIcon,
  457. orderIcon: orderIcon,
  458. cycleIcon: cycleIcon,
  459. searchPageNum: 0, //第一次加载,设置1
  460. searchSongList: [], //放置返回数据的数组,设为空
  461. isFromSearch: true, //第一次加载,设置true
  462. searchLoading: true, //把"上拉加载"的变量设为true,显示
  463. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  464. });
  465. if (res.data.rows.length < 10) {
  466. that.setData({
  467. searchPageNum: 0, //第一次加载,设置1
  468. searchSongList: [], //放置返回数据的数组,设为空
  469. isFromSearch: true, //第一次加载,设置true
  470. searchLoading: false, //把"上拉加载"的变量设为true,显示
  471. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  472. });
  473. }
  474. if (res == null || res.data == null) {
  475. console.error('网络请求失败');
  476. return;
  477. }
  478. }
  479. });
  480. } else if (objectId == -3) {//点击的是推荐类型 - SALE[打折品]
  481. wx.request({
  482. url: host + "commodityapi/findAllforNewproduct",
  483. data: {
  484. commodity_recommend: '3',
  485. sort_type: filtrateId,
  486. offset: 0,
  487. limit: 10
  488. },
  489. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  490. header: {
  491. 'Accept': 'application/json'
  492. },
  493. success: function (res) {
  494. that.setData({
  495. contentList: res.data.rows,
  496. filtrateId: filtrateId,
  497. priceIcon: priceIcon,
  498. countIcon: countIcon,
  499. orderIcon: orderIcon,
  500. cycleIcon: cycleIcon,
  501. searchPageNum: 0, //第一次加载,设置1
  502. searchSongList: [], //放置返回数据的数组,设为空
  503. isFromSearch: true, //第一次加载,设置true
  504. searchLoading: true, //把"上拉加载"的变量设为true,显示
  505. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  506. });
  507. if (res.data.rows.length < 10) {
  508. that.setData({
  509. searchPageNum: 0, //第一次加载,设置1
  510. searchSongList: [], //放置返回数据的数组,设为空
  511. isFromSearch: true, //第一次加载,设置true
  512. searchLoading: false, //把"上拉加载"的变量设为true,显示
  513. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  514. });
  515. }
  516. if (res == null || res.data == null) {
  517. console.error('网络请求失败');
  518. return;
  519. }
  520. }
  521. });
  522. }else{
  523. wx.request({
  524. url: host + "commodityapi/findAllforNewproduct",
  525. data: {
  526. sort_type: filtrateId,
  527. offset: 0,
  528. limit: 10
  529. },
  530. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  531. header: {
  532. 'Accept': 'application/json'
  533. },
  534. success: function (res) {
  535. that.setData({
  536. contentList: res.data.rows,
  537. filtrateId: filtrateId,
  538. priceIcon: priceIcon,
  539. countIcon: countIcon,
  540. orderIcon: orderIcon,
  541. cycleIcon: cycleIcon,
  542. searchPageNum: 0, //第一次加载,设置1
  543. searchSongList: [], //放置返回数据的数组,设为空
  544. isFromSearch: true, //第一次加载,设置true
  545. searchLoading: true, //把"上拉加载"的变量设为true,显示
  546. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  547. });
  548. if (res.data.rows.length < 10) {
  549. that.setData({
  550. searchPageNum: 0, //第一次加载,设置1
  551. searchSongList: [], //放置返回数据的数组,设为空
  552. isFromSearch: true, //第一次加载,设置true
  553. searchLoading: false, //把"上拉加载"的变量设为true,显示
  554. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  555. });
  556. }
  557. if (res == null || res.data == null) {
  558. console.error('网络请求失败');
  559. return;
  560. }
  561. }
  562. });
  563. }
  564. },
  565. })
  566. var that;
  567. var Util = require('../../utils/util.js');