123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- //index.js
- //获取应用实例
- var app = getApp();
- let host = app.globalData.servsers; // 请求的url
- var coupon = [{
- coupon_monry: '1000',
- coupon_rule: '9999',
- coupon_name: '新年专属红包',
- coupon_begin_time: '2018-01-01',
- coupon_end_time: '2018-02-08'
- },
- {
- coupon_monry: '300',
- coupon_rule: '4999',
- coupon_name: '新年专属红包',
- coupon_begin_time: '2018-01-01',
- coupon_end_time: '2018-02-08'
- },
- {
- coupon_monry: '50',
- coupon_rule: '999',
- coupon_name: '新年专属红包',
- coupon_begin_time: '2018-01-01',
- coupon_end_time: '2018-02-08'
- }
- ];
- Page({
- data: {
- urlHttp: '',
- host: '',
- previous: 30,
- next: 180,
- scrollLeft: 0, //tab标题的滚动条位置
- search: {
- placeholder: "输入搜索关键字"
- },
- navTab: [{
- url: '/',
- icon: 'icon-dingzhijiaju',
- src: '../../images/news/nav_01.png',
- text: '杯类'
- },
- {
- url: '/',
- icon: 'icon-dingzhijiaju',
- src: '../../images/news/nav_02.png',
- text: '行李箱'
- },
- {
- url: '/',
- icon: 'icon-dingzhijiaju',
- src: '../../images/news/nav_03.png',
- text: '手机壳'
- },
- {
- url: '/',
- icon: 'icon-dingzhijiaju',
- src: '../../images/news/nav_04.png',
- text: '板画'
- },
- {
- url: '/',
- icon: 'icon-dingzhijiaju',
- src: '../../images/news/nav_05.png',
- text: '包袋'
- }
- ],
- navArray: [
- // {
- // src: '/images/news/nav_1.png',
- // bg: '#fafcff',
- // type: 0,
- // href: '/'
- // },
- // {
- // src: '/images/news/nav_2.png',
- // bg: '#fef9f8',
- // type: 1,
- // href: '/pages/kindSecondList/kindSecondList'
- // },
- {
- src: '/images/news/nav_3.png',
- bg: '#f7f6fb',
- type: 2,
- href: '/customized/pages/index/index'
- },
- {
- src: '/images/news/nav_4.png',
- bg: '#f1f7fc',
- type: 3,
- href: '/pages/patternMenu/patternMenu'
- }
- ],
- specArray: [],
- navList: ["推荐", "中秋", "改良生活", "优化办公", "智能科技"],
- firstActive: "header_nav_active",
- currentItem: '',
- flag: true,
- banners: [],
- rexiao: [],
- tuijian: [],
- tuijiannew: [],
- forviewFir: [],
- forviewSec: [],
- forviewtitele: '',
- title1: '',
- title2: '',
- title3: '',
- intro1: '',
- intro2: '',
- intro3: '',
- id1: '',
- id2: '',
- id3: '',
- src1: '',
- src2: '',
- src3: '',
- src4: '',
- src5: '',
- src6: '',
- price1: '',
- price2: '',
- price3: '',
- host: '',
- idTwo: '',
- find_name: '',
- find_id: '',
- find_logo: '',
- find_yuedu: '',
- find_shoucang: '',
- datatime: new Date().getTime(),
- city_name: '',
- jingpin: { // 发现精品
- id: 1,
- src: "../../images/jingxuan_banner.jpg",
- title: "各星座员工生日礼品如何选",
- liulan: 117,
- zan: 34
- },
- page: 1,
- hasMore: true,
- hidden: '',
- winHeight: "", //窗口高度
- coupon: coupon, //优惠劵
- showCoupon: false,
- couponSta: 0, //对于用户来说,是否是第一次显示
- un_id: '',
- showMsg: true, //显示切换模式提示
- showChangeModel: false, //显示切换模式确认弹窗
- bannerFlag: 0, //banner数量
- recommendArray: [], // /推荐数组
- goodsNewsArray: [], //按照时间排序来
- // channelId:null ,//用户登录后的id
- page: 1, //默认第一页
- limit: 10, //展示的数量
- requestState: true, //请求状态,默认是有数据的
- loginStatic: false, //登陆状态,默认为false
- },
- //tab切换
- tagChoose: function (options) {
- var that = this
- var name = options.currentTarget.dataset.name;
- var des = options.currentTarget.dataset.des;
- var forid = options.currentTarget.dataset.forid;
- wx: wx.navigateTo({
- url: '/pages/kindSecondList/kindSecondList?classify_name=' + name + '&classify_des=' + des + '&id=' + forid
- })
- },
- // 滚动切换标签样式
- switchTab: function (e) {
- var that = this;
- var host = getApp().globalData.servsers;
- var current = e.detail.current;
- if (e.detail.current == 0) {
- var forid = 0;
- } else {
- var forid = that.data.navList[e.detail.current - 1].id;
- var forname = that.data.navList[e.detail.current - 1].classify_name;
- var classifydes = that.data.navList[e.detail.current - 1].classify_des;
- }
- this.setData({
- currentItem: e.detail.current
- })
- if (forid > 0) {
- wx.request({
- url: that.data.host + "classifyapi/findAllforviewFir",
- data: {
- id: forid
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT flag: true,
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- wx.request({
- url: that.data.host + "commodityapi/findOneforxcx",
- data: {
- com_id: forid,
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT flag: true,
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- that.setData({
- tuijiannew: res.data.rows
- });
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- that.setData({
- forviewFir: res.data.rows,
- forviewtitele: res.data.rows[0].classify_des,
- 'firstActive': "",
- flag: false,
- });
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- } else {
- //设置当前样式
- that.setData({
- 'firstActive': "",
- 'currentItem': 0,
- flag: true,
- })
- }
- that.checkCor();
- },
- checkCor: function () {
- if (this.data.currentItem > 2) {
- this.setData({
- scrollLeft: 300
- })
- } else {
- this.setData({
- scrollLeft: 0
- })
- }
- },
- onLoad: function () {
- var that = this;
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- that.setData({
- urlHttp: host
- })
- //首页banner
- wx.request({
- url: host + "homebannerapi/homebannerall",
- data: {},
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- that.setData({
- banners: res.data.rows,
- host: host
- });
- console.log(res.data.rows);
- //判断banner位置是否为空
- for (var i = 0; i < res.data.rows.length; i++) {
- var bannerFlag = that.data.bannerFlag;
- if (bannerFlag > 0) {
- return false;
- } else {
- if (res.data.rows[i].banner_flag == 0) {
- bannerFlag++;
- that.setData({
- bannerFlag: bannerFlag
- })
- return false;
- }
- }
- }
- //console.log(that.data.banners);
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- //品牌定制
- wx.request({
- url: host + "brandapi/findforfirst",
- data: {},
- method: 'GET',
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (res.data.rows[0] == undefined) {
- that.setData({
- hidden: 'hidden'
- })
- } else {
- var img = res.data.rows[0].brand_logo;
- that.setData({
- title1: res.data.rows[0].brand_name,
- intro1: res.data.rows[0].brand_des,
- src1: res.data.rows[0].brand_logo,
- src4: res.data.rows[0].brand_logo1,
- price1: res.data.rows[0].price,
- id1: res.data.rows[0].id,
- });
- }
- if (res.data.rows[1] == undefined) {
- // that.setData({
- // hidden: 'hidden'
- // })
- } else {
- var img = res.data.rows[0].brand_logo;
- that.setData({
- title2: res.data.rows[1].brand_name,
- intro2: res.data.rows[1].brand_des,
- src2: res.data.rows[1].brand_logo,
- src5: res.data.rows[1].brand_logo1,
- price2: res.data.rows[1].price,
- id2: res.data.rows[1].id,
- });
- }
- if (res.data.rows[2] == undefined) {
- // that.setData({
- // hidden: 'hidden'
- // })
- } else {
- var img = res.data.rows[0].brand_logo;
- that.setData({
- title3: res.data.rows[2].brand_name,
- intro3: res.data.rows[2].brand_des,
- src3: res.data.rows[2].brand_logo,
- src6: res.data.rows[2].brand_logo1,
- price3: res.data.rows[2].price,
- id3: res.data.rows[2].id,
- });
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- })
- // 高度自适应
- wx.getSystemInfo({
- success: function (res) {
- var clientHeight = res.windowHeight,
- clientWidth = res.windowWidth,
- rpxR = 750 / clientWidth;
- var calc = clientHeight * rpxR;
- that.setData({
- winHeight: calc
- });
- }
- });
- },
- onReady: function (e) {
- var that = this;
- var host = getApp().globalData.servsers;
- //判断时间,在规定时间内显示优惠劵弹窗
- var beiginTime = '2017/12/28';
- var endTime = '2018/01/08';
- var beginTimestamp = beiginTime.replace(/-/g, '/');
- beginTimestamp = Date.parse(beginTimestamp);
- var endTimestamp = endTime.replace(/-/g, '/');
- endTimestamp = Date.parse(endTimestamp);
- //获取当前日期
- var date = new Date();
- var Y = date.getFullYear();
- var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
- var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
- var nowTime = Y + '/' + M + '/' + D;
- nowTime = nowTime.replace(/-/g, '/');
- nowTime = Date.parse(nowTime);
- wx.login({
- success: function (res) {
- var code = res.code;
- wx.getUserInfo({
- withCredentials: true,
- success: function (res) {
- wx.request({
- url: host + "userapi/insertadd",
- data: {
- user_id: code,
- name: res.userInfo.nickName,
- icon: res.userInfo.avatarUrl,
- iv: res.iv,
- encryptedData: res.encryptedData,
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- that.setData({
- un_id: res.data.unionId
- })
- var un_id = res.data.unionId;
- if (parseInt(nowTime) >= parseInt(beginTimestamp) && parseInt(nowTime) <= parseInt(endTimestamp)) { //当前日期在优惠劵领取时间内
- console.log("un_id:" + un_id);
- if (un_id != undefined && un_id != '' && un_id != null) {
- wx.request({ //优惠活动-对于用户来说,是否应该显示
- url: host + "mycouponapi/getAlertFlag",
- data: {
- user_id: un_id,
- batch_no: 1,
- alert_num: 1 //优惠活动对于每个用户来说,一共显示的次数
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (res.data == 0) {
- that.setData({
- showCoupon: true
- })
- } else {
- that.setData({
- showCoupon: false
- })
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- }
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- })
- }
- })
- }
- })
- },
- footerTap: app.footerTap,
- onShow: function () {
- var that = this;
- that.onLoad();
- //商品推荐
- that.getGoodsRecommendList(that);
- // 按照时间排序
- that.setData({
- goodsNewsArray: [],
- page: 1,
- })
- that.getGoodsNews(that)
- that.getSpecList(that)
- if (wx.getStorageSync('channelIdObj').channelId) {
- that.setData({
- loginStatic: true,
- })
- }
- },
- //跳转到“发现”tab页
- find: function (e) {
- wx.switchTab({
- url: "/pages/find/index"
- })
- },
- getSpecList(that) {
- wx.request({
- url: host + '/classifyapi/classifyTwoAll',
- method: 'get',
- data: {
- classifyHigher: 3072
- },
- success: function (res) {
- console.log(res)
- that.setData({
- specArray: res.data.rows
- })
- }
- })
- },
- onReachBottom() {
- var that = this;
- if (that.data.requestState) {
- that.setData({
- page: that.data.page + 1
- })
- that.getGoodsNews(that)
- }
- console.log('到底了')
- },
- //下拉刷新
- onPullDownRefresh: function (e) {
- },
- onShareAppMessage: function (res) { //页面分享
- var that = this;
- var host = getApp().globalData.servsers;
- if (res.from === 'button') {
- // 来自页面内转发按钮
- console.log(res.target)
- }
- return {
- title: '大良造-精良之选,用心造物!',
- path: '/pages/index/index',
- success: function (res) {
- },
- fail: function (res) {
- // 转发失败
- }
- }
- },
- //关闭优惠劵弹窗
- closeCoupon: function (e) {
- var that = this;
- that.setData({
- showCoupon: false
- })
- },
- //关闭切换模式提示
- closeMsg: function (e) {
- var that = this;
- that.setData({
- showMsg: false
- })
- },
- //打开切换提示
- openChangeModel: function (e) {
- var that = this;
- that.setData({
- showMsg: false,
- showChangeModel: true
- })
- },
- //跳转至一键选礼
- goChooseGift: function (e) {
- var that = this;
- that.setData({
- showChangeModel: false
- })
- wx.navigateTo({
- url: '/pages/patternMenu/patternMenu'
- })
- },
- //关闭切换模式确认弹窗
- closeChangeModel: function (e) {
- var that = this;
- that.setData({
- showChangeModel: false
- })
- },
- // 商品推荐
- getGoodsRecommendList(that) {
- let data = {
- limit: 6,
- offset: 1,
- channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
- }
- wx.request({
- url: host + '/commodityapi/queryCommodityGroom',
- method: "get",
- data: data,
- success(res) {
- res.data.rows.forEach(el => {
- el.logo = el.commodity_logo.split(",")
- })
- that.setData({
- recommendArray: res.data.rows
- })
- }
- })
- },
- // 按时间排序来的
- getGoodsNews(that) {
- let data = {
- limit: that.data.limit,
- offset: that.data.page,
- channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
- }
- wx.request({
- url: host + '/commodityapi/findAllforNewproduct',
- method: "get",
- data: data,
- success(res) {
- let goods = that.data.goodsNewsArray;
- console.log(goods)
- if (that.data.page == 1) {
- goods = [];
- }
- goods.push(...res.data.rows);
- console.log(goods)
- that.setData({
- goodsNewsArray: goods,
- requestState: res.data.rows.length === that.data.limit
- })
- }
- })
- },
- toGoodsDetail(e) { // 进入商品详情页
- let that = this,
- id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/buy/buy?com_id=' + id,
- })
- },
- navTap(e) {
- // console.log(e);
- let item = e.currentTarget.dataset.item;
- if (item.type == 1 && !wx.getStorageSync('channelIdObj')) { // 表示是优质的杯,并且还没有登录过渠道
- wx.navigateTo({
- url: '/pages/login/login?url=' + item.href,
- })
- } else {
- wx.navigateTo({
- url: item.href,
- })
- }
- },
- tapMomo() {
- // if (!wx.getStorageSync('channelIdObj')) { // 还没有登录过渠道
- // wx.navigateTo({
- // url: '/pages/login/login?url=/pages/momo/momo',
- // })
- // } else {
- // wx.switchTo({
- // url: '/pages/momo/momo',
- // })
- // }
- },
- swiperChange(e) {
- console.log(e.detail.current, this.data.specArray.length,"detail")
- if (e.detail.current == this.data.specArray.length-1) {
- console.log("等于了")
- this.setData({
- previous: 210,
- next: 0,
- })
- } else {
- this.setData({
- previous: 30,
- next: 180,
- })
- }
- }
- })
- var banners = []
- // 热销新品
- var rexiao = []
- // 热销新品
- var pinpai = []
- // 人气推荐
- var tuijian = []
- var that;
- var Util = require('../../utils/util.js');
|