1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167 |
- var util = require('../../utils/util.js');
- var status = require('../../utils/index.js');
- var a = require("../../utils/public");
- var countDownInit = require("../../utils/countDown");
- var wcache = require('../../utils/wcache.js');
- var app = getApp();
- var timerOut = '';
- Page({
- mixins: [countDownInit.default, require('../../mixin/globalMixin.js'), require('../../mixin/compoentCartMixin.js')],
- data: {
- needAuth: false,
- stopClick: false,
- community: {},
- rushList: [],
- commingList: [],
- countDownMap: [],
- actEndMap: [],
- skuList: [],
- pageNum: 1,
- notice_list: [],
- slider_list: [],
- shop_info: {},
- showEmpty: false,
- indexBottomImage: '',
- classification: {
- tabs: [],
- activeIndex: -1
- },
- commingClassification: {
- tabs: [],
- activeIndex: -1
- },
- isShowCommingClassification: true,
- isShowClassification: true,
- showChangeCommunity: false,
- isTipShow: false,
- isShowGuide: false,
- index_lead_image: '',
- theme: 0,
- cartNum: 0,
- navigat: [],
- navigatSwiper: {page: 1, current:0, totnav: 0},
- tabIdx: 0,
- scrollDirect: "",
- isSticky: false,
- showCommingEmpty: false,
- stopNotify: true,
- reduction: {},
- is_share_html: true,
- commingNum: 0,
- couponRefresh: false,
- index_change_cate_btn: 0,
- newComerRefresh: false,
- showCouponModal: false,
- copy_text_arr: [],
- showCopyText: false,
- totalAlertMoney: 0,
- groupInfo: {
- group_name: '社区',
- owner_name: '团长'
- },
- needPosition: true,
- typeTopicList: [],
- pinList: {},
- cube: [],
- secRushList: [],
- secKillGoodsIndex: 1,
- isblack: 0,
- imageSize: {
- imageWidth: "100%",
- imageHeight: 600
- },
- fmShow: true,
- presale_index_info: '',
- isDiy: 0,
- diyManyGoodsList: []
- },
- isFirst: 0,
- $data: {
- stickyFlag: false,
- scrollTop: 0,
- overPageNum: 1,
- loadOver: false,
- hasOverGoods: false,
- countDownMap: {},
- actEndMap: {},
- timer: {},
- scrollHeight: 1300,
- stickyTop: 0,
- hasCommingGoods: true
- },
- tpage: 1,
- hasRefeshin: false,
- postion: {},
- options: '',
- focusFlag: false,
- /**
- * 监控滚动事件
- */
- onPageScroll: function (t) {
- if (!this.$data.isLoadData) {
- if (t.scrollTop < this.$data.scrollHeight) {
- if (t.scrollTop > this.$data.scrollTop) {
- "down" !== this.data.scrollDirect && this.setData({
- scrollDirect: "down"
- })
- } else {
- "up" != this.data.scrollDirect && this.setData({
- scrollDirect: "up"
- })
- }
- } else {
- "down" !== this.data.scrollDirect && this.setData({
- scrollDirect: "down"
- })
- }
- if (t.scrollTop > this.$data.stickyTop) {
- this.data.isSticky || (this.setData({
- isSticky: true
- }), this.$data.stickyFlag = true)
- } else {
- t.scrollTop < this.$data.stickyBackTop && this.data.isSticky && (this.setData({
- isSticky: false
- }), this.$data.stickyFlag = false)
- }
- this.$data.scrollTop = t.scrollTop
- }
- },
- onLoad: function(options) {
- app.setShareConfig();
- wx.hideTabBar();
- var that = this;
- var token = wx.getStorageSync('token');
- status.setNavBgColor();
- status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
- console.log('step1');
- let community = wx.getStorageSync('community');
- let community_id = community.communityId || '';
-
- let isparse_formdata = wx.getStorageSync('isparse_formdata') || 0;
- if (isparse_formdata != 1) {
- // this.get_index_info();
- if (options && Object.keys(options).length != 0) {
- console.log('step2');
- var scene = decodeURIComponent(options.scene);
- if (scene != 'undefined') {
- var opt_arr = scene.split("_");
- options.community_id = opt_arr[0];
- wcache.put('share_id', opt_arr[1]);
- }
- that.options = options;
- if (options.share_id != 'undefined' && options.share_id > 0) wcache.put('share_id', options.share_id);
- if (options.community_id != 'undefined' && options.community_id > 0) {
- console.log('step3');
- util.getCommunityById(options.community_id).then((res)=>{
- if (res.code == 0) {
- console.log('step4');
- var shareCommunity = res.data;
- console.log('分享community_id', options.community_id);
- console.log('历史community_id', community_id);
- let sdata = {};
- if (res.open_danhead_model == 1) {
- console.log('开启单社区', res.default_head_info);
- sdata.community = res.default_head_info;
- sdata.open_danhead_model = res.open_danhead_model;
- token && that.addhistory(res.default_head_info.communityId || '');
- wx.setStorageSync('community', res.default_head_info);
- } else if (shareCommunity){
- if (options.community_id != community_id) {
- if (community_id) {
- sdata.showChangeCommunity = true;
- sdata.changeCommunity = shareCommunity;
- sdata.community = community;
- } else {
- sdata.community = shareCommunity;
- sdata.shareCommunity = shareCommunity;
- wcache.put('community', shareCommunity);
- }
- } else {
- sdata.community = community;
- }
- }
- sdata.hidetip = false;
- sdata.token = token;
- sdata.showEmpty = false;
- sdata.needPosition = false;
- that.setData(sdata, ()=>{
- that.loadPage();
- });
- } else {
- console.log('step5');
- that.loadPage();
- that.setData({
- hidetip: false,
- token: token,
- showEmpty: false,
- needPosition: false
- })
- }
- token && that.addhistory();
- })
- } else {
- util.getCommunityById(options.community_id).then((res) => {
- if (res.code == 0) {
- if (res.open_danhead_model == 1) {
- console.log('开启单社区step6');
- that.setData({ community: res.default_head_info, open_danhead_model: res.open_danhead_model })
- token && that.addhistory(res.default_head_info.communityId || '');
- wx.setStorageSync('community', res.default_head_info);
- }
- console.log('step6');
- that.loadPage();
- }
- }).catch(() => {
- that.loadPage();
- })
- }
- } else {
- util.getCommunityById(options.community_id).then((res) => {
- if (res.code == 0) {
- if (res.open_danhead_model == 1) {
- console.log('开启单社区step7');
- that.setData({ community: res.default_head_info, open_danhead_model: res.open_danhead_model })
- token && that.addhistory(res.default_head_info.communityId || '');
- wx.setStorageSync('community', res.default_head_info);
- }
- that.loadPage();
- }
- }).catch(()=>{
- that.loadPage();
- })
- console.log('step7');
- that.setData({
- hidetip: false,
- token: token,
- showEmpty: false,
- community
- })
- }
- }
- },
- addhistory: function (id=0) {
- console.log('step13');
- let community_id = 0;
- if (id==0) {
- var community = wx.getStorageSync('community');
- community_id = community.communityId;
- } else {
- community_id = id;
- }
- console.log('history community_id=' + community_id);
- var token = wx.getStorageSync('token');
- let that = this;
- community_id !==void 0 && app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'index.addhistory_community',
- community_id: community_id,
- 'token': token
- },
- dataType: 'json',
- success: function(res) {
- if(id!=0) that.getHistoryCommunity(), console.log('addhistory+id', id);
- }
- })
- },
- loadPage: function() {
- wx.showLoading();
- console.log('step8');
- let that = this;
- that.get_index_info();
- if(this.data.isDiy==0) {
- that.get_type_topic();
- that.getNavigat();
- that.getPinList();
- } else {
- this.getDiyInfo();
- }
- that.getCoupon();
- status.loadStatus().then(function() {
- let appLoadStatus = app.globalData.appLoadStatus;
- console.log('appLoadStatus',appLoadStatus)
- if (appLoadStatus == 0) {
- // wx.hideLoading();
- setTimeout(function(){ wx.hideLoading(); },1000);
- that.setData({ needAuth: true, couponRefresh: false });
- that.data.isDiy==0&&that.load_goods_data();
- } else if (appLoadStatus == 2) {
- console.log('step9');
- that.getHistoryCommunity();
- } else {
- console.log('step12');
- let community = wx.getStorageSync('community');
- community || (community=app.globalData.community);
- if (!community){
- util.getCommunityInfo().then((res) => {
- that.setData({
- community: that.fliterCommunity(res)
- })
- })
- } else {
- that.setData({
- community: that.fliterCommunity(community)
- })
- }
- console.log('step18');
- that.data.isDiy==0&&that.load_goods_data();
- }
- });
- },
- // 不显示社区省份
- fliterCommunity: function (community){
- let resArr = community && community.fullAddress && community.fullAddress.split('省');
- if (resArr) {
- return Object.assign({}, community, { address: resArr[1] || resArr[0] });
- } else {
- return community;
- }
- },
- onReady: function (res) {
- this.videoContext = wx.createVideoContext('myVideo');
- },
- onShow: function() {
- // 页面显示
- let that = this;
- console.log('isblack', app.globalData.isblack)
- this.setData({ stopNotify: false, tabbarRefresh: true, isblack: app.globalData.isblack || 0 })
- util.check_login_new().then((res) => {
- if(res) {
- that.setData({ needAuth: false })
- } else {
- this.setData({ needAuth: true, couponRefresh: false });
- return;
- }
- })
- app.globalData.timer.start();
- var token = wx.getStorageSync('token');
- token&&(0, status.cartNum)('', true).then((res)=>{
- res.code == 0 && that.setData({ cartNum: res.data })
- });
- if (app.globalData.changedCommunity) {
- console.log('change')
- app.globalData.goodsListCarCount = [];
- let community = app.globalData.community;
- this.setData({
- community: that.fliterCommunity(community),
- newComerRefresh: false
- });
- this.getCommunityPos(community.communityId);
- this.hasRefeshin = false;
- this.setData({
- newComerRefresh: true,
- rushList: [],
- pageNum: 1,
- classificationId: null,
- "classification.activeIndex": -1
- }, () => {
- this.setData({
- "classification.activeIndex": 0
- })
- })
- this.$data = {
- ...this.$data, ...{
- overPageNum: 1,
- loadOver: false,
- hasOverGoods: false,
- countDownMap: {},
- actEndMap: {},
- timer: {},
- stickyFlag: false,
- hasCommingGoods: true
- }
- }
- app.globalData.changedCommunity = false, this.get_index_info(), this.addhistory();
- this.load_goods_data(), this.get_type_topic(),this.getPinList();
- } else {
- console.log('nochange')
- if (that.isFirst>=1){
- this.setData({ loadOver: true })
- this.changeRushListNum();
- }
- }
- if (that.isFirst==0) {
- this.setData({ couponRefresh: true });
- } else {
- this.getCoupon();
- let cid = app.globalData.indexCateId || '';
- cid && this.goIndexType(cid);
- app.globalData.indexCateId = '';
- }
-
- that.isFirst++;
- },
- /**
- * 动态变化列表购物车数量
- */
- changeRushListNum: function(){
- let that = this;
- let goodsListCarCount = app.globalData.goodsListCarCount;
- let rushList = this.data.rushList;
- let changeCarCount = false;
- this.setData({ changeCarCount })
- if (goodsListCarCount.length > 0 && rushList.length > 0) {
- goodsListCarCount.forEach(function (item) {
- let k = that.arrayHasElement(rushList, item.actId);
- if (k[0] != -1 && rushList[k[0]][k[1]].skuList.length === 0) {
- let newNum = item.num * 1;
- rushList[k[0]][k[1]].car_count = newNum >= 0 ? newNum : 0;
- changeCarCount = true;
- }
- })
- // goodsListCarCount.forEach(function (item) {
- // let k = rushList.findIndex((n) => n.actId == item.actId);
- // if (k != -1 && rushList[k].skuList.length === 0) {
- // let newNum = item.num * 1;
- // rushList[k].car_count = newNum >= 0 ? newNum : 0;
- // changeCarCount = true;
- // }
- // })
- this.setData({ rushList, changeCarCount })
- }
- },
- arrayHasElement: function(array, element) {
- let el=array;
- for(let number in el){
- if (el[number].length > 0) {
- for (var index in el[number]) {
- if (el[number][index].actId == element) {
- return [number, index]
- }
- }
- }
- }
- return [-1, -1];
- },
- changeNotListCartNum: function (t) {
- let that = this;
- let e = t.detail;
- (0, status.cartNum)(that.setData({ cartNum: e }));
- this.changeRushListNum();
- },
- onHide: function() {
- this.setData({ stopNotify: true, tabbarRefresh: false, changeCarCount: false })
- console.log('详情页', this.data.stopNotify)
- app.globalData.timer.stop();
- console.log('onHide')
- },
- /**
- * 授权成功回调
- */
- authSuccess: function() {
- console.log('authSuccess');
- let that = this;
- this.tpage = 1;
- this.hasRefeshin = false;
- this.setData({
- rushList: [],
- pageNum: 1,
- needAuth: false,
- newComerRefresh: false,
- couponRefresh: true,
- isblack: app.globalData.isblack || 0,
- diyLoaded: false
- })
- this.$data = {
- ...this.$data, ...{
- overPageNum: 1,
- loadOver: false,
- hasOverGoods: false,
- countDownMap: {},
- actEndMap: {},
- timer: {},
- hasCommingGoods: true
- }
- }
- status.getInNum().then((isCan) => {
- if (isCan) {
- that.setData({ isTipShow: true })
- timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 7000);
- }
- })
- this.loadPage();
- this.data.isTipShow && (timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 7000));
- },
- authModal: function (e = {}) {
- let needAuth = (e && e.detail) || this.data.needAuth;
- if (this.data.needAuth || e.detail) {
- this.setData({
- showAuthModal: !this.data.showAuthModal,
- needAuth
- });
- return false;
- }
- return true;
- },
- //获取历史社区
- getHistoryCommunity: function () {
- let that = this;
- var token = wx.getStorageSync('token');
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'index.load_history_community',
- token: token
- },
- dataType: 'json',
- success: function (res) {
- console.log('step14');
- if (res.data.code == 0) {
- console.log('getHistoryCommunity');
- let history_communities = res.data.list;
- let isNotHistory = false;
- if (Object.keys(history_communities).length == 0 || history_communities.communityId == 0) isNotHistory = true;
-
- let resArr = history_communities && history_communities.fullAddress && history_communities.fullAddress.split('省');
- history_communities = Object.assign({}, history_communities, { address: resArr[1] })
- that.setData({
- community: history_communities
- })
- wcache.put('community', history_communities);
- app.globalData.community = history_communities;
- if (token && !isNotHistory) {
- let lastCommunity = wx.getStorageSync('lastCommunity');
- let lastCommunityId = lastCommunity.communityId || '';
- if (lastCommunityId != '' && lastCommunityId != history_communities.communityId) {
- that.setData({
- showChangeCommunity: true,
- changeCommunity: lastCommunity
- }, ()=> {
- wx.removeStorageSync('lastCommunity');
- })
- }
- }
- that.setData({
- community: app.globalData.community
- })
- that.load_goods_data();
- } else {
- let options = that.options;
- if (options !== void 0 && options.community_id) {
- console.log('新人加入分享进来的社区id:', that.options);
- that.addhistory(options.community_id);
- } else if (res.data.code == 1) {
- console.log('获取历史社区');
- wx.redirectTo({
- url: "/lionfish_comshop/pages/position/community"
- })
- } else {
- that.setData({ needAuth: true })
- }
- }
- }
- })
- },
-
- getScrollHeight: function () {
- wx.createSelectorQuery().select('.rush-list-box').boundingClientRect((rect) => {
- rect && rect.height && (this.$data.scrollHeight = rect.height || 1300);
- console.log(this.$data.scrollHeight)
- }).exec()
- },
- /**
- * 引导页切换
- */
- handleProxy: function(){
- clearTimeout(timerOut);
- this.setData({
- isTipShow: false,
- isShowGuide: true
- })
- wcache.put('inNum', 4);
- },
- handleHideProxy: function(){
- this.setData({
- isTipShow: false,
- isShowGuide: false
- })
- },
- /**
- * 获取首页信息
- */
- get_index_info: function() {
- let that = this;
- let community = wx.getStorageSync('community');
- let communityId = community && community.communityId || '';
- let token = wx.getStorageSync('token');
- app.util.request({
- url: 'entry/wxapp/index',
- data: {
- controller: 'index.index_info',
- communityId,
- token
- },
- dataType: 'json',
- success: function(res) {
- let rdata = res.data;
- let groupInfo = that.data.groupInfo;
- if (rdata.code == 0) {
- if (!res.data.is_community && communityId && !that.data.needAuth) {
- let changeCommunity = that.data.changeCommunity || {};
- let changeCommunityId = changeCommunity.communityId || '';
- if (changeCommunityId) {
- wcache.put('community', changeCommunity);
- that.addhistory(changeCommunity.community_id);
- that.setData({
- community: changeCommunity,
- showChangeCommunity: false
- })
- that.loadPage();
- } else {
- wx.showModal({
- title: '提示',
- content: `该${groupInfo.group_name}不在,请重新选择${groupInfo.group_name}`,
- showCancel: false,
- confirmColor: '#F75451',
- success(res) {
- if (res.confirm) {
- wx.redirectTo({
- url: '/lionfish_comshop/pages/position/community',
- })
- }
- }
- })
- }
- }
- let notice_list = rdata.notice_list;
- let slider_list = rdata.slider_list;
- let index_lead_image = rdata.index_lead_image;
- if(index_lead_image){
- status.getInNum().then((isCan)=>{
- if (isCan) {
- that.setData({ isTipShow: true },()=>{
- timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 9000);
- })
- }
- })
- } else {
- that.setData({ isTipShow: false })
- }
- let common_header_backgroundimage = rdata.common_header_backgroundimage;
- app.globalData.common_header_backgroundimage = common_header_backgroundimage;
- let order_notify_switch = rdata.order_notify_switch;
- let index_list_top_image_on = rdata.index_list_top_image_on;
- let index_change_cate_btn = rdata.index_change_cate_btn || 0;
- let default_img = '../../images/rush-title.png';
- // if (index_list_top_image_on == 1) default_img='';
- let index_list_top_image = rdata.index_list_top_image ? rdata.index_list_top_image : default_img;
- let shop_info = {
- shoname: rdata.shoname,
- shop_index_share_image: rdata.shop_index_share_image,
- index_list_top_image: index_list_top_image,
- title: rdata.title,
- common_header_backgroundimage,
- order_notify_switch,
- index_top_img_bg_open: rdata.index_top_img_bg_open || 0,
- index_top_font_color: rdata.index_top_font_color || '#fff',
- index_communityinfo_showtype: rdata.index_communityinfo_showtype || 0,
- index_list_top_image_on
- }
- app.globalData.placeholdeImg = rdata.index_loading_image || '';
- let placeholdeImg = rdata.index_loading_image || '';
- wcache.put('shopname', rdata.shoname);
- wx.setNavigationBarTitle({ title: rdata.shoname });
- let category_list = rdata.category_list || [];
- let index_type_first_name = rdata.index_type_first_name || '全部';
- if (category_list.length > 0) {
- category_list.unshift({
- name: index_type_first_name,
- id: 0
- })
- that.setData({
- isShowClassification: true,
- "classification.tabs": category_list
- })
- } else {
- that.setData({
- isShowClassification: false
- })
- }
- let theme = rdata.theme || 0;
- let rushEndTime = rdata.rushtime*1000 || 0;
- let isShowShareBtn = rdata.index_share_switch || 0;
- let isShowListCount = rdata.is_show_list_count || 0;
- let isShowListTimer = rdata.is_show_list_timer || 0;
- let isShowContactBtn = rdata.index_service_switch || 0;
- let index_switch_search = rdata.index_switch_search || 0;
- let ishow_index_gotop = rdata.ishow_index_gotop || 0;
- if (rdata.is_comunity_rest == 1 && !that.data.needAuth) {
- wx.showModal({
- title: '温馨提示',
- content: `${groupInfo.owner_name}休息中,欢迎下次光临!`,
- showCancel: false,
- confirmColor: '#F75451',
- confirmText: '好的',
- success(res) { }
- })
- }
- that.postion = rdata.postion;
- //秒杀
- let { scekill_time_arr, seckill_bg_color, seckill_is_open, seckill_is_show_index, hide_community_change_word,index_qgtab_counttime, hide_index_type } = rdata;
- let myDate = new Date();
- let curHour = myDate.getHours(); // 当前时间
- console.log('当前时间:', curHour);
- let curSeckillIdx = 0; //当前时间索引
- let scekillTimeArr = []; //显示的时间段
- if (scekill_time_arr.length > 3) {
- let timeLen = scekill_time_arr.length;
- curSeckillIdx = scekill_time_arr.findIndex(item => {
- return item >= curHour;
- });
- console.log('当前时间索引:', curSeckillIdx)
- //取三个时间段
- if (curSeckillIdx === -1) {
- //没有进行或者未开始 取最后三个
- scekillTimeArr = scekill_time_arr.slice(-3);
- } else if (curSeckillIdx === 0) {
- //全部未开始 取最前三个
- scekillTimeArr = scekill_time_arr.slice(0, 3);
- } else if ((curSeckillIdx + 1) == timeLen) {
- //剩最后一个 取最后三个
- scekillTimeArr = scekill_time_arr.slice(-3);
- } else {
- scekillTimeArr = scekill_time_arr.slice(curSeckillIdx - 1, curSeckillIdx + 2);
- }
- } else {
- scekillTimeArr = scekill_time_arr;
- }
- //判断各个时段状态
- let scekillTimeList = [];
- let secKillActiveIdx = 0;
- if(scekillTimeArr.length){
- scekillTimeArr.forEach((item, idx) => {
- let secObj = {};
- //state: 0已开抢 1疯抢中 2即将开抢
- if (item == curHour) {
- secObj.state = 1;
- secObj.desc = '疯抢中';
- secKillActiveIdx = idx;
- } else if (item < curHour) {
- secObj.state = 0;
- secObj.desc = '已开抢';
- } else {
- secObj.state = 2;
- secObj.desc = '即将开抢';
- }
- secObj.timeStr = (item < 10 ? '0' + item : item) + ':00';
- secObj.timeArr = [item < 10 ? '0' + item : item, '00'];
- secObj.seckillTime = item;
- scekillTimeList.push(secObj);
- })
- //获取当前秒杀商品
- that.getSecKillGoods(scekillTimeArr[secKillActiveIdx]);
- }
- let index_video_arr = rdata.index_video_arr;
- // 预售信息
- let presale_index_info = rdata.presale_index_info || '';
- if(presale_index_info&&presale_index_info.goods_list) {
- let goods_list = presale_index_info.goods_list;
- let nowtime = Date.parse(new Date())/1000;
- goods_list.forEach((item, idx)=>{
- let { presale_ding_money, actPrice, presale_deduction_money, presale_type, presale_ding_time_start_int, presale_ding_time_end_int } = item;
- if(presale_type==0) {
- presale_deduction_money = presale_deduction_money>0?presale_deduction_money:presale_ding_money;
- let goodsPrice = (actPrice[0]+'.'+actPrice[1])*1;
- presale_index_info.goods_list[idx].weikuan = (goodsPrice - presale_deduction_money*1).toFixed(2);
- presale_ding_money = presale_ding_money.toFixed(2);
- presale_index_info.goods_list[idx].dingArr = (presale_ding_money+'').split('.');
- presale_index_info.goods_list[idx].presale_deduction_money = presale_deduction_money;
- }
- let saleStatus = 1; //客付定金 0未开始 2已结束
- if(nowtime<presale_ding_time_start_int) {
- saleStatus = 0;
- } else if(nowtime>presale_ding_time_end_int) {
- saleStatus = 2;
- }
- presale_index_info.goods_list[idx].saleStatus = saleStatus;
- })
- }
- let isDiy = rdata.open_diy_index_page || 0;
- wx.setStorageSync('is_diy', isDiy);
- (isDiy==1)&&that.getDiyInfo();
- // 礼品卡
- let virtualcard_info = rdata.virtualcard_info || '';
- if(virtualcard_info&&virtualcard_info.goods_list) {
- var timestamp = Date.parse(new Date())/1000;
- let newList = [];
- if(Object.keys(virtualcard_info.goods_list).length) {
- virtualcard_info.goods_list.forEach(item=>{
- (item.end_time<timestamp)&&(item.actEnd = 1);
- newList.push(item);
- })
- }
- virtualcard_info.goods_list = newList;
- }
- that.setData({
- notice_list,
- slider_list,
- index_lead_image,
- theme,
- indexBottomImage: rdata.index_bottom_image || '',
- shop_info: shop_info,
- loadOver: true,
- rushEndTime,
- commingNum: rdata.comming_goods_total,
- isShowShareBtn,
- isShowListCount,
- isShowListTimer,
- is_comunity_rest: rdata.is_comunity_rest,
- index_change_cate_btn,
- isShowContactBtn,
- index_switch_search,
- is_show_new_buy: rdata.is_show_new_buy || 0,
- qgtab: res.data.qgtab || {},
- notice_setting: rdata.notice_setting || {},
- index_hide_headdetail_address: rdata.index_hide_headdetail_address || 0,
- is_show_spike_buy: rdata.is_show_spike_buy || 0,
- hide_community_change_btn: rdata.hide_community_change_btn || 0,
- hide_top_community: rdata.hide_top_community || 0,
- index_qgtab_text: rdata.index_qgtab_text,
- ishow_index_copy_text: rdata.ishow_index_copy_text || 0,
- newComerRefresh: true,
- cube: rdata.cube,
- placeholdeImg,
- seckill_bg_color,
- seckill_is_open,
- seckill_is_show_index,
- scekillTimeList,
- secKillActiveIdx,
- hide_community_change_word,
- ishow_index_gotop,
- ishow_index_pickup_time: rdata.ishow_index_pickup_time || 0,
- index_video_arr,
- index_qgtab_counttime,
- hide_index_type,
- show_index_wechat_oa: rdata.show_index_wechat_oa,
- ishide_index_goodslist: rdata.ishide_index_goodslist,
- can_index_notice_alert: rdata.can_index_notice_alert,
- presale_index_info,
- isDiy,
- virtualcard_info
- })
- }
- }
- })
- },
- /**
- * 确认切换社区
- */
- confrimChangeCommunity: function() {
- let community = this.data.changeCommunity;
- app.globalData.community = community;
- wcache.put('community', community);
- this.$data = {
- ...this.$data, ...{
- overPageNum: 1,
- loadOver: false,
- hasOverGoods: false,
- countDownMap: {},
- actEndMap: {},
- timer: {},
- stickyFlag: false
- }
- }
- this.hasRefeshin = false;
- this.setData({
- showChangeCommunity: false,
- community: community,
- rushList: [],
- pageNum: 1
- }, () => {
- this.loadPage();
- this.addhistory();
- })
- },
- /**
- * 关闭切换社区
- */
- closeChangeCommunity: function(){
- this.setData({
- showChangeCommunity: false
- })
- },
- /**
- * 获取商品列表
- */
- load_goods_data: function() {
- var token = wx.getStorageSync('token');
- var that = this;
- var cur_community = wx.getStorageSync('community');
- var gid = that.data.classificationId;
- this.$data.isLoadData = true;
- console.log('load_goods_begin ');
- if (!that.hasRefeshin && !that.$data.loadOver) {
- console.log('load_goods_in ');
- this.hasRefeshin = true;
- that.setData({
- loadMore: true
- });
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'index.load_gps_goodslist',
- token: token,
- pageNum: that.data.pageNum,
- head_id: cur_community.communityId,
- gid,
- per_page: 12
- },
- dataType: 'json',
- success: function(res) {
- if (that.data.pageNum == 1) {
- that.setData({ cate_info: res.data.cate_info || {} })
- }
- if (res.data.code == 0) {
- let rushList = [];
- if (res.data.is_show_list_timer==1) {
- rushList = that.transTime(res.data.list);
- for (let s in that.$data.countDownMap) that.initCountDown(that.$data.countDownMap[s]);
- } else {
- rushList = that.data.rushList;
- rushList[that.data.pageNum-1] = res.data.list;
- }
- let rdata = res.data;
- let { full_money, full_reducemoney, is_open_fullreduction, is_open_vipcard_buy, is_vip_card_member, is_member_level_buy } = rdata;
- let reduction = { full_money, full_reducemoney, is_open_fullreduction }
- // 是否可以会员折扣购买
- let canLevelBuy = false;
- if (is_open_vipcard_buy == 1) {
- if (is_vip_card_member != 1 && is_member_level_buy == 1) canLevelBuy = true;
- } else {
- (is_member_level_buy == 1) && (canLevelBuy = true);
- }
- if (that.data.pageNum==1) that.setData({ copy_text_arr: rdata.copy_text_arr || [] })
- that.hasRefeshin = false;
- that.setData({
- rushList: rushList,
- pageNum: that.data.pageNum + 1,
- loadMore: false,
- reduction,
- tip: '',
- is_open_vipcard_buy: is_open_vipcard_buy || 0,
- is_vip_card_member,
- is_member_level_buy,
- canLevelBuy
- }, ()=>{
- if (that.isFirst == 1) {
- that.isFirst++;
- }
- if (rushList.length && !that.$data.stickyTop) {
- wx.createSelectorQuery().select(".tab-nav-query").boundingClientRect(function (t) {
- if (t && t.top){
- wcache.put('tabPos', t);
- that.$data.stickyTop = t.top + t.height, that.$data.stickyBackTop = t.top;
- } else {
- let tabpos = wcache.get('tabPos', false);
- if (tabpos) that.$data.stickyTop = tabpos.top + tabpos.height, that.$data.stickyBackTop = tabpos.top;
- }
- }).exec();
- that.$data.scrollTop > that.$data.stickyTop && wx.pageScrollTo({
- duration: 0,
- scrollTop: that.$data.stickyTop + 4
- });
- }
- that.getScrollHeight();
-
- if (that.data.pageNum == 2 && res.data.list.length < 10) {
- console.log('load_over_goods_list_begin')
- that.$data.loadOver = true;
- that.hasRefeshin = true;
- that.setData({
- loadMore: true
- }, () => {
- that.load_over_gps_goodslist();
- });
- }
- });
- } else if (res.data.code == 1) {
- that.$data.loadOver = true;
- that.load_over_gps_goodslist();
- } else if (res.data.code == 2) {
- //no login
- that.setData({ needAuth: true, couponRefresh: false })
- }
- },
- complete: function() {
- that.$data.isLoadData = false;
- // wx.hideLoading();
- setTimeout(function(){ wx.hideLoading(); },1000);
- }
- })
- } else {
- that.load_over_gps_goodslist();
- }
- },
- /**
- * 组合倒计时时间
- */
- transTime: function(list) {
- let that = this;
- let e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
- e === 0 && list.map(function(t) {
- t.end_time *= 1000;
- that.$data.countDownMap[t.end_time] = t.end_time, that.$data.actEndMap[t.end_time] = t.end_time <= new Date().getTime() || t.spuCanBuyNum == 0;
- })
- let rushList = that.data.rushList;
- let idx = that.data.pageNum+that.$data.overPageNum-2;
- rushList[idx] = list;
- return rushList;
- // return that.data.rushList.concat(list);
- },
- /**
- * 获取售罄商品
- */
- load_over_gps_goodslist: function() {
- var token = wx.getStorageSync('token');
- var that = this;
- var cur_community = wx.getStorageSync('community');
- var gid = that.data.classificationId;
- if (!that.$data.hasOverGoods && that.$data.loadOver) {
- that.$data.hasOverGoods = true;
- that.setData({
- loadMore: true
- });
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'index.load_over_gps_goodslist',
- token: token,
- pageNum: that.$data.overPageNum,
- head_id: cur_community.communityId,
- gid,
- is_index_show: 1
- },
- dataType: 'json',
- success: function(res) {
- if (res.data.code == 0) {
- let rushList = that.transTime(res.data.list);
- for (let s in that.$data.countDownMap) that.initCountDown(that.$data.countDownMap[s]);
- that.$data.hasOverGoods = false;
- that.$data.overPageNum += 1;
- that.setData({
- rushList: rushList,
- loadMore: false,
- tip: ''
- }, ()=>{
- if (that.isFirst == 1) {
- that.isFirst++;
- if (rushList.length && !that.$data.stickyTop) {
- wx.createSelectorQuery().select(".tab-nav-query").boundingClientRect(function (t) {
- if (t && t.top) {
- wcache.put('tabPos', t);
- that.$data.stickyTop = t.top + t.height, that.$data.stickyBackTop = t.top;
- } else {
- let tabpos = wcache.get('tabPos', false);
- if (tabpos) that.$data.stickyTop = tabpos.top + tabpos.height, that.$data.stickyBackTop = tabpos.top;
- }
- }).exec();
- that.$data.scrollTop > that.$data.stickyTop && wx.pageScrollTo({
- duration: 0,
- scrollTop: that.$data.stickyTop + 4
- });
- }
- that.getScrollHeight();
- }
- });
- } else if (res.data.code == 1) {
- if (that.$data.overPageNum == 1 && that.data.rushList.length == 0) that.setData({
- showEmpty: true
- })
- that.setData({
- loadMore: false,
- tip: '^_^已经到底了'
- })
- } else if (res.data.code == 2) {
- that.setData({ needAuth: true, couponRefresh: false })
- }
- that.$data.isLoadData = false;
- }
- })
- } else {
- that.$data.isLoadData = false;
- }
- },
- /**
- * 监控分类导航
- */
- classificationChange: function(t, autoScroll=0) {
- console.log(t.detail.e)
- wx.showLoading();
- var that = this;
- this.$data = {...this.$data, ...{
- overPageNum: 1,
- loadOver: false,
- hasOverGoods: false,
- countDownMap: {},
- actEndMap: {},
- timer: {}
- }
- }, this.hasRefeshin = false, this.setData({
- rushList: [],
- showEmpty: false,
- pageNum: 1,
- "classification.activeIndex": t.detail.e,
- classificationId: t.detail.a
- }, function() {
- if ((this.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop+5)) || autoScroll){
- console.log('滚动了')
- let windowWidth = app.globalData.systemInfo && app.globalData.systemInfo.windowWidth || 375;
- let taBH = windowWidth/750*72;
- wx.pageScrollTo({ scrollTop: that.$data.stickyTop - taBH, duration: 0 })
- }
- that.load_goods_data();
- });
- },
- /**
- * 监控即将抢购分类导航
- */
- commingClassificationChange: function (t) {
- wx.showLoading();
- var that = this;
- that.tpage = 1;
- this.$data = {...this.$data, ...{hasCommingGoods: true} },
- this.setData({
- showCommingEmpty: false,
- commingList: [],
- "commingClassification.activeIndex": t.detail.e,
- commingClassificationId: t.detail.a
- }, function () {
- if (this.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop + 5)) {
- wx.pageScrollTo({ scrollTop: that.$data.stickyTop + 5, duration: 0 })
- }
- that.getCommingList();
- });
- },
- // 抢购切换
- tabSwitch: function (t) {
- var that = this;
- var tabIdx = 1 * t.currentTarget.dataset.idx;
- this.setData({ tabIdx: tabIdx }, ()=>{
- if (tabIdx == 1) {
- if (that.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop + 5)) {
- wx.pageScrollTo({ scrollTop: that.$data.stickyTop + 5, duration: 0 })
- }
- if (that.tpage == 1) {
- that.getCommingList();
- }
- }
- })
- },
- /**
- * 即将开抢列表
- */
- getCommingList: function(){
- this.data.commigLoadMore && wx.showLoading();
- var token = wx.getStorageSync('token');
- var that = this;
- var cur_community = wx.getStorageSync('community');
- var gid = this.data.commingClassificationId || 0;
- that.$data.isLoadData = true;
- if (that.$data.hasCommingGoods) {
- that.$data.hasCommingGoods = false;
- that.setData({ commigLoadMore: true });
- app.util.request({
- url: 'entry/wxapp/index',
- data: {
- controller: 'index.load_comming_goodslist',
- token: token,
- pageNum: that.tpage,
- head_id: cur_community.communityId,
- gid
- },
- dataType: 'json',
- success: function (res) {
- wx.hideLoading();
- if (res.data.code == 0) {
- let commingList = res.data.list;
- commingList = that.data.commingList.concat(commingList);
- that.$data.hasCommingGoods = true;
- that.tpage += 1;
- that.setData({
- commingList: commingList,
- commigLoadMore: false,
- commigTip: ''
- },()=>{
- that.getScrollHeight();
- });
- } else if (res.data.code == 1) {
- if (that.tpage == 1 && that.data.commingList.length == 0) that.setData({
- showCommingEmpty: true
- })
- that.setData({
- commigLoadMore: false,
- commigTip: '^_^已经到底了'
- })
- } else if (res.data.code == 2) {
- that.setData({ needAuth: true, couponRefresh: false })
- }
- that.$data.isLoadData = false;
- }
- })
- } else{
- that.$data.isLoadData = false;
- !that.data.commigLoadMore && wx.hideLoading();
- }
- },
- /**
- * 返回顶部
- */
- backTop: function() {
- this.stickyFlag = false, wx.pageScrollTo({
- scrollTop: 0,
- duration: 500
- });
- },
- goLink: function(event) {
- let url = event.currentTarget.dataset.link;
- let needauth = event.currentTarget.dataset.needauth || '';
- console.log(needauth)
- if(needauth){ if (!this.authModal()) return; }
- url && wx.navigateTo({ url })
- },
- /**
- * 导航小图标
- */
- getNavigat: function(){
- let that = this;
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'index.get_navigat'
- },
- dataType: 'json',
- success: function (res) {
- if (res.data.code == 0) {
- let navigat = res.data.data || [];
- let navigatEmpty = [];
- let navigatSwiper = {page: 1, current:0, totnav: 0};
- let chunks = [];
- if (navigat.length>0) {
- let len = (5-navigat.length%5) || 0;
- if(len<5&&len>0) navigatEmpty = new Array(len);
- for(let i=0;i<navigat.length;i=i+10){
- chunks.push(navigat.slice(i,i+10));
- }
- navigatSwiper.page = chunks.length;
- navigatSwiper.totnav = navigat.length;
- }
- that.setData({ navigat: chunks, navigatEmpty, navigatSwiper })
- }
- }
- })
- },
- navigatSwiperChange: function(t) {
- this.setData({
- "navigatSwiper.current": t.detail.current
- });
- },
-
- /**
- * 导航图标跳转
- */
- goNavUrl: function(t) {
- let idx = t.currentTarget.dataset.idx;
- console.log(idx)
- let { navigat, needAuth, navigatSwiper } = this.data;
- let sidx = navigatSwiper.current;
- navigat = navigat[sidx];
- if (navigat.length > 0) {
- let url = navigat[idx].link;
- let type = navigat[idx].type;
- if(util.checkRedirectTo(url, needAuth)){
- this.authModal();
- return;
- }
- if (type== 0){
- // 跳转webview
- wx.navigateTo({
- url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url),
- })
- } else if (type==1) {
- if (url.indexOf('lionfish_comshop/pages/index/index') != -1 || url.indexOf('lionfish_comshop/pages/order/shopCart') != -1 || url.indexOf('lionfish_comshop/pages/user/me') != -1 || url.indexOf('lionfish_comshop/pages/type/index') != -1) {
- wx.switchTab({ url: url })
- } else {
- wx.navigateTo({ url: url })
- }
- } else if (type==2){
- // 跳转小程序
- let appid = navigat[idx].appid;
- appid && wx.navigateToMiniProgram({
- appId: navigat[idx].appid,
- path: url,
- extraData: {},
- envVersion: 'release',
- success(res) {
- // 打开成功
- },
- fail(error) {
- console.log(error)
- }
- })
- } else if (type == 3){
- //首页分类
- // t.detail.e 选中索引
- // t.detail.a 选中id
- let classification = this.data.classification;
- let tabs = classification && classification.tabs;
- let cid = url;
- let activeIdx = tabs.findIndex((p) => { return p.id == cid });
- if (activeIdx!=-1) {
- let cateInfo = {
- detail: { e: activeIdx, a: cid }
- };
- this.classificationChange(cateInfo, 1);
- } else {
- wx.showToast({
- title: '分类不存在或已关闭',
- icon: 'none'
- })
- }
- } else if (type == 4) {
- //独立分类
- app.globalData.typeCateId = url;
- wx.switchTab({
- url: '/lionfish_comshop/pages/type/index'
- })
- } else if (type == 6) {
- //领券
- let url = navigat[idx].link;
- wx.navigateTo({
- url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
- })
- }
- }
- },
- /**
- * 幻灯片跳转
- */
- goBannerUrl: function (t) {
- let idx = t.currentTarget.dataset.idx;
- let { slider_list, needAuth } = this.data;
- if (slider_list.length > 0) {
- let url = slider_list[idx].link;
- let type = slider_list[idx].linktype;
- if (util.checkRedirectTo(url, needAuth)) {
- this.authModal();
- return;
- }
- if (type == 0) {
- // 跳转webview
- url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) })
- } else if (type == 1) {
- if (url.indexOf('lionfish_comshop/pages/index/index') != -1 || url.indexOf('lionfish_comshop/pages/order/shopCart') != -1 || url.indexOf('lionfish_comshop/pages/user/me') != -1 || url.indexOf('lionfish_comshop/pages/type/index') != -1) {
- url && wx.switchTab({ url: url })
- } else {
- url && wx.navigateTo({ url: url })
- }
- } else if (type == 2) {
- // 跳转小程序
- let appid = slider_list[idx].appid;
- appid && wx.navigateToMiniProgram({
- appId: slider_list[idx].appid,
- path: url,
- extraData: {},
- envVersion: 'release',
- success(res) {
- // 打开成功
- },
- fail(error) {
- console.log(error)
- }
- })
- } else if (type == 6) {
- //领券
- wx.navigateTo({
- url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
- })
- }
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.setData({ couponRefresh: false, newComerRefresh: false, stopNotify: true });
- this.tpage = 1;
- this.$data = {
- ...this.$data, ...{
- overPageNum: 1,
- loadOver: false,
- hasOverGoods: false,
- countDownMap: {},
- actEndMap: {},
- timer: {},
- stickyFlag: false,
- hasCommingGoods: true
- }
- }
- this.hasRefeshin = false;
- this.setData({
- rushList: [],
- commingList: [],
- tabIdx: 0,
- pageNum: 1,
- couponRefresh: true,
- newComerRefresh: true,
- stopNotify: false,
- rushEndTime: 0,
- diyLoaded: false
- }, ()=>{
- this.loadPage();
- })
- wx.stopPullDownRefresh();
- },
- onReachBottom: function(e) {
- if(this.data.ishide_index_goodslist==1||this.data.isDiy==1) return;
- if (this.data.tabIdx==0){
- this.load_goods_data();
- } else {
- this.getCommingList();
- }
- },
- /**
- * 获取团长位置
- */
- getCommunityPos: function (community_id){
- let that = this;
- app.util.request({
- 'url': 'entry/wxapp/user',
- 'data': {
- controller: 'index.get_community_position',
- communityId: community_id
- },
- dataType: 'json',
- method: 'POST',
- success: function (res) {
- if (res.data.code == 0) {
- that.postion = res.data.postion;
- }
- }
- })
- },
- /**
- * 查看地图
- */
- gotoMap: function () {
- let community = this.data.community;
- let postion = this.postion || {lat: 0, lon: 0};
- let longitude = parseFloat(postion.lon),
- latitude = parseFloat(postion.lat),
- name = community.disUserName,
- address = `${community.fullAddress}(${community.communityName})`;
- wx.openLocation({
- latitude: latitude,
- longitude: longitude,
- name: name,
- address: address,
- scale: 28
- })
- },
- share_handler: function () {
- this.setData({
- is_share_html: false
- })
- },
- hide_share_handler: function () {
- this.setData({
- is_share_html: true
- })
- },
- // 搜索
- goResult: function (e) {
- let value = e.detail.value.keyword ? e.detail.value.keyword : e.detail.value;
- let keyword = value.replace(/\s+/g, '');
- if (!keyword) {
- wx.showToast({
- title: '请输入关键词',
- icon: 'none'
- })
- return;
- }
- wx.navigateTo({
- url: '/lionfish_comshop/pages/type/result?keyword=' + keyword,
- })
- },
- /**
- * 新人优惠券显示开关
- */
- toggleCoupon: function(e){
- let auth = e.currentTarget.dataset.auth || '';
- let needAuth = this.data.needAuth || '';
- if(needAuth && auth) {
- this.setData({
- showAuthModal: true,
- showCouponModal: false
- })
- } else {
- this.setData({
- showCouponModal: !this.data.showCouponModal,
- hasAlertCoupon: false
- })
- }
- },
- changeCartNum: function(t) {
- let that = this;
- let e = t.detail;
- (0, status.cartNum)(that.setData({ cartNum: e }));
- },
- /**
- * 一键复制文本
- */
- copyText: function (e) {
- let copy_text_arr = this.data.copy_text_arr;
- let community = this.data.community;
- let communityName = community.communityName;
- let disUserName = community.disUserName;
- let communityAddress = community.address || community.communityAddress || community.fullAddress;
- let data = '-团长信息-\r\n小区:' + communityName + '\r\n团长:' + disUserName + '\r\n自提点:' + communityAddress + '\r\n\r\n今日推荐\r\n';
- if (copy_text_arr.length) {
- copy_text_arr.forEach(function(item, index){
- data += (index + 1) + '.【' + item.goods_name + '】 团购价' + item.price + '\r\n';
- data += '~~~~~~~~~~~~~~~~~~~~\r\n';
- })
- }
- let that = this;
- wx.setClipboardData({
- data: data,
- success: function (res) {
- wx.getClipboardData({
- success: function (res) {
- that.setData({ showCopyText: false })
- wx.showToast({
- title: '复制成功'
- })
- }
- })
- }
- })
- },
- /**
- * 显示关闭复制文本
- */
- showCopyTextHandle: function(e){
- if (!this.authModal()) return;
- let showCopyText = e.currentTarget.dataset.status;
- this.setData({ showCopyText })
- },
- /**
- * 优惠券获取
- */
- getCoupon: function () {
- let that = this;
- let token = wx.getStorageSync('token');
- app.util.request({
- url: 'entry/wxapp/index',
- data: { controller: 'goods.get_seller_quan', token },
- dataType: 'json',
- success: function (res) {
- let list = res.data.quan_list;
- let hasCoupon = false;
- let hasAlertCoupon = false;
- if (Object.prototype.toString.call(list) == '[object Object]' && Object.keys(list).length > 0) hasCoupon = true;
- if (Object.prototype.toString.call(list) == '[object Array]' && list.length > 0) hasCoupon = true;
- let alert_quan_list = res.data.alert_quan_list || [];
- if (Object.prototype.toString.call(alert_quan_list) == '[object Object]' && Object.keys(alert_quan_list).length > 0) hasAlertCoupon = true;
- if (Object.prototype.toString.call(alert_quan_list) == '[object Array]' && alert_quan_list.length > 0) hasAlertCoupon = true;
- let totalAlertMoney = 0;
- if (Object.prototype.toString.call(alert_quan_list) == '[object Object]' && Object.keys(alert_quan_list).length > 0) {
- Object.keys(alert_quan_list).forEach(function(item){
- totalAlertMoney += alert_quan_list[item].credit*1;
- })
- } else if (Object.prototype.toString.call(alert_quan_list) == '[object Array]' && alert_quan_list.length > 0) {
- alert_quan_list.forEach(function (item) {
- totalAlertMoney += item.credit * 1;
- })
- }
- that.setData({
- quan: res.data.quan_list || [],
- alert_quan_list,
- hasCoupon,
- hasAlertCoupon,
- showCouponModal: hasAlertCoupon,
- totalAlertMoney: totalAlertMoney.toFixed(2)
- })
- }
- });
- },
- receiveCoupon: function (event) {
- if (!this.authModal()) return;
- let quan_id = event.currentTarget.dataset.quan_id;
- let type = event.currentTarget.dataset.type || 0;
- var token = wx.getStorageSync('token');
- var quan_list = [];
- if(type==1) {
- quan_list = this.data.alert_quan_list;
- } else {
- quan_list = this.data.quan;
- }
- var that = this;
- app.util.request({
- url: 'entry/wxapp/index',
- data: { controller: 'goods.getQuan', token, quan_id },
- dataType: 'json',
- success: function (msg) {
- //1 被抢光了 2 已领过 3 领取成功
- if (msg.data.code == 0) {
- wx.showToast({
- title: msg.data.msg || '被抢光了',
- icon: 'none'
- })
- } else if (msg.data.code == 1) {
- wx.showToast({
- title: '被抢光了',
- icon: 'none'
- })
- } else if (msg.data.code == 2) {
- wx.showToast({
- title: '已领取',
- icon: 'none'
- })
- var new_quan = [];
- for (var i in quan_list) {
- if (quan_list[i].id == quan_id) quan_list[i].is_get = 1;
- new_quan.push(quan_list[i]);
- }
- that.setData({ quan: new_quan })
- }
- else if (msg.data.code == 4) {
- wx.showToast({
- title: '新人专享',
- icon: 'none'
- })
- }
- else if (msg.data.code == 3) {
- var new_quan = [];
- for (var i in quan_list) {
- if (quan_list[i].id == quan_id){
- quan_list[i].is_get = 1;
- quan_list[i].is_hide = msg.data.is_hide;
- }
- new_quan.push(quan_list[i]);
- }
- if(type==1) {
- that.setData({ alert_quan_list: new_quan })
- } else {
- that.setData({ quan: new_quan })
- }
- wx.showToast({
- title: '领取成功',
- })
- } else if (msg.data.code == 4) {
- // 未登录
- }
- }
- })
- },
- goUse: function (e) {
- this.setData({ showCouponModal: false, hasAlertCoupon: false })
- let idx = e.currentTarget.dataset.idx;
- let quan = this.data.alert_quan_list || [];
- console.log(Object.keys(quan).length)
- if (Object.keys(quan).length >= idx) {
- if (quan[idx].is_limit_goods_buy == 0) {
- wx.switchTab({
- url: '/lionfish_comshop/pages/index/index',
- })
- } else if (quan[idx].is_limit_goods_buy == 1) {
- let id = quan[idx].limit_goods_list;
- let ids = id.split(',');
- let url = '';
- if (ids.length > 1) {
- url = '/lionfish_comshop/pages/type/result?type=2&good_ids=' + id;
- } else {
- url = '/lionfish_comshop/pages/goods/goodsDetail?id=' + id;
- }
- wx.navigateTo({ url: url })
- } else if (quan[idx].is_limit_goods_buy == 2) {
- let gid = quan[idx].goodscates || 0;
- wx.navigateTo({
- url: '/lionfish_comshop/pages/type/result?type=1&gid=' + gid,
- })
- }
- }
- },
- /**
- * 分类专题
- */
- get_type_topic: function () {
- let that = this;
- var cur_community = wx.getStorageSync('community');
- var token = wx.getStorageSync('token');
- app.util.request({
- url: 'entry/wxapp/index',
- data: {
- controller: 'goods.get_category_col_list',
- head_id: cur_community.communityId,
- token
- },
- dataType: 'json',
- success: function (res) {
- if(res.data.code == 0) {
- let typeTopicList = res.data.data || [];
- that.setData({ typeTopicList })
- }
- }
- })
- },
- /**
- * 拼团列表
- */
- getPinList: function () {
- let that = this;
- var community = wx.getStorageSync('community');
- let head_id = community.communityId || '';
- var token = wx.getStorageSync('token');
- app.util.request({
- url: 'entry/wxapp/index',
- data: {
- controller: 'group.get_pintuan_list',
- is_index: 1,
- head_id,
- token
- },
- dataType: 'json',
- success: function (res) {
- if (res.data.code == 0) {
- let pinList = {};
- let { list, pintuan_index_coming_img, pintuan_index_show } = res.data;
- pinList.list = list || [];
- pinList.img = pintuan_index_coming_img || '';
- pinList.show = pintuan_index_show || 0;
- that.setData({ pinList })
- }
- }
- })
- },
- /**
- * 魔方图标跳转
- */
- goCube: function (t) {
- let idx = t.currentTarget.dataset.idx; // 当前链接索引
- let index = t.currentTarget.dataset.index; // 当前魔方索引
- let { cube, needAuth } = this.data;
- console.log(cube)
- if (cube.length > 0) {
- let url = cube[index].thumb.link[idx];
- let url2 = cube[index].thumb.outlink[idx];
- let type = (cube[index].thumb.linktype && cube[index].thumb.linktype[idx]);
- (type === (void 0)) && (type = 1);
- if (util.checkRedirectTo(url, needAuth)) {
- this.authModal();
- return;
- }
- if (type == 0) {
- // 跳转webview
- url = cube[index].thumb.webview[idx];
- wx.navigateTo({
- url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url)
- })
- } else if (type == 1) {
- if (url.indexOf('lionfish_comshop/pages/index/index') != -1 || url.indexOf('lionfish_comshop/pages/order/shopCart') != -1 || url.indexOf('lionfish_comshop/pages/user/me') != -1 || url.indexOf('lionfish_comshop/pages/type/index') != -1) {
- url && wx.switchTab({
- url,
- fail: (err)=>{
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- })
- }
- })
- } else {
- url && wx.navigateTo({
- url,
- fail: (err)=>{
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- })
- }
- })
- }
- } else if (type == 2) {
- // 跳转小程序
- let appid = navigat[idx].appid;
- appid && wx.navigateToMiniProgram({
- appId: navigat[idx].appid,
- path: url,
- extraData: {},
- envVersion: 'release',
- success(res) {
- // 打开成功
- },
- fail(error) {
- console.log(error)
- }
- })
- } else if (type == 3) {
- let cid = cube[index].thumb.cateid[idx];
- this.goIndexType(cid);
- } else if (type == 4) {
- //独立分类
- let url = cube[index].thumb.cateid[idx];
- app.globalData.typeCateId = url;
- wx.switchTab({
- url: '/lionfish_comshop/pages/type/index'
- })
- }else if (type==5){
- // 跳转小程序
- let appid = cube[index].thumb.appid[idx];
- appid && wx.navigateToMiniProgram({
- appId: appid,
- path: url2,
- extraData: {},
- envVersion: 'release',
- success(res) {
- // 打开成功
- },
- fail(error) {
- console.log(error)
- }
- })
- } else if (type == 6) {
- //领券
- wx.navigateTo({
- url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
- })
- }
- }
- },
- goIndexType: function(cid){
- if(cid.detail) {
- cid = cid.detail;
- }
- let classification = this.data.classification;
- let tabs = classification && classification.tabs;
- let activeIdx = tabs.findIndex((p) => { return p.id == cid });
- if (activeIdx != -1) {
- let cateInfo = {
- detail: { e: activeIdx, a: cid }
- };
- this.classificationChange(cateInfo, 1);
- }
- },
- getSecKillGoods: function (seckill_time){
- var that = this;
- var cur_community = wx.getStorageSync('community');
- var token = wx.getStorageSync('token');
- app.util.request({
- url: 'entry/wxapp/index',
- data: {
- controller: 'index.load_gps_goodslist',
- token: token,
- pageNum: 1,
- head_id: cur_community.communityId,
- seckill_time,
- is_seckill: 1,
- per_page: 10000
- },
- dataType: 'json',
- success: function (res) {
- if(res.data.code==0) {
- let secRushList = res.data.list || [];
- that.setData({ secRushList })
- }
- }
- })
- },
- scrollSecKillGoodsChange: function (t) {
- this.setData({
- secKillGoodsIndex: t.detail.current + 1
- });
- },
- /**
- * 显示秒杀时间切换
- */
- changeSecKillTime(t){
- let that = this;
- let seckill_time = t.currentTarget.dataset.time;
- let secKillActiveIdx = t.currentTarget.dataset.idx;
- this.setData({
- secRushList: [],
- secKillActiveIdx
- }, ()=>{
- that.getSecKillGoods(seckill_time);
- })
- },
- /**
- * 图片信息
- */
- imageLoad: function (e) {
- var imageSize = util.imageUtil(e)
- this.setData({
- imageSize
- })
- },
- /**
- * 播放视频隐藏封面图
- */
- btnPlay: function () {
- this.setData({
- fmShow: false
- })
- this.videoContext.play();
- },
- videEnd: function () {
- this.setData({
- fmShow: true
- })
- },
- bindload: function(t){
- console.log(t.detail)
- },
- binderror: function(t){
- this.setData({ hideMpAccount: true })
- console.log(t.detail)
- },
- closeMpaccount: function(){
- this.setData({ show_index_wechat_oa: 0 })
- },
- showNoticeTextHandle: function(e){
- if(this.data.can_index_notice_alert==1) {
- let showNoticeText = e.currentTarget.dataset.status;
- let noticeIdx = e.currentTarget.dataset.idx;
- this.setData({ showNoticeText, noticeIdx })
- }
- },
- /**
- * DIY公用链接跳转
- */
- goDiysliderUrl: function(t) {
- let link = t.currentTarget.dataset.link;
- let needAuth = this.data.needAuth;
- if (Object.keys(link).length > 0) {
- let type = link.parents;
- if (util.checkRedirectTo(link.wap_url, needAuth)) {
- this.authModal();
- return;
- }
- switch(type) {
- case "WEBVIEW":
- let url = link.wap_url;
- url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) });
- break;
- case "MALL_LINK":
- url = link.wap_url;
- if (url.indexOf('lionfish_comshop/pages/index/index') != -1 || url.indexOf('lionfish_comshop/pages/order/shopCart') != -1 || url.indexOf('lionfish_comshop/pages/user/me') != -1 || url.indexOf('lionfish_comshop/pages/type/index') != -1) {
- url && wx.switchTab({ url })
- } else {
- url && wx.navigateTo({ url })
- }
- break;
- case "OTHER_APPLET":
- // 跳转小程序
- let appId = link.appid;
- let path = link.wap_url;
- appId && wx.navigateToMiniProgram({
- appId,
- path,
- extraData: {},
- envVersion: 'release',
- success(res) {},
- fail(error) { wx.showModal({ title: "提示", content: error.errMsg, showCancel: false }) }
- })
- break;
- case "CUSTOM_LINK":
- url = link.wap_url;
- if (url.indexOf('lionfish_comshop/pages/index/index') != -1 || url.indexOf('lionfish_comshop/pages/order/shopCart') != -1 || url.indexOf('lionfish_comshop/pages/user/me') != -1 || url.indexOf('lionfish_comshop/pages/type/index') != -1) {
- url && wx.switchTab({ url })
- } else {
- url && wx.navigateTo({ url })
- }
- break;
- case "GOODS_CATEGORY":
- //独立分类
- let cateId = link.id;
- app.globalData.typeCateId = cateId;
- wx.switchTab({
- url: '/lionfish_comshop/pages/type/index'
- })
- break;
- default:
- url = link.wap_url;
- url && wx.navigateTo({ url })
- break;
- }
- }
- },
- /**
- * DIY商品列表组获取
- */
- getDiyGoodsList(res) {
- console.log('getDiyGoodsList', res)
- let data = res.detail.data;
- let idx = res.detail.id;
- let diyGoodsList = [];
- let is_open_vipcard_buy = 0;
- if(data.code==0) {
- let resGoodsList = data.list;
- if (data.is_show_list_timer==1&&resGoodsList.length>0) {
- diyGoodsList = this.transTime(resGoodsList);
- for (let s in this.$data.countDownMap) this.initCountDown(this.$data.countDownMap[s]);
- } else {
- diyGoodsList[0] = resGoodsList;
- }
- is_open_vipcard_buy = data.is_open_vipcard_buy;
- }
- let list = this.data.diyGoodsList;
- list[idx] = diyGoodsList;
- this.setData({ diyGoodsList: list, is_open_vipcard_buy })
- },
- getDiyManyGoodsList(res) {
- let data = res.detail.data;
- let list = [];
- if(data.code==0) {
- let resGoodsList = data.list;
- if (data.is_show_list_timer==1&&resGoodsList.length>0) {
- list = this.transTime(resGoodsList);
- for (let s in this.$data.countDownMap) this.initCountDown(this.$data.countDownMap[s]);
- } else {
- list[0] = resGoodsList;
- }
- }
- this.setData({ diyManyGoodsList: list })
- },
- /**
- * DIY数据
- */
- getDiyInfo: function() {
- app.util.ProReq('index.get_diy_info').then(res => {
- console.log(res.global)
- let { diyJson, global } = res;
- global.title && wx.setNavigationBarTitle({ title: global.title });
- wx.setNavigationBarColor({
- backgroundColor: global.topNavColor,
- frontColor: global.textNavColor,
- })
- let diyGoodsList = Array.from(Array(diyJson.length), () => '');
- this.setData({
- diyJson, globalDiyData: global, diyGoodsList, diyLoaded: true
- })
- })
- },
- onShareAppMessage: function(res) {
- this.setData({ is_share_html: true });
- var community = wx.getStorageSync('community');
- var community_id = community.communityId;
- var member_id = wx.getStorageSync('member_id');
- console.log('首页分享地址:');
- console.log(community_id, member_id);
- return {
- title: this.data.shop_info.title,
- path: "lionfish_comshop/pages/index/index?community_id=" + community_id + '&share_id=' + member_id,
- imageUrl: this.data.shop_info.shop_index_share_image,
- success: function() {},
- fail: function() {}
- };
- },
- onShareTimeline: function(res) {
- var community = wx.getStorageSync('community');
- var community_id = community.communityId;
- var share_id = wx.getStorageSync('member_id');
- var query= `share_id=${share_id}&community_id=${community_id}`;
- return {
- title: this.data.shop_info.title,
- query,
- imageUrl: this.data.shop_info.shop_index_share_image,
- success: function() {},
- fail: function() {}
- };
- }
- })
|