index.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  1. var util = require('../../utils/util.js');
  2. var status = require('../../utils/index.js');
  3. var a = require("../../utils/public");
  4. var e = require('../../wxParse/wxParse.js');
  5. var countDownInit = require("../../utils/countDown");
  6. var wcache = require('../../utils/wcache.js');
  7. var app = getApp();
  8. var timerOut = '';
  9. Page(Object.assign({}, countDownInit.default, {
  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: 0
  28. },
  29. commingClassification: {
  30. tabs: [],
  31. activeIndex: 0
  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. tabIdx: 0,
  43. scrollDirect: "",
  44. isSticky: false,
  45. showCommingEmpty: false,
  46. stopNotify: true,
  47. reduction: {},
  48. is_share_html: true,
  49. commingNum: 0,
  50. couponRefresh: false,
  51. index_change_cate_btn: 0,
  52. newComerRefresh: false,
  53. showNewCoupon: false,
  54. copy_text_arr: [],
  55. showCopyText: false
  56. },
  57. isFirst: 0,
  58. $data: {
  59. stickyFlag: false,
  60. scrollTop: 0,
  61. overPageNum: 1,
  62. loadOver: false,
  63. hasOverGoods: false,
  64. countDownMap: {},
  65. actEndMap: {},
  66. timer: {},
  67. scrollHeight: 1300,
  68. stickyTop: 0,
  69. hasCommingGoods: true,
  70. groupInfo: {
  71. group_name: '社区',
  72. owner_name: '团长'
  73. },
  74. },
  75. tpage: 1,
  76. hasRefeshin: false,
  77. postion: {},
  78. options: '',
  79. /**
  80. * 监控滚动事件
  81. */
  82. onPageScroll: function (t) {
  83. if (!this.$data.isLoadData) {
  84. if (t.scrollTop < this.$data.scrollHeight) {
  85. if (t.scrollTop > this.$data.scrollTop) {
  86. "down" !== this.data.scrollDirect && this.setData({
  87. scrollDirect: "down"
  88. })
  89. } else {
  90. "up" != this.data.scrollDirect && this.setData({
  91. scrollDirect: "up"
  92. })
  93. }
  94. } else {
  95. "down" !== this.data.scrollDirect && this.setData({
  96. scrollDirect: "down"
  97. })
  98. }
  99. if (t.scrollTop > this.$data.stickyTop) {
  100. this.data.isSticky || (this.setData({
  101. isSticky: true
  102. }), this.$data.stickyFlag = true)
  103. } else {
  104. t.scrollTop < this.$data.stickyBackTop && this.data.isSticky && (this.setData({
  105. isSticky: false
  106. }), this.$data.stickyFlag = false)
  107. }
  108. this.$data.scrollTop = t.scrollTop
  109. }
  110. },
  111. onLoad: function(options) {
  112. console.log('options', options);
  113. wx.hideTabBar();
  114. var that = this;
  115. status.setNavBgColor();
  116. that.setData({ systemInfo: app.globalData.systemInfo });
  117. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  118. console.log('step1');
  119. if (options && Object.keys(options).length != 0) {
  120. console.log('step2');
  121. var scene = decodeURIComponent(options.scene);
  122. let community = wx.getStorageSync('community');
  123. let community_id = community.communityId;
  124. if (scene != 'undefined') {
  125. //$share_id.'_'.$member_id
  126. var opt_arr = scene.split("_");
  127. options.community_id = opt_arr[0];
  128. wcache.put('share_id', opt_arr[1]);
  129. }
  130. that.options = options;
  131. if (options.share_id != 'undefined' && options.share_id > 0) wcache.put('share_id', options.share_id);
  132. if (options.community_id != 'undefined' && options.community_id > 0) {
  133. console.log('step3');
  134. app.util.request({
  135. 'url': 'entry/wxapp/index',
  136. 'data': {
  137. controller: 'index.get_community_info',
  138. 'community_id': options.community_id
  139. },
  140. dataType: 'json',
  141. success: function(res) {
  142. var token = wx.getStorageSync('token');
  143. if (res.data.code == 0) {
  144. console.log('step4');
  145. var community = res.data.data;
  146. if (options.community_id != community_id) {
  147. that.setData({
  148. showChangeCommunity: true,
  149. changeCommunity: community
  150. })
  151. }
  152. that.loadPage();
  153. that.setData({
  154. hidetip: false,
  155. token: token,
  156. showEmpty: false
  157. })
  158. } else {
  159. console.log('step5');
  160. that.loadPage();
  161. that.setData({
  162. hidetip: false,
  163. token: token,
  164. showEmpty: false
  165. })
  166. }
  167. token && that.addhistory();
  168. }
  169. })
  170. } else {
  171. console.log('step6');
  172. that.loadPage();
  173. }
  174. } else {
  175. console.log('step7');
  176. that.loadPage();
  177. var token = wx.getStorageSync('token');
  178. that.setData({
  179. hidetip: false,
  180. token: token,
  181. showEmpty: false
  182. })
  183. }
  184. },
  185. addhistory: function (id=0) {
  186. console.log('step13');
  187. let community_id = 0;
  188. if (id==0) {
  189. var community = wx.getStorageSync('community');
  190. community_id = community.communityId;
  191. } else {
  192. community_id = id;
  193. }
  194. console.log('history community_id=' + community_id);
  195. var token = wx.getStorageSync('token');
  196. let that = this;
  197. community_id !==void 0 && app.util.request({
  198. 'url': 'entry/wxapp/index',
  199. 'data': {
  200. controller: 'index.addhistory_community',
  201. community_id: community_id,
  202. 'token': token
  203. },
  204. dataType: 'json',
  205. success: function(res) {
  206. if(id!=0) that.getHistoryCommunity(), console.log('addhistory+id', id);
  207. }
  208. })
  209. },
  210. loadPage: function() {
  211. wx.showLoading();
  212. console.log('step8');
  213. let that = this;
  214. that.get_index_info();
  215. that.getNavigat();
  216. status.loadStatus().then(function() {
  217. let appLoadStatus = app.globalData.appLoadStatus;
  218. console.log('appLoadStatus',appLoadStatus)
  219. if (appLoadStatus == 0) {
  220. wx.hideLoading();
  221. that.setData({ needAuth: true });
  222. } else if (appLoadStatus == 2) {
  223. console.log('step9');
  224. that.getHistoryCommunity();
  225. } else {
  226. console.log('step12');
  227. let community = wx.getStorageSync('community');
  228. community || (community=app.globalData.community);
  229. if (!community){
  230. util.getCommunityInfo().then((res) => {
  231. that.setData({
  232. community: that.fliterCommunity(res)
  233. })
  234. })
  235. } else {
  236. that.setData({
  237. community: that.fliterCommunity(community)
  238. })
  239. }
  240. console.log('step18');
  241. that.load_goods_data();
  242. }
  243. });
  244. },
  245. // 不显示社区省份
  246. fliterCommunity: function (community){
  247. let resArr = community && community.fullAddress && community.fullAddress.split('省');
  248. let newCommunity = Object.assign({}, community, { address: resArr[1] || resArr[0] });
  249. return newCommunity;
  250. },
  251. onShow: function() {
  252. // 页面显示
  253. let that = this;
  254. console.log('isFirst',that.isFirst)
  255. this.setData({ stopNotify: false, couponRefresh: true, tabbarRefresh: true })
  256. if (util.check_login()) {
  257. this.setData({ needAuth: false })
  258. } else {
  259. this.setData({ needAuth: true });
  260. }
  261. app.globalData.timer.start();
  262. (0, status.cartNum)('', true).then((res)=>{
  263. res.code == 0 && that.setData({ cartNum: res.data })
  264. });
  265. if (app.globalData.changedCommunity) {
  266. console.log('change')
  267. app.globalData.goodsListCarCount = [];
  268. let community = app.globalData.community;
  269. this.setData({
  270. community: that.fliterCommunity(community),
  271. newComerRefresh: false
  272. });
  273. this.getCommunityPos(community.communityId);
  274. this.hasRefeshin = false;
  275. this.setData({
  276. newComerRefresh: true,
  277. rushList: [],
  278. pageNum: 1,
  279. classificationId: null,
  280. "classification.activeIndex": -1
  281. }, () => {
  282. this.setData({
  283. "classification.activeIndex": 0
  284. })
  285. })
  286. this.$data = {
  287. ...this.$data, ...{
  288. overPageNum: 1,
  289. loadOver: false,
  290. hasOverGoods: false,
  291. countDownMap: {},
  292. actEndMap: {},
  293. timer: {},
  294. stickyFlag: false,
  295. hasCommingGoods: true
  296. }
  297. }
  298. app.globalData.changedCommunity = false, this.get_index_info(), this.addhistory();
  299. this.load_goods_data();
  300. } else {
  301. console.log('nochange')
  302. if (that.isFirst>=1){
  303. this.setData({ loadOver: true })
  304. let goodsListCarCount = app.globalData.goodsListCarCount; //[{ actId: 84, num: 2}]
  305. let rushList = this.data.rushList;
  306. if (goodsListCarCount.length > 0 && rushList.length>0){
  307. let newRushList = [];
  308. let changeCarCount = false;
  309. goodsListCarCount.forEach(function(item){
  310. let k = rushList.findIndex((n) => n.actId == item.actId);
  311. if (k != -1 && rushList[k].skuList.length === 0) {
  312. let newNum = item.num * 1;
  313. rushList[k].car_count = newNum >= 0 ? newNum : 0;
  314. changeCarCount = true;
  315. }
  316. })
  317. this.setData({ rushList, changeCarCount })
  318. // app.globalData.goodsListCarCount = [];
  319. }
  320. }
  321. }
  322. that.isFirst++;
  323. },
  324. onHide: function() {
  325. this.setData({ stopNotify: true, couponRefresh: false, tabbarRefresh: false, changeCarCount: false })
  326. console.log('详情页', this.data.stopNotify)
  327. app.globalData.timer.stop();
  328. console.log('onHide')
  329. },
  330. /**
  331. * 授权成功回调
  332. */
  333. authSuccess: function() {
  334. console.log('authSuccess');
  335. let that = this;
  336. this.tpage = 1;
  337. this.hasRefeshin = false;
  338. this.setData({
  339. rushList: [],
  340. pageNum: 1,
  341. needAuth: false
  342. })
  343. this.$data = {
  344. ...this.$data, ...{
  345. overPageNum: 1,
  346. loadOver: false,
  347. hasOverGoods: false,
  348. countDownMap: {},
  349. actEndMap: {},
  350. timer: {},
  351. hasCommingGoods: true
  352. }
  353. }
  354. status.getInNum().then((isCan) => {
  355. if (isCan) {
  356. that.setData({ isTipShow: true })
  357. timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 7000);
  358. }
  359. })
  360. this.loadPage();
  361. this.data.isTipShow && (timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 7000));
  362. },
  363. //获取历史社区
  364. getHistoryCommunity: function () {
  365. let that = this;
  366. var token = wx.getStorageSync('token');
  367. app.util.request({
  368. 'url': 'entry/wxapp/index',
  369. 'data': {
  370. controller: 'index.load_history_community',
  371. token: token
  372. },
  373. dataType: 'json',
  374. success: function (res) {
  375. console.log('step14');
  376. if (res.data.code == 0) {
  377. console.log('getHistoryCommunity');
  378. let history_communities = res.data.list;
  379. let isNotHistory = false;
  380. if (Object.keys(history_communities).length == 0 || history_communities.communityId == 0) isNotHistory = true;
  381. let resArr = history_communities && history_communities.fullAddress && history_communities.fullAddress.split('省');
  382. history_communities = Object.assign({}, history_communities, { address: resArr[1] })
  383. that.setData({
  384. community: history_communities
  385. })
  386. wcache.put('community', history_communities);
  387. app.globalData.community = history_communities;
  388. that.setData({
  389. community: app.globalData.community
  390. })
  391. that.load_goods_data();
  392. } else {
  393. let options = that.options;
  394. if (options !== void 0 && options.community_id) {
  395. console.log('新人加入分享进来的社区id:', that.options);
  396. that.addhistory(options.community_id);
  397. } else {
  398. wx.redirectTo({
  399. url: "/lionfish_comshop/pages/position/community"
  400. })
  401. }
  402. }
  403. }
  404. })
  405. },
  406. getScrollHeight: function () {
  407. wx.createSelectorQuery().select('.rush-list-box').boundingClientRect((rect) => {
  408. rect && rect.height && (this.$data.scrollHeight = rect.height || 1300);
  409. console.log(this.$data.scrollHeight)
  410. }).exec()
  411. },
  412. /**
  413. * 引导页切换
  414. */
  415. handleProxy: function(){
  416. clearTimeout(timerOut);
  417. this.setData({
  418. isTipShow: false,
  419. isShowGuide: true
  420. })
  421. wcache.put('inNum', 4);
  422. },
  423. handleHideProxy: function(){
  424. this.setData({
  425. isTipShow: false,
  426. isShowGuide: false
  427. })
  428. },
  429. /**
  430. * 获取首页信息
  431. */
  432. get_index_info: function() {
  433. let that = this;
  434. let community = wx.getStorageSync('community');
  435. let communityId = community && community.communityId || '';
  436. let token = wx.getStorageSync('token');
  437. app.util.request({
  438. 'url': 'entry/wxapp/index',
  439. 'data': {
  440. controller: 'index.index_info',
  441. communityId,
  442. token
  443. },
  444. dataType: 'json',
  445. success: function(res) {
  446. let rdata = res.data;
  447. if (rdata.code == 0) {
  448. if (!res.data.is_community && communityId && !that.data.needAuth) {
  449. wx.showModal({
  450. title: '提示',
  451. content: '该小区不在,请重新选择小区',
  452. showCancel: false,
  453. confirmColor: '#F75451',
  454. success(res) {
  455. if (res.confirm) {
  456. wx.redirectTo({
  457. url: '/lionfish_comshop/pages/position/community',
  458. })
  459. }
  460. }
  461. })
  462. }
  463. let notice_list = rdata.notice_list;
  464. let slider_list = rdata.slider_list;
  465. let index_lead_image = rdata.index_lead_image;
  466. if(index_lead_image){
  467. status.getInNum().then((isCan)=>{
  468. if (isCan) {
  469. that.setData({ isTipShow: true },()=>{
  470. timerOut = setTimeout(() => { that.setData({ isTipShow: false }) }, 9000);
  471. })
  472. }
  473. })
  474. } else {
  475. that.setData({ isTipShow: false })
  476. }
  477. let common_header_backgroundimage = rdata.common_header_backgroundimage;
  478. app.globalData.common_header_backgroundimage = common_header_backgroundimage;
  479. let order_notify_switch = rdata.order_notify_switch;
  480. let index_list_top_image_on = rdata.index_list_top_image_on || 1;
  481. let index_change_cate_btn = rdata.index_change_cate_btn || 0;
  482. let default_img = '../../images/rush-title.png';
  483. if (index_list_top_image_on == 1) default_img='';
  484. let index_list_top_image = rdata.index_list_top_image ? rdata.index_list_top_image : default_img;
  485. let shop_info = {
  486. shoname: rdata.shoname,
  487. shop_index_share_image: rdata.shop_index_share_image,
  488. index_list_top_image: index_list_top_image,
  489. title: rdata.title,
  490. common_header_backgroundimage,
  491. order_notify_switch,
  492. index_top_img_bg_open: rdata.index_top_img_bg_open || 0,
  493. index_top_font_color: rdata.index_top_font_color || '#fff'
  494. }
  495. app.globalData.placeholdeImg = rdata.index_loading_image || '';
  496. wcache.put('shopname', rdata.shoname);
  497. wx.setNavigationBarTitle({ title: rdata.shoname });
  498. let category_list = rdata.category_list || [];
  499. let index_type_first_name = rdata.index_type_first_name || '全部';
  500. if (category_list.length > 0) {
  501. category_list.unshift({
  502. name: index_type_first_name,
  503. id: 0
  504. })
  505. that.setData({
  506. isShowClassification: true,
  507. "classification.tabs": category_list
  508. })
  509. } else {
  510. that.setData({
  511. isShowClassification: false
  512. })
  513. }
  514. let theme = rdata.theme || 0;
  515. let rushEndTime = rdata.rushtime*1000 || 0;
  516. let isShowShareBtn = rdata.index_share_switch || 0;
  517. let isShowListCount = rdata.is_show_list_count || 0;
  518. let isShowListTimer = rdata.is_show_list_timer || 0;
  519. let isShowContactBtn = rdata.index_service_switch || 0;
  520. let index_switch_search = rdata.index_switch_search || 0;
  521. if (rdata.is_comunity_rest == 1 && !that.data.needAuth) {
  522. wx.showModal({
  523. title: '温馨提示',
  524. content: '团长休息中,欢迎下次光临!',
  525. showCancel: false,
  526. confirmColor: '#F75451',
  527. confirmText: '好的',
  528. success(res) { }
  529. })
  530. }
  531. that.postion = rdata.postion;
  532. that.setData({
  533. notice_list,
  534. slider_list,
  535. index_lead_image,
  536. theme,
  537. indexBottomImage: rdata.index_bottom_image || '',
  538. shop_info: shop_info,
  539. loadOver: true,
  540. rushEndTime,
  541. commingNum: rdata.comming_goods_total,
  542. isShowShareBtn,
  543. isShowListCount,
  544. isShowListTimer,
  545. is_comunity_rest: rdata.is_comunity_rest,
  546. index_change_cate_btn,
  547. isShowContactBtn,
  548. index_switch_search,
  549. is_show_new_buy: rdata.is_show_new_buy || 0,
  550. qgtab: res.data.qgtab || {},
  551. notice_setting: rdata.notice_setting || {},
  552. index_hide_headdetail_address: rdata.index_hide_headdetail_address || 0,
  553. is_show_spike_buy: rdata.is_show_spike_buy || 0,
  554. hide_community_change_btn: rdata.hide_community_change_btn || 0,
  555. hide_top_community: rdata.hide_top_community || 0,
  556. index_qgtab_text: rdata.index_qgtab_text,
  557. ishow_index_copy_text: rdata.ishow_index_copy_text || 0
  558. })
  559. }
  560. }
  561. })
  562. },
  563. /**
  564. * 跳转地址选择
  565. */
  566. goSelectCommunity: function() {
  567. wx.redirectTo({
  568. url: '/lionfish_comshop/pages/position/community',
  569. })
  570. },
  571. /**
  572. * 确认切换社区
  573. */
  574. confrimChangeCommunity: function() {
  575. let community = this.data.changeCommunity;
  576. app.globalData.community = community;
  577. wcache.put('community', community);
  578. this.$data = {
  579. ...this.$data, ...{
  580. overPageNum: 1,
  581. loadOver: false,
  582. hasOverGoods: false,
  583. countDownMap: {},
  584. actEndMap: {},
  585. timer: {},
  586. stickyFlag: false
  587. }
  588. }
  589. this.hasRefeshin = false;
  590. this.setData({
  591. showChangeCommunity: false,
  592. community: community,
  593. rushList: [],
  594. pageNum: 1
  595. }, () => {
  596. this.loadPage();
  597. this.addhistory();
  598. })
  599. },
  600. /**
  601. * 关闭切换社区
  602. */
  603. closeChangeCommunity: function(){
  604. this.setData({
  605. showChangeCommunity: false
  606. })
  607. },
  608. /**
  609. * 获取商品列表
  610. */
  611. load_goods_data: function() {
  612. var token = wx.getStorageSync('token');
  613. var that = this;
  614. var cur_community = wx.getStorageSync('community');
  615. var gid = that.data.classificationId;
  616. this.$data.isLoadData = true;
  617. console.log('load_goods_begin ');
  618. if (!that.hasRefeshin && !that.$data.loadOver) {
  619. console.log('load_goods_in ');
  620. this.hasRefeshin = true;
  621. that.setData({
  622. loadMore: true
  623. });
  624. app.util.request({
  625. 'url': 'entry/wxapp/index',
  626. 'data': {
  627. controller: 'index.load_gps_goodslist',
  628. token: token,
  629. pageNum: that.data.pageNum,
  630. head_id: cur_community.communityId,
  631. gid
  632. },
  633. dataType: 'json',
  634. success: function(res) {
  635. if (res.data.code == 0) {
  636. let rushList = '';
  637. if (res.data.is_show_list_timer==1) {
  638. rushList = that.transTime(res.data.list);
  639. for (let s in that.$data.countDownMap) that.initCountDown(that.$data.countDownMap[s]);
  640. } else {
  641. let oldRushList = that.data.rushList;
  642. rushList = oldRushList.concat(res.data.list);
  643. }
  644. let rdata = res.data;
  645. let reduction = { full_money: rdata.full_money, full_reducemoney: rdata.full_reducemoney, is_open_fullreduction: rdata.is_open_fullreduction }
  646. if (that.data.pageNum==1) that.setData({ copy_text_arr: rdata.copy_text_arr || [] })
  647. that.hasRefeshin = false;
  648. that.setData({
  649. rushList: rushList,
  650. pageNum: that.data.pageNum + 1,
  651. loadMore: false,
  652. reduction,
  653. tip: ''
  654. }, ()=>{
  655. if (that.isFirst == 1) {
  656. that.isFirst++;
  657. if (rushList.length && !that.$data.stickyTop) {
  658. wx.createSelectorQuery().select(".tab-nav").boundingClientRect(function (t) {
  659. if (t && t.top){
  660. wcache.put('tabPos', t);
  661. that.$data.stickyTop = t.top + t.height, that.$data.stickyBackTop = t.top;
  662. } else {
  663. let tabpos = wcache.get('tabPos', false);
  664. if (tabpos) that.$data.stickyTop = tabpos.top + tabpos.height, that.$data.stickyBackTop = tabpos.top;
  665. }
  666. }).exec();
  667. that.$data.scrollTop > that.$data.stickyTop && wx.pageScrollTo({
  668. duration: 0,
  669. scrollTop: that.$data.stickyTop + 4
  670. });
  671. }
  672. }
  673. that.getScrollHeight();
  674. if (that.data.pageNum == 2 && res.data.list.length < 10) {
  675. console.log('load_over_goods_list_begin')
  676. that.$data.loadOver = true;
  677. that.hasRefeshin = true;
  678. that.setData({
  679. loadMore: true
  680. }, () => {
  681. that.load_over_gps_goodslist();
  682. });
  683. }
  684. });
  685. } else if (res.data.code == 1) {
  686. that.$data.loadOver = true;
  687. that.load_over_gps_goodslist();
  688. } else if (res.data.code == 2) {
  689. //no login
  690. that.setData({ needAuth: true })
  691. }
  692. },
  693. complete: function() {
  694. that.$data.isLoadData = false;
  695. wx.hideLoading();
  696. }
  697. })
  698. } else {
  699. that.load_over_gps_goodslist();
  700. }
  701. },
  702. /**
  703. * 组合倒计时时间
  704. */
  705. transTime: function(list) {
  706. let that = this;
  707. e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
  708. e === 0 && list.map(function(t) {
  709. t.end_time *= 1000;
  710. that.$data.countDownMap[t.end_time] = t.end_time, that.$data.actEndMap[t.end_time] = t.end_time <= new Date().getTime() || t.spuCanBuyNum == 0;
  711. })
  712. return that.data.rushList.concat(list);
  713. },
  714. /**
  715. * 获取售罄商品
  716. */
  717. load_over_gps_goodslist: function() {
  718. var token = wx.getStorageSync('token');
  719. var that = this;
  720. var cur_community = wx.getStorageSync('community');
  721. var gid = that.data.classificationId;
  722. if (!that.$data.hasOverGoods && that.$data.loadOver) {
  723. that.$data.hasOverGoods = true;
  724. that.setData({
  725. loadMore: true
  726. });
  727. app.util.request({
  728. 'url': 'entry/wxapp/index',
  729. 'data': {
  730. controller: 'index.load_over_gps_goodslist',
  731. token: token,
  732. pageNum: that.$data.overPageNum,
  733. head_id: cur_community.communityId,
  734. gid
  735. },
  736. dataType: 'json',
  737. success: function(res) {
  738. if (res.data.code == 0) {
  739. let rushList = that.transTime(res.data.list);
  740. for (let s in that.$data.countDownMap) that.initCountDown(that.$data.countDownMap[s]);
  741. that.$data.hasOverGoods = false;
  742. that.$data.overPageNum += 1;
  743. that.setData({
  744. rushList: rushList,
  745. loadMore: false,
  746. tip: ''
  747. }, ()=>{
  748. if (that.isFirst == 1) {
  749. that.isFirst++;
  750. if (rushList.length && !that.$data.stickyTop) {
  751. wx.createSelectorQuery().select(".tab-nav").boundingClientRect(function (t) {
  752. if (t && t.top) {
  753. wcache.put('tabPos', t);
  754. that.$data.stickyTop = t.top + t.height, that.$data.stickyBackTop = t.top;
  755. } else {
  756. let tabpos = wcache.get('tabPos', false);
  757. if (tabpos) that.$data.stickyTop = tabpos.top + tabpos.height, that.$data.stickyBackTop = tabpos.top;
  758. }
  759. }).exec();
  760. that.$data.scrollTop > that.$data.stickyTop && wx.pageScrollTo({
  761. duration: 0,
  762. scrollTop: that.$data.stickyTop + 4
  763. });
  764. }
  765. }
  766. that.getScrollHeight();
  767. });
  768. } else if (res.data.code == 1) {
  769. if (that.$data.overPageNum == 1 && that.data.rushList.length == 0) that.setData({
  770. showEmpty: true
  771. })
  772. that.setData({
  773. loadMore: false,
  774. tip: '^_^已经到底了'
  775. })
  776. } else if (res.data.code == 2) {
  777. that.setData({ needAuth: true })
  778. }
  779. that.$data.isLoadData = false;
  780. }
  781. })
  782. } else {
  783. that.$data.isLoadData = false;
  784. }
  785. },
  786. /**
  787. * 监控分类导航
  788. */
  789. classificationChange: function(t) {
  790. console.log(t.detail.e)
  791. wx.showLoading();
  792. var that = this;
  793. this.$data = {...this.$data, ...{
  794. overPageNum: 1,
  795. loadOver: false,
  796. hasOverGoods: false,
  797. countDownMap: {},
  798. actEndMap: {},
  799. timer: {}
  800. }
  801. }, this.hasRefeshin = false, this.setData({
  802. rushList: [],
  803. showEmpty: false,
  804. pageNum: 1,
  805. "classification.activeIndex": t.detail.e,
  806. classificationId: t.detail.a
  807. }, function() {
  808. if (this.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop+5)){
  809. wx.pageScrollTo({ scrollTop: that.$data.stickyTop + 5, duration: 0 })
  810. }
  811. that.load_goods_data();
  812. });
  813. },
  814. /**
  815. * 监控即将抢购分类导航
  816. */
  817. commingClassificationChange: function (t) {
  818. wx.showLoading();
  819. var that = this;
  820. that.tpage = 1;
  821. this.$data = {...this.$data, ...{hasCommingGoods: true} },
  822. this.setData({
  823. showCommingEmpty: false,
  824. commingList: [],
  825. "commingClassification.activeIndex": t.detail.e,
  826. commingClassificationId: t.detail.a
  827. }, function () {
  828. if (this.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop + 5)) {
  829. wx.pageScrollTo({ scrollTop: that.$data.stickyTop + 5, duration: 0 })
  830. }
  831. that.getCommingList();
  832. });
  833. },
  834. // 抢购切换
  835. tabSwitch: function (t) {
  836. var that = this;
  837. var tabIdx = 1 * t.currentTarget.dataset.idx;
  838. this.setData({ tabIdx: tabIdx }, ()=>{
  839. if (tabIdx == 1) {
  840. if (that.$data.stickyFlag && (that.$data.scrollTop != that.$data.stickyTop + 5)) {
  841. wx.pageScrollTo({ scrollTop: that.$data.stickyTop + 5, duration: 0 })
  842. }
  843. if (that.tpage == 1) {
  844. that.getCommingList();
  845. }
  846. }
  847. })
  848. },
  849. /**
  850. * 即将开抢列表
  851. */
  852. getCommingList: function(){
  853. this.data.commigLoadMore && wx.showLoading();
  854. var token = wx.getStorageSync('token');
  855. var that = this;
  856. var cur_community = wx.getStorageSync('community');
  857. var gid = this.data.commingClassificationId || 0;
  858. that.$data.isLoadData = true;
  859. if (that.$data.hasCommingGoods) {
  860. that.$data.hasCommingGoods = false;
  861. that.setData({ commigLoadMore: true });
  862. app.util.request({
  863. url: 'entry/wxapp/index',
  864. data: {
  865. controller: 'index.load_comming_goodslist',
  866. token: token,
  867. pageNum: that.tpage,
  868. head_id: cur_community.communityId,
  869. gid
  870. },
  871. dataType: 'json',
  872. success: function (res) {
  873. wx.hideLoading();
  874. if (res.data.code == 0) {
  875. let commingList = res.data.list;
  876. commingList = that.data.commingList.concat(commingList);
  877. that.$data.hasCommingGoods = true;
  878. that.tpage += 1;
  879. that.setData({
  880. commingList: commingList,
  881. commigLoadMore: false,
  882. commigTip: ''
  883. },()=>{
  884. that.getScrollHeight();
  885. });
  886. } else if (res.data.code == 1) {
  887. if (that.tpage == 1 && that.data.commingList.length == 0) that.setData({
  888. showCommingEmpty: true
  889. })
  890. that.setData({
  891. commigLoadMore: false,
  892. commigTip: '^_^已经到底了'
  893. })
  894. } else if (res.data.code == 2) {
  895. that.setData({ needAuth: true })
  896. }
  897. that.$data.isLoadData = false;
  898. }
  899. })
  900. } else{
  901. that.$data.isLoadData = false;
  902. !that.data.commigLoadMore && wx.hideLoading();
  903. }
  904. },
  905. openSku: function(t) {
  906. var that = this,
  907. e = t.detail;
  908. var goods_id = e.actId;
  909. var options = e.skuList;
  910. that.setData({
  911. addCar_goodsid: goods_id
  912. })
  913. let list = options.list || [];
  914. let arr = [];
  915. if (list.length > 0) {
  916. for (let i = 0; i < list.length; i++) {
  917. let sku = list[i]['option_value'][0];
  918. let temp = {
  919. name: sku['name'],
  920. id: sku['option_value_id'],
  921. index: i,
  922. idx: 0
  923. };
  924. arr.push(temp);
  925. }
  926. //把单价剔除出来begin
  927. var id = '';
  928. for (let i = 0; i < arr.length; i++) {
  929. if (i == arr.length - 1) {
  930. id = id + arr[i]['id'];
  931. } else {
  932. id = id + arr[i]['id'] + "_";
  933. }
  934. }
  935. var cur_sku_arr = options.sku_mu_list[id];
  936. that.setData({
  937. sku: arr,
  938. sku_val: 1,
  939. cur_sku_arr: cur_sku_arr,
  940. skuList: e.skuList,
  941. visible: true,
  942. showSku: true
  943. });
  944. } else {
  945. let goodsInfo = e.allData;
  946. that.setData({
  947. sku: [],
  948. sku_val: 1,
  949. skuList: [],
  950. cur_sku_arr: goodsInfo
  951. })
  952. let formIds = {
  953. detail: {
  954. formId: ""
  955. }
  956. };
  957. formIds.detail.formId = "the formId is a mock one";
  958. that.gocarfrom(formIds);
  959. //todo...addcart
  960. }
  961. },
  962. focus: function() {
  963. this.data.focusFlag = true;
  964. },
  965. canBuyFn: function(a, e) {
  966. var u = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {},
  967. i = this.data.skuList[e].canBuyNum - a,
  968. s = {
  969. value: a
  970. };
  971. i <= 10 && (s.canBuyMsg = "还可以购买 " + i + " 件"), this.data.canBuyMsg && i > 10 && (s.canBuyMsg = ""),
  972. this.setData(t({}, s, u));
  973. },
  974. changeNumber: function(t) {
  975. var a = t.detail;
  976. this.data.focusFlag = false, a && this.canBuyFn(a.value, this.data.current);
  977. },
  978. goOrder: function() {
  979. var that = this;
  980. if (that.data.can_car) {
  981. that.data.can_car = false;
  982. }
  983. var token = wx.getStorageSync('token');
  984. var community = wx.getStorageSync('community');
  985. var goods_id = that.data.addCar_goodsid;
  986. var community_id = community.communityId;
  987. var quantity = that.data.sku_val;
  988. var cur_sku_arr = that.data.cur_sku_arr;
  989. var sku_str = '';
  990. var is_just_addcar = 1;
  991. if (cur_sku_arr && cur_sku_arr.option_item_ids) {
  992. sku_str = cur_sku_arr.option_item_ids;
  993. }
  994. //addCar_goodsid: goods_id
  995. app.util.request({
  996. 'url': 'entry/wxapp/user',
  997. 'data': {
  998. controller: 'car.add',
  999. 'token': token,
  1000. "goods_id": goods_id,
  1001. "community_id": community_id,
  1002. "quantity": quantity,
  1003. "sku_str": sku_str,
  1004. "buy_type": 'dan',
  1005. "pin_id": 0,
  1006. "is_just_addcar": is_just_addcar
  1007. },
  1008. dataType: 'json',
  1009. method: 'POST',
  1010. success: function(res) {
  1011. //console.log(res);
  1012. if (res.data.code == 3) {
  1013. wx.showToast({
  1014. title: res.data.msg,
  1015. icon: 'none',
  1016. duration: 2000
  1017. })
  1018. } else if (res.data.code == 4) {
  1019. wx.showToast({
  1020. title: '您未登录',
  1021. duration: 2000,
  1022. success: () => {
  1023. that.setData({ needAuth: true })
  1024. }
  1025. })
  1026. } else if (res.data.code == 6) {
  1027. let max_quantity = res.data.max_quantity || '';
  1028. (max_quantity > 0) && that.setData({ sku_val: max_quantity })
  1029. var msg = res.data.msg;
  1030. wx.showToast({
  1031. title: msg,
  1032. icon: 'none',
  1033. duration: 2000
  1034. })
  1035. } else {
  1036. if (is_just_addcar == 1) {
  1037. that.closeSku();
  1038. (0, status.cartNum)(res.data.total);
  1039. that.setData({ cartNum: res.data.total })
  1040. wx.showToast({
  1041. title: "已加入购物车",
  1042. image: "../../images/addShopCart.png"
  1043. })
  1044. } else {
  1045. var pages_all = getCurrentPages();
  1046. if (pages_all.length > 3) {
  1047. wx.redirectTo({
  1048. url: '/lionfish_comshop/pages/buy/index?type=' + that.data.order.buy_type
  1049. })
  1050. } else {
  1051. wx.navigateTo({
  1052. url: '/lionfish_comshop/pages/buy/index?type=' + that.data.order.buy_type
  1053. })
  1054. }
  1055. }
  1056. }
  1057. }
  1058. })
  1059. },
  1060. /**
  1061. * 确认加入购物车
  1062. */
  1063. gocarfrom: function(e) {
  1064. var that = this;
  1065. var is_just_addcar = 1;
  1066. wx.showLoading();
  1067. a.collectFormIds(e.detail.formId);
  1068. that.goOrder();
  1069. },
  1070. /**
  1071. * 关闭购物车选项卡
  1072. */
  1073. closeSku: function() {
  1074. this.setData({
  1075. visible: 0,
  1076. stopClick: false,
  1077. });
  1078. },
  1079. selectSku: function(event) {
  1080. var that = this;
  1081. let str = event.currentTarget.dataset.type;
  1082. let obj = str.split("_");
  1083. let arr = that.data.sku;
  1084. let temp = {
  1085. name: obj[3],
  1086. id: obj[2],
  1087. index: obj[0],
  1088. idx: obj[1]
  1089. };
  1090. arr.splice(obj[0], 1, temp);
  1091. that.setData({
  1092. sku: arr
  1093. })
  1094. var id = '';
  1095. for (let i = 0; i < arr.length; i++) {
  1096. if (i == arr.length - 1) {
  1097. id = id + arr[i]['id'];
  1098. } else {
  1099. id = id + arr[i]['id'] + "_";
  1100. }
  1101. }
  1102. var options = this.data.skuList;
  1103. var cur_sku_arr = options.sku_mu_list[id];
  1104. that.setData({
  1105. cur_sku_arr: cur_sku_arr
  1106. });
  1107. console.log(id);
  1108. },
  1109. /**
  1110. * 数量加减
  1111. */
  1112. setNum: function(event) {
  1113. let types = event.currentTarget.dataset.type;
  1114. var that = this;
  1115. var num = 1;
  1116. let sku_val = this.data.sku_val * 1;
  1117. if (types == 'add') {
  1118. num = sku_val + 1;
  1119. } else if (types == 'decrease') {
  1120. if (sku_val > 1) {
  1121. num = sku_val - 1;
  1122. }
  1123. }
  1124. let arr = that.data.sku;
  1125. var options = this.data.skuList;
  1126. if (arr.length > 0) {
  1127. var id = '';
  1128. for (let i = 0; i < arr.length; i++) {
  1129. if (i == arr.length - 1) {
  1130. id = id + arr[i]['id'];
  1131. } else {
  1132. id = id + arr[i]['id'] + "_";
  1133. }
  1134. }
  1135. }
  1136. if (options.length > 0) {
  1137. let cur_sku_arr = options.sku_mu_list[id];
  1138. if (num > cur_sku_arr['canBuyNum']) {
  1139. num = num - 1;
  1140. }
  1141. } else {
  1142. let cur_sku_arr = this.data.cur_sku_arr;
  1143. if (num > cur_sku_arr['canBuyNum']) {
  1144. num = num - 1;
  1145. }
  1146. }
  1147. this.setData({
  1148. sku_val: num
  1149. })
  1150. },
  1151. skuConfirm: function() {
  1152. this.closeSku(), (0, status.cartNum)().then((res) => {
  1153. res.code == 0 && that.setData({ cartNum: res.data })
  1154. });
  1155. },
  1156. /**
  1157. * 返回顶部
  1158. */
  1159. backTop: function() {
  1160. this.stickyFlag = false, wx.pageScrollTo({
  1161. scrollTop: 0
  1162. });
  1163. },
  1164. goLink: function(event) {
  1165. let url = event.currentTarget.dataset.link;
  1166. wx.redirectTo({
  1167. url: url
  1168. })
  1169. },
  1170. goGoods: function(goods_id) {
  1171. let id = goods_id;
  1172. if (!util.check_login()) {
  1173. util.login('/Snailfish_shop/pages/goods/index?id=' + id);
  1174. return false;
  1175. }
  1176. var pages_all = getCurrentPages();
  1177. if (pages_all.length > 3) {
  1178. wx.redirectTo({
  1179. url: '/Snailfish_shop/pages/goods/index?id=' + id
  1180. })
  1181. } else {
  1182. wx.navigateTo({
  1183. url: '/Snailfish_shop/pages/goods/index?id=' + id
  1184. })
  1185. }
  1186. },
  1187. /**
  1188. * 导航小图标
  1189. */
  1190. getNavigat: function(){
  1191. let that = this;
  1192. app.util.request({
  1193. 'url': 'entry/wxapp/index',
  1194. 'data': {
  1195. controller: 'index.get_navigat'
  1196. },
  1197. dataType: 'json',
  1198. success: function (res) {
  1199. if (res.data.code == 0) {
  1200. let navigat = res.data.data || []
  1201. that.setData({ navigat })
  1202. }
  1203. }
  1204. })
  1205. },
  1206. /**
  1207. * 导航图标跳转
  1208. */
  1209. goNavUrl: function(t) {
  1210. let idx = t.currentTarget.dataset.idx;
  1211. let navigat = this.data.navigat;
  1212. if (navigat.length > 0) {
  1213. let url = navigat[idx].link;
  1214. let type = navigat[idx].type;
  1215. if (type== 0){
  1216. // 跳转webview
  1217. wx.navigateTo({
  1218. url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url),
  1219. })
  1220. } else if (type==1) {
  1221. 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) {
  1222. wx.switchTab({ url: url })
  1223. } else {
  1224. wx.navigateTo({ url: url })
  1225. }
  1226. } else if (type==2){
  1227. // 跳转小程序
  1228. let appid = navigat[idx].appid;
  1229. appid && wx.navigateToMiniProgram({
  1230. appId: navigat[idx].appid,
  1231. path: url,
  1232. extraData: {},
  1233. envVersion: 'release',
  1234. success(res) {
  1235. // 打开成功
  1236. },
  1237. fail(error) {
  1238. console.log(error)
  1239. }
  1240. })
  1241. } else if (type == 3){
  1242. //首页分类
  1243. // t.detail.e 选中索引
  1244. // t.detail.a 选中id
  1245. let classification = this.data.classification;
  1246. let tabs = classification && classification.tabs;
  1247. let cid = url;
  1248. let activeIdx = tabs.findIndex((p) => { return p.id == cid });
  1249. if (activeIdx!=-1) {
  1250. let cateInfo = {
  1251. detail: { e: activeIdx, a: cid }
  1252. };
  1253. this.classificationChange(cateInfo);
  1254. }
  1255. } else if (type == 4) {
  1256. //独立分类
  1257. app.globalData.typeCateId = url;
  1258. wx.switchTab({
  1259. url: '/lionfish_comshop/pages/type/index'
  1260. })
  1261. }
  1262. }
  1263. },
  1264. /**
  1265. * 幻灯片跳转
  1266. */
  1267. goBannerUrl: function (t) {
  1268. let idx = t.currentTarget.dataset.idx;
  1269. let slider_list = this.data.slider_list;
  1270. if (slider_list.length > 0) {
  1271. let url = slider_list[idx].link;
  1272. let type = slider_list[idx].linktype;
  1273. if (type == 0) {
  1274. // 跳转webview
  1275. url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) })
  1276. } else if (type == 1) {
  1277. 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) {
  1278. url && wx.switchTab({ url: url })
  1279. } else {
  1280. url && wx.navigateTo({ url: url })
  1281. }
  1282. } else if (type == 2) {
  1283. // 跳转小程序
  1284. let appid = slider_list[idx].appid;
  1285. appid && wx.navigateToMiniProgram({
  1286. appId: slider_list[idx].appid,
  1287. path: url,
  1288. extraData: {},
  1289. envVersion: 'release',
  1290. success(res) {
  1291. // 打开成功
  1292. },
  1293. fail(error) {
  1294. console.log(error)
  1295. }
  1296. })
  1297. }
  1298. }
  1299. },
  1300. /**
  1301. * 页面相关事件处理函数--监听用户下拉动作
  1302. */
  1303. onPullDownRefresh: function () {
  1304. this.setData({ couponRefresh: false, newComerRefresh: false });
  1305. this.tpage = 1;
  1306. this.$data = {
  1307. ...this.$data, ...{
  1308. overPageNum: 1,
  1309. loadOver: false,
  1310. hasOverGoods: false,
  1311. countDownMap: {},
  1312. actEndMap: {},
  1313. timer: {},
  1314. stickyFlag: false,
  1315. hasCommingGoods: true
  1316. }
  1317. }
  1318. this.hasRefeshin = false;
  1319. this.setData({
  1320. rushList: [],
  1321. commingList: [],
  1322. tabIdx: 0,
  1323. pageNum: 1,
  1324. couponRefresh: true,
  1325. newComerRefresh: true
  1326. }, ()=>{
  1327. this.loadPage();
  1328. })
  1329. wx.stopPullDownRefresh();
  1330. console.log(111)
  1331. },
  1332. onReachBottom: function(e) {
  1333. if (this.data.tabIdx==0){
  1334. this.load_goods_data();
  1335. } else {
  1336. this.getCommingList();
  1337. }
  1338. },
  1339. /**
  1340. * 获取团长位置
  1341. */
  1342. getCommunityPos: function (community_id){
  1343. let that = this;
  1344. app.util.request({
  1345. 'url': 'entry/wxapp/user',
  1346. 'data': {
  1347. controller: 'index.get_community_position',
  1348. communityId: community_id
  1349. },
  1350. dataType: 'json',
  1351. method: 'POST',
  1352. success: function (res) {
  1353. if (res.data.code == 0) {
  1354. that.postion = res.data.postion;
  1355. }
  1356. }
  1357. })
  1358. },
  1359. /**
  1360. * 查看地图
  1361. */
  1362. gotoMap: function () {
  1363. let community = this.data.community;
  1364. let postion = this.postion || {lat: 0, lon: 0};
  1365. let longitude = parseFloat(postion.lon),
  1366. latitude = parseFloat(postion.lat),
  1367. name = community.disUserName,
  1368. address = `${community.fullAddress}(${community.communityName})`;
  1369. wx.openLocation({
  1370. latitude: latitude,
  1371. longitude: longitude,
  1372. name: name,
  1373. address: address,
  1374. scale: 28
  1375. })
  1376. },
  1377. share_handler: function () {
  1378. this.setData({
  1379. is_share_html: false
  1380. })
  1381. },
  1382. hide_share_handler: function () {
  1383. this.setData({
  1384. is_share_html: true
  1385. })
  1386. },
  1387. // 搜索
  1388. goResult: function (e) {
  1389. let keyword = e.detail.value.replace(/\s+/g, '');
  1390. if (!keyword) {
  1391. wx.showToast({
  1392. title: '请输入关键词',
  1393. icon: 'none'
  1394. })
  1395. return;
  1396. }
  1397. wx.navigateTo({
  1398. url: '/lionfish_comshop/pages/type/result?keyword=' + keyword,
  1399. })
  1400. },
  1401. /**
  1402. * 新人优惠券显示开关
  1403. */
  1404. toggleCoupon: function(){
  1405. this.setData({
  1406. showNewCoupon: !this.data.showNewCoupon
  1407. })
  1408. },
  1409. changeCartNum: function(t) {
  1410. let that = this;
  1411. let e = t.detail;
  1412. (0, status.cartNum)(that.setData({ cartNum: e }));
  1413. },
  1414. /**
  1415. * 一键复制文本
  1416. */
  1417. copyText: function (e) {
  1418. let copy_text_arr = this.data.copy_text_arr;
  1419. let community = this.data.community;
  1420. let communityName = community.communityName;
  1421. let disUserName = community.disUserName;
  1422. let communityAddress = community.address || community.communityAddress || community.fullAddress;
  1423. let data = '-团长信息-\r\n小区:' + communityName + '\r\n团长:' + disUserName + '\r\n自提点:' + communityAddress + '\r\n\r\n今日推荐\r\n';
  1424. if (copy_text_arr.length) {
  1425. copy_text_arr.forEach(function(item, index){
  1426. data += (index + 1) + '.【' + item.goods_name + '】 团购价' + item.price + '\r\n';
  1427. data += '~~~~~~~~~~~~~~~~~~~~\r\n';
  1428. })
  1429. }
  1430. let that = this;
  1431. wx.setClipboardData({
  1432. data: data,
  1433. success: function (res) {
  1434. wx.getClipboardData({
  1435. success: function (res) {
  1436. that.setData({ showCopyText: false })
  1437. wx.showToast({
  1438. title: '复制成功'
  1439. })
  1440. }
  1441. })
  1442. }
  1443. })
  1444. },
  1445. /**
  1446. * 显示关闭复制文本
  1447. */
  1448. showCopyTextHandle: function(e){
  1449. let showCopyText = e.currentTarget.dataset.status;
  1450. this.setData({ showCopyText })
  1451. },
  1452. onShareAppMessage: function(res) {
  1453. this.setData({ is_share_html: true });
  1454. var community = wx.getStorageSync('community');
  1455. var community_id = community.communityId;
  1456. var member_id = wx.getStorageSync('member_id');
  1457. console.log('首页分享地址:');
  1458. console.log(community_id, member_id);
  1459. return {
  1460. title: this.data.shop_info.title,
  1461. path: "lionfish_comshop/pages/index/index?community_id=" + community_id + '&share_id=' + member_id,
  1462. imageUrl: this.data.shop_info.shop_index_share_image,
  1463. success: function() {},
  1464. fail: function() {}
  1465. };
  1466. }
  1467. }))