index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. nodata: util.nodata(),
  19. indicatorData: true,
  20. autoplay: true,
  21. interval: 3000,
  22. circular: true,
  23. autostop: false,
  24. params: {
  25. pageNum: 1,
  26. pageSize: 10,
  27. city: "",
  28. area: "",
  29. type: 1, //1推荐 2最新 3最热
  30. },
  31. total: {
  32. currPage: 0,
  33. totalPage: 0,
  34. },
  35. noMore: false,
  36. statusBarHeight: 0,
  37. nameIndex: 0,
  38. nameList: [
  39. {
  40. name: "推荐兼职",
  41. },
  42. {
  43. name: "最新兼职",
  44. },
  45. {
  46. name: "最热兼职",
  47. },
  48. ],
  49. classList: [
  50. {
  51. image: app.appAssetsUrl2 + "wjxy/homejianzhi.png",
  52. name: "精选兼职",
  53. },
  54. {
  55. image: app.appAssetsUrl2 + "wjxy/homeactive.png",
  56. name: "精选活动",
  57. },
  58. {
  59. image: app.appAssetsUrl2 + "wjxy/homeshen.png",
  60. name: "大神约见",
  61. },
  62. {
  63. image: app.appAssetsUrl2 + "wjxy/homevip.png",
  64. name: "我的会员",
  65. },
  66. {
  67. image: app.appAssetsUrl2 + "wjxy/homecode.png",
  68. name: "邀请码",
  69. },
  70. ],
  71. cityList: [],
  72. cityListPickerData: [],
  73. cityListIndex: [],
  74. listData: [],
  75. imglist: [],
  76. currentCity: {},
  77. current: 0,
  78. maskShow: false,
  79. activeList: [],
  80. jobList: [],
  81. perList: [],
  82. expertList: [],
  83. shopObj: {},
  84. popupImg: "",
  85. latitude: "",
  86. longitude: "",
  87. },
  88. moreHandler() {
  89. this.experience();
  90. },
  91. experience(e) {
  92. console.log(e);
  93. if (
  94. e.currentTarget.dataset.index == 4 ||
  95. e.currentTarget.dataset.index == 3
  96. ) {
  97. if (wx.getStorageSync("USER")) {
  98. wx.navigateTo({
  99. url:
  100. e.currentTarget.dataset.index == 4
  101. ? "/invitationCode/index"
  102. : "/pages/myMember/myMember",
  103. });
  104. } else {
  105. wx.navigateTo({
  106. url: "/pages/login",
  107. });
  108. }
  109. } else {
  110. app.params.pePageToIndex =
  111. e === undefined ? 0 : e.currentTarget.dataset.index + 1;
  112. switch (e.currentTarget.dataset.index) {
  113. case 0:
  114. wx.switchTab({
  115. url: "/pages/practicalExperience/practicalExperience",
  116. });
  117. break;
  118. case 1:
  119. wx.switchTab({
  120. url: "/pages/experience/index/index",
  121. });
  122. break;
  123. case 2:
  124. wx.switchTab({
  125. url: "/pages/dashen/index",
  126. });
  127. break;
  128. case 3:
  129. wx.navigateTo({
  130. url: "/pages/myMember/myMember",
  131. });
  132. break;
  133. default:
  134. wx.navigateTo({
  135. url: "/invitationCode/index",
  136. });
  137. }
  138. }
  139. },
  140. // 热门活动
  141. hotActive() {
  142. let nowCity = wx.getStorageSync("CHOOSECITY");
  143. let that = this;
  144. app._post_form(
  145. "act/list",
  146. "",
  147. {
  148. city: nowCity.cityId,
  149. limit: 10,
  150. page: 1,
  151. isFrontPage: 1,
  152. },
  153. function (res) {
  154. if (res.code == 0) {
  155. res.page.list.map((v) => {
  156. v.startTime = v.startTime.replace(/-/g, ".").split(" ")[0];
  157. v.endTime = v.endTime.replace(/-/g, ".").split(" ")[0];
  158. });
  159. that.setData({
  160. activeList: res.page.list,
  161. });
  162. }
  163. },
  164. function (res) {}
  165. );
  166. },
  167. // 最新兼职
  168. newJob() {
  169. let nowCity = wx.getStorageSync("CHOOSECITY");
  170. let that = this;
  171. app._post_form(
  172. "home/label",
  173. "",
  174. {
  175. city: nowCity.cityId,
  176. pageNum: 1,
  177. isHome: 1,
  178. pageSize: 4,
  179. },
  180. function (res) {
  181. if (res.code == 0) {
  182. that.setData({
  183. jobList: res.page.list,
  184. });
  185. }
  186. },
  187. function (res) {}
  188. );
  189. },
  190. // 校园代理人
  191. schoolPer() {
  192. let that = this;
  193. app._get(
  194. `campusagent/page`,
  195. {
  196. page: 1,
  197. limit: 10,
  198. },
  199. (res) => {
  200. if (res.code === 0) {
  201. that.setData({
  202. perList: res.page.list,
  203. });
  204. }
  205. }
  206. );
  207. },
  208. // 推荐行家
  209. getExpert() {
  210. let that = this;
  211. let nowCity = wx.getStorageSync("CHOOSECITY");
  212. app._get(
  213. "expert/greatGodGangPage",
  214. {
  215. page: 1,
  216. limit: 10,
  217. city: nowCity.cityId,
  218. },
  219. function (res) {
  220. if (res.code == 0) {
  221. that.setData({
  222. expertList: res.page.list,
  223. });
  224. }
  225. }
  226. );
  227. },
  228. // 门店推荐
  229. getShop() {
  230. let that = this;
  231. let nowCity = wx.getStorageSync("CHOOSECITY");
  232. app._get(
  233. "store/storeRecommendation",
  234. {
  235. lon: that.data.longitude,
  236. lat: that.data.latitude,
  237. },
  238. function (res) {
  239. if (res.code == 0 && res.data) {
  240. let val = res.data.calculateNew / 1000;
  241. let formatVal = parseInt(val * 10);
  242. that.setData({
  243. shopObj: res.data,
  244. "shopObj.calculateNew": formatVal / 10,
  245. "shopObj.storePhoto": res.data.storePhoto.split(",")[0],
  246. });
  247. }
  248. }
  249. );
  250. },
  251. // 查看门店详情
  252. goStore(e) {
  253. console.log(e, 111);
  254. let that = this;
  255. wx.navigateTo({
  256. url:
  257. "/expert/storedetail/storedetail?id=" +
  258. that.data.shopObj.id +
  259. "&lon=" +
  260. that.data.longitude +
  261. "&lat=" +
  262. that.data.latitude,
  263. });
  264. },
  265. // 查看地图
  266. goLocal() {
  267. let that = this;
  268. let [latitude, longitude] = [
  269. this.data.shopObj.coordinate.split(",")[0],
  270. this.data.shopObj.coordinate.split(",")[1],
  271. ];
  272. console.log(Number(latitude), Number(longitude));
  273. wx.openLocation({
  274. latitude: Number(longitude),
  275. longitude: Number(latitude),
  276. name: that.data.shopObj.name,
  277. address: that.data.shopObj.address,
  278. success: function () {
  279. console.log("success");
  280. },
  281. });
  282. },
  283. callPhone() {
  284. let that = this;
  285. wx.makePhoneCall({
  286. phoneNumber: that.data.shopObj.phone,
  287. });
  288. },
  289. // 开屏弹窗
  290. openPopup() {
  291. app._get("openscreenpopup/openScreenPopup", {}, (res) => {
  292. if (res.code == 0 && res.data) {
  293. let maskShow = false;
  294. if (wx.getStorageSync("popId") != res.data.id) {
  295. wx.setStorageSync("popId", res.data.id);
  296. maskShow = true;
  297. }
  298. this.setData({
  299. popupImg: res.data.popUpPicture,
  300. maskShow: maskShow,
  301. });
  302. }
  303. });
  304. },
  305. // 兼职详情
  306. toPartDetail(e) {
  307. wx.navigateTo({
  308. url: `/pages/home/index/partDetail/partDetail?id=${e.currentTarget.dataset.id}`,
  309. });
  310. },
  311. // 校园代理人详情
  312. perDetail(e) {
  313. // console.log(e)
  314. wx.navigateTo({
  315. url:
  316. "/expert/agentdetail/agentdetail?id=" +
  317. e.currentTarget.dataset.id +
  318. "&type=校园代理人",
  319. });
  320. },
  321. // 行家详情
  322. toExpertDetail(e) {
  323. wx.navigateTo({
  324. url: `/expert/detail/detail?id=${e.currentTarget.dataset.id}`,
  325. });
  326. },
  327. onBindFocus: function (e) {
  328. let _this = this;
  329. wx.navigateTo({
  330. url: "/pages/search/index",
  331. });
  332. },
  333. closePopup() {
  334. this.setData({
  335. maskShow: false,
  336. });
  337. },
  338. nameHandler(e) {
  339. this.setData({
  340. nameIndex: e.target.dataset.index,
  341. });
  342. this.loadList(true);
  343. },
  344. growthMore: function (event) {
  345. wx.navigateTo({
  346. url: "/pages/home/index/growth/growthMore/growthMore",
  347. });
  348. },
  349. activitymore: function (event) {
  350. wx.reLaunch({
  351. url: "/pages/experience/index/index?type=1",
  352. });
  353. },
  354. onReady: function () {
  355. // this.setData({
  356. // maskShow: true
  357. // })
  358. },
  359. onLoad: function (options) {
  360. this.loadCity();
  361. this.height();
  362. if (wx.getStorageSync("USER")) {
  363. this.PushVipInfo();
  364. }
  365. let _this = this;
  366. _this.data.option = options;
  367. setTimeout(function () {
  368. _this.loadDictionary();
  369. }, 100);
  370. _this.addScore();
  371. _this.getLocal();
  372. },
  373. onShow() {
  374. this.openPopup();
  375. },
  376. //获取城市信息
  377. getLocal() {
  378. const _this = this;
  379. wx.getLocation({
  380. type: "gcj02",
  381. success(res) {
  382. console.log("经纬度", res);
  383. const latitude = res.latitude;
  384. const longitude = res.longitude;
  385. _this.setData({
  386. latitude: res.latitude,
  387. longitude: res.longitude,
  388. });
  389. //通过【小程序定位】获取经纬度,在通过第三方sdk获取的地址信息
  390. _this.pointToAddress(latitude, longitude, function (address) {
  391. if (address) {
  392. wx.setStorageSync("CHOOSECITY", {
  393. cityName: address.city,
  394. areaName: address.district,
  395. });
  396. _this.loadCity();
  397. }
  398. });
  399. console.log("111");
  400. },
  401. fail(e) {
  402. _this.loadCity();
  403. console.log("222");
  404. },
  405. });
  406. },
  407. // 定义 pointToAddress 方法
  408. pointToAddress: function (latitude, longitude, callback) {
  409. var _this = this;
  410. // 调用接口
  411. map.reverseGeocoder({
  412. location: {
  413. latitude: latitude,
  414. longitude: longitude,
  415. },
  416. success: function (res) {
  417. // 解析成功返回地址
  418. callback(res.result.ad_info);
  419. },
  420. fail: function (res) {
  421. console.log(res);
  422. },
  423. complete: function (res) {},
  424. });
  425. },
  426. //统计积分(每日登录)
  427. addScore: function () {
  428. if (!util.getUserId()) {
  429. return;
  430. }
  431. wx.showLoading({
  432. title: "努力加载中...",
  433. });
  434. app._post_form(
  435. "scoreStu/dailyLogin",
  436. "",
  437. {
  438. stuId: util.getUserId(),
  439. },
  440. function (res) {
  441. if (res.code === 0) {
  442. }
  443. }
  444. );
  445. },
  446. // 首页banner
  447. loadImg: function () {
  448. let _this = this;
  449. let nowCity = wx.getStorageSync("CHOOSECITY");
  450. let params = {
  451. type: "01",
  452. area: "",
  453. };
  454. app._post_form("img/mylist", "application/json", params, function (res) {
  455. if (res.code == 0) {
  456. _this.setData({
  457. imglist: res.data,
  458. });
  459. }
  460. });
  461. },
  462. //banner跳转
  463. imgJump(v) {
  464. console.log(v);
  465. console.log(v.currentTarget.dataset.item.jumpAddressType);
  466. if (v.currentTarget.dataset.item.jumpAddressType == 0) {
  467. //内部跳转
  468. wx.navigateTo({
  469. url: v.currentTarget.dataset.item.linkUrl,
  470. });
  471. } else if (v.currentTarget.dataset.item.jumpAddressType == 1) {
  472. //公众号跳转 'https://www.kujiale.cn/design/3FO4EQWQJF0M/show'
  473. wx.setStorageSync("gzurl", v.currentTarget.dataset.item.linkUrl);
  474. wx.navigateTo({
  475. url: "./gz/gz",
  476. });
  477. }
  478. },
  479. more(e) {
  480. console.log(e);
  481. if (e.currentTarget.dataset.type == "tab") {
  482. wx.switchTab({
  483. url: e.currentTarget.dataset.url,
  484. });
  485. } else {
  486. wx.navigateTo({
  487. url: e.currentTarget.dataset.url,
  488. });
  489. }
  490. },
  491. popupDetail() {
  492. this.setData({
  493. maskShow: false,
  494. });
  495. wx.navigateTo({
  496. url: "/expert/popupdetail/popupdetail",
  497. });
  498. },
  499. changeSwiper(e) {
  500. let { current, source } = e.detail;
  501. if (source === "autoplay" || source === "touch") {
  502. this.setData({
  503. current: current,
  504. });
  505. }
  506. // this.setData({
  507. // current: e.detail.current
  508. // })
  509. },
  510. loadCity: function () {
  511. let _this = this;
  512. app._post_form("region/list", "", null, function (res) {
  513. if (res.data.length) {
  514. //设置城市选择的数据
  515. let cityData = {
  516. cityName: "",
  517. cityId: "",
  518. // areaName: '',
  519. // areaId: ''
  520. };
  521. console.log(res.data);
  522. //设置城市下拉框数据
  523. let cityListPickerData = res.data;
  524. let cityListIndex = [];
  525. //nowCity是之前首页的城市选择下拉框的数据
  526. let nowCity = wx.getStorageSync("CHOOSECITY");
  527. if (nowCity) {
  528. a: for (let i = 0; i < res.data.length; i++) {
  529. let cityName = res.data[i].name;
  530. if (nowCity.cityName === cityName) {
  531. cityData.cityName = res.data[i].name;
  532. cityData.cityId = res.data[i].id;
  533. cityListIndex.push(i);
  534. // for (let m = 0; m < res.data[i].childRegionList.length; m++) {
  535. // let areaName = res.data[i].childRegionList[m].name;
  536. // if (nowCity.areaName === areaName) {
  537. // cityData.areaName = res.data[i].childRegionList[m].name;
  538. // cityData.areaId = res.data[i].childRegionList[m].id;
  539. // cityListPickerData.push(res.data[i].childRegionList);
  540. // cityListIndex.push(m);
  541. // break a;
  542. // }
  543. // }
  544. }
  545. }
  546. } else {
  547. cityData.cityName = res.data[0].name;
  548. cityData.cityId = res.data[0].id;
  549. cityData.areaName = res.data[0].childRegionList[0].name;
  550. cityData.areaId = res.data[0].childRegionList[0].id;
  551. cityListPickerData = [res.data, res.data[0].childRegionList];
  552. cityListIndex = [0, 0];
  553. }
  554. //设置城市选择数据
  555. wx.setStorageSync("CHOOSECITY", cityData);
  556. //设置城市下拉框数据
  557. _this.setData({
  558. cityList: res.data,
  559. cityListPickerData,
  560. cityListIndex,
  561. currentCity: cityData,
  562. });
  563. console.log(_this.data.cityListPickerData);
  564. setTimeout(function () {
  565. _this.loadImg();
  566. _this.hotActive();
  567. _this.newJob();
  568. _this.schoolPer();
  569. _this.getExpert();
  570. _this.getShop();
  571. // _this.loadList(true);
  572. }, 300);
  573. }
  574. });
  575. },
  576. // 查看活动详情
  577. activeDetail: function (e) {
  578. if (e.currentTarget.dataset.id) {
  579. wx.navigateTo({
  580. url:
  581. "/pages/home/index/activityDetail/activityDetail?id=" +
  582. e.currentTarget.dataset.id,
  583. });
  584. }
  585. },
  586. // 自定义高度处理
  587. height() {
  588. const { platform, statusBarHeight } = wx.getSystemInfoSync();
  589. let height = statusBarHeight + 4; //ios 24px
  590. let mH = statusBarHeight + 4;
  591. if (platform.toLowerCase() == "android") {
  592. height += 4; //android 28px
  593. mH += 4;
  594. }
  595. height = height + 38;
  596. // 胶囊高度 32px 下边框6px height 状态栏高度
  597. this.setData({
  598. statusBarHeight: height + "px",
  599. statusBarMH: mH + "px",
  600. });
  601. },
  602. loadDictionary() {
  603. let _this = this;
  604. app._post_form(
  605. "bizcatelog/apiSelectBizcatelog/workUnit",
  606. "",
  607. null,
  608. function (res) {
  609. _this.setData(res);
  610. }
  611. );
  612. },
  613. PushVipInfo() {
  614. let _this = this;
  615. let id = util.getUserId();
  616. let parm = {
  617. id,
  618. };
  619. app._post_form(
  620. "member/apiSelectMeberInfo",
  621. "application/json",
  622. JSON.stringify(parm),
  623. function (res) {
  624. if (res.code === 0) {
  625. wx.setStorageSync("USER", res.member);
  626. } else {
  627. wx.removeStorageSync("USER");
  628. // wx.reLaunch({
  629. // url: '/pages/login',
  630. // })
  631. wx.switchTab({
  632. url: "/pages/my/index/index",
  633. });
  634. }
  635. }
  636. );
  637. },
  638. /**
  639. * 页面相关事件处理函数--监听用户下拉动作
  640. */
  641. onPullDownRefresh: function () {
  642. var _this = this;
  643. //强制更新
  644. setTimeout(() => {
  645. _this.getLocal();
  646. }, 200);
  647. // 处理完成后,终止下拉刷新
  648. wx.stopPullDownRefresh();
  649. },
  650. /**
  651. * 页面上拉触底事件的处理函数
  652. */
  653. onReachBottom: function () {
  654. // this.loadList();
  655. },
  656. //重新选择城市
  657. cityPickerChange(e) {
  658. let cityListIndex = e.detail.value;
  659. let cityData = {
  660. cityName: this.data.cityListPickerData[cityListIndex].name,
  661. cityId: this.data.cityListPickerData[cityListIndex].id,
  662. // areaName: this.data.cityList[cityListIndex[0]].childRegionList[cityListIndex[1]].name,
  663. // areaId: this.data.cityList[cityListIndex[0]].childRegionList[cityListIndex[1]].id,
  664. };
  665. this.setData({
  666. cityListIndex,
  667. currentCity: cityData,
  668. });
  669. //设置城市选择数据
  670. wx.setStorageSync("CHOOSECITY", cityData);
  671. // this.loadList(true)
  672. this.hotActive();
  673. this.newJob();
  674. this.schoolPer();
  675. this.getExpert();
  676. this.getShop();
  677. console.log(e);
  678. },
  679. cityPickerColumnChange(e) {
  680. if (e.detail.column == 0) {
  681. this.setData({
  682. cityListPickerData: [
  683. this.data.cityList,
  684. this.data.cityList[e.detail.value].childRegionList,
  685. ],
  686. });
  687. }
  688. },
  689. /**
  690. * @param {Object} isRefresh 是否刷新,否则就是下一页
  691. */
  692. loadList(isRefresh) {
  693. let that = this;
  694. if (!isRefresh && this.data.noMore) {
  695. wx.showToast({
  696. title: "没有更多了~",
  697. icon: "none",
  698. });
  699. return false;
  700. }
  701. let nowCity = wx.getStorageSync("CHOOSECITY");
  702. if (!nowCity || !nowCity.cityId) {
  703. return false;
  704. }
  705. this.setData({
  706. listData: isRefresh ? [] : this.data.listData,
  707. params: {
  708. ...this.data.params,
  709. pageNum: isRefresh ? 1 : this.data.params.pageNum + 1,
  710. city: nowCity.cityId,
  711. area: nowCity.areaId,
  712. type: this.data.nameIndex + 1,
  713. },
  714. noMore: isRefresh ? false : this.data.noMore,
  715. });
  716. wx.showLoading({
  717. title: "努力加载中...",
  718. });
  719. app._post_form(
  720. "home/mylist",
  721. "",
  722. this.data.params,
  723. function (res) {
  724. if (res.code == 0) {
  725. if (
  726. res.page.list.length > 0 &&
  727. that.data.listData.length > 0 &&
  728. res.page.list[0].id == that.data.listData[0].id
  729. ) {
  730. return;
  731. }
  732. let listData = that.data.listData;
  733. listData.push(...res.page.list);
  734. that.setData({
  735. listData,
  736. currPage: res.page.currPage,
  737. totalPage: res.page.totalPage,
  738. noMore: res.page.totalPage == res.page.currPage,
  739. });
  740. }
  741. },
  742. function (res) {
  743. wx.hideLoading();
  744. }
  745. );
  746. },
  747. onShareAppMessage: function () {},
  748. });