index.js 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. import tool from "../../../utils/tool.js";
  2. import volunteer from "../../../pages/data/volunteer.js";
  3. import growth from "../../../pages/data/growth.js";
  4. var app = getApp();
  5. var util = require("../../../utils/util.js");
  6. var QQMapWX = require("../../../utils/qqmap-wx-jssdk.js");
  7. var map;
  8. map = new QQMapWX({
  9. key: "RA3BZ-PSGW4-GZUUX-DDAU7-6B54E-KJFQ7", // 必填
  10. });
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. appAssetsUrl: app.appAssetsUrl,
  17. appAssetsUrl2: app.appAssetsUrl2,
  18. appAssetsUrl3: app.appAssetsUrl3,
  19. nodata: util.nodata(),
  20. indicatorData: true,
  21. autoplay: true,
  22. interval: 3000,
  23. circular: true,
  24. autostop: false,
  25. params: {
  26. pageNum: 1,
  27. pageSize: 10,
  28. city: "",
  29. area: "",
  30. type: 1, //1推荐 2最新 3最热
  31. },
  32. total: {
  33. currPage: 0,
  34. totalPage: 0,
  35. },
  36. noMore: false,
  37. statusBarHeightTop: 0,
  38. statusBarHeight: 0,
  39. nameIndex: 0,
  40. nameList: [{
  41. name: "推荐兼职",
  42. },
  43. {
  44. name: "最新兼职",
  45. },
  46. {
  47. name: "最热兼职",
  48. },
  49. ],
  50. classList: [{
  51. // image: app.appAssetsUrl2 + "wjxy/homejianzhi.png",
  52. // image: app.appAssetsUrl2 + "new/job-icon.png",
  53. image: app.appAssetsUrl3 + 'home/icon_1.png',
  54. name: "勤工俭学",
  55. },
  56. {
  57. // image: app.appAssetsUrl2 + "wjxy/homeactive.png",
  58. // image: app.appAssetsUrl2 + "new/activity-icon.png",
  59. image: app.appAssetsUrl3 + 'home/icon_2.png',
  60. name: "热门活动",
  61. },
  62. {
  63. // image: app.appAssetsUrl2 + "wjxy/homeshen.png",
  64. image: app.appAssetsUrl3 + 'home/icon_3.png',
  65. name: "青雲问鼎",
  66. },
  67. // {
  68. // // image: app.appAssetsUrl2 + "wjxy/homevip.png",
  69. // image: app.appAssetsUrl2 + "new/goods-icon.png",
  70. // name: "市集优选",
  71. // },
  72. {
  73. // image: app.appAssetsUrl2 + "wjxy/homevip.png",
  74. // image: app.appAssetsUrl2 + "new/member-icon.png",
  75. image: app.appAssetsUrl3 + 'home/icon_4.png',
  76. name: "联名福利",
  77. },
  78. // {
  79. // image: app.appAssetsUrl2 + "wjxy/homecode.png",
  80. // name: "邀请码",
  81. // },
  82. ],
  83. cityList: [],
  84. cityListPickerData: [],
  85. cityListIndex: [],
  86. listData: [],
  87. imglist: [],
  88. currentCity: {},
  89. current: 0,
  90. maskShow: false,
  91. activeList: [],
  92. jobList: [],
  93. perList: [],
  94. expertList: [],
  95. shopObj: {},
  96. popupImg: "",
  97. latitude: "",
  98. longitude: "",
  99. goodsClassfiyList: [],
  100. goodsList0: [],
  101. goodsList1: [],
  102. shopList: [],
  103. activeTitle: false
  104. },
  105. moreHandler() {
  106. this.experience();
  107. },
  108. selectCity(e) {
  109. wx.navigateTo({
  110. url: "/pages/home/location/index",
  111. });
  112. },
  113. experience(e) {
  114. // console.log(e, 11111111);
  115. if (
  116. e.currentTarget.dataset.index == 4 ||
  117. e.currentTarget.dataset.index == 3
  118. ) {
  119. // if (wx.getStorageSync("USER")) {
  120. const obj = this.data.goodsClassfiyList.find(v => v.name == '联名福利') || '';
  121. // console.log(obj);
  122. wx.setStorageSync('classfiyId', obj ? obj.id : '')
  123. wx.navigateTo({
  124. url: e.currentTarget.dataset.index == 4 ?
  125. "/invitationCode/index" : `/pages/quality/index/index`,
  126. });
  127. // } else {
  128. // wx.navigateTo({
  129. // url: "/pages/login",
  130. // });
  131. // }
  132. } else {
  133. app.params.pePageToIndex =
  134. e === undefined ? 0 : e.currentTarget.dataset.index + 1;
  135. switch (e.currentTarget.dataset.index) {
  136. case 0:
  137. wx.switchTab({
  138. url: "/pages/practicalExperience/practicalExperience",
  139. });
  140. break;
  141. case 1:
  142. wx.navigateTo({
  143. url: "/pages/experience/index/index",
  144. });
  145. break;
  146. case 2:
  147. wx.switchTab({
  148. url: "/pages/dashen/index",
  149. // url: "/pages/quality/index/index",
  150. });
  151. break;
  152. case 3:
  153. wx.navigateTo({
  154. url: "/pages/myMember/myMember",
  155. });
  156. break;
  157. default:
  158. wx.navigateTo({
  159. url: "/invitationCode/index",
  160. });
  161. }
  162. }
  163. },
  164. // 热门活动
  165. hotActive() {
  166. let nowCity = wx.getStorageSync("CHOOSECITY");
  167. let that = this;
  168. app._post_form(
  169. "act/list",
  170. "", {
  171. city: nowCity.cityId,
  172. limit: 10,
  173. page: 1,
  174. isFrontPage: 1,
  175. },
  176. function (res) {
  177. if (res.code == 0) {
  178. res.page.list.map((v) => {
  179. v.startTime = v.startTime.replace(/-/g, ".").split(" ")[0];
  180. v.endTime = v.endTime.replace(/-/g, ".").split(" ")[0];
  181. });
  182. that.setData({
  183. activeList: res.page.list,
  184. });
  185. }
  186. },
  187. function (res) { }
  188. );
  189. },
  190. // 最新兼职
  191. newJob() {
  192. let nowCity = wx.getStorageSync("CHOOSECITY");
  193. console.log(nowCity);
  194. let that = this;
  195. app._post_form(
  196. "home/label",
  197. "", {
  198. city: nowCity.cityId,
  199. pageNum: 1,
  200. isHome: 1,
  201. pageSize: 4,
  202. },
  203. function (res) {
  204. if (res.code == 0) {
  205. that.setData({
  206. jobList: res.page.list,
  207. });
  208. }
  209. },
  210. function (res) { }
  211. );
  212. },
  213. // 校园代理人
  214. schoolPer() {
  215. let that = this;
  216. app._get(
  217. `campusagent/page`, {
  218. page: 1,
  219. limit: 10,
  220. },
  221. (res) => {
  222. if (res.code === 0) {
  223. that.setData({
  224. perList: res.page.list,
  225. });
  226. }
  227. }
  228. );
  229. },
  230. // 推荐行家
  231. getExpert() {
  232. let that = this;
  233. let nowCity = wx.getStorageSync("CHOOSECITY");
  234. app._get(
  235. "expert/greatGodGangPage", {
  236. page: 1,
  237. limit: 10,
  238. city: nowCity.cityId,
  239. },
  240. function (res) {
  241. if (res.code == 0) {
  242. that.setData({
  243. expertList: res.page.list,
  244. });
  245. }
  246. }
  247. );
  248. },
  249. // 门店推荐
  250. getShop() {
  251. let that = this;
  252. let nowCity = wx.getStorageSync("CHOOSECITY");
  253. app._get(
  254. "store/storeRecommendation", {
  255. lon: that.data.longitude,
  256. lat: that.data.latitude,
  257. },
  258. function (res) {
  259. if (res.code == 0 && res.data) {
  260. let val = res.data.calculateNew / 1000;
  261. let formatVal = parseInt(val * 10);
  262. that.setData({
  263. shopObj: res.data,
  264. "shopObj.calculateNew": formatVal / 10,
  265. "shopObj.storePhoto": res.data.storePhoto.split(",")[0],
  266. });
  267. }
  268. }
  269. );
  270. },
  271. // 查看门店详情
  272. goStore(e) {
  273. console.log(e, 111);
  274. let that = this;
  275. wx.navigateTo({
  276. url: "/expert/storedetail/storedetail?id=" +
  277. that.data.shopObj.id +
  278. "&lon=" +
  279. that.data.longitude +
  280. "&lat=" +
  281. that.data.latitude,
  282. });
  283. },
  284. // 查看地图
  285. goLocal() {
  286. let that = this;
  287. let [latitude, longitude] = [
  288. this.data.shopObj.coordinate.split(",")[0],
  289. this.data.shopObj.coordinate.split(",")[1],
  290. ];
  291. console.log(Number(latitude), Number(longitude));
  292. wx.openLocation({
  293. latitude: Number(longitude),
  294. longitude: Number(latitude),
  295. name: that.data.shopObj.name,
  296. address: that.data.shopObj.address,
  297. success: function () {
  298. console.log("success");
  299. },
  300. });
  301. },
  302. callPhone() {
  303. let that = this;
  304. wx.makePhoneCall({
  305. phoneNumber: that.data.shopObj.phone,
  306. });
  307. },
  308. // 开屏弹窗
  309. openPopup() {
  310. app._get("openscreenpopup/openScreenPopup", {}, (res) => {
  311. if (res.code == 0 && res.data) {
  312. let maskShow = false;
  313. if (wx.getStorageSync("popId") != res.data.id) {
  314. wx.setStorageSync("popId", res.data.id);
  315. maskShow = true;
  316. }
  317. this.setData({
  318. popupImg: res.data.popUpPicture,
  319. maskShow: maskShow,
  320. });
  321. }
  322. });
  323. },
  324. // 兼职详情
  325. toPartDetail(e) {
  326. wx.navigateTo({
  327. url: `/pages/home/index/partDetail/partDetail?id=${e.currentTarget.dataset.id}`,
  328. });
  329. },
  330. // 校园代理人详情
  331. perDetail(e) {
  332. // console.log(e)
  333. wx.navigateTo({
  334. url: "/expert/agentdetail/agentdetail?id=" +
  335. e.currentTarget.dataset.id +
  336. "&type=校园代理人",
  337. });
  338. },
  339. // 行家详情
  340. toExpertDetail(e) {
  341. wx.navigateTo({
  342. url: `/expert/detail/detail?id=${e.currentTarget.dataset.id}`,
  343. });
  344. },
  345. onBindFocus: function (e) {
  346. let _this = this;
  347. wx.navigateTo({
  348. url: "/pages/search/index",
  349. });
  350. },
  351. closePopup() {
  352. this.setData({
  353. maskShow: false,
  354. });
  355. },
  356. nameHandler(e) {
  357. this.setData({
  358. nameIndex: e.target.dataset.index,
  359. });
  360. this.loadList(true);
  361. },
  362. growthMore: function (event) {
  363. wx.navigateTo({
  364. url: "/pages/home/index/growth/growthMore/growthMore",
  365. });
  366. },
  367. activitymore: function (event) {
  368. wx.reLaunch({
  369. url: "/pages/experience/index/index?type=1",
  370. });
  371. },
  372. onReady: function () {
  373. this.popup2 = this.selectComponent("#popup2");
  374. // this.setData({
  375. // maskShow: true
  376. // })
  377. },
  378. onLoad: function (options) {
  379. console.log("options", options);
  380. if (!options.cityId) {
  381. this.loadCity();
  382. }
  383. this.height();
  384. if (wx.getStorageSync("USER")) {
  385. this.PushVipInfo();
  386. }
  387. let _this = this;
  388. _this.data.option = options;
  389. setTimeout(function () {
  390. _this.loadDictionary();
  391. }, 100);
  392. _this.addScore();
  393. if (options.cityId) {
  394. _this.loadImg();
  395. let cityData = {
  396. cityName: options.cityName,
  397. cityId: options.cityId
  398. };
  399. wx.setStorageSync("CHOOSECITY", cityData);
  400. this.setData({
  401. currentCity: cityData,
  402. }, () => {
  403. console.log("currentCity", this.data.currentCity)
  404. //设置城市选择数据
  405. this.loadList(true)
  406. _this.hotActive();
  407. _this.newJob();
  408. _this.schoolPer();
  409. _this.getExpert();
  410. _this.getShop();
  411. _this.getGoodsClassfiy();
  412. _this.getShopList();
  413. });
  414. } else {
  415. _this.getLocal();
  416. }
  417. _this.getAgree()
  418. },
  419. toPrivacy() {
  420. wx.openPrivacyContract({
  421. success: () => { }, // 打开成功
  422. fail: () => { }, // 打开失败
  423. complete: () => { }
  424. })
  425. // wx.navigateTo({
  426. // url: "/pages/privacy/privacy",
  427. // });
  428. },
  429. closeAgree() {
  430. this.popup2.hidePopup();
  431. },
  432. handleAgreePrivacyAuthorization() {
  433. this.getLocal();
  434. this.popup2.hidePopup();
  435. },
  436. getAgree() {
  437. wx.getPrivacySetting({
  438. success: res => {
  439. // console.log(res, 3333) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  440. if (res.needAuthorization) {
  441. this.popup2.showPopup();
  442. // 需要弹出隐私协议
  443. } else {
  444. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  445. // wx.getUserProfile()
  446. // wx.chooseMedia()
  447. // wx.getClipboardData()
  448. // wx.startRecord()
  449. }
  450. },
  451. fail: () => { },
  452. complete: () => { }
  453. })
  454. },
  455. onShow() {
  456. this.openPopup();
  457. },
  458. //获取城市信息
  459. getLocal() {
  460. const _this = this;
  461. wx.getFuzzyLocation({
  462. type: "gcj02",
  463. isHighAccuracy: true,
  464. success(res) {
  465. console.log("经纬度", res);
  466. const latitude = res.latitude;
  467. const longitude = res.longitude;
  468. _this.setData({
  469. latitude: res.latitude,
  470. longitude: res.longitude,
  471. });
  472. //通过【小程序定位】获取经纬度,在通过第三方sdk获取的地址信息
  473. _this.pointToAddress(latitude, longitude, function (address) {
  474. if (address) {
  475. wx.setStorageSync("CHOOSECITY", {
  476. cityName: address.city,
  477. areaName: address.district,
  478. });
  479. _this.loadCity();
  480. }
  481. });
  482. console.log("111");
  483. },
  484. fail(e) {
  485. console.log(e);
  486. _this.loadCity();
  487. },
  488. });
  489. },
  490. // 定义 pointToAddress 方法
  491. pointToAddress: function (latitude, longitude, callback) {
  492. var _this = this;
  493. // 调用接口
  494. map.reverseGeocoder({
  495. location: {
  496. latitude: latitude,
  497. longitude: longitude,
  498. },
  499. success: function (res) {
  500. // 解析成功返回地址
  501. callback(res.result.ad_info);
  502. },
  503. fail: function (res) {
  504. // console.log(res);
  505. },
  506. complete: function (res) { },
  507. });
  508. },
  509. //统计积分(每日登录)
  510. addScore: function () {
  511. if (!util.getUserId()) {
  512. return;
  513. }
  514. wx.showLoading({
  515. title: "努力加载中...",
  516. });
  517. app._post_form(
  518. "scoreStu/dailyLogin",
  519. "", {
  520. stuId: util.getUserId(),
  521. },
  522. function (res) {
  523. if (res.code === 0) { }
  524. }
  525. );
  526. },
  527. // 首页banner
  528. loadImg: function () {
  529. let _this = this;
  530. let nowCity = wx.getStorageSync("CHOOSECITY");
  531. let params = {
  532. type: "01",
  533. area: "",
  534. };
  535. app._post_form("img/mylist", "application/json", params, function (res) {
  536. if (res.code == 0) {
  537. _this.setData({
  538. imglist: res.data,
  539. });
  540. }
  541. });
  542. },
  543. //banner跳转
  544. imgJump(v) {
  545. console.log(v);
  546. console.log(v.currentTarget.dataset.item.jumpAddressType);
  547. if (v.currentTarget.dataset.item.jumpAddressType == 0) {
  548. //内部跳转
  549. wx.navigateTo({
  550. url: v.currentTarget.dataset.item.linkUrl,
  551. });
  552. } else if (v.currentTarget.dataset.item.jumpAddressType == 1) {
  553. //公众号跳转 'https://www.kujiale.cn/design/3FO4EQWQJF0M/show'
  554. wx.setStorageSync("gzurl", v.currentTarget.dataset.item.linkUrl);
  555. wx.navigateTo({
  556. url: "./gz/gz",
  557. });
  558. }
  559. },
  560. more(e) {
  561. console.log(e);
  562. if (e.currentTarget.dataset.type == "tab") {
  563. wx.switchTab({
  564. url: e.currentTarget.dataset.url,
  565. });
  566. } else {
  567. wx.navigateTo({
  568. url: e.currentTarget.dataset.url,
  569. });
  570. }
  571. },
  572. popupDetail() {
  573. this.setData({
  574. maskShow: false,
  575. });
  576. wx.navigateTo({
  577. url: "/expert/popupdetail/popupdetail",
  578. });
  579. },
  580. changeSwiper(e) {
  581. let {
  582. current,
  583. source
  584. } = e.detail;
  585. if (source === "autoplay" || source === "touch") {
  586. this.setData({
  587. current: current,
  588. });
  589. }
  590. // this.setData({
  591. // current: e.detail.current
  592. // })
  593. },
  594. loadCity: function () {
  595. let _this = this;
  596. app._post_form("serviceCityList", "", null, function (res) {
  597. if (res.data.length) {
  598. //设置城市选择的数据
  599. let cityData = {
  600. cityName: "",
  601. cityId: "",
  602. // areaName: '',
  603. // areaId: ''
  604. };
  605. // console.log(res.data);
  606. //设置城市下拉框数据
  607. let cityListPickerData = res.data;
  608. let cityListIndex = [];
  609. //nowCity是之前首页的城市选择下拉框的数据
  610. let nowCity = wx.getStorageSync("CHOOSECITY");
  611. if (nowCity) {
  612. a: for (let i = 0; i < res.data.length; i++) {
  613. let cityName = res.data[i].name;
  614. if (nowCity.cityName === cityName) {
  615. cityData.cityName = res.data[i].name;
  616. cityData.cityId = res.data[i].cityId;
  617. cityListIndex.push(i);
  618. }
  619. }
  620. if (cityListIndex.length == 0) {
  621. cityData.cityName = res.data[0].name;
  622. cityData.cityId = res.data[0].cityId;
  623. cityListIndex.push(0);
  624. }
  625. }
  626. else {
  627. cityData.cityName = res.data[0].name;
  628. cityData.cityId = res.data[0].cityId;
  629. cityListIndex = [0, 0];
  630. }
  631. //设置城市选择数据
  632. wx.setStorageSync("CHOOSECITY", cityData);
  633. //设置城市下拉框数据
  634. _this.setData({
  635. cityList: res.data,
  636. cityListPickerData,
  637. cityListIndex,
  638. currentCity: cityData,
  639. });
  640. // console.log(_this.data.cityListPickerData);
  641. setTimeout(function () {
  642. _this.loadImg();
  643. _this.hotActive();
  644. _this.newJob();
  645. _this.schoolPer();
  646. _this.getExpert();
  647. _this.getShop();
  648. _this.getGoodsClassfiy();
  649. _this.getShopList();
  650. // _this.loadList(true);
  651. }, 300);
  652. }
  653. });
  654. },
  655. // 查看活动详情
  656. activeDetail: function (e) {
  657. if (e.currentTarget.dataset.id) {
  658. wx.navigateTo({
  659. url: "/pages/home/index/activityDetail/activityDetail?id=" +
  660. e.currentTarget.dataset.id,
  661. });
  662. }
  663. },
  664. // 自定义高度处理
  665. height() {
  666. const {
  667. platform,
  668. statusBarHeight
  669. } = wx.getSystemInfoSync();
  670. // console.log("statusBarHeight======", statusBarHeight);
  671. let statusBarHeightTop = statusBarHeight;
  672. let height = statusBarHeight + 4; //ios 24px
  673. let mH = statusBarHeight + 4;
  674. if (platform.toLowerCase() == "android") {
  675. height += 4; //android 28px
  676. mH += 4;
  677. }
  678. height = height + 100;
  679. // height = height + 38 + 118;
  680. // 胶囊高度 32px 下边框6px height 状态栏高度
  681. let then = this
  682. this.setData({
  683. statusBarHeightTop: statusBarHeightTop + "px",
  684. statusBarHeight: statusBarHeight + 88 + "px",
  685. statusBarMH: mH + "px",
  686. }, res => {
  687. // console.log("加载完成======", height);
  688. // 创建选择器查询
  689. // const query = wx.createSelectorQuery();
  690. // console.log("query======", query);
  691. // 选择 id 为 diy-top 的节点
  692. wx.createSelectorQuery().in(this).select('#diy-top').boundingClientRect(rect => {
  693. // console.log("rect===", rect) //这 里有值
  694. then.setData({
  695. statusBarHeight: rect.height + "px"
  696. })
  697. }).exec();
  698. });
  699. },
  700. loadDictionary() {
  701. let _this = this;
  702. app._post_form(
  703. "bizcatelog/apiSelectBizcatelog/workUnit",
  704. "",
  705. null,
  706. function (res) {
  707. _this.setData(res);
  708. }
  709. );
  710. },
  711. PushVipInfo() {
  712. let _this = this;
  713. let id = util.getUserId();
  714. let parm = {
  715. id,
  716. };
  717. app._post_form(
  718. "member/apiSelectMeberInfo",
  719. "application/json",
  720. JSON.stringify(parm),
  721. function (res) {
  722. if (res.code === 0) {
  723. wx.setStorageSync("USER", res.member);
  724. } else {
  725. // wx.removeStorageSync("USER");
  726. wx.clearStorage();
  727. // wx.reLaunch({
  728. // url: '/pages/login',
  729. // })
  730. wx.switchTab({
  731. url: "/pages/my/index/index",
  732. });
  733. }
  734. }
  735. );
  736. },
  737. // 获取商品分类
  738. getGoodsClassfiy() {
  739. app._get("goodscategory/select", {}, (res) => {
  740. if (res.code == 0) {
  741. // const arr = res.list.splice(0, 2);
  742. this.setData({
  743. goodsClassfiyList: res.list,
  744. });
  745. if (this.data.goodsClassfiyList[0]) {
  746. // this.getGoodsList0(this.data.goodsClassfiyList[0].id);
  747. }
  748. const obj = res.list.find(v => v.name == '联名福利') || '';
  749. // console.log(obj);
  750. if (!obj) return
  751. this.getGoodsList1(obj.id);
  752. }
  753. });
  754. },
  755. getGoodsList0(categoryId, i) {
  756. app._get(
  757. "goods/page", {
  758. pageSize: 1,
  759. pageNum: 1,
  760. categoryId: categoryId,
  761. },
  762. (res) => {
  763. if (res.code == 0) {
  764. this.setData({
  765. goodsList0: res.page.list || [],
  766. });
  767. }
  768. }
  769. );
  770. },
  771. getGoodsList1(categoryId) {
  772. app._get(
  773. "goods/page", {
  774. pageSize: 3,
  775. pageNum: 1,
  776. categoryId: categoryId,
  777. },
  778. (res) => {
  779. if (res.code == 0) {
  780. this.setData({
  781. goodsList1: res.page.list || [],
  782. });
  783. }
  784. }
  785. );
  786. },
  787. toGoodsList(e) {
  788. let name = e.currentTarget.dataset.name;
  789. const obj = this.data.goodsClassfiyList.find(v => v.name == name) || '';
  790. // console.log(obj);
  791. wx.setStorageSync('classfiyId', obj ? obj.id : '')
  792. wx.navigateTo({
  793. url: `/pages/quality/index/index`,
  794. });
  795. },
  796. goodsDetail(e) {
  797. wx.navigateTo({
  798. url: `/pages/quality/detail/index?id=${e.currentTarget.dataset.id}`,
  799. });
  800. },
  801. getShopList() {
  802. let nowCity = wx.getStorageSync("CHOOSECITY");
  803. app._get(
  804. "store/list", {
  805. lon: this.data.longitude,
  806. lat: this.data.latitude,
  807. limit: 2,
  808. },
  809. (res) => {
  810. if (res.code == 0) {
  811. this.setData({
  812. shopList: res.list || [],
  813. });
  814. }
  815. }
  816. );
  817. },
  818. // tanslateM(value) {
  819. // let val = value > 1000 ? (value / 1000).toFixed(2) + "KM" : value + "M";
  820. // return val;
  821. // },
  822. // 查看地图
  823. goLocalNew(e) {
  824. let that = this;
  825. let [latitude, longitude] = [
  826. this.data.shopObj.coordinate.split(",")[0],
  827. this.data.shopObj.coordinate.split(",")[1],
  828. ];
  829. console.log(Number(latitude), Number(longitude));
  830. wx.openLocation({
  831. latitude: Number(longitude),
  832. longitude: Number(latitude),
  833. name: e.currentTarget.dataset.name,
  834. address: e.currentTarget.dataset.address,
  835. success: function () {
  836. console.log("success");
  837. },
  838. });
  839. },
  840. callPhoneNew(e) {
  841. let that = this;
  842. wx.makePhoneCall({
  843. phoneNumber: e.currentTarget.dataset.phone,
  844. });
  845. },
  846. // 查看门店详情
  847. goShopStore(e) {
  848. let that = this;
  849. wx.navigateTo({
  850. url: "/expert/storedetail/storedetail?id=" +
  851. e.currentTarget.dataset.id +
  852. "&lon=" +
  853. that.data.longitude +
  854. "&lat=" +
  855. that.data.latitude,
  856. });
  857. },
  858. /**
  859. * 页面相关事件处理函数--监听用户下拉动作
  860. */
  861. onPullDownRefresh: function () {
  862. var _this = this;
  863. //强制更新
  864. setTimeout(() => {
  865. _this.getLocal();
  866. }, 200);
  867. // 处理完成后,终止下拉刷新
  868. wx.stopPullDownRefresh();
  869. },
  870. /**
  871. * 页面上拉触底事件的处理函数
  872. */
  873. onReachBottom: function () {
  874. // this.loadList();
  875. },
  876. //重新选择城市
  877. cityPickerChange(e) {
  878. // console.log('e.detail.value===>', e.detail.value);
  879. let cityListIndex = e.detail.value;
  880. let cityData = {
  881. cityName: this.data.cityListPickerData[cityListIndex].name,
  882. cityId: this.data.cityListPickerData[cityListIndex].id,
  883. // areaName: this.data.cityList[cityListIndex[0]].childRegionList[cityListIndex[1]].name,
  884. // areaId: this.data.cityList[cityListIndex[0]].childRegionList[cityListIndex[1]].id,
  885. };
  886. // console.log('cityData===>', cityData);
  887. wx.setStorageSync("CHOOSECITY", cityData);
  888. this.setData({
  889. cityListIndex,
  890. currentCity: cityData,
  891. }, () => {
  892. //设置城市选择数据
  893. // this.loadList(true)
  894. this.hotActive();
  895. this.newJob();
  896. this.schoolPer();
  897. this.getExpert();
  898. this.getShop();
  899. this.getGoodsClassfiy();
  900. this.getShopList();
  901. });
  902. },
  903. cityPickerColumnChange(e) {
  904. if (e.detail.column == 0) {
  905. this.setData({
  906. cityListPickerData: [
  907. this.data.cityList,
  908. this.data.cityList[e.detail.value].childRegionList,
  909. ],
  910. });
  911. }
  912. },
  913. /**
  914. * @param {Object} isRefresh 是否刷新,否则就是下一页
  915. */
  916. loadList(isRefresh) {
  917. let that = this;
  918. if (!isRefresh && this.data.noMore) {
  919. wx.showToast({
  920. title: "没有更多了~",
  921. icon: "none",
  922. });
  923. return false;
  924. }
  925. let nowCity = wx.getStorageSync("CHOOSECITY");
  926. if (!nowCity || !nowCity.cityId) {
  927. return false;
  928. }
  929. this.setData({
  930. listData: isRefresh ? [] : this.data.listData,
  931. params: {
  932. ...this.data.params,
  933. pageNum: isRefresh ? 1 : this.data.params.pageNum + 1,
  934. city: nowCity.cityId,
  935. area: nowCity.areaId,
  936. type: this.data.nameIndex + 1,
  937. },
  938. noMore: isRefresh ? false : this.data.noMore,
  939. });
  940. wx.showLoading({
  941. title: "努力加载中...",
  942. });
  943. app._post_form(
  944. "home/mylist",
  945. "",
  946. this.data.params,
  947. function (res) {
  948. if (res.code == 0) {
  949. if (
  950. res.page.list.length > 0 &&
  951. that.data.listData.length > 0 &&
  952. res.page.list[0].id == that.data.listData[0].id
  953. ) {
  954. return;
  955. }
  956. let listData = that.data.listData;
  957. listData.push(...res.page.list);
  958. that.setData({
  959. listData,
  960. currPage: res.page.currPage,
  961. totalPage: res.page.totalPage,
  962. noMore: res.page.totalPage == res.page.currPage,
  963. });
  964. }
  965. },
  966. function (res) {
  967. wx.hideLoading();
  968. }
  969. );
  970. },
  971. onShareAppMessage: function () { },
  972. onPageScroll: function (e) {
  973. if (
  974. e.scrollTop >= 10 &&
  975. this.data.activeTitle == false
  976. ) {
  977. this.setData({
  978. activeTitle: true,
  979. });
  980. }
  981. if (
  982. e.scrollTop < 10 &&
  983. this.data.activeTitle == true
  984. ) {
  985. this.setData({
  986. activeTitle: false,
  987. });
  988. }
  989. },
  990. });