index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. <template>
  2. <view class="container">
  3. <!-- 顶部logo and 搜索 start-->
  4. <view class="status_bar"></view>
  5. <!-- 背景图片 -->
  6. <view class="top-bg">
  7. <!-- <image :style="{ 'background':'#'+ titleNViewBackground }"></image> -->
  8. <image src="../../static/img/index.png"></image>
  9. </view>
  10. <view class="top-search flex">
  11. <view
  12. class="search-box flex"
  13. @click="clickSearch()">
  14. <image
  15. class="search"
  16. src="../../static/sy-img/img8.png"
  17. mode=""></image>
  18. <view class="search-font">输入关键词搜索</view>
  19. </view>
  20. </view>
  21. <!-- 顶部logo and 搜索 end-->
  22. <view
  23. class="jg"
  24. style="background-color: #fff"></view>
  25. <!-- 轮播图 start -->
  26. <swiper
  27. class="top-swiper"
  28. autoplay="true"
  29. duration="400"
  30. interval="5000"
  31. @change="swiperChange">
  32. <swiper-item
  33. v-for="(item, index) in processedCarouselList"
  34. :key="index"
  35. class="carousel-item"
  36. @click="bannerNavToUrl(item)">
  37. <image :src="item.pic" />
  38. </swiper-item>
  39. </swiper>
  40. <!-- 轮播图 end -->
  41. <!-- 分类 start -->
  42. <view class="cate-section flex">
  43. <view
  44. class="cate-item flex"
  45. @click="navto('/pages/category/category')">
  46. <view class="img-wrapper flex">
  47. <image
  48. src="../../static/sy-img/img10.png"
  49. mode=""></image>
  50. </view>
  51. <view class="item-title">所有商品</view>
  52. </view>
  53. <view
  54. class="cate-item flex"
  55. @click="navto('/pages/store/store')">
  56. <view class="img-wrapper flex">
  57. <image
  58. src="../../static/sy-img/img4.png"
  59. mode=""></image>
  60. </view>
  61. <view class="item-title">合作门店</view>
  62. </view>
  63. <view
  64. class="cate-item flex"
  65. @click="navto('/pages/gift/gift')">
  66. <view class="img-wrapper flex">
  67. <image
  68. src="../../static/sy-img/img11.png"
  69. mode=""></image>
  70. </view>
  71. <view class="item-title">礼包</view>
  72. </view>
  73. <view
  74. class="cate-item flex"
  75. @click="navto('/pages/shareQrCode/index')">
  76. <view class="img-wrapper flex">
  77. <image
  78. src="../../static/sy-img/yq.png"
  79. mode=""></image>
  80. </view>
  81. <view class="item-title">邀请好友</view>
  82. </view>
  83. </view>
  84. <view class="goodsList">
  85. <view class="goodsList-title flex">
  86. <!-- <view class="goodsList-title flex"> -->
  87. <view class="xian"></view>
  88. <view class="title">积分兑换商城</view>
  89. <view class="xian"></view>
  90. <!-- </view> -->
  91. </view>
  92. </view>
  93. <!-- 普通商品列表start -->
  94. <view class="goodsList-box flex">
  95. <view
  96. class="goodsList-item"
  97. v-for="(ls, ind) in firstList"
  98. :key="ind"
  99. @click="navTo('/pages/product/product?id=' + ls.id)">
  100. <view class="image-wrapper">
  101. <image
  102. class="image"
  103. :src="ls.image"
  104. mode="scaleToFill"></image>
  105. </view>
  106. <view
  107. class="list-item"
  108. style="width: 229rpx; height: 195rpx">
  109. <view class="title clamp2">
  110. {{ ls.store_name }}
  111. </view>
  112. <view class="little">
  113. {{ ls.unit_name || "" }}
  114. </view>
  115. <view class="hot-price">
  116. <view
  117. class="price"
  118. style="
  119. font-size: 26rpx;
  120. color: #ff4c4c;
  121. font-weight: bold;
  122. display: flex;
  123. white-space: nowrap;
  124. ">
  125. ¥{{ ls.price }}+{{ ls.min_integral }}积分
  126. <image
  127. class="imgCart"
  128. src="../../static/sy-img/cart.png"
  129. mode=""></image>
  130. </view>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. </view>
  136. </template>
  137. <script>
  138. import { uview } from "uview-ui";
  139. import { loadIndexs, groom } from "@/api/index.js";
  140. import { getUserInfo, spread } from "@/api/user.js";
  141. import {
  142. getBargainList,
  143. getProducts,
  144. goodsDetail,
  145. poster,
  146. } from "@/api/product.js";
  147. import { saveUrl, interceptor } from "@/utils/loginUtils";
  148. import { mapState, mapMutations } from "vuex";
  149. // #ifdef H5
  150. import { weixindata, shareLoad } from "@/utils/wxAuthorized";
  151. // #endif
  152. export default {
  153. data() {
  154. return {
  155. img: "",
  156. titleNViewBackground: "",
  157. text: "", //客服微信
  158. current: 0,
  159. swiperHeight: 0,
  160. checkid: 0,
  161. titleNViewBackground: "",
  162. swiperCurrent: 0,
  163. swiperLength: 0,
  164. carouselList: [], //轮播列表
  165. page: 1,
  166. limit: 10,
  167. loadingType: "more",
  168. firstList: [],
  169. shareImage: "",
  170. text1: ["省委副书记亲临实地考察数字"],
  171. max_integral: "", //最大积分
  172. min_integral: "", //最小积分
  173. openid: uni.getStorageSync("openid"),
  174. };
  175. },
  176. computed: {
  177. ...mapState("user", ["hasLogin", "userInfo"]),
  178. },
  179. onShareAppMessage(options) {
  180. // 设置菜单中的转发按钮触发转发事件时的转发内容
  181. let pages = getCurrentPages(); //获取加载的页面
  182. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  183. let url = currentPage.route; //当前页面url
  184. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  185. let shareObj = {};
  186. if (this.userInfo.uid) {
  187. shareObj = {
  188. title: this.userInfo.nickname + "邀请您加入华中康新堂", // 默认是小程序的名称(可以写slogan等)
  189. path: url + "?scene=" + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  190. imageUrl: "",
  191. success: function (res) {
  192. // 转发成功之后的回调
  193. if (res.errMsg == "shareAppMessage:ok") {
  194. }
  195. },
  196. fail: function () {
  197. // 转发失败之后的回调
  198. if (res.errMsg == "shareAppMessage:fail cancel") {
  199. // 用户取消转发
  200. } else if (res.errMsg == "shareAppMessage:fail") {
  201. // 转发失败,其中 detail message 为详细失败信息
  202. }
  203. },
  204. };
  205. } else {
  206. shareObj = {
  207. title: "华中康新堂", // 默认是小程序的名称(可以写slogan等)
  208. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  209. imageUrl: "",
  210. success: function (res) {
  211. // 转发成功之后的回调
  212. if (res.errMsg == "shareAppMessage:ok") {
  213. }
  214. },
  215. fail: function () {
  216. // 转发失败之后的回调
  217. if (res.errMsg == "shareAppMessage:fail cancel") {
  218. // 用户取消转发
  219. } else if (res.errMsg == "shareAppMessage:fail") {
  220. // 转发失败,其中 detail message 为详细失败信息
  221. }
  222. },
  223. };
  224. }
  225. return shareObj;
  226. },
  227. onReachBottom() {
  228. this.getgroom();
  229. },
  230. onLoad: function (option) {
  231. // #ifdef MP
  232. if (option.scene) {
  233. // 存储小程序邀请人
  234. uni.setStorage({
  235. key: "spread_code",
  236. data: option.scene,
  237. });
  238. }
  239. // #endif
  240. // #ifdef H5
  241. if (option.spread) {
  242. // 存储小程序邀请人
  243. uni.setStorage({
  244. key: "spread",
  245. data: option.spread,
  246. });
  247. }
  248. // #endif
  249. },
  250. onShow: function () {
  251. this.page = 1;
  252. this.limit = 10;
  253. this.loadingType = "more";
  254. this.firstList = [];
  255. this.loadData();
  256. this.getgroom();
  257. if (this.hasLogin) {
  258. this.getuser();
  259. }
  260. },
  261. computed: {
  262. processedCarouselList() {
  263. return this.carouselList.map(item => {
  264. // 如果颜色值没有带#前缀,则添加#前缀
  265. if (!item.color.startsWith("#")) {
  266. return {
  267. ...item,
  268. color: `#${item.color}`,
  269. };
  270. }
  271. return item;
  272. });
  273. },
  274. },
  275. methods: {
  276. ...mapMutations("user", ["setUserInfo"]),
  277. getuser() {
  278. getUserInfo({})
  279. .then(({ data }) => {
  280. this.setUserInfo(data);
  281. })
  282. .catch(e => {
  283. console.log(e);
  284. });
  285. },
  286. getgroom() {
  287. const obj = this;
  288. if (
  289. obj.loadingType == "nomore" ||
  290. obj.loadingType == "loading"
  291. ) {
  292. return;
  293. }
  294. obj.loadingType = "loading";
  295. groom(
  296. {
  297. page: this.page,
  298. limit: this.limit,
  299. },
  300. 3
  301. ).then(({ data }) => {
  302. console.log(data, "123456");
  303. // obj.firstList = obj.firstList.concat(data.list)
  304. obj.page++;
  305. if (obj.limit == data.list.length) {
  306. obj.loadingType = "more";
  307. } else {
  308. obj.loadingType = "nomore";
  309. }
  310. });
  311. },
  312. navto(url, type = 0) {
  313. if (type == 1) {
  314. if (!this.hasLogin) {
  315. // 保存地址
  316. saveUrl();
  317. // 登录拦截
  318. interceptor();
  319. } else {
  320. uni.navigateTo({
  321. url,
  322. fail() {
  323. uni.switchTab({
  324. url,
  325. });
  326. },
  327. });
  328. }
  329. } else {
  330. uni.navigateTo({
  331. url,
  332. fail() {
  333. uni.switchTab({
  334. url,
  335. });
  336. },
  337. });
  338. }
  339. },
  340. navTo(url) {
  341. if (url == "") {
  342. this.$api.msg("暂未开通,敬请期待");
  343. } else {
  344. this.navto(url);
  345. }
  346. },
  347. // 點擊搜索框
  348. clickSearch() {
  349. uni.navigateTo({
  350. url: "/pages/product/search",
  351. });
  352. },
  353. // 监听图片加载完成
  354. onImageError(key, index) {
  355. this[key][index].image = "/static/error/errorImage.jpg";
  356. },
  357. // 请求载入数据
  358. async loadData() {
  359. loadIndexs({})
  360. .then(({ data }) => {
  361. let goods = data.info;
  362. console.log(goods, "商品信息");
  363. this.carouselList = data.banner;
  364. this.swiperLength = this.carouselList.length;
  365. this.firstList = data.integral; //首页商品
  366. uni.stopPullDownRefresh();
  367. })
  368. .catch(e => {
  369. uni.stopPullDownRefresh();
  370. });
  371. },
  372. //轮播图切换修改背景色
  373. swiperChange(e) {
  374. const index = e.detail.current;
  375. // console.log('1111',index);
  376. this.swiperCurrent = index;
  377. this.titleNViewBackground = this.carouselList[index].color;
  378. // console.log(this.titleNViewBackground,'titleNViewBackground');
  379. this.img = this.carouselList[index].pic;
  380. console.log(this.img, "img");
  381. },
  382. // 轮播图跳转
  383. bannerNavToUrl(item) {
  384. // #ifdef H5
  385. console.log(item.wap_url.indexOf("http"), "banner");
  386. if (item.wap_url.indexOf("http") >= 0) {
  387. window.location.href = item.wap_url;
  388. }
  389. // #endif
  390. //测试数据没有写id,用title代替
  391. uni.navigateTo({
  392. url: item.wap_url,
  393. });
  394. },
  395. comfirm(text) {
  396. console.log(text);
  397. const result = this.uniCopy(text);
  398. if (result === false) {
  399. uni.showToast({
  400. title: "不支持",
  401. });
  402. } else {
  403. uni.showToast({
  404. title: "复制成功",
  405. icon: "none",
  406. });
  407. }
  408. this.$refs.popupkf.close();
  409. },
  410. uniCopy(content) {
  411. /**
  412. * 小程序端 和 app端的复制逻辑
  413. */
  414. //#ifndef H5
  415. uni.setClipboardData({
  416. data: content,
  417. success: function () {
  418. console.log("success");
  419. return true;
  420. },
  421. });
  422. //#endif
  423. /**
  424. * H5端的复制逻辑
  425. */
  426. // #ifdef H5
  427. if (!document.queryCommandSupported("copy")) {
  428. //为了兼容有些浏览器 queryCommandSupported 的判断
  429. // 不支持
  430. return false;
  431. }
  432. let textarea = document.createElement("textarea");
  433. textarea.value = content;
  434. textarea.readOnly = "readOnly";
  435. document.body.appendChild(textarea);
  436. textarea.select(); // 选择对象
  437. textarea.setSelectionRange(0, content.length); //核心
  438. let result = document.execCommand("copy"); // 执行浏览器复制命令
  439. textarea.remove();
  440. return result;
  441. // #endif
  442. },
  443. // 打开客服
  444. openKf() {
  445. this.$refs.popupkf.open();
  446. },
  447. // 关闭客服
  448. cancel() {
  449. this.$refs.popupkf.close();
  450. },
  451. },
  452. };
  453. </script>
  454. <style lang="scss">
  455. page {
  456. min-height: 100%;
  457. height: auto;
  458. background: #ffffff;
  459. }
  460. // 背景图片
  461. .top-bg {
  462. position: absolute;
  463. top: 0;
  464. left: 0;
  465. right: 0;
  466. width: 750rpx;
  467. height: 346rpx;
  468. image {
  469. width: 100%;
  470. background: linear-gradient(to bottom, #ff0000, #ffffff);
  471. }
  472. }
  473. // 顶部搜索
  474. .top-search {
  475. position: relative;
  476. z-index: 2;
  477. height: 80rpx;
  478. padding: 0 20rpx;
  479. // background-color: #fff;
  480. .top-logo {
  481. width: 50rpx;
  482. // height: 50rpx;
  483. margin-right: 10rpx;
  484. image {
  485. width: 48rpx;
  486. }
  487. }
  488. .search-box {
  489. justify-content: center;
  490. width: 698rpx;
  491. height: 60rpx;
  492. background: rgba(#ffffff, 0.47);
  493. box-shadow: 0rpx 9rpx 21rpx 0rpx rgba(4, 114, 69, 0.22);
  494. border-radius: 30rpx;
  495. .search {
  496. width: 34rpx;
  497. height: 34rpx;
  498. }
  499. .search-font {
  500. margin-left: 14rpx;
  501. font-size: 28rpx;
  502. font-family: PingFang SC;
  503. font-weight: 500;
  504. color: #ffffff;
  505. }
  506. }
  507. }
  508. // 顶部轮播图
  509. .top-swiper {
  510. margin: 20rpx auto 0;
  511. width: 700rpx;
  512. border-radius: 14rpx;
  513. image {
  514. width: 700rpx;
  515. height: 300rpx;
  516. }
  517. }
  518. .swiper-btm {
  519. height: 60rpx;
  520. width: 750rpx;
  521. background-color: #fff;
  522. margin-bottom: 20rpx;
  523. font-size: 26rpx;
  524. font-weight: 500;
  525. color: #333333;
  526. .btm-item {
  527. flex-grow: 1;
  528. justify-content: center;
  529. image {
  530. width: 25rpx;
  531. height: 25rpx;
  532. margin-right: 14rpx;
  533. }
  534. }
  535. }
  536. .jg {
  537. height: 20rpx;
  538. background: #f8f8f8;
  539. }
  540. // 分类
  541. .cate-section {
  542. justify-content: space-around;
  543. background-color: #fff;
  544. padding: 30rpx 0 30rpx;
  545. .cate-item {
  546. flex-grow: 0;
  547. width: 20%;
  548. flex-direction: column;
  549. text-align: center;
  550. align-items: center;
  551. justify-content: center;
  552. .img-wrapper {
  553. width: 100rpx;
  554. height: 100rpx;
  555. border-radius: 20rpx;
  556. position: relative;
  557. image {
  558. width: 100%;
  559. height: 100%;
  560. position: absolute;
  561. left: 50%;
  562. top: 50%;
  563. transform: translate(-50%, -50%);
  564. }
  565. }
  566. .item-title {
  567. margin-top: 15rpx;
  568. font-size: 24rpx;
  569. font-weight: 500;
  570. color: #333333;
  571. }
  572. }
  573. }
  574. .popup-box {
  575. width: 522rpx;
  576. height: 605rpx;
  577. background-color: #ffffff;
  578. border-radius: 20rpx;
  579. position: relative;
  580. .img {
  581. position: relative;
  582. top: -56rpx;
  583. left: 0;
  584. width: 522rpx;
  585. height: 132rpx;
  586. display: flex;
  587. justify-content: center;
  588. image {
  589. border-radius: 20rpx 20rpx 0 0;
  590. width: 450rpx;
  591. height: 132rpx;
  592. }
  593. }
  594. .mian {
  595. margin-top: -44rpx;
  596. display: flex;
  597. flex-direction: column;
  598. align-items: center;
  599. // padding: 32rpx 32rpx;
  600. background-color: #ffffff;
  601. border-radius: 0 0 20rpx 20rpx;
  602. text-align: center;
  603. .delivery {
  604. font-size: 40rpx;
  605. color: #333333;
  606. display: flex;
  607. align-items: center;
  608. flex-direction: column;
  609. image {
  610. margin-top: 48rpx;
  611. width: 172rpx;
  612. height: 160rpx;
  613. }
  614. }
  615. .nocancel {
  616. font-size: 32rpx;
  617. color: #333333;
  618. margin-top: 14rpx;
  619. }
  620. .comfirm-box {
  621. margin-top: 52rpx;
  622. display: flex;
  623. // margin-bottom: 32rpx;
  624. // justify-content: space-around;
  625. .cancel {
  626. display: flex;
  627. align-items: center;
  628. justify-content: center;
  629. width: 197rpx;
  630. height: 74rpx;
  631. border: 1px solid #dcc786;
  632. border-radius: 38rpx;
  633. font-size: 32rpx;
  634. color: #605128;
  635. }
  636. .comfirm {
  637. margin-left: 32rpx;
  638. display: flex;
  639. align-items: center;
  640. justify-content: center;
  641. width: 197rpx;
  642. height: 74rpx;
  643. background: linear-gradient(
  644. -90deg,
  645. #d1ba77 0%,
  646. #f7e8ad 100%
  647. );
  648. border-radius: 38px;
  649. font-size: 32rpx;
  650. color: #605128;
  651. }
  652. }
  653. }
  654. }
  655. .jhq {
  656. margin: 0 auto;
  657. width: 750rpx;
  658. image {
  659. width: 100%;
  660. }
  661. }
  662. .goodsList {
  663. background: #ffffff;
  664. padding-top: 41rpx;
  665. .goodsList-title {
  666. margin: 0 auto 32rpx;
  667. justify-content: center;
  668. // width: 376rpx;
  669. // height: 34rpx;
  670. .xian {
  671. width: 120rpx;
  672. height: 1rpx;
  673. background: #999999;
  674. }
  675. .title {
  676. margin: 0 70rpx;
  677. font-size: 30rpx;
  678. font-family: PingFang SC;
  679. font-weight: 500;
  680. color: #363636;
  681. }
  682. }
  683. }
  684. .goodsList-box {
  685. background: #ffffff;
  686. padding: 26rpx 20rpx 20rpx;
  687. flex-wrap: wrap;
  688. .goodsList-item {
  689. width: 345rpx;
  690. background-color: #ffffff;
  691. border-radius: 12rpx;
  692. box-shadow: 0 0 15rpx rgba(0, 0, 0, 0.2);
  693. margin-bottom: 20rpx;
  694. .image-wrapper {
  695. width: 345rpx;
  696. height: 345rpx;
  697. border-radius: 3px;
  698. position: relative;
  699. .image {
  700. width: 100%;
  701. height: 100%;
  702. opacity: 1;
  703. border-radius: 12rpx 12rpx 0 0;
  704. }
  705. }
  706. .title {
  707. margin-top: 28rpx;
  708. padding: 0 20rpx;
  709. font-size: 30rpx;
  710. font-weight: 500;
  711. color: #333333;
  712. overflow: hidden;
  713. text-overflow: ellipsis;
  714. white-space: nowrap;
  715. text-overflow: ellipsis; /* 溢出显示省略号 */
  716. overflow: hidden; /* 溢出隐藏 */
  717. white-space: nowrap; /* 强制不换行 */
  718. }
  719. .little {
  720. width: 154rpx;
  721. height: 25rpx;
  722. margin-top: 16rpx;
  723. margin-left: 20rpx;
  724. font-size: 26rpx;
  725. font-family: PingFang SC;
  726. font-weight: 500;
  727. color: #666666;
  728. }
  729. .imgCart {
  730. margin-left: 12rpx;
  731. width: 44rpx;
  732. height: 44rpx;
  733. }
  734. .hot-price {
  735. margin-top: 50rpx;
  736. width: 195rpx;
  737. height: 29rpx;
  738. display: flex;
  739. justify-content: flex-start;
  740. align-items: center;
  741. .price {
  742. margin-left: 10rpx;
  743. font-size: 32rpx;
  744. color: #9c0b18;
  745. font-weight: 500;
  746. display: flex;
  747. justify-content: flex-start;
  748. align-items: center;
  749. .ot-price {
  750. margin-right: 7rpx;
  751. font-size: 26rpx;
  752. font-weight: 500;
  753. text-decoration: line-through;
  754. color: #999999;
  755. }
  756. }
  757. }
  758. }
  759. }
  760. </style>