goodsGift.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. // goodsGift.js - 心礼盒
  2. var app = getApp();
  3. // 列表
  4. var contentList = [];
  5. var conditionTab1 = [
  6. { id: 1, scene_name:'500以内'},
  7. { id: 2, scene_name: '500-1000' },
  8. { id: 3, scene_name: '1000-2000' },
  9. { id: 4, scene_name: '2000以上' }
  10. ];
  11. var conditionTab2 = [
  12. { id: 10, scene_name: '商务送礼' },
  13. { id: 29, scene_name: '员工福利' },
  14. { id: 20, scene_name: '节日送礼' },
  15. { id: 17, scene_name: '馈赠亲友' },
  16. ];
  17. Page({
  18. data: {
  19. conditionTab1: conditionTab1,
  20. conditionTab2: conditionTab2,
  21. pageNo: 1,
  22. activeIndex: 0,
  23. tuijian:[],
  24. Title:'',
  25. contentList: contentList,
  26. navId: 0,
  27. systemInfo: [],
  28. loadingHidden: false,
  29. list: [],
  30. num: 1,
  31. limt: 20,
  32. tab: '',
  33. classify_name: '',
  34. classify_des: '',
  35. id: '',
  36. winHeight: "",//窗口高度
  37. currentTab: 0, //预设当前项的值
  38. hidden : '',
  39. hiddenAll : 'hidden',
  40. forid : '',//当前选中tab id
  41. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  42. callbackcount: 10, //返回数据的个数
  43. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  44. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  45. selectOneId : -1 , //价钱筛选默认未选中
  46. selectTwoId : -1, //送礼用途默认未选中
  47. selectPriceId: -1, //默认选中的价钱的id
  48. selectWayId: -1, //默认选中送礼用途id
  49. kindId : '', //当前页面 - 礼物盒ID
  50. },
  51. checkCor: function () {
  52. if (this.data.currentTab > 2) {
  53. this.setData({
  54. scrollLeft: 300
  55. })
  56. } else {
  57. this.setData({
  58. scrollLeft: 0
  59. })
  60. }
  61. },
  62. onLoad: function (options) {
  63. var that = this;
  64. var host = getApp().globalData.servsers;
  65. var classify_name = options.classify_name;
  66. that.setData({
  67. kindId: options.id
  68. })
  69. wx.request({
  70. url: host+"classifyapi/findAllforviewSce",
  71. data: {
  72. id: options.id
  73. },
  74. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  75. header: {
  76. 'Accept': 'application/json'
  77. },
  78. success: function (res) {
  79. that.setData({
  80. contentList: res.data.rows
  81. });
  82. if (res.data.rows != ''){
  83. var forid = res.data.rows[0].id;
  84. var forname = res.data.rows[0].classify_name;
  85. var classifydes = res.data.rows[0].classify_des;
  86. var selectPriceId = that.data.selectPriceId;
  87. var selectWayId = that.data.selectWayId;
  88. console.log("selectPriceId:" + selectPriceId);
  89. wx.request({
  90. url: host + "commodityapi/commoditviewfoeeverybody",
  91. data: {
  92. commodity_levelTwo: forid,
  93. //priceType: selectPriceId,
  94. //purposeId: selectWayId,
  95. offset: 0,
  96. limit: 10,
  97. },
  98. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  99. header: {
  100. 'Accept': 'application/json'
  101. },
  102. success: function (res) {
  103. that.setData({
  104. tuijian: res.data.rows,
  105. Title: classifydes,
  106. forid: forid,
  107. searchPageNum: 0, //第一次加载,设置1
  108. searchSongList: [], //放置返回数据的数组,设为空
  109. isFromSearch: true, //第一次加载,设置true
  110. searchLoading: true, //把"上拉加载"的变量设为true,显示
  111. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  112. });
  113. if (res.data.rows.length<10){
  114. that.setData({
  115. searchPageNum: 0, //第一次加载,设置1
  116. searchSongList: [], //放置返回数据的数组,设为空
  117. isFromSearch: true, //第一次加载,设置true
  118. searchLoading: false, //把"上拉加载"的变量设为true,显示
  119. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  120. });
  121. }
  122. console.log(res.data.rows);
  123. if (res == null || res.data == null) {
  124. console.error('网络请求失败');
  125. return;
  126. }
  127. }
  128. });
  129. }
  130. if (res == null || res.data == null) {
  131. console.error('网络请求失败');
  132. return;
  133. }
  134. }
  135. });
  136. wx.setNavigationBarTitle({
  137. title: options.classify_name
  138. })
  139. this.setData({
  140. classify_name: options.classify_name,
  141. classify_des: options.classify_des,
  142. })
  143. var that = this;
  144. // 高度自适应
  145. wx.getSystemInfo({
  146. success: function (res) {
  147. var clientHeight = res.windowHeight,
  148. clientWidth = res.windowWidth,
  149. rpxR = 750 / clientWidth;
  150. var calc = clientHeight * rpxR;
  151. that.setData({
  152. winHeight: calc
  153. });
  154. }
  155. });
  156. },
  157. footerTap: app.footerTap,
  158. //下拉刷新
  159. onPullDownRefresh: function (e) {
  160. this.onLoad();
  161. wx.stopPullDownRefresh();
  162. },
  163. fetchSearchList: function () {//加载更多
  164. var that = this;
  165. var host = getApp().globalData.servsers;
  166. var forid = that.data.forid;
  167. var selectPriceId = that.data.selectPriceId;
  168. var selectWayId = that.data.selectWayId;
  169. if (selectPriceId == -1 && selectWayId == -1){
  170. wx.request({
  171. url: host + "commodityapi/commoditviewfoeeverybody",
  172. data: {
  173. commodity_levelTwo: forid,
  174. offset: parseInt(that.data.searchPageNum),
  175. limit: 10
  176. },
  177. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  178. header: {
  179. 'Accept': 'application/json'
  180. },
  181. success: function (res) {
  182. if (res.data.rows.length != 0) {
  183. let tuijian = [];
  184. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  185. that.data.isFromSearch ? tuijian = res.data.rows : tuijian = that.data.tuijian.concat(res.data.rows)
  186. that.setData({
  187. tuijian: tuijian, //获取数据数组
  188. searchLoading: true //把"上拉加载"的变量设为false,显示
  189. });
  190. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  191. } else {
  192. that.setData({
  193. searchLoadingComplete: true, //把“没有数据”设为true,显示
  194. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  195. });
  196. }
  197. if (res == null || res.data == null) {
  198. console.error('网络请求失败');
  199. return;
  200. }
  201. wx.hideNavigationBarLoading(
  202. that.setData({
  203. hidden: 'hidden'
  204. })
  205. )
  206. }
  207. });
  208. } else if (selectPriceId == -1){
  209. wx.request({
  210. url: host + "commodityapi/commoditviewfoeeverybody",
  211. data: {
  212. commodity_levelTwo: forid,
  213. purposeId: selectWayId,
  214. offset: parseInt(that.data.searchPageNum),
  215. limit: 10
  216. },
  217. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  218. header: {
  219. 'Accept': 'application/json'
  220. },
  221. success: function (res) {
  222. if (res.data.rows.length != 0) {
  223. let tuijian = [];
  224. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  225. that.data.isFromSearch ? tuijian = res.data.rows : tuijian = that.data.tuijian.concat(res.data.rows)
  226. that.setData({
  227. tuijian: tuijian, //获取数据数组
  228. searchLoading: true //把"上拉加载"的变量设为false,显示
  229. });
  230. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  231. } else {
  232. that.setData({
  233. searchLoadingComplete: true, //把“没有数据”设为true,显示
  234. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  235. });
  236. }
  237. if (res == null || res.data == null) {
  238. console.error('网络请求失败');
  239. return;
  240. }
  241. wx.hideNavigationBarLoading(
  242. that.setData({
  243. hidden: 'hidden'
  244. })
  245. )
  246. }
  247. });
  248. } else if (selectWayId == -1) {
  249. wx.request({
  250. url: host + "commodityapi/commoditviewfoeeverybody",
  251. data: {
  252. commodity_levelTwo: forid,
  253. priceType: selectPriceId,
  254. offset: parseInt(that.data.searchPageNum),
  255. limit: 10
  256. },
  257. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  258. header: {
  259. 'Accept': 'application/json'
  260. },
  261. success: function (res) {
  262. if (res.data.rows.length != 0) {
  263. let tuijian = [];
  264. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  265. that.data.isFromSearch ? tuijian = res.data.rows : tuijian = that.data.tuijian.concat(res.data.rows)
  266. that.setData({
  267. tuijian: tuijian, //获取数据数组
  268. searchLoading: true //把"上拉加载"的变量设为false,显示
  269. });
  270. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  271. } else {
  272. that.setData({
  273. searchLoadingComplete: true, //把“没有数据”设为true,显示
  274. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  275. });
  276. }
  277. if (res == null || res.data == null) {
  278. console.error('网络请求失败');
  279. return;
  280. }
  281. wx.hideNavigationBarLoading(
  282. that.setData({
  283. hidden: 'hidden'
  284. })
  285. )
  286. }
  287. });
  288. }else{
  289. wx.request({
  290. url: host + "commodityapi/commoditviewfoeeverybody",
  291. data: {
  292. commodity_levelTwo: forid,
  293. priceType: selectPriceId,
  294. purposeId: selectWayId,
  295. offset: parseInt(that.data.searchPageNum),
  296. limit: 10
  297. },
  298. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  299. header: {
  300. 'Accept': 'application/json'
  301. },
  302. success: function (res) {
  303. if (res.data.rows.length != 0) {
  304. let tuijian = [];
  305. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  306. that.data.isFromSearch ? tuijian = res.data.rows : tuijian = that.data.tuijian.concat(res.data.rows)
  307. that.setData({
  308. tuijian: tuijian, //获取数据数组
  309. searchLoading: true //把"上拉加载"的变量设为false,显示
  310. });
  311. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  312. } else {
  313. that.setData({
  314. searchLoadingComplete: true, //把“没有数据”设为true,显示
  315. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  316. });
  317. }
  318. if (res == null || res.data == null) {
  319. console.error('网络请求失败');
  320. return;
  321. }
  322. wx.hideNavigationBarLoading(
  323. that.setData({
  324. hidden: 'hidden'
  325. })
  326. )
  327. }
  328. });
  329. }
  330. },
  331. //滚动到底部触发事件
  332. searchScrollLower: function () {
  333. var that = this;
  334. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  335. that.setData({
  336. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  337. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  338. });
  339. that.fetchSearchList();
  340. }
  341. } ,
  342. //价钱筛选
  343. filtratePrice:function(e){
  344. var that = this;
  345. var host = getApp().globalData.servsers;
  346. var id = e.currentTarget.dataset.id;
  347. var flagid = e.currentTarget.dataset.flagid;
  348. that.setData({
  349. selectOneId : id,
  350. selectPriceId: flagid,
  351. })
  352. var forid = that.data.contentList[0].id;
  353. var forname = that.data.contentList[0].classify_name;
  354. var classifydes = that.data.contentList[0].classify_des;
  355. var selectPriceId = that.data.selectPriceId;
  356. var selectWayId = that.data.selectWayId;
  357. if (selectWayId == -1){
  358. wx.request({
  359. url: host + "commodityapi/commoditviewfoeeverybody",
  360. data: {
  361. commodity_levelTwo: forid,
  362. priceType: selectPriceId,
  363. offset: 0,
  364. limit: 10,
  365. },
  366. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  367. header: {
  368. 'Accept': 'application/json'
  369. },
  370. success: function (res) {
  371. that.setData({
  372. tuijian: res.data.rows,
  373. Title: classifydes,
  374. forid: forid,
  375. searchPageNum: 0, //第一次加载,设置1
  376. searchSongList: [], //放置返回数据的数组,设为空
  377. isFromSearch: true, //第一次加载,设置true
  378. searchLoading: true, //把"上拉加载"的变量设为true,显示
  379. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  380. });
  381. console.log(res.data.rows);
  382. if (res.data.rows.length < 10) {
  383. that.setData({
  384. searchPageNum: 0, //第一次加载,设置1
  385. searchSongList: [], //放置返回数据的数组,设为空
  386. isFromSearch: true, //第一次加载,设置true
  387. searchLoading: false, //把"上拉加载"的变量设为true,显示
  388. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  389. });
  390. }
  391. if (res == null || res.data == null) {
  392. console.error('网络请求失败');
  393. return;
  394. }
  395. }
  396. });
  397. }else{
  398. wx.request({
  399. url: host + "commodityapi/commoditviewfoeeverybody",
  400. data: {
  401. commodity_levelTwo: forid,
  402. priceType: selectPriceId,
  403. purposeId: selectWayId,
  404. offset: 0,
  405. limit: 10,
  406. },
  407. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  408. header: {
  409. 'Accept': 'application/json'
  410. },
  411. success: function (res) {
  412. that.setData({
  413. tuijian: res.data.rows,
  414. Title: classifydes,
  415. forid: forid,
  416. searchPageNum: 0, //第一次加载,设置1
  417. searchSongList: [], //放置返回数据的数组,设为空
  418. isFromSearch: true, //第一次加载,设置true
  419. searchLoading: true, //把"上拉加载"的变量设为true,显示
  420. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  421. });
  422. console.log(res.data.rows);
  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. }
  439. },
  440. //送礼用途筛选
  441. filtrateWay: function (e) {
  442. var that = this;
  443. var host = getApp().globalData.servsers;
  444. var id = e.currentTarget.dataset.id;
  445. var flagid = e.currentTarget.dataset.flagid;
  446. that.setData({
  447. selectTwoId: id,
  448. selectWayId: flagid
  449. })
  450. var forid = that.data.contentList[0].id;
  451. var forname = that.data.contentList[0].classify_name;
  452. var classifydes = that.data.contentList[0].classify_des;
  453. var selectPriceId = that.data.selectPriceId;
  454. var selectWayId = that.data.selectWayId;
  455. if (selectPriceId == -1){
  456. wx.request({
  457. url: host + "commodityapi/commoditviewfoeeverybody",
  458. data: {
  459. commodity_levelTwo: forid,
  460. purposeId: selectWayId,
  461. offset: 0,
  462. limit: 10,
  463. },
  464. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  465. header: {
  466. 'Accept': 'application/json'
  467. },
  468. success: function (res) {
  469. that.setData({
  470. tuijian: res.data.rows,
  471. Title: classifydes,
  472. forid: forid,
  473. searchPageNum: 0, //第一次加载,设置1
  474. searchSongList: [], //放置返回数据的数组,设为空
  475. isFromSearch: true, //第一次加载,设置true
  476. searchLoading: true, //把"上拉加载"的变量设为true,显示
  477. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  478. });
  479. if (res.data.rows.length < 10) {
  480. that.setData({
  481. searchPageNum: 0, //第一次加载,设置1
  482. searchSongList: [], //放置返回数据的数组,设为空
  483. isFromSearch: true, //第一次加载,设置true
  484. searchLoading: false, //把"上拉加载"的变量设为true,显示
  485. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  486. });
  487. }
  488. if (res == null || res.data == null) {
  489. console.error('网络请求失败');
  490. return;
  491. }
  492. }
  493. });
  494. }else{
  495. wx.request({
  496. url: host + "commodityapi/commoditviewfoeeverybody",
  497. data: {
  498. commodity_levelTwo: forid,
  499. priceType: selectPriceId,
  500. purposeId: selectWayId,
  501. offset: 0,
  502. limit: 10,
  503. },
  504. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  505. header: {
  506. 'Accept': 'application/json'
  507. },
  508. success: function (res) {
  509. that.setData({
  510. tuijian: res.data.rows,
  511. Title: classifydes,
  512. forid: forid,
  513. searchPageNum: 0, //第一次加载,设置1
  514. searchSongList: [], //放置返回数据的数组,设为空
  515. isFromSearch: true, //第一次加载,设置true
  516. searchLoading: true, //把"上拉加载"的变量设为true,显示
  517. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  518. });
  519. if (res.data.rows.length < 10) {
  520. that.setData({
  521. searchPageNum: 0, //第一次加载,设置1
  522. searchSongList: [], //放置返回数据的数组,设为空
  523. isFromSearch: true, //第一次加载,设置true
  524. searchLoading: false, //把"上拉加载"的变量设为true,显示
  525. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  526. });
  527. }
  528. if (res == null || res.data == null) {
  529. console.error('网络请求失败');
  530. return;
  531. }
  532. }
  533. });
  534. }
  535. console.log("selectPriceId2:" + selectPriceId);
  536. },
  537. })
  538. var that;
  539. var Util = require('../../utils/util.js');