123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- // pages/pinduoduo/category.js
- var util = require('../../utils/util.js');
- var app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- loadover: false,
- subcate: [],
- level: 0,
- show_more_cate: false,
- cur_pid: 0,
- cur_ppid: 0,
- tablebar: 2,
- hidetip: true,
- tip_html: '^_^已经到底了',
- pageNum: 1,
- hasRefesh: false,
- list: [],
- LoadingComplete: true,
- isHidenotice: true
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var that = this;
- var cur_pid = options.id;
- this.setData({
- cur_pid: cur_pid,
- cur_ppid: cur_pid
- })
- wx.showLoading({
- })
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'goods.get_subcategory',
- 'id': cur_pid
- },
- dataType: 'json',
- success: function (res) {
- wx.setNavigationBarTitle({
- title: res.data.cur_cate_name
- });
- if (res.data.code == 0) {
- that.setData({
- level: res.data.level,
- subcate: res.data.data,
- })
- } else {
- that.setData({
- level: res.data.level,
- })
- }
- }
- })
-
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'goods.get_category_goods',
- 'id': cur_pid
- },
- dataType: 'json',
- success: function (res) {
- if (res.data.code == 0) {
- that.setData({
- list: res.data.data,
- hidetip: true
- })
- } else {
- that.setData({
- LoadingComplete: false,
- tip_html: '^_^已经到底了',
- hidetip: true
- })
- }
- }
- })
- wx.hideLoading();
- this.setData({ loadover: true })
- },
- show_more_cate: function () {
- this.setData({ show_more_cate: true })
- },
- hide_cate_d: function () {
- this.setData({ show_more_cate: false })
- },
- goLink: function (event) {
- let url = event.currentTarget.dataset.link;
- wx.reLaunch({
- url: url
- })
- },
- nav_dir_go_link: function (url) {
- wx.navigateTo({
- url: url,
- fail: function () {
- wx.redirectTo({
- url: url
- })
- }
- })
- },
- common_godir_link: function (e) {
- var url = e.currentTarget.dataset.link;
- var that = this;
- if (url == '/Snailfish_shop/pages/index/index') {
- wx.reLaunch({
- url: url
- })
- } else
- this.nav_dir_go_link(url);
- },
- common_go_link: function (e) {
- var url = e.currentTarget.dataset.link;
- var id = e.currentTarget.dataset.id;
- var that = this;
- console.log(id);
- this.setData({
- show_more_cate: false
- })
- if (url == '/Snailfish_shop/pages/index/index') {
- wx.reLaunch({
- url: url
- })
- } else
- if (this.data.level == 2) {
- that.setData({
- hasRefesh: false,
- cur_pid: id,
- list: [],
- pageNum: 0,
- hidetip: false,
- });
- this.loadMore();
- } else {
- this.nav_dir_go_link(url);
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- this.loadMore();
- },
- loadMore: function () {
- let that = this;
- if (!that.data.hasRefesh) {
- that.setData({
- hasRefesh: true,
- hidetip: false
- });
- var cur_pid = that.data.cur_pid;
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'goods.get_category_goods',
- 'id': cur_pid,
- 'page': that.data.pageNum + 1
- },
- dataType: 'json',
- success: function (res) {
- if (res.data.code == 0) {
- var list = that.data.list;
- var n_data = res.data.data;
- //list.push(n_data);
- //console.log(list);
- n_data.map(function (good) {
- list.push(good);
- });
- that.setData({
- list: list,
- pageNum: that.data.pageNum + 1,
- hasRefesh: false,
- hidetip: true
- });
- } else {
- that.setData({
- LoadingComplete: false,
- tip_html: '^_^已经到底了',
- hidetip: true
- });
- }
- }
- })
- }
- },
- goGoods_link: function (e) {
- var goods_id = e.currentTarget.dataset.type;
- var url = "/Snailfish_shop/pages/goods/index?id=" + goods_id;
- this.nav_dir_go_link(url);
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|