| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- var _request = require('../../utils/request.js')
- Page({
- data: {
- projects_page: 1,
- projects_per_page: 5,
- projects_more: true,
- projects_change: false,
- projects: [],
- vershow: true,
- navData:[],
- currentTab: 0,
- navScrollLeft: 0,
- balance: 0,
- todaysend: Date.parse(new Date()) / 1000,
- searchword:'',
-
- statusBarHeight:20,
- navBarHeight:45,
- windowWidth:375,
- word:'',
- price_sort:0,
- sale_sort:0,
-
- selectShow: false,//控制下拉列表的显示隐藏,false隐藏、true显示
- selectData: [],//下拉列表的数据
- index: 0,//选择的下拉列表下标
- zones:[],
- currentZones:0,
- info:{}
- },
- onLoad: function (options) {
- console.log('options',options);
- const info = wx.getSystemInfoSync();
- console.log('info',info);
- this.setData({
- statusBarHeight:info.statusBarHeight
- })
- this.info()
- this.getData()
- this.getBalanceInfo()
- this.setData({
- vershow: getApp().globalData.vershow,
- currentTab:options.currentTab ? options.currentTab : 0,
- searchword:options.searchword ? options.searchword : ''
- // currentTab: getApp().globalData.isshow
- })
- if (getApp().globalData.isupdate == true) {
- this.getType()
- }
- wx.getSystemInfo({
- success: (res) => {
- this.setData({
- windowWidth: res.windowWidth
- })
- }
- })
-
- },
- onShow: function () {
- if (getApp().globalData.isshow) {
- this.setData({
- currentTab: getApp().globalData.isshow,
- projects_more: true,
- projects_page: 1,
- projects_change: true,
- })
- this.getType()
- }
- },
- onUnload: function () {
- getApp().globalData.isshow = ''
- // this.setData({
- // currentTab: 0,
- // })
- },
- onHide: function () {
- getApp().globalData.isshow = ''
- // this.setData({
- // currentTab: 0,
- // })
- },
- onPullDownRefresh: function () {
- this.setData({
- projects_more: true,
- projects_page: 1,
- projects_change: true
- })
- this.getProjects()
- wx.stopPullDownRefresh()
- },
- onReachBottom: function () {
- if (this.data.projects_more) {
- var page = this.data.projects_page + 1
- this.setData({
- projects_page: page
- })
- this.getProjects()
- }
- },
- getData: function () {
- var that = this
- var url = 'v1/product/commend_words'
- var params = {}
- var success = function (res) {
- console.log('res',res.data.list);
- that.setData({
- word:res.data.list[0]?res.data.list[0].title:''
- })
-
- }
- _request.$get(url, params, success)
- },
- getType: function () {
- var that = this
- var url = 'v1/product/cats'
- var params = {}
- var success = function (res) {
- that.setData({
- navData: res.data
- });
-
-
- let currentid = that.data.navData[that.data.currentTab]['id'];
- console.log('currentid',currentid);
-
- if(currentid == 25){
- wx.hideShareMenu();
- }else{
- wx.showShareMenu();
- }
-
- that.getZones()
- that.getProjects()
- }
- _request.$get(url, params, success)
- },
- getZones:function(){
- var that = this
- var url = 'v1/zones'
- var params = {}
- var success = function (res) {
- that.setData({
- zones: res.data
- })
- }
- _request.$get(url, params, success)
- },
- getProjects: function () {
- console.log('this.data.navData',this.data.navData);
- console.log('this.data.currentTab',this.data.currentTab);
- var id = this.data.navData[this.data.currentTab]['id'];
- if (!this.data.vershow) {
- id = 3
- }
- var that = this
-
- var url = 'v1/cat/' + id + '/products'
- if(that.data.searchword){
- var params = {
- page: this.data.projects_page,
- per_page: this.data.projects_per_page,
- words:this.data.searchword,
- price_sort:this.data.price_sort,
- sale_sort:this.data.sale_sort,
- sale_zone: this.data.currentZones
- }
- }else{
- var params = {
- page: this.data.projects_page,
- per_page: this.data.projects_per_page,
- price_sort:this.data.price_sort,
- sale_sort:this.data.sale_sort,
- sale_zone: this.data.currentZones
- }
- }
-
-
- var success = function (res) {
- if (that.data.projects_change) {
- that.setData({
- projects: [],
- projects_change: false
- })
- }
- var result = that.data.projects.concat(res.data.list || [])
- that.setData({
- projects: result
- })
- var listMore = res.data.list_count > that.data.projects.length
- that.setData({
- projects_more: listMore
- })
- }
- _request.$get(url, params, success)
- },
- toProject: function (val) {
- var id = val.currentTarget.dataset.val;
-
- let currentid = this.data.navData[this.data.currentTab]['id'];
- console.log('currentid',currentid);
-
- if(currentid == 25){
- wx.navigateTo({
- url: '/pages/projects/project-detail/project-detail?id=' + id+'&read=2'
- })
- }else{
- wx.navigateTo({
- url: '/pages/projects/project-detail/project-detail?id=' + id
- })
- }
-
- },
- switchNav(event){
- var cur = event.currentTarget.dataset.current
- var singleNavWidth = this.data.windowWidth / 5
- this.setData({
- navScrollLeft: (cur - 2) * singleNavWidth
- })
- if (this.data.currentTab == cur) {
- return false
- } else {
- this.setData({
- currentTab: cur,
- projects_more: true,
- projects_page: 1,
- projects_change: true
- })
- this.getProjects()
- }
- },
- getBalanceInfo () {
- var that = this
- var url = 'v1/user/balance/info'
- var params = {
- }
- var success = function (res) {
- var result = res.data.total
- that.setData({
- balance: result
- })
- }
- _request.$get(url, params, success)
- },
- onShareAppMessage: function (val) {
- if(read == 0){
- return _request.share({
- // path: '/pages/start/start?url=pages/projects/projects',
- sc: 'xcx_products'
- })
- }else{
- return {};
- }
-
- },
- tosearch: function (val) {
- var id = val.currentTarget.dataset.val;
- wx.navigateTo({
- url: '/pages/search/search'
- })
- },
-
- sortchangenormal(){
- this.setData({
- projects_page: 1,
- projects_per_page: 5,
- projects_more: true,
- projects_change: false,
- projects: [],
- price_sort:0,
- sale_sort:0
- })
- this.getProjects()
- },
- salesort(){
- var type = this.data.sale_sort+1;
- if(type>2) type = 0;
- this.setData({
- projects_page: 1,
- projects_per_page: 5,
- projects_more: true,
- projects_change: false,
- projects: [],
- sale_sort:type,
- })
- this.getProjects()
- },
- pricesort(e){
- var type = this.data.price_sort+1;
- if(type>2) type = 0;
- this.setData({
- projects_page: 1,
- projects_per_page: 5,
- projects_more: true,
- projects_change: false,
- projects: [],
- price_sort:type,
- })
- this.getProjects()
- },
- // 点击下拉显示框
- selectTap() {
- this.setData({
- selectShow: !this.data.selectShow
- });
- },
- // 点击下拉列表
- optionTap(e) {
- var cur = e.currentTarget.dataset.current;
- if (this.data.currentTab == cur) {
- return false
- } else {
- this.setData({
- currentTab: cur,
- projects_more: true,
- projects_page: 1,
- projects_change: true,
- selectShow: !this.data.selectShow,
- currentZones: 0
- })
- this.getProjects()
-
- let currentid = this.data.navData[cur]['id'];
- console.log('currentid',currentid);
-
- if(currentid == 25){
- wx.hideShareMenu();
- }else{
- wx.showShareMenu();
- }
- }
- },
- closeselect(){
- this.setData({
- selectShow: false
- });
- },
- selectzones(e){
- var cur = e.currentTarget.dataset.id;
- if (this.data.currentZones == cur) {
- return false
- } else {
- this.setData({
- currentZones: cur,
- projects_more: true,
- projects_page: 1,
- projects_change: true,
- projects: []
- })
- this.getProjects()
- }
- },
- info(){
- var that = this
- var url = 'v1/user/info'
- var params = {}
- var success = function (res) {
- that.setData({
- info:res.data,
- })
- }
- _request.$get(url, params, success)
- },
- })
|