index.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167
  1. var util = require('../../utils/util.js');
  2. var status = require('../../utils/index.js');
  3. var a = require("../../utils/public");
  4. var countDownInit = require("../../utils/countDown");
  5. var wcache = require('../../utils/wcache.js');
  6. var app = getApp();
  7. var timerOut = '';
  8. Page({
  9. mixins: [countDownInit.default, require('../../mixin/globalMixin.js'), require('../../mixin/compoentCartMixin.js')],
  10. data: {
  11. needAuth: false,
  12. stopClick: false,
  13. community: {},
  14. rushList: [],
  15. commingList: [],
  16. countDownMap: [],
  17. actEndMap: [],
  18. skuList: [],
  19. pageNum: 1,
  20. notice_list: [],
  21. slider_list: [],
  22. shop_info: {},
  23. showEmpty: false,
  24. indexBottomImage: '',
  25. classification: {
  26. tabs: [],
  27. activeIndex: -1
  28. },
  29. commingClassification: {
  30. tabs: [],
  31. activeIndex: -1
  32. },
  33. isShowCommingClassification: true,
  34. isShowClassification: true,
  35. showChangeCommunity: false,
  36. isTipShow: false,
  37. isShowGuide: false,
  38. index_lead_image: '',
  39. theme: 0,
  40. cartNum: 0,
  41. navigat: [],
  42. navigatSwiper: {page: 1, current:0, totnav: 0},
  43. tabIdx: 0,
  44. scrollDirect: "",
  45. isSticky: false,
  46. showCommingEmpty: false,
  47. stopNotify: true,
  48. reduction: {},
  49. is_share_html: true,
  50. commingNum: 0,
  51. couponRefresh: false,
  52. index_change_cate_btn: 0,
  53. newComerRefresh: false,
  54. showCouponModal: false,
  55. copy_text_arr: [],
  56. showCopyText: false,
  57. totalAlertMoney: 0,
  58. groupInfo: {
  59. group_name: '社区',
  60. owner_name: '团长'
  61. },
  62. needPosition: true,
  63. typeTopicList: [],
  64. pinList: {},
  65. cube: [],
  66. secRushList: [],
  67. secKillGoodsIndex: 1,
  68. isblack: 0,
  69. imageSize: {
  70. imageWidth: "100%",
  71. imageHeight: 600
  72. },
  73. fmShow: true,
  74. presale_index_info: '',
  75. isDiy: 0,
  76. diyManyGoodsList: []
  77. },
  78. isFirst: 0,
  79. $data: {
  80. stickyFlag: false,
  81. scrollTop: 0,
  82. overPageNum: 1,
  83. loadOver: false,
  84. hasOverGoods: false,
  85. countDownMap: {},
  86. actEndMap: {},
  87. timer: {},
  88. scrollHeight: 1300,
  89. stickyTop: 0,
  90. hasCommingGoods: true
  91. },
  92. tpage: 1,
  93. hasRefeshin: false,
  94. postion: {},
  95. options: '',
  96. focusFlag: false,
  97. /**
  98. * 监控滚动事件
  99. */
  100. onPageScroll: function (t) {
  101. if (!this.$data.isLoadData) {
  102. if (t.scrollTop < this.$data.scrollHeight) {
  103. if (t.scrollTop > this.$data.scrollTop) {
  104. "down" !== this.data.scrollDirect && this.setData({
  105. scrollDirect: "down"
  106. })
  107. } else {
  108. "up" != this.data.scrollDirect && this.setData({
  109. scrollDirect: "up"
  110. })
  111. }
  112. } else {
  113. "down" !== this.data.scrollDirect && this.setData({
  114. scrollDirect: "down"
  115. })
  116. }
  117. if (t.scrollTop > this.$data.stickyTop) {
  118. this.data.isSticky || (this.setData({
  119. isSticky: true
  120. }), this.$data.stickyFlag = true)
  121. } else {
  122. t.scrollTop < this.$data.stickyBackTop && this.data.isSticky && (this.setData({
  123. isSticky: false
  124. }), this.$data.stickyFlag = false)
  125. }
  126. this.$data.scrollTop = t.scrollTop
  127. }
  128. },
  129. onLoad: function(options) {
  130. app.setShareConfig();
  131. wx.hideTabBar();
  132. var that = this;
  133. var token = wx.getStorageSync('token');
  134. status.setNavBgColor();
  135. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  136. console.log('step1');
  137. let community = wx.getStorageSync('community');
  138. let community_id = community.communityId || '';
  139. let isparse_formdata = wx.getStorageSync('isparse_formdata') || 0;
  140. if (isparse_formdata != 1) {
  141. // this.get_index_info();
  142. if (options && Object.keys(options).length != 0) {
  143. console.log('step2');
  144. var scene = decodeURIComponent(options.scene);
  145. if (scene != 'undefined') {
  146. var opt_arr = scene.split("_");
  147. options.community_id = opt_arr[0];
  148. wcache.put('share_id', opt_arr[1]);
  149. }
  150. that.options = options;
  151. if (options.share_id != 'undefined' && options.share_id > 0) wcache.put('share_id', options.share_id);
  152. if (options.community_id != 'undefined' && options.community_id > 0) {
  153. console.log('step3');
  154. util.getCommunityById(options.community_id).then((res)=>{
  155. if (res.code == 0) {
  156. console.log('step4');
  157. var shareCommunity = res.data;
  158. console.log('分享community_id', options.community_id);
  159. console.log('历史community_id', community_id);
  160. let sdata = {};
  161. if (res.open_danhead_model == 1) {
  162. console.log('开启单社区', res.default_head_info);
  163. sdata.community = res.default_head_info;
  164. sdata.open_danhead_model = res.open_danhead_model;
  165. token && that.addhistory(res.default_head_info.communityId || '');
  166. wx.setStorageSync('community', res.default_head_info);
  167. } else if (shareCommunity){
  168. if (options.community_id != community_id) {
  169. if (community_id) {
  170. sdata.showChangeCommunity = true;
  171. sdata.changeCommunity = shareCommunity;
  172. sdata.community = community;
  173. } else {
  174. sdata.community = shareCommunity;
  175. sdata.shareCommunity = shareCommunity;
  176. wcache.put('community', shareCommunity);
  177. }
  178. } else {
  179. sdata.community = community;
  180. }
  181. }
  182. sdata.hidetip = false;
  183. sdata.token = token;
  184. sdata.showEmpty = false;
  185. sdata.needPosition = false;
  186. that.setData(sdata, ()=>{
  187. that.loadPage();
  188. });
  189. } else {
  190. console.log('step5');
  191. that.loadPage();
  192. that.setData({
  193. hidetip: false,
  194. token: token,
  195. showEmpty: false,
  196. needPosition: false
  197. })
  198. }
  199. token && that.addhistory();
  200. })
  201. } else {
  202. util.getCommunityById(options.community_id).then((res) => {
  203. if (res.code == 0) {
  204. if (res.open_danhead_model == 1) {
  205. console.log('开启单社区step6');
  206. that.setData({ community: res.default_head_info, open_danhead_model: res.open_danhead_model })
  207. token && that.addhistory(res.default_head_info.communityId || '');
  208. wx.setStorageSync('community', res.default_head_info);
  209. }
  210. console.log('step6');
  211. that.loadPage();
  212. }
  213. }).catch(() => {
  214. that.loadPage();
  215. })
  216. }
  217. } else {
  218. util.getCommunityById(options.community_id).then((res) => {
  219. if (res.code == 0) {
  220. if (res.open_danhead_model == 1) {
  221. console.log('开启单社区step7');
  222. that.setData({ community: res.default_head_info, open_danhead_model: res.open_danhead_model })
  223. token && that.addhistory(res.default_head_info.communityId || '');
  224. wx.setStorageSync('community', res.default_head_info);
  225. }
  226. that.loadPage();
  227. }
  228. }).catch(()=>{
  229. that.loadPage();
  230. })
  231. console.log('step7');
  232. that.setData({
  233. hidetip: false,
  234. token: token,
  235. showEmpty: false,
  236. community
  237. })
  238. }
  239. }
  240. },
  241. addhistory: function (id=0) {
  242. console.log('step13');
  243. let community_id = 0;
  244. if (id==0) {
  245. var community = wx.getStorageSync('community');
  246. community_id = community.communityId;
  247. } else {
  248. community_id = id;
  249. }
  250. console.log('history community_id=' + community_id);
  251. var token = wx.getStorageSync('token');
  252. let that = this;
  253. community_id !==void 0 && app.util.request({
  254. 'url': 'entry/wxapp/index',
  255. 'data': {
  256. controller: 'index.addhistory_community',
  257. community_id: community_id,
  258. 'token': token
  259. },
  260. dataType: 'json',
  261. success: function(res) {
  262. if(id!=0) that.getHistoryCommunity(), console.log('addhistory+id', id);
  263. }
  264. })
  265. },
  266. loadPage: function() {
  267. wx.showLoading();
  268. console.log('step8');
  269. let that = this;
  270. that.get_index_info();
  271. if(this.data.isDiy==0) {
  272. that.get_type_topic();
  273. that.getNavigat();
  274. that.getPinList();
  275. } else {
  276. this.getDiyInfo();
  277. }
  278. that.getCoupon();
  279. status.loadStatus().then(function() {
  280. let appLoadStatus = app.globalData.appLoadStatus;
  281. console.log('appLoadStatus',appLoadStatus)
  282. if (appLoadStatus == 0) {
  283. // wx.hideLoading();
  284. setTimeout(function(){ wx.hideLoading(); },1000);
  285. that.setData({ needAuth: true, couponRefresh: false });
  286. that.data.isDiy==0&&that.load_goods_data();
  287. } else if (appLoadStatus == 2) {
  288. console.log('step9');
  289. that.getHistoryCommunity();
  290. } else {
  291. console.log('step12');
  292. let community = wx.getStorageSync('community');
  293. community || (community=app.globalData.community);
  294. if (!community){
  295. util.getCommunityInfo().then((res) => {
  296. that.setData({
  297. community: that.fliterCommunity(res)
  298. })
  299. })
  300. } else {
  301. that.setData({
  302. community: that.fliterCommunity(community)
  303. })
  304. }
  305. console.log('step18');
  306. that.data.isDiy==0&&that.load_goods_data();
  307. }
  308. });
  309. },
  310. // 不显示社区省份
  311. fliterCommunity: function (community){
  312. let resArr = community && community.fullAddress && community.fullAddress.split('省');
  313. if (resArr) {
  314. return Object.assign({}, community, { address: resArr[1] || resArr[0] });
  315. } else {
  316. return community;
  317. }
  318. },
  319. onReady: function (res) {
  320. this.videoContext = wx.createVideoContext('myVideo');
  321. },
  322. onShow: function() {
  323. // 页面显示
  324. let that = this;
  325. console.log('isblack', app.globalData.isblack)
  326. this.setData({ stopNotify: false, tabbarRefresh: true, isblack: app.globalData.isblack || 0 })
  327. util.check_login_new().then((res) => {
  328. if(res) {
  329. that.setData({ needAuth: false })
  330. } else {
  331. this.setData({ needAuth: true, couponRefresh: false });
  332. return;
  333. }
  334. })
  335. app.globalData.timer.start();
  336. var token = wx.getStorageSync('token');
  337. token&&(0, status.cartNum)('', true).then((res)=>{
  338. res.code == 0 && that.setData({ cartNum: res.data })
  339. });
  340. if (app.globalData.changedCommunity) {
  341. console.log('change')
  342. app.globalData.goodsListCarCount = [];
  343. let community = app.globalData.community;
  344. this.setData({
  345. community: that.fliterCommunity(community),
  346. newComerRefresh: false
  347. });
  348. this.getCommunityPos(community.communityId);
  349. this.hasRefeshin = false;
  350. this.setData({
  351. newComerRefresh: true,
  352. rushList: [],
  353. pageNum: 1,
  354. classificationId: null,
  355. "classification.activeIndex": -1
  356. }, () => {
  357. this.setData({
  358. "classification.activeIndex": 0
  359. })
  360. })
  361. this.$data = {
  362. ...this.$data, ...{
  363. overPageNum: 1,
  364. loadOver: false,
  365. hasOverGoods: false,
  366. countDownMap: {},
  367. actEndMap: {},
  368. timer: {},
  369. stickyFlag: false,
  370. hasCommingGoods: true
  371. }
  372. }
  373. app.globalData.changedCommunity = false, this.get_index_info(), this.addhistory();
  374. this.load_goods_data(), this.get_type_topic(),this.getPinList();
  375. } else {
  376. console.log('nochange')
  377. if (that.isFirst>=1){
  378. this.setData({ loadOver: true })
  379. this.changeRushListNum();
  380. }
  381. }
  382. if (that.isFirst==0) {
  383. this.setData({ couponRefresh: true });
  384. } else {
  385. this.getCoupon();
  386. let cid = app.globalData.indexCateId || '';
  387. cid && this.goIndexType(cid);
  388. app.globalData.indexCateId = '';
  389. }
  390. that.isFirst++;
  391. },
  392. /**
  393. * 动态变化列表购物车数量
  394. */
  395. changeRushListNum: function(){
  396. let that = this;
  397. let goodsListCarCount = app.globalData.goodsListCarCount;
  398. let rushList = this.data.rushList;
  399. let changeCarCount = false;
  400. this.setData({ changeCarCount })
  401. if (goodsListCarCount.length > 0 && rushList.length > 0) {
  402. goodsListCarCount.forEach(function (item) {
  403. let k = that.arrayHasElement(rushList, item.actId);
  404. if (k[0] != -1 && rushList[k[0]][k[1]].skuList.length === 0) {
  405. let newNum = item.num * 1;
  406. rushList[k[0]][k[1]].car_count = newNum >= 0 ? newNum : 0;
  407. changeCarCount = true;
  408. }
  409. })
  410. // goodsListCarCount.forEach(function (item) {
  411. // let k = rushList.findIndex((n) => n.actId == item.actId);
  412. // if (k != -1 && rushList[k].skuList.length === 0) {
  413. // let newNum = item.num * 1;
  414. // rushList[k].car_count = newNum >= 0 ? newNum : 0;
  415. // changeCarCount = true;
  416. // }
  417. // })
  418. this.setData({ rushList, changeCarCount })
  419. }
  420. },
  421. arrayHasElement: function(array, element) {
  422. let el=array;
  423. for(let number in el){
  424. if (el[number].length > 0) {
  425. for (var index in el[number]) {
  426. if (el[number][index].actId == element) {
  427. return [number, index]
  428. }
  429. }
  430. }
  431. }
  432. return [-1, -1];
  433. },
  434. changeNotListCartNum: function (t) {
  435. let that = this;
  436. let e = t.detail;
  437. (0, status.cartNum)(that.setData({ cartNum: e }));
  438. this.changeRushListNum();
  439. },
  440. onHide: function() {
  441. this.setData({ stopNotify: true, tabbarRefresh: false, changeCarCount: false })
  442. console.log('详情页', this.data.stopNotify)
  443. app.globalData.timer.stop();
  444. console.log('onHide')
  445. },
  446. /**
  447. * 授权成功回调
  448. */
  449. authSuccess: function() {
  450. console.log('authSuccess');
  451. let that = this;
  452. this.tpage = 1;
  453. this.hasRefeshin = false;
  454. this.setData({
  455. rushList: [],
  456. pageNum: 1,
  457. needAuth: false,
  458. newComerRefresh: false,
  459. couponRefresh: true,
  460. isblack: app.globalData.isblack || 0,
  461. diyLoaded: false
  462. })
  463. this.$data = {
  464. ...this.$data, ...{
  465. overPageNum: 1,
  466. loadOver: false,
  467. hasOverGoods: false,
  468. countDownMap: {},
  469. actEndMap: {},
  470. timer: {},
  471. hasCommingGoods: true
  472. }
  473. }
  474. status.getInNum().then((isCan) => {
  475. if (isCan) {
  476. that.setData({ isTipShow: true })
  477. timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 7000);
  478. }
  479. })
  480. this.loadPage();
  481. this.data.isTipShow && (timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 7000));
  482. },
  483. authModal: function (e = {}) {
  484. let needAuth = (e && e.detail) || this.data.needAuth;
  485. if (this.data.needAuth || e.detail) {
  486. this.setData({
  487. showAuthModal: !this.data.showAuthModal,
  488. needAuth
  489. });
  490. return false;
  491. }
  492. return true;
  493. },
  494. //获取历史社区
  495. getHistoryCommunity: function () {
  496. let that = this;
  497. var token = wx.getStorageSync('token');
  498. app.util.request({
  499. 'url': 'entry/wxapp/index',
  500. 'data': {
  501. controller: 'index.load_history_community',
  502. token: token
  503. },
  504. dataType: 'json',
  505. success: function (res) {
  506. console.log('step14');
  507. if (res.data.code == 0) {
  508. console.log('getHistoryCommunity');
  509. let history_communities = res.data.list;
  510. let isNotHistory = false;
  511. if (Object.keys(history_communities).length == 0 || history_communities.communityId == 0) isNotHistory = true;
  512. let resArr = history_communities && history_communities.fullAddress && history_communities.fullAddress.split('省');
  513. history_communities = Object.assign({}, history_communities, { address: resArr[1] })
  514. that.setData({
  515. community: history_communities
  516. })
  517. wcache.put('community', history_communities);
  518. app.globalData.community = history_communities;
  519. if (token && !isNotHistory) {
  520. let lastCommunity = wx.getStorageSync('lastCommunity');
  521. let lastCommunityId = lastCommunity.communityId || '';
  522. if (lastCommunityId != '' && lastCommunityId != history_communities.communityId) {
  523. that.setData({
  524. showChangeCommunity: true,
  525. changeCommunity: lastCommunity
  526. }, ()=> {
  527. wx.removeStorageSync('lastCommunity');
  528. })
  529. }
  530. }
  531. that.setData({
  532. community: app.globalData.community
  533. })
  534. that.load_goods_data();
  535. } else {
  536. let options = that.options;
  537. if (options !== void 0 && options.community_id) {
  538. console.log('新人加入分享进来的社区id:', that.options);
  539. that.addhistory(options.community_id);
  540. } else if (res.data.code == 1) {
  541. console.log('获取历史社区');
  542. wx.redirectTo({
  543. url: "/lionfish_comshop/pages/position/community"
  544. })
  545. } else {
  546. that.setData({ needAuth: true })
  547. }
  548. }
  549. }
  550. })
  551. },
  552. getScrollHeight: function () {
  553. wx.createSelectorQuery().select('.rush-list-box').boundingClientRect((rect) => {
  554. rect && rect.height && (this.$data.scrollHeight = rect.height || 1300);
  555. console.log(this.$data.scrollHeight)
  556. }).exec()
  557. },
  558. /**
  559. * 引导页切换
  560. */
  561. handleProxy: function(){
  562. clearTimeout(timerOut);
  563. this.setData({
  564. isTipShow: false,
  565. isShowGuide: true
  566. })
  567. wcache.put('inNum', 4);
  568. },
  569. handleHideProxy: function(){
  570. this.setData({
  571. isTipShow: false,
  572. isShowGuide: false
  573. })
  574. },
  575. /**
  576. * 获取首页信息
  577. */
  578. get_index_info: function() {
  579. let that = this;
  580. let community = wx.getStorageSync('community');
  581. let communityId = community && community.communityId || '';
  582. let token = wx.getStorageSync('token');
  583. app.util.request({
  584. url: 'entry/wxapp/index',
  585. data: {
  586. controller: 'index.index_info',
  587. communityId,
  588. token
  589. },
  590. dataType: 'json',
  591. success: function(res) {
  592. let rdata = res.data;
  593. let groupInfo = that.data.groupInfo;
  594. if (rdata.code == 0) {
  595. if (!res.data.is_community && communityId && !that.data.needAuth) {
  596. let changeCommunity = that.data.changeCommunity || {};
  597. let changeCommunityId = changeCommunity.communityId || '';
  598. if (changeCommunityId) {
  599. wcache.put('community', changeCommunity);
  600. that.addhistory(changeCommunity.community_id);
  601. that.setData({
  602. community: changeCommunity,
  603. showChangeCommunity: false
  604. })
  605. that.loadPage();
  606. } else {
  607. wx.showModal({
  608. title: '提示',
  609. content: `该${groupInfo.group_name}不在,请重新选择${groupInfo.group_name}`,
  610. showCancel: false,
  611. confirmColor: '#F75451',
  612. success(res) {
  613. if (res.confirm) {
  614. wx.redirectTo({
  615. url: '/lionfish_comshop/pages/position/community',
  616. })
  617. }
  618. }
  619. })
  620. }
  621. }
  622. let notice_list = rdata.notice_list;
  623. let slider_list = rdata.slider_list;
  624. let index_lead_image = rdata.index_lead_image;
  625. if(index_lead_image){
  626. status.getInNum().then((isCan)=>{
  627. if (isCan) {
  628. that.setData({ isTipShow: true },()=>{
  629. timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 9000);
  630. })
  631. }
  632. })
  633. } else {
  634. that.setData({ isTipShow: false })
  635. }
  636. let common_header_backgroundimage = rdata.common_header_backgroundimage;
  637. app.globalData.common_header_backgroundimage = common_header_backgroundimage;
  638. let order_notify_switch = rdata.order_notify_switch;
  639. let index_list_top_image_on = rdata.index_list_top_image_on;
  640. let index_change_cate_btn = rdata.index_change_cate_btn || 0;
  641. let default_img = '../../images/rush-title.png';
  642. // if (index_list_top_image_on == 1) default_img='';
  643. let index_list_top_image = rdata.index_list_top_image ? rdata.index_list_top_image : default_img;
  644. let shop_info = {
  645. shoname: rdata.shoname,
  646. shop_index_share_image: rdata.shop_index_share_image,
  647. index_list_top_image: index_list_top_image,
  648. title: rdata.title,
  649. common_header_backgroundimage,
  650. order_notify_switch,
  651. index_top_img_bg_open: rdata.index_top_img_bg_open || 0,
  652. index_top_font_color: rdata.index_top_font_color || '#fff',
  653. index_communityinfo_showtype: rdata.index_communityinfo_showtype || 0,
  654. index_list_top_image_on
  655. }
  656. app.globalData.placeholdeImg = rdata.index_loading_image || '';
  657. let placeholdeImg = rdata.index_loading_image || '';
  658. wcache.put('shopname', rdata.shoname);
  659. wx.setNavigationBarTitle({ title: rdata.shoname });
  660. let category_list = rdata.category_list || [];
  661. let index_type_first_name = rdata.index_type_first_name || '全部';
  662. if (category_list.length > 0) {
  663. category_list.unshift({
  664. name: index_type_first_name,
  665. id: 0
  666. })
  667. that.setData({
  668. isShowClassification: true,
  669. "classification.tabs": category_list
  670. })
  671. } else {
  672. that.setData({
  673. isShowClassification: false
  674. })
  675. }
  676. let theme = rdata.theme || 0;
  677. let rushEndTime = rdata.rushtime*1000 || 0;
  678. let isShowShareBtn = rdata.index_share_switch || 0;
  679. let isShowListCount = rdata.is_show_list_count || 0;
  680. let isShowListTimer = rdata.is_show_list_timer || 0;
  681. let isShowContactBtn = rdata.index_service_switch || 0;
  682. let index_switch_search = rdata.index_switch_search || 0;
  683. let ishow_index_gotop = rdata.ishow_index_gotop || 0;
  684. if (rdata.is_comunity_rest == 1 && !that.data.needAuth) {
  685. wx.showModal({
  686. title: '温馨提示',
  687. content: `${groupInfo.owner_name}休息中,欢迎下次光临!`,
  688. showCancel: false,
  689. confirmColor: '#F75451',
  690. confirmText: '好的',
  691. success(res) { }
  692. })
  693. }
  694. that.postion = rdata.postion;
  695. //秒杀
  696. 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;
  697. let myDate = new Date();
  698. let curHour = myDate.getHours(); // 当前时间
  699. console.log('当前时间:', curHour);
  700. let curSeckillIdx = 0; //当前时间索引
  701. let scekillTimeArr = []; //显示的时间段
  702. if (scekill_time_arr.length > 3) {
  703. let timeLen = scekill_time_arr.length;
  704. curSeckillIdx = scekill_time_arr.findIndex(item => {
  705. return item >= curHour;
  706. });
  707. console.log('当前时间索引:', curSeckillIdx)
  708. //取三个时间段
  709. if (curSeckillIdx === -1) {
  710. //没有进行或者未开始 取最后三个
  711. scekillTimeArr = scekill_time_arr.slice(-3);
  712. } else if (curSeckillIdx === 0) {
  713. //全部未开始 取最前三个
  714. scekillTimeArr = scekill_time_arr.slice(0, 3);
  715. } else if ((curSeckillIdx + 1) == timeLen) {
  716. //剩最后一个 取最后三个
  717. scekillTimeArr = scekill_time_arr.slice(-3);
  718. } else {
  719. scekillTimeArr = scekill_time_arr.slice(curSeckillIdx - 1, curSeckillIdx + 2);
  720. }
  721. } else {
  722. scekillTimeArr = scekill_time_arr;
  723. }
  724. //判断各个时段状态
  725. let scekillTimeList = [];
  726. let secKillActiveIdx = 0;
  727. if(scekillTimeArr.length){
  728. scekillTimeArr.forEach((item, idx) => {
  729. let secObj = {};
  730. //state: 0已开抢 1疯抢中 2即将开抢
  731. if (item == curHour) {
  732. secObj.state = 1;
  733. secObj.desc = '疯抢中';
  734. secKillActiveIdx = idx;
  735. } else if (item < curHour) {
  736. secObj.state = 0;
  737. secObj.desc = '已开抢';
  738. } else {
  739. secObj.state = 2;
  740. secObj.desc = '即将开抢';
  741. }
  742. secObj.timeStr = (item < 10 ? '0' + item : item) + ':00';
  743. secObj.timeArr = [item < 10 ? '0' + item : item, '00'];
  744. secObj.seckillTime = item;
  745. scekillTimeList.push(secObj);
  746. })
  747. //获取当前秒杀商品
  748. that.getSecKillGoods(scekillTimeArr[secKillActiveIdx]);
  749. }
  750. let index_video_arr = rdata.index_video_arr;
  751. // 预售信息
  752. let presale_index_info = rdata.presale_index_info || '';
  753. if(presale_index_info&&presale_index_info.goods_list) {
  754. let goods_list = presale_index_info.goods_list;
  755. let nowtime = Date.parse(new Date())/1000;
  756. goods_list.forEach((item, idx)=>{
  757. let { presale_ding_money, actPrice, presale_deduction_money, presale_type, presale_ding_time_start_int, presale_ding_time_end_int } = item;
  758. if(presale_type==0) {
  759. presale_deduction_money = presale_deduction_money>0?presale_deduction_money:presale_ding_money;
  760. let goodsPrice = (actPrice[0]+'.'+actPrice[1])*1;
  761. presale_index_info.goods_list[idx].weikuan = (goodsPrice - presale_deduction_money*1).toFixed(2);
  762. presale_ding_money = presale_ding_money.toFixed(2);
  763. presale_index_info.goods_list[idx].dingArr = (presale_ding_money+'').split('.');
  764. presale_index_info.goods_list[idx].presale_deduction_money = presale_deduction_money;
  765. }
  766. let saleStatus = 1; //客付定金 0未开始 2已结束
  767. if(nowtime<presale_ding_time_start_int) {
  768. saleStatus = 0;
  769. } else if(nowtime>presale_ding_time_end_int) {
  770. saleStatus = 2;
  771. }
  772. presale_index_info.goods_list[idx].saleStatus = saleStatus;
  773. })
  774. }
  775. let isDiy = rdata.open_diy_index_page || 0;
  776. wx.setStorageSync('is_diy', isDiy);
  777. (isDiy==1)&&that.getDiyInfo();
  778. // 礼品卡
  779. let virtualcard_info = rdata.virtualcard_info || '';
  780. if(virtualcard_info&&virtualcard_info.goods_list) {
  781. var timestamp = Date.parse(new Date())/1000;
  782. let newList = [];
  783. if(Object.keys(virtualcard_info.goods_list).length) {
  784. virtualcard_info.goods_list.forEach(item=>{
  785. (item.end_time<timestamp)&&(item.actEnd = 1);
  786. newList.push(item);
  787. })
  788. }
  789. virtualcard_info.goods_list = newList;
  790. }
  791. that.setData({
  792. notice_list,
  793. slider_list,
  794. index_lead_image,
  795. theme,
  796. indexBottomImage: rdata.index_bottom_image || '',
  797. shop_info: shop_info,
  798. loadOver: true,
  799. rushEndTime,
  800. commingNum: rdata.comming_goods_total,
  801. isShowShareBtn,
  802. isShowListCount,
  803. isShowListTimer,
  804. is_comunity_rest: rdata.is_comunity_rest,
  805. index_change_cate_btn,
  806. isShowContactBtn,
  807. index_switch_search,
  808. is_show_new_buy: rdata.is_show_new_buy || 0,
  809. qgtab: res.data.qgtab || {},
  810. notice_setting: rdata.notice_setting || {},
  811. index_hide_headdetail_address: rdata.index_hide_headdetail_address || 0,
  812. is_show_spike_buy: rdata.is_show_spike_buy || 0,
  813. hide_community_change_btn: rdata.hide_community_change_btn || 0,
  814. hide_top_community: rdata.hide_top_community || 0,
  815. index_qgtab_text: rdata.index_qgtab_text,
  816. ishow_index_copy_text: rdata.ishow_index_copy_text || 0,
  817. newComerRefresh: true,
  818. cube: rdata.cube,
  819. placeholdeImg,
  820. seckill_bg_color,
  821. seckill_is_open,
  822. seckill_is_show_index,
  823. scekillTimeList,
  824. secKillActiveIdx,
  825. hide_community_change_word,
  826. ishow_index_gotop,
  827. ishow_index_pickup_time: rdata.ishow_index_pickup_time || 0,
  828. index_video_arr,
  829. index_qgtab_counttime,
  830. hide_index_type,
  831. show_index_wechat_oa: rdata.show_index_wechat_oa,
  832. ishide_index_goodslist: rdata.ishide_index_goodslist,
  833. can_index_notice_alert: rdata.can_index_notice_alert,
  834. presale_index_info,
  835. isDiy,
  836. virtualcard_info
  837. })
  838. }
  839. }
  840. })
  841. },
  842. /**
  843. * 确认切换社区
  844. */
  845. confrimChangeCommunity: function() {
  846. let community = this.data.changeCommunity;
  847. app.globalData.community = community;
  848. wcache.put('community', community);
  849. this.$data = {
  850. ...this.$data, ...{
  851. overPageNum: 1,
  852. loadOver: false,
  853. hasOverGoods: false,
  854. countDownMap: {},
  855. actEndMap: {},
  856. timer: {},
  857. stickyFlag: false
  858. }
  859. }
  860. this.hasRefeshin = false;
  861. this.setData({
  862. showChangeCommunity: false,
  863. community: community,
  864. rushList: [],
  865. pageNum: 1
  866. }, () => {
  867. this.loadPage();
  868. this.addhistory();
  869. })
  870. },
  871. /**
  872. * 关闭切换社区
  873. */
  874. closeChangeCommunity: function(){
  875. this.setData({
  876. showChangeCommunity: false
  877. })
  878. },
  879. /**
  880. * 获取商品列表
  881. */
  882. load_goods_data: function() {
  883. var token = wx.getStorageSync('token');
  884. var that = this;
  885. var cur_community = wx.getStorageSync('community');
  886. var gid = that.data.classificationId;
  887. this.$data.isLoadData = true;
  888. console.log('load_goods_begin ');
  889. if (!that.hasRefeshin && !that.$data.loadOver) {
  890. console.log('load_goods_in ');
  891. this.hasRefeshin = true;
  892. that.setData({
  893. loadMore: true
  894. });
  895. app.util.request({
  896. 'url': 'entry/wxapp/index',
  897. 'data': {
  898. controller: 'index.load_gps_goodslist',
  899. token: token,
  900. pageNum: that.data.pageNum,
  901. head_id: cur_community.communityId,
  902. gid,
  903. per_page: 12
  904. },
  905. dataType: 'json',
  906. success: function(res) {
  907. if (that.data.pageNum == 1) {
  908. that.setData({ cate_info: res.data.cate_info || {} })
  909. }
  910. if (res.data.code == 0) {
  911. let rushList = [];
  912. if (res.data.is_show_list_timer==1) {
  913. rushList = that.transTime(res.data.list);
  914. for (let s in that.$data.countDownMap) that.initCountDown(that.$data.countDownMap[s]);
  915. } else {
  916. rushList = that.data.rushList;
  917. rushList[that.data.pageNum-1] = res.data.list;
  918. }
  919. let rdata = res.data;
  920. let { full_money, full_reducemoney, is_open_fullreduction, is_open_vipcard_buy, is_vip_card_member, is_member_level_buy } = rdata;
  921. let reduction = { full_money, full_reducemoney, is_open_fullreduction }
  922. // 是否可以会员折扣购买
  923. let canLevelBuy = false;
  924. if (is_open_vipcard_buy == 1) {
  925. if (is_vip_card_member != 1 && is_member_level_buy == 1) canLevelBuy = true;
  926. } else {
  927. (is_member_level_buy == 1) && (canLevelBuy = true);
  928. }
  929. if (that.data.pageNum==1) that.setData({ copy_text_arr: rdata.copy_text_arr || [] })
  930. that.hasRefeshin = false;
  931. that.setData({
  932. rushList: rushList,
  933. pageNum: that.data.pageNum + 1,
  934. loadMore: false,
  935. reduction,
  936. tip: '',
  937. is_open_vipcard_buy: is_open_vipcard_buy || 0,
  938. is_vip_card_member,
  939. is_member_level_buy,
  940. canLevelBuy
  941. }, ()=>{
  942. if (that.isFirst == 1) {
  943. that.isFirst++;
  944. }
  945. if (rushList.length && !that.$data.stickyTop) {
  946. wx.createSelectorQuery().select(".tab-nav-query").boundingClientRect(function (t) {
  947. if (t && t.top){
  948. wcache.put('tabPos', t);
  949. that.$data.stickyTop = t.top + t.height, that.$data.stickyBackTop = t.top;
  950. } else {
  951. let tabpos = wcache.get('tabPos', false);
  952. if (tabpos) that.$data.stickyTop = tabpos.top + tabpos.height, that.$data.stickyBackTop = tabpos.top;
  953. }
  954. }).exec();
  955. that.$data.scrollTop > that.$data.stickyTop && wx.pageScrollTo({
  956. duration: 0,
  957. scrollTop: that.$data.stickyTop + 4
  958. });
  959. }
  960. that.getScrollHeight();
  961. if (that.data.pageNum == 2 && res.data.list.length < 10) {
  962. console.log('load_over_goods_list_begin')
  963. that.$data.loadOver = true;
  964. that.hasRefeshin = true;
  965. that.setData({
  966. loadMore: true
  967. }, () => {
  968. that.load_over_gps_goodslist();
  969. });
  970. }
  971. });
  972. } else if (res.data.code == 1) {
  973. that.$data.loadOver = true;
  974. that.load_over_gps_goodslist();
  975. } else if (res.data.code == 2) {
  976. //no login
  977. that.setData({ needAuth: true, couponRefresh: false })
  978. }
  979. },
  980. complete: function() {
  981. that.$data.isLoadData = false;
  982. // wx.hideLoading();
  983. setTimeout(function(){ wx.hideLoading(); },1000);
  984. }
  985. })
  986. } else {
  987. that.load_over_gps_goodslist();
  988. }
  989. },
  990. /**
  991. * 组合倒计时时间
  992. */
  993. transTime: function(list) {
  994. let that = this;
  995. let e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
  996. e === 0 && list.map(function(t) {
  997. t.end_time *= 1000;
  998. that.$data.countDownMap[t.end_time] = t.end_time, that.$data.actEndMap[t.end_time] = t.end_time <= new Date().getTime() || t.spuCanBuyNum == 0;
  999. })
  1000. let rushList = that.data.rushList;
  1001. let idx = that.data.pageNum+that.$data.overPageNum-2;
  1002. rushList[idx] = list;
  1003. return rushList;
  1004. // return that.data.rushList.concat(list);
  1005. },
  1006. /**
  1007. * 获取售罄商品
  1008. */
  1009. load_over_gps_goodslist: function() {
  1010. var token = wx.getStorageSync('token');
  1011. var that = this;
  1012. var cur_community = wx.getStorageSync('community');
  1013. var gid = that.data.classificationId;
  1014. if (!that.$data.hasOverGoods && that.$data.loadOver) {
  1015. that.$data.hasOverGoods = true;
  1016. that.setData({
  1017. loadMore: true
  1018. });
  1019. app.util.request({
  1020. 'url': 'entry/wxapp/index',
  1021. 'data': {
  1022. controller: 'index.load_over_gps_goodslist',
  1023. token: token,
  1024. pageNum: that.$data.overPageNum,
  1025. head_id: cur_community.communityId,
  1026. gid,
  1027. is_index_show: 1
  1028. },
  1029. dataType: 'json',
  1030. success: function(res) {
  1031. if (res.data.code == 0) {
  1032. let rushList = that.transTime(res.data.list);
  1033. for (let s in that.$data.countDownMap) that.initCountDown(that.$data.countDownMap[s]);
  1034. that.$data.hasOverGoods = false;
  1035. that.$data.overPageNum += 1;
  1036. that.setData({
  1037. rushList: rushList,
  1038. loadMore: false,
  1039. tip: ''
  1040. }, ()=>{
  1041. if (that.isFirst == 1) {
  1042. that.isFirst++;
  1043. if (rushList.length && !that.$data.stickyTop) {
  1044. wx.createSelectorQuery().select(".tab-nav-query").boundingClientRect(function (t) {
  1045. if (t && t.top) {
  1046. wcache.put('tabPos', t);
  1047. that.$data.stickyTop = t.top + t.height, that.$data.stickyBackTop = t.top;
  1048. } else {
  1049. let tabpos = wcache.get('tabPos', false);
  1050. if (tabpos) that.$data.stickyTop = tabpos.top + tabpos.height, that.$data.stickyBackTop = tabpos.top;
  1051. }
  1052. }).exec();
  1053. that.$data.scrollTop > that.$data.stickyTop && wx.pageScrollTo({
  1054. duration: 0,
  1055. scrollTop: that.$data.stickyTop + 4
  1056. });
  1057. }
  1058. that.getScrollHeight();
  1059. }
  1060. });
  1061. } else if (res.data.code == 1) {
  1062. if (that.$data.overPageNum == 1 && that.data.rushList.length == 0) that.setData({
  1063. showEmpty: true
  1064. })
  1065. that.setData({
  1066. loadMore: false,
  1067. tip: '^_^已经到底了'
  1068. })
  1069. } else if (res.data.code == 2) {
  1070. that.setData({ needAuth: true, couponRefresh: false })
  1071. }
  1072. that.$data.isLoadData = false;
  1073. }
  1074. })
  1075. } else {
  1076. that.$data.isLoadData = false;
  1077. }
  1078. },
  1079. /**
  1080. * 监控分类导航
  1081. */
  1082. classificationChange: function(t, autoScroll=0) {
  1083. console.log(t.detail.e)
  1084. wx.showLoading();
  1085. var that = this;
  1086. this.$data = {...this.$data, ...{
  1087. overPageNum: 1,
  1088. loadOver: false,
  1089. hasOverGoods: false,
  1090. countDownMap: {},
  1091. actEndMap: {},
  1092. timer: {}
  1093. }
  1094. }, this.hasRefeshin = false, this.setData({
  1095. rushList: [],
  1096. showEmpty: false,
  1097. pageNum: 1,
  1098. "classification.activeIndex": t.detail.e,
  1099. classificationId: t.detail.a
  1100. }, function() {
  1101. if ((this.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop+5)) || autoScroll){
  1102. console.log('滚动了')
  1103. let windowWidth = app.globalData.systemInfo && app.globalData.systemInfo.windowWidth || 375;
  1104. let taBH = windowWidth/750*72;
  1105. wx.pageScrollTo({ scrollTop: that.$data.stickyTop - taBH, duration: 0 })
  1106. }
  1107. that.load_goods_data();
  1108. });
  1109. },
  1110. /**
  1111. * 监控即将抢购分类导航
  1112. */
  1113. commingClassificationChange: function (t) {
  1114. wx.showLoading();
  1115. var that = this;
  1116. that.tpage = 1;
  1117. this.$data = {...this.$data, ...{hasCommingGoods: true} },
  1118. this.setData({
  1119. showCommingEmpty: false,
  1120. commingList: [],
  1121. "commingClassification.activeIndex": t.detail.e,
  1122. commingClassificationId: t.detail.a
  1123. }, function () {
  1124. if (this.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop + 5)) {
  1125. wx.pageScrollTo({ scrollTop: that.$data.stickyTop + 5, duration: 0 })
  1126. }
  1127. that.getCommingList();
  1128. });
  1129. },
  1130. // 抢购切换
  1131. tabSwitch: function (t) {
  1132. var that = this;
  1133. var tabIdx = 1 * t.currentTarget.dataset.idx;
  1134. this.setData({ tabIdx: tabIdx }, ()=>{
  1135. if (tabIdx == 1) {
  1136. if (that.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop + 5)) {
  1137. wx.pageScrollTo({ scrollTop: that.$data.stickyTop + 5, duration: 0 })
  1138. }
  1139. if (that.tpage == 1) {
  1140. that.getCommingList();
  1141. }
  1142. }
  1143. })
  1144. },
  1145. /**
  1146. * 即将开抢列表
  1147. */
  1148. getCommingList: function(){
  1149. this.data.commigLoadMore && wx.showLoading();
  1150. var token = wx.getStorageSync('token');
  1151. var that = this;
  1152. var cur_community = wx.getStorageSync('community');
  1153. var gid = this.data.commingClassificationId || 0;
  1154. that.$data.isLoadData = true;
  1155. if (that.$data.hasCommingGoods) {
  1156. that.$data.hasCommingGoods = false;
  1157. that.setData({ commigLoadMore: true });
  1158. app.util.request({
  1159. url: 'entry/wxapp/index',
  1160. data: {
  1161. controller: 'index.load_comming_goodslist',
  1162. token: token,
  1163. pageNum: that.tpage,
  1164. head_id: cur_community.communityId,
  1165. gid
  1166. },
  1167. dataType: 'json',
  1168. success: function (res) {
  1169. wx.hideLoading();
  1170. if (res.data.code == 0) {
  1171. let commingList = res.data.list;
  1172. commingList = that.data.commingList.concat(commingList);
  1173. that.$data.hasCommingGoods = true;
  1174. that.tpage += 1;
  1175. that.setData({
  1176. commingList: commingList,
  1177. commigLoadMore: false,
  1178. commigTip: ''
  1179. },()=>{
  1180. that.getScrollHeight();
  1181. });
  1182. } else if (res.data.code == 1) {
  1183. if (that.tpage == 1 && that.data.commingList.length == 0) that.setData({
  1184. showCommingEmpty: true
  1185. })
  1186. that.setData({
  1187. commigLoadMore: false,
  1188. commigTip: '^_^已经到底了'
  1189. })
  1190. } else if (res.data.code == 2) {
  1191. that.setData({ needAuth: true, couponRefresh: false })
  1192. }
  1193. that.$data.isLoadData = false;
  1194. }
  1195. })
  1196. } else{
  1197. that.$data.isLoadData = false;
  1198. !that.data.commigLoadMore && wx.hideLoading();
  1199. }
  1200. },
  1201. /**
  1202. * 返回顶部
  1203. */
  1204. backTop: function() {
  1205. this.stickyFlag = false, wx.pageScrollTo({
  1206. scrollTop: 0,
  1207. duration: 500
  1208. });
  1209. },
  1210. goLink: function(event) {
  1211. let url = event.currentTarget.dataset.link;
  1212. let needauth = event.currentTarget.dataset.needauth || '';
  1213. console.log(needauth)
  1214. if(needauth){ if (!this.authModal()) return; }
  1215. url && wx.navigateTo({ url })
  1216. },
  1217. /**
  1218. * 导航小图标
  1219. */
  1220. getNavigat: function(){
  1221. let that = this;
  1222. app.util.request({
  1223. 'url': 'entry/wxapp/index',
  1224. 'data': {
  1225. controller: 'index.get_navigat'
  1226. },
  1227. dataType: 'json',
  1228. success: function (res) {
  1229. if (res.data.code == 0) {
  1230. let navigat = res.data.data || [];
  1231. let navigatEmpty = [];
  1232. let navigatSwiper = {page: 1, current:0, totnav: 0};
  1233. let chunks = [];
  1234. if (navigat.length>0) {
  1235. let len = (5-navigat.length%5) || 0;
  1236. if(len<5&&len>0) navigatEmpty = new Array(len);
  1237. for(let i=0;i<navigat.length;i=i+10){
  1238. chunks.push(navigat.slice(i,i+10));
  1239. }
  1240. navigatSwiper.page = chunks.length;
  1241. navigatSwiper.totnav = navigat.length;
  1242. }
  1243. that.setData({ navigat: chunks, navigatEmpty, navigatSwiper })
  1244. }
  1245. }
  1246. })
  1247. },
  1248. navigatSwiperChange: function(t) {
  1249. this.setData({
  1250. "navigatSwiper.current": t.detail.current
  1251. });
  1252. },
  1253. /**
  1254. * 导航图标跳转
  1255. */
  1256. goNavUrl: function(t) {
  1257. let idx = t.currentTarget.dataset.idx;
  1258. console.log(idx)
  1259. let { navigat, needAuth, navigatSwiper } = this.data;
  1260. let sidx = navigatSwiper.current;
  1261. navigat = navigat[sidx];
  1262. if (navigat.length > 0) {
  1263. let url = navigat[idx].link;
  1264. let type = navigat[idx].type;
  1265. if(util.checkRedirectTo(url, needAuth)){
  1266. this.authModal();
  1267. return;
  1268. }
  1269. if (type== 0){
  1270. // 跳转webview
  1271. wx.navigateTo({
  1272. url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url),
  1273. })
  1274. } else if (type==1) {
  1275. 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) {
  1276. wx.switchTab({ url: url })
  1277. } else {
  1278. wx.navigateTo({ url: url })
  1279. }
  1280. } else if (type==2){
  1281. // 跳转小程序
  1282. let appid = navigat[idx].appid;
  1283. appid && wx.navigateToMiniProgram({
  1284. appId: navigat[idx].appid,
  1285. path: url,
  1286. extraData: {},
  1287. envVersion: 'release',
  1288. success(res) {
  1289. // 打开成功
  1290. },
  1291. fail(error) {
  1292. console.log(error)
  1293. }
  1294. })
  1295. } else if (type == 3){
  1296. //首页分类
  1297. // t.detail.e 选中索引
  1298. // t.detail.a 选中id
  1299. let classification = this.data.classification;
  1300. let tabs = classification && classification.tabs;
  1301. let cid = url;
  1302. let activeIdx = tabs.findIndex((p) => { return p.id == cid });
  1303. if (activeIdx!=-1) {
  1304. let cateInfo = {
  1305. detail: { e: activeIdx, a: cid }
  1306. };
  1307. this.classificationChange(cateInfo, 1);
  1308. } else {
  1309. wx.showToast({
  1310. title: '分类不存在或已关闭',
  1311. icon: 'none'
  1312. })
  1313. }
  1314. } else if (type == 4) {
  1315. //独立分类
  1316. app.globalData.typeCateId = url;
  1317. wx.switchTab({
  1318. url: '/lionfish_comshop/pages/type/index'
  1319. })
  1320. } else if (type == 6) {
  1321. //领券
  1322. let url = navigat[idx].link;
  1323. wx.navigateTo({
  1324. url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
  1325. })
  1326. }
  1327. }
  1328. },
  1329. /**
  1330. * 幻灯片跳转
  1331. */
  1332. goBannerUrl: function (t) {
  1333. let idx = t.currentTarget.dataset.idx;
  1334. let { slider_list, needAuth } = this.data;
  1335. if (slider_list.length > 0) {
  1336. let url = slider_list[idx].link;
  1337. let type = slider_list[idx].linktype;
  1338. if (util.checkRedirectTo(url, needAuth)) {
  1339. this.authModal();
  1340. return;
  1341. }
  1342. if (type == 0) {
  1343. // 跳转webview
  1344. url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) })
  1345. } else if (type == 1) {
  1346. 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) {
  1347. url && wx.switchTab({ url: url })
  1348. } else {
  1349. url && wx.navigateTo({ url: url })
  1350. }
  1351. } else if (type == 2) {
  1352. // 跳转小程序
  1353. let appid = slider_list[idx].appid;
  1354. appid && wx.navigateToMiniProgram({
  1355. appId: slider_list[idx].appid,
  1356. path: url,
  1357. extraData: {},
  1358. envVersion: 'release',
  1359. success(res) {
  1360. // 打开成功
  1361. },
  1362. fail(error) {
  1363. console.log(error)
  1364. }
  1365. })
  1366. } else if (type == 6) {
  1367. //领券
  1368. wx.navigateTo({
  1369. url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
  1370. })
  1371. }
  1372. }
  1373. },
  1374. /**
  1375. * 页面相关事件处理函数--监听用户下拉动作
  1376. */
  1377. onPullDownRefresh: function () {
  1378. this.setData({ couponRefresh: false, newComerRefresh: false, stopNotify: true });
  1379. this.tpage = 1;
  1380. this.$data = {
  1381. ...this.$data, ...{
  1382. overPageNum: 1,
  1383. loadOver: false,
  1384. hasOverGoods: false,
  1385. countDownMap: {},
  1386. actEndMap: {},
  1387. timer: {},
  1388. stickyFlag: false,
  1389. hasCommingGoods: true
  1390. }
  1391. }
  1392. this.hasRefeshin = false;
  1393. this.setData({
  1394. rushList: [],
  1395. commingList: [],
  1396. tabIdx: 0,
  1397. pageNum: 1,
  1398. couponRefresh: true,
  1399. newComerRefresh: true,
  1400. stopNotify: false,
  1401. rushEndTime: 0,
  1402. diyLoaded: false
  1403. }, ()=>{
  1404. this.loadPage();
  1405. })
  1406. wx.stopPullDownRefresh();
  1407. },
  1408. onReachBottom: function(e) {
  1409. if(this.data.ishide_index_goodslist==1||this.data.isDiy==1) return;
  1410. if (this.data.tabIdx==0){
  1411. this.load_goods_data();
  1412. } else {
  1413. this.getCommingList();
  1414. }
  1415. },
  1416. /**
  1417. * 获取团长位置
  1418. */
  1419. getCommunityPos: function (community_id){
  1420. let that = this;
  1421. app.util.request({
  1422. 'url': 'entry/wxapp/user',
  1423. 'data': {
  1424. controller: 'index.get_community_position',
  1425. communityId: community_id
  1426. },
  1427. dataType: 'json',
  1428. method: 'POST',
  1429. success: function (res) {
  1430. if (res.data.code == 0) {
  1431. that.postion = res.data.postion;
  1432. }
  1433. }
  1434. })
  1435. },
  1436. /**
  1437. * 查看地图
  1438. */
  1439. gotoMap: function () {
  1440. let community = this.data.community;
  1441. let postion = this.postion || {lat: 0, lon: 0};
  1442. let longitude = parseFloat(postion.lon),
  1443. latitude = parseFloat(postion.lat),
  1444. name = community.disUserName,
  1445. address = `${community.fullAddress}(${community.communityName})`;
  1446. wx.openLocation({
  1447. latitude: latitude,
  1448. longitude: longitude,
  1449. name: name,
  1450. address: address,
  1451. scale: 28
  1452. })
  1453. },
  1454. share_handler: function () {
  1455. this.setData({
  1456. is_share_html: false
  1457. })
  1458. },
  1459. hide_share_handler: function () {
  1460. this.setData({
  1461. is_share_html: true
  1462. })
  1463. },
  1464. // 搜索
  1465. goResult: function (e) {
  1466. let value = e.detail.value.keyword ? e.detail.value.keyword : e.detail.value;
  1467. let keyword = value.replace(/\s+/g, '');
  1468. if (!keyword) {
  1469. wx.showToast({
  1470. title: '请输入关键词',
  1471. icon: 'none'
  1472. })
  1473. return;
  1474. }
  1475. wx.navigateTo({
  1476. url: '/lionfish_comshop/pages/type/result?keyword=' + keyword,
  1477. })
  1478. },
  1479. /**
  1480. * 新人优惠券显示开关
  1481. */
  1482. toggleCoupon: function(e){
  1483. let auth = e.currentTarget.dataset.auth || '';
  1484. let needAuth = this.data.needAuth || '';
  1485. if(needAuth && auth) {
  1486. this.setData({
  1487. showAuthModal: true,
  1488. showCouponModal: false
  1489. })
  1490. } else {
  1491. this.setData({
  1492. showCouponModal: !this.data.showCouponModal,
  1493. hasAlertCoupon: false
  1494. })
  1495. }
  1496. },
  1497. changeCartNum: function(t) {
  1498. let that = this;
  1499. let e = t.detail;
  1500. (0, status.cartNum)(that.setData({ cartNum: e }));
  1501. },
  1502. /**
  1503. * 一键复制文本
  1504. */
  1505. copyText: function (e) {
  1506. let copy_text_arr = this.data.copy_text_arr;
  1507. let community = this.data.community;
  1508. let communityName = community.communityName;
  1509. let disUserName = community.disUserName;
  1510. let communityAddress = community.address || community.communityAddress || community.fullAddress;
  1511. let data = '-团长信息-\r\n小区:' + communityName + '\r\n团长:' + disUserName + '\r\n自提点:' + communityAddress + '\r\n\r\n今日推荐\r\n';
  1512. if (copy_text_arr.length) {
  1513. copy_text_arr.forEach(function(item, index){
  1514. data += (index + 1) + '.【' + item.goods_name + '】 团购价' + item.price + '\r\n';
  1515. data += '~~~~~~~~~~~~~~~~~~~~\r\n';
  1516. })
  1517. }
  1518. let that = this;
  1519. wx.setClipboardData({
  1520. data: data,
  1521. success: function (res) {
  1522. wx.getClipboardData({
  1523. success: function (res) {
  1524. that.setData({ showCopyText: false })
  1525. wx.showToast({
  1526. title: '复制成功'
  1527. })
  1528. }
  1529. })
  1530. }
  1531. })
  1532. },
  1533. /**
  1534. * 显示关闭复制文本
  1535. */
  1536. showCopyTextHandle: function(e){
  1537. if (!this.authModal()) return;
  1538. let showCopyText = e.currentTarget.dataset.status;
  1539. this.setData({ showCopyText })
  1540. },
  1541. /**
  1542. * 优惠券获取
  1543. */
  1544. getCoupon: function () {
  1545. let that = this;
  1546. let token = wx.getStorageSync('token');
  1547. app.util.request({
  1548. url: 'entry/wxapp/index',
  1549. data: { controller: 'goods.get_seller_quan', token },
  1550. dataType: 'json',
  1551. success: function (res) {
  1552. let list = res.data.quan_list;
  1553. let hasCoupon = false;
  1554. let hasAlertCoupon = false;
  1555. if (Object.prototype.toString.call(list) == '[object Object]' && Object.keys(list).length > 0) hasCoupon = true;
  1556. if (Object.prototype.toString.call(list) == '[object Array]' && list.length > 0) hasCoupon = true;
  1557. let alert_quan_list = res.data.alert_quan_list || [];
  1558. if (Object.prototype.toString.call(alert_quan_list) == '[object Object]' && Object.keys(alert_quan_list).length > 0) hasAlertCoupon = true;
  1559. if (Object.prototype.toString.call(alert_quan_list) == '[object Array]' && alert_quan_list.length > 0) hasAlertCoupon = true;
  1560. let totalAlertMoney = 0;
  1561. if (Object.prototype.toString.call(alert_quan_list) == '[object Object]' && Object.keys(alert_quan_list).length > 0) {
  1562. Object.keys(alert_quan_list).forEach(function(item){
  1563. totalAlertMoney += alert_quan_list[item].credit*1;
  1564. })
  1565. } else if (Object.prototype.toString.call(alert_quan_list) == '[object Array]' && alert_quan_list.length > 0) {
  1566. alert_quan_list.forEach(function (item) {
  1567. totalAlertMoney += item.credit * 1;
  1568. })
  1569. }
  1570. that.setData({
  1571. quan: res.data.quan_list || [],
  1572. alert_quan_list,
  1573. hasCoupon,
  1574. hasAlertCoupon,
  1575. showCouponModal: hasAlertCoupon,
  1576. totalAlertMoney: totalAlertMoney.toFixed(2)
  1577. })
  1578. }
  1579. });
  1580. },
  1581. receiveCoupon: function (event) {
  1582. if (!this.authModal()) return;
  1583. let quan_id = event.currentTarget.dataset.quan_id;
  1584. let type = event.currentTarget.dataset.type || 0;
  1585. var token = wx.getStorageSync('token');
  1586. var quan_list = [];
  1587. if(type==1) {
  1588. quan_list = this.data.alert_quan_list;
  1589. } else {
  1590. quan_list = this.data.quan;
  1591. }
  1592. var that = this;
  1593. app.util.request({
  1594. url: 'entry/wxapp/index',
  1595. data: { controller: 'goods.getQuan', token, quan_id },
  1596. dataType: 'json',
  1597. success: function (msg) {
  1598. //1 被抢光了 2 已领过 3 领取成功
  1599. if (msg.data.code == 0) {
  1600. wx.showToast({
  1601. title: msg.data.msg || '被抢光了',
  1602. icon: 'none'
  1603. })
  1604. } else if (msg.data.code == 1) {
  1605. wx.showToast({
  1606. title: '被抢光了',
  1607. icon: 'none'
  1608. })
  1609. } else if (msg.data.code == 2) {
  1610. wx.showToast({
  1611. title: '已领取',
  1612. icon: 'none'
  1613. })
  1614. var new_quan = [];
  1615. for (var i in quan_list) {
  1616. if (quan_list[i].id == quan_id) quan_list[i].is_get = 1;
  1617. new_quan.push(quan_list[i]);
  1618. }
  1619. that.setData({ quan: new_quan })
  1620. }
  1621. else if (msg.data.code == 4) {
  1622. wx.showToast({
  1623. title: '新人专享',
  1624. icon: 'none'
  1625. })
  1626. }
  1627. else if (msg.data.code == 3) {
  1628. var new_quan = [];
  1629. for (var i in quan_list) {
  1630. if (quan_list[i].id == quan_id){
  1631. quan_list[i].is_get = 1;
  1632. quan_list[i].is_hide = msg.data.is_hide;
  1633. }
  1634. new_quan.push(quan_list[i]);
  1635. }
  1636. if(type==1) {
  1637. that.setData({ alert_quan_list: new_quan })
  1638. } else {
  1639. that.setData({ quan: new_quan })
  1640. }
  1641. wx.showToast({
  1642. title: '领取成功',
  1643. })
  1644. } else if (msg.data.code == 4) {
  1645. // 未登录
  1646. }
  1647. }
  1648. })
  1649. },
  1650. goUse: function (e) {
  1651. this.setData({ showCouponModal: false, hasAlertCoupon: false })
  1652. let idx = e.currentTarget.dataset.idx;
  1653. let quan = this.data.alert_quan_list || [];
  1654. console.log(Object.keys(quan).length)
  1655. if (Object.keys(quan).length >= idx) {
  1656. if (quan[idx].is_limit_goods_buy == 0) {
  1657. wx.switchTab({
  1658. url: '/lionfish_comshop/pages/index/index',
  1659. })
  1660. } else if (quan[idx].is_limit_goods_buy == 1) {
  1661. let id = quan[idx].limit_goods_list;
  1662. let ids = id.split(',');
  1663. let url = '';
  1664. if (ids.length > 1) {
  1665. url = '/lionfish_comshop/pages/type/result?type=2&good_ids=' + id;
  1666. } else {
  1667. url = '/lionfish_comshop/pages/goods/goodsDetail?id=' + id;
  1668. }
  1669. wx.navigateTo({ url: url })
  1670. } else if (quan[idx].is_limit_goods_buy == 2) {
  1671. let gid = quan[idx].goodscates || 0;
  1672. wx.navigateTo({
  1673. url: '/lionfish_comshop/pages/type/result?type=1&gid=' + gid,
  1674. })
  1675. }
  1676. }
  1677. },
  1678. /**
  1679. * 分类专题
  1680. */
  1681. get_type_topic: function () {
  1682. let that = this;
  1683. var cur_community = wx.getStorageSync('community');
  1684. var token = wx.getStorageSync('token');
  1685. app.util.request({
  1686. url: 'entry/wxapp/index',
  1687. data: {
  1688. controller: 'goods.get_category_col_list',
  1689. head_id: cur_community.communityId,
  1690. token
  1691. },
  1692. dataType: 'json',
  1693. success: function (res) {
  1694. if(res.data.code == 0) {
  1695. let typeTopicList = res.data.data || [];
  1696. that.setData({ typeTopicList })
  1697. }
  1698. }
  1699. })
  1700. },
  1701. /**
  1702. * 拼团列表
  1703. */
  1704. getPinList: function () {
  1705. let that = this;
  1706. var community = wx.getStorageSync('community');
  1707. let head_id = community.communityId || '';
  1708. var token = wx.getStorageSync('token');
  1709. app.util.request({
  1710. url: 'entry/wxapp/index',
  1711. data: {
  1712. controller: 'group.get_pintuan_list',
  1713. is_index: 1,
  1714. head_id,
  1715. token
  1716. },
  1717. dataType: 'json',
  1718. success: function (res) {
  1719. if (res.data.code == 0) {
  1720. let pinList = {};
  1721. let { list, pintuan_index_coming_img, pintuan_index_show } = res.data;
  1722. pinList.list = list || [];
  1723. pinList.img = pintuan_index_coming_img || '';
  1724. pinList.show = pintuan_index_show || 0;
  1725. that.setData({ pinList })
  1726. }
  1727. }
  1728. })
  1729. },
  1730. /**
  1731. * 魔方图标跳转
  1732. */
  1733. goCube: function (t) {
  1734. let idx = t.currentTarget.dataset.idx; // 当前链接索引
  1735. let index = t.currentTarget.dataset.index; // 当前魔方索引
  1736. let { cube, needAuth } = this.data;
  1737. console.log(cube)
  1738. if (cube.length > 0) {
  1739. let url = cube[index].thumb.link[idx];
  1740. let url2 = cube[index].thumb.outlink[idx];
  1741. let type = (cube[index].thumb.linktype && cube[index].thumb.linktype[idx]);
  1742. (type === (void 0)) && (type = 1);
  1743. if (util.checkRedirectTo(url, needAuth)) {
  1744. this.authModal();
  1745. return;
  1746. }
  1747. if (type == 0) {
  1748. // 跳转webview
  1749. url = cube[index].thumb.webview[idx];
  1750. wx.navigateTo({
  1751. url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url)
  1752. })
  1753. } else if (type == 1) {
  1754. 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) {
  1755. url && wx.switchTab({
  1756. url,
  1757. fail: (err)=>{
  1758. wx.showToast({
  1759. title: err.errMsg,
  1760. icon: 'none'
  1761. })
  1762. }
  1763. })
  1764. } else {
  1765. url && wx.navigateTo({
  1766. url,
  1767. fail: (err)=>{
  1768. wx.showToast({
  1769. title: err.errMsg,
  1770. icon: 'none'
  1771. })
  1772. }
  1773. })
  1774. }
  1775. } else if (type == 2) {
  1776. // 跳转小程序
  1777. let appid = navigat[idx].appid;
  1778. appid && wx.navigateToMiniProgram({
  1779. appId: navigat[idx].appid,
  1780. path: url,
  1781. extraData: {},
  1782. envVersion: 'release',
  1783. success(res) {
  1784. // 打开成功
  1785. },
  1786. fail(error) {
  1787. console.log(error)
  1788. }
  1789. })
  1790. } else if (type == 3) {
  1791. let cid = cube[index].thumb.cateid[idx];
  1792. this.goIndexType(cid);
  1793. } else if (type == 4) {
  1794. //独立分类
  1795. let url = cube[index].thumb.cateid[idx];
  1796. app.globalData.typeCateId = url;
  1797. wx.switchTab({
  1798. url: '/lionfish_comshop/pages/type/index'
  1799. })
  1800. }else if (type==5){
  1801. // 跳转小程序
  1802. let appid = cube[index].thumb.appid[idx];
  1803. appid && wx.navigateToMiniProgram({
  1804. appId: appid,
  1805. path: url2,
  1806. extraData: {},
  1807. envVersion: 'release',
  1808. success(res) {
  1809. // 打开成功
  1810. },
  1811. fail(error) {
  1812. console.log(error)
  1813. }
  1814. })
  1815. } else if (type == 6) {
  1816. //领券
  1817. wx.navigateTo({
  1818. url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
  1819. })
  1820. }
  1821. }
  1822. },
  1823. goIndexType: function(cid){
  1824. if(cid.detail) {
  1825. cid = cid.detail;
  1826. }
  1827. let classification = this.data.classification;
  1828. let tabs = classification && classification.tabs;
  1829. let activeIdx = tabs.findIndex((p) => { return p.id == cid });
  1830. if (activeIdx != -1) {
  1831. let cateInfo = {
  1832. detail: { e: activeIdx, a: cid }
  1833. };
  1834. this.classificationChange(cateInfo, 1);
  1835. }
  1836. },
  1837. getSecKillGoods: function (seckill_time){
  1838. var that = this;
  1839. var cur_community = wx.getStorageSync('community');
  1840. var token = wx.getStorageSync('token');
  1841. app.util.request({
  1842. url: 'entry/wxapp/index',
  1843. data: {
  1844. controller: 'index.load_gps_goodslist',
  1845. token: token,
  1846. pageNum: 1,
  1847. head_id: cur_community.communityId,
  1848. seckill_time,
  1849. is_seckill: 1,
  1850. per_page: 10000
  1851. },
  1852. dataType: 'json',
  1853. success: function (res) {
  1854. if(res.data.code==0) {
  1855. let secRushList = res.data.list || [];
  1856. that.setData({ secRushList })
  1857. }
  1858. }
  1859. })
  1860. },
  1861. scrollSecKillGoodsChange: function (t) {
  1862. this.setData({
  1863. secKillGoodsIndex: t.detail.current + 1
  1864. });
  1865. },
  1866. /**
  1867. * 显示秒杀时间切换
  1868. */
  1869. changeSecKillTime(t){
  1870. let that = this;
  1871. let seckill_time = t.currentTarget.dataset.time;
  1872. let secKillActiveIdx = t.currentTarget.dataset.idx;
  1873. this.setData({
  1874. secRushList: [],
  1875. secKillActiveIdx
  1876. }, ()=>{
  1877. that.getSecKillGoods(seckill_time);
  1878. })
  1879. },
  1880. /**
  1881. * 图片信息
  1882. */
  1883. imageLoad: function (e) {
  1884. var imageSize = util.imageUtil(e)
  1885. this.setData({
  1886. imageSize
  1887. })
  1888. },
  1889. /**
  1890. * 播放视频隐藏封面图
  1891. */
  1892. btnPlay: function () {
  1893. this.setData({
  1894. fmShow: false
  1895. })
  1896. this.videoContext.play();
  1897. },
  1898. videEnd: function () {
  1899. this.setData({
  1900. fmShow: true
  1901. })
  1902. },
  1903. bindload: function(t){
  1904. console.log(t.detail)
  1905. },
  1906. binderror: function(t){
  1907. this.setData({ hideMpAccount: true })
  1908. console.log(t.detail)
  1909. },
  1910. closeMpaccount: function(){
  1911. this.setData({ show_index_wechat_oa: 0 })
  1912. },
  1913. showNoticeTextHandle: function(e){
  1914. if(this.data.can_index_notice_alert==1) {
  1915. let showNoticeText = e.currentTarget.dataset.status;
  1916. let noticeIdx = e.currentTarget.dataset.idx;
  1917. this.setData({ showNoticeText, noticeIdx })
  1918. }
  1919. },
  1920. /**
  1921. * DIY公用链接跳转
  1922. */
  1923. goDiysliderUrl: function(t) {
  1924. let link = t.currentTarget.dataset.link;
  1925. let needAuth = this.data.needAuth;
  1926. if (Object.keys(link).length > 0) {
  1927. let type = link.parents;
  1928. if (util.checkRedirectTo(link.wap_url, needAuth)) {
  1929. this.authModal();
  1930. return;
  1931. }
  1932. switch(type) {
  1933. case "WEBVIEW":
  1934. let url = link.wap_url;
  1935. url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) });
  1936. break;
  1937. case "MALL_LINK":
  1938. url = link.wap_url;
  1939. 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) {
  1940. url && wx.switchTab({ url })
  1941. } else {
  1942. url && wx.navigateTo({ url })
  1943. }
  1944. break;
  1945. case "OTHER_APPLET":
  1946. // 跳转小程序
  1947. let appId = link.appid;
  1948. let path = link.wap_url;
  1949. appId && wx.navigateToMiniProgram({
  1950. appId,
  1951. path,
  1952. extraData: {},
  1953. envVersion: 'release',
  1954. success(res) {},
  1955. fail(error) { wx.showModal({ title: "提示", content: error.errMsg, showCancel: false }) }
  1956. })
  1957. break;
  1958. case "CUSTOM_LINK":
  1959. url = link.wap_url;
  1960. 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) {
  1961. url && wx.switchTab({ url })
  1962. } else {
  1963. url && wx.navigateTo({ url })
  1964. }
  1965. break;
  1966. case "GOODS_CATEGORY":
  1967. //独立分类
  1968. let cateId = link.id;
  1969. app.globalData.typeCateId = cateId;
  1970. wx.switchTab({
  1971. url: '/lionfish_comshop/pages/type/index'
  1972. })
  1973. break;
  1974. default:
  1975. url = link.wap_url;
  1976. url && wx.navigateTo({ url })
  1977. break;
  1978. }
  1979. }
  1980. },
  1981. /**
  1982. * DIY商品列表组获取
  1983. */
  1984. getDiyGoodsList(res) {
  1985. console.log('getDiyGoodsList', res)
  1986. let data = res.detail.data;
  1987. let idx = res.detail.id;
  1988. let diyGoodsList = [];
  1989. let is_open_vipcard_buy = 0;
  1990. if(data.code==0) {
  1991. let resGoodsList = data.list;
  1992. if (data.is_show_list_timer==1&&resGoodsList.length>0) {
  1993. diyGoodsList = this.transTime(resGoodsList);
  1994. for (let s in this.$data.countDownMap) this.initCountDown(this.$data.countDownMap[s]);
  1995. } else {
  1996. diyGoodsList[0] = resGoodsList;
  1997. }
  1998. is_open_vipcard_buy = data.is_open_vipcard_buy;
  1999. }
  2000. let list = this.data.diyGoodsList;
  2001. list[idx] = diyGoodsList;
  2002. this.setData({ diyGoodsList: list, is_open_vipcard_buy })
  2003. },
  2004. getDiyManyGoodsList(res) {
  2005. let data = res.detail.data;
  2006. let list = [];
  2007. if(data.code==0) {
  2008. let resGoodsList = data.list;
  2009. if (data.is_show_list_timer==1&&resGoodsList.length>0) {
  2010. list = this.transTime(resGoodsList);
  2011. for (let s in this.$data.countDownMap) this.initCountDown(this.$data.countDownMap[s]);
  2012. } else {
  2013. list[0] = resGoodsList;
  2014. }
  2015. }
  2016. this.setData({ diyManyGoodsList: list })
  2017. },
  2018. /**
  2019. * DIY数据
  2020. */
  2021. getDiyInfo: function() {
  2022. app.util.ProReq('index.get_diy_info').then(res => {
  2023. console.log(res.global)
  2024. let { diyJson, global } = res;
  2025. global.title && wx.setNavigationBarTitle({ title: global.title });
  2026. wx.setNavigationBarColor({
  2027. backgroundColor: global.topNavColor,
  2028. frontColor: global.textNavColor,
  2029. })
  2030. let diyGoodsList = Array.from(Array(diyJson.length), () => '');
  2031. this.setData({
  2032. diyJson, globalDiyData: global, diyGoodsList, diyLoaded: true
  2033. })
  2034. })
  2035. },
  2036. onShareAppMessage: function(res) {
  2037. this.setData({ is_share_html: true });
  2038. var community = wx.getStorageSync('community');
  2039. var community_id = community.communityId;
  2040. var member_id = wx.getStorageSync('member_id');
  2041. console.log('首页分享地址:');
  2042. console.log(community_id, member_id);
  2043. return {
  2044. title: this.data.shop_info.title,
  2045. path: "lionfish_comshop/pages/index/index?community_id=" + community_id + '&share_id=' + member_id,
  2046. imageUrl: this.data.shop_info.shop_index_share_image,
  2047. success: function() {},
  2048. fail: function() {}
  2049. };
  2050. },
  2051. onShareTimeline: function(res) {
  2052. var community = wx.getStorageSync('community');
  2053. var community_id = community.communityId;
  2054. var share_id = wx.getStorageSync('member_id');
  2055. var query= `share_id=${share_id}&community_id=${community_id}`;
  2056. return {
  2057. title: this.data.shop_info.title,
  2058. query,
  2059. imageUrl: this.data.shop_info.shop_index_share_image,
  2060. success: function() {},
  2061. fail: function() {}
  2062. };
  2063. }
  2064. })