catalog.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <template>
  2. <view class="container" style="padding-bottom: 100rpx">
  3. <view class="no-login" v-if="!hasLogin">
  4. <view class="c">
  5. <text>您还没有注册</text>
  6. <button open-type="getUserInfo" @getuserinfo="goLogin">点击授权登录</button>
  7. </view>
  8. </view>
  9. <view class="login" v-else>
  10. <view class="search">
  11. <!-- <picker mode="selector" style="font-size:32rpx" range="{{citys}}" value="{{cityIndex}}" bindchange="listenerCitySelected">
  12. <view style="width: 160rpx;text-align: center;display: flex;">
  13. <image style="width: 45rpx;height: 45rpx;" src="/static/images/address.png"></image>
  14. <view style="font-size:32rpx">{{city}}</view>
  15. </view>
  16. </picker> -->
  17. <navigator url="/pages/category/search/search" class="input">
  18. <!-- <van-icon name="search" size="16px" /> -->
  19. <image src="https://mall.zhaijieshi.cc/file/wx-dy/icon-search-grey.png" class="img" mode="aspectFit"></image>
  20. <text class="txt">商品搜索, 共{{ goodsCount }}款好物</text>
  21. </navigator>
  22. </view>
  23. <view class="catalog">
  24. <scroll-view class="nav" :scroll-y="true">
  25. <view
  26. :class="'item ' + (currentCategory.id == item.id ? 'active' : '')"
  27. :data-id="item.id"
  28. :data-index="index"
  29. :data-name="item.name"
  30. @tap="switchCate"
  31. v-for="(item, index) in categoryList"
  32. :key="index"
  33. >
  34. <!-- <image src="https://mall.zhaijieshi.cc/file/wx-dy/cate-select.png" class="active-img" mode="aspectFit" v-if="currentCategory.id == item.id"></image>
  35. <image src="https://mall.zhaijieshi.cc/file/wx-dy/text-jian.png" class="hot-img" mode="aspectFit" v-if="index == 0"></image> -->
  36. <text class="text">{{ item.name }}</text>
  37. </view>
  38. </scroll-view>
  39. <scroll-view class="cate" :scroll-y="true">
  40. <!-- url="/pages/servant/servantList/servantList" -->
  41. <navigator url="/pages/servant/servantList/servantList" class="banner" v-if="currentCategory.name == '保姆/月嫂'">
  42. <image class="category-banner" mode="aspectFill" :src="currentCategory.picUrl"></image>
  43. <!-- <view class="txt">{{currentCategory.frontName}}</view> -->
  44. </navigator>
  45. <view v-if="goodsList.length > 0" v-for="(category, idx) in goodsList" :key="idx">
  46. <view class="hd">
  47. <!-- <text class="line"></text> -->
  48. <text class="txt">{{ category.name }}</text>
  49. <view class="grey-devide"></view>
  50. <view class="blue-devide"></view>
  51. </view>
  52. <!-- <view class="bd">
  53. <navigator url="/pages/category/category?id={{item.id}}" class="item {{(index+1) % 3 == 0 ? 'last' : ''}}" wx:key="id" wx:for="{{currentSubCategoryList}}">
  54. <image class="icon" src="{{item.picUrl}}"></image>
  55. <text class="txt">{{item.name}}</text>
  56. </navigator>
  57. </view> -->
  58. <view class="a-section a-popular">
  59. <view class="b category-line">
  60. <view class="item" v-for="(item, index) in category.goodsList" :key="index">
  61. <navigator :url="'/pages/goods/goods?id=' + item.id" class="product-item">
  62. <image class="img" :src="item.picUrl + '?w=200'" mode="aspectFit"></image>
  63. <view class="product-name">{{ item.name }}</view>
  64. <!-- <view class="right">
  65. <view class="text">
  66. <text class="name">{{item.name}}</text>
  67. <text class="desc">{{item.brief}}</text>
  68. <view class="price">¥{{item.retailPrice}}
  69. <span wx:if="{{item.unit}}">/{{item.unit}}</span>
  70. <span wx:else>/次</span>
  71. <view class="btn">详情</view>
  72. </view>
  73. </view>
  74. </view> -->
  75. </navigator>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </scroll-view>
  81. </view>
  82. </view>
  83. <!-- 广告 -->
  84. <!-- <view class="adv" bindtap='goinviteFriends'>
  85. <view style="width:100%;height:100%">
  86. <image src="/static/images/active/xyhxd.jpg" style="width:100%;height:100%" />
  87. </view>
  88. </view> -->
  89. </view>
  90. </template>
  91. <script>
  92. var util = require('../../../utils/util.js');
  93. var api = require('../../../config/api.js');
  94. const user = require('../../../utils/user.js');
  95. const area = require('../../../utils/area.js');
  96. //获取应用实例
  97. const app = getApp();
  98. export default {
  99. data() {
  100. return {
  101. categoryList: [],
  102. currentCategory: {
  103. id: '',
  104. name: '',
  105. picUrl: ''
  106. },
  107. currentSubCategoryList: {},
  108. scrollLeft: 0,
  109. scrollTop: 0,
  110. goodsList: [],
  111. goodsCount: 0,
  112. scrollHeight: 0,
  113. hasLogin: true,
  114. city: '',
  115. //当前业务城市
  116. citys: [],
  117. cityIndex: 0,
  118. addressInfo: {},
  119. category: {
  120. name: '',
  121. goodsList: []
  122. }
  123. };
  124. },
  125. onLoad: function (options) {
  126. // this.getCatalog();
  127. },
  128. onPullDownRefresh() {
  129. uni.showNavigationBarLoading(); //在标题栏中显示加载
  130. this.getCatalog();
  131. uni.hideNavigationBarLoading(); //完成停止加载
  132. uni.stopPullDownRefresh(); //停止下拉刷新
  133. },
  134. onReady: function () {
  135. // 页面渲染完成
  136. if (app.globalData.hasLogin) {
  137. this.setData({
  138. hasLogin: true
  139. });
  140. }
  141. },
  142. onShow: function () {
  143. // 页面显示
  144. //显示购物车角标
  145. //user.cartshow();
  146. //确定业务城市
  147. var addressInfo = uni.getStorageSync('addressInfo');
  148. console.info(addressInfo);
  149. if (addressInfo) {
  150. this.setData({
  151. addressInfo: addressInfo
  152. });
  153. } else {
  154. //手机性能慢,可能首页接口没初始化完毕
  155. let that = this;
  156. setTimeout(() => {
  157. var addressInfo = uni.getStorageSync('addressInfo');
  158. if (addressInfo) {
  159. that.setData({
  160. addressInfo: addressInfo
  161. });
  162. }
  163. }, 500);
  164. }
  165. this.getCatalog();
  166. },
  167. onHide: function () {
  168. // 页面隐藏
  169. },
  170. onUnload: function () {
  171. // 页面关闭
  172. },
  173. methods: {
  174. listenerCitySelected(e) {
  175. this.setData({
  176. cityIndex: e.detail.value,
  177. city: this.citys[e.detail.value]
  178. });
  179. app.globalData.city = this.city;
  180. },
  181. getCatalog: function () {
  182. //CatalogList
  183. let that = this;
  184. var addressInfo = uni.getStorageSync('addressInfo');
  185. that.setData({
  186. city: addressInfo.city
  187. });
  188. uni.showLoading({
  189. title: '加载中...'
  190. });
  191. util.request(api.CatalogList, {
  192. shopId: addressInfo.shopId,
  193. city: addressInfo.city
  194. }).then(function (res) {
  195. //1036763 写死值 如果地址不是苏州市 隐藏活动专享
  196. //20220223关闭所有活动合作专区
  197. //console.info(res.data.categoryList)
  198. var list = res.data.categoryList;
  199. that.setData({
  200. categoryList: list,
  201. currentCategory: res.data.currentCategory,
  202. currentSubCategoryList: res.data.currentSubCategory
  203. });
  204. that.getCategoryGoods();
  205. uni.hideLoading();
  206. });
  207. util.request(api.GoodsCount).then(function (res) {
  208. that.setData({
  209. goodsCount: res.data
  210. });
  211. });
  212. },
  213. getCategoryGoods() {
  214. //获取一级类目下所有商品
  215. let that = this;
  216. util.request(api.GoodsL1Category, {
  217. id: that.currentCategory.name == '热销商品' ? '-1' : that.currentCategory.id,
  218. shopId: that.addressInfo.shopId,
  219. isHot: that.currentCategory.name == '热销商品' ? true : false,
  220. city: that.city
  221. }).then((res) => {
  222. console.info(res.data);
  223. that.setData({
  224. goodsList: res.data
  225. });
  226. });
  227. },
  228. getCurrentCategory: function (id) {
  229. let that = this;
  230. util.request(api.CatalogCurrent, {
  231. id: id
  232. }).then(function (res) {
  233. that.setData({
  234. currentCategory: res.data.currentCategory,
  235. currentSubCategoryList: res.data.currentSubCategory
  236. });
  237. that.getCategoryGoods();
  238. });
  239. },
  240. goLogin: function (e) {
  241. if (e.detail.userInfo == null) {
  242. app.globalData.hasLogin = false;
  243. util.showErrorToast('微信授权失败');
  244. return;
  245. }
  246. app.globalData.hasLogin = false;
  247. uni.setStorageSync('userInfo', null);
  248. user.loginByWeixin(e.detail.userInfo)
  249. .then((res) => {
  250. //跳转注册页
  251. uni.navigateTo({
  252. url: '/pages/auth/register/register'
  253. });
  254. })
  255. .catch((err) => {
  256. app.globalData.hasLogin = false;
  257. });
  258. },
  259. switchCate: function (event) {
  260. var that = this;
  261. var currentTarget = event.currentTarget;
  262. if (this.currentCategory.id == event.currentTarget.dataset.id) {
  263. return false;
  264. }
  265. this.getCurrentCategory(event.currentTarget.dataset.id);
  266. },
  267. goinviteFriends(e) {
  268. console.log(app.globalData.hasLogin);
  269. //跳转到邀请页面
  270. if (app.globalData.hasLogin) {
  271. uni.navigateTo({
  272. url: '/pages/activity/invitefriends/inviteFriends'
  273. });
  274. } else {
  275. uni.navigateTo({
  276. url: '/pages/auth/login/login'
  277. });
  278. }
  279. }
  280. }
  281. };
  282. </script>
  283. <style>
  284. page {
  285. color: #2A2A2A; /*主要颜色*/
  286. font-size: 28rpx;
  287. background:#f5f5f5;
  288. }
  289. .container {
  290. height: 100%;
  291. width: 100%;
  292. display: flex;
  293. flex-direction: column;
  294. }
  295. .adv {
  296. position: fixed;
  297. left: 0rpx;
  298. bottom: 0;
  299. z-index: 100;
  300. width: 750rpx;
  301. height: 165rpx;
  302. display: flex;
  303. /* border: 1px solid red; */
  304. }
  305. .search {
  306. /* height: 98rpx;
  307. width: 100%; */
  308. margin-bottom: 6rpx;
  309. padding: 0 30rpx;
  310. display: flex;
  311. align-items: center;
  312. width: 750rpx;
  313. height: 116rpx;
  314. /* background: #ffffff; */
  315. box-shadow: 0px 4rpx 8rpx 0px rgba(245, 246, 250, 0.72);
  316. }
  317. .search .input {
  318. width: 690rpx;
  319. height: 76rpx;
  320. /* background: #f5f6fa; */
  321. background: #fff;
  322. border-radius: 76rpx;
  323. display: flex;
  324. align-items: center;
  325. justify-content: center;
  326. color: #bec0c5;
  327. font-size: 26rpx;
  328. }
  329. .search .img {
  330. width: 24rpx;
  331. height: 24rpx;
  332. margin-right: 20rpx;
  333. }
  334. .search .txt {
  335. font-size: 24rpx;
  336. /* padding:0 0 0 14rpx; */
  337. }
  338. .login {
  339. height: 100%;
  340. /* margin-bottom: 380rpx; */
  341. }
  342. .catalog {
  343. flex: 1;
  344. width: 100%;
  345. /* background: #fff; */
  346. display: flex;
  347. /* border-top: 1px solid #fafafa; */
  348. height: 100%;
  349. /* line-height: 100%; */
  350. }
  351. .catalog .nav {
  352. /* width: 176rpx;
  353. height: 100%;
  354. background: #f5f6fa; */
  355. width: 162rpx;
  356. height: 100%;
  357. background:#EDEDED;
  358. }
  359. .catalog .nav .item {
  360. text-align: center;
  361. line-height: 76rpx;
  362. width: 176rpx;
  363. height: 76rpx;
  364. color: #333;
  365. font-size: 26rpx;
  366. /* border-left: 4rpx solid #fff; */
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. }
  371. .catalog .nav .item .text {
  372. width: 148rpx;
  373. overflow: hidden;
  374. text-overflow: ellipsis;
  375. font-size: 26rpx;
  376. white-space: nowrap;
  377. margin-left: 8rpx;
  378. }
  379. .catalog .nav .item.active .text {
  380. flex: 1;
  381. text-align: center;
  382. }
  383. .catalog .nav .item.active {
  384. /* font-size: 28rpx; */
  385. /*border-left: 6rpx solid #ab956d;*/
  386. /* border-left: 4rpx solid #09afff; */
  387. /* color: #00c0ff;
  388. background: url('https://mall.zhaijieshi.cc/file/wx-dy/cate-bg.png') no-repeat center center;
  389. justify-content: flex-start;
  390. height: 130rpx;
  391. background-size: 175rpx 130rpx; */
  392. font-size: 28rpx;
  393. border-left: 4rpx solid #09afff;
  394. color: #09afff;
  395. background:#f5f5f5;
  396. }
  397. .catalog .cate {
  398. /* border-left: 1px solid #fafafa; */
  399. flex: 1;
  400. height: 100%;
  401. padding: 0 20rpx 0 10rpx;
  402. overflow-x: hidden;
  403. box-sizing: border-box;
  404. }
  405. .banner {
  406. display: block;
  407. height: 212rpx;
  408. width: 100%;
  409. position: relative;
  410. }
  411. .banner .category-banner {
  412. /* position: absolute;
  413. top: 30rpx;
  414. left: 0; */
  415. border-radius: 8rpx;
  416. height: 212rpx;
  417. width: 566rpx;
  418. }
  419. .banner .txt {
  420. position: absolute;
  421. top: 30rpx;
  422. text-align: center;
  423. color: #fff;
  424. font-size: 28rpx;
  425. left: 0;
  426. height: 192rpx;
  427. line-height: 192rpx;
  428. width: 100%;
  429. }
  430. .catalog .hd {
  431. /* height: 64rpx; */
  432. width: 568rpx;
  433. display: flex;
  434. align-items: center;
  435. margin:20rpx 0 24rpx ;
  436. flex-direction: column;
  437. }
  438. .grey-devide{
  439. width:568rpx;
  440. height:2rpx;
  441. background: #D3D2C7;
  442. }
  443. .blue-devide{
  444. width:98rpx;
  445. height:2rpx;
  446. background: #09AFFF;
  447. margin-top:-2rpx;
  448. }
  449. .catalog .hd .txt {
  450. font-size: 26rpx;
  451. padding: 0 6rpx;
  452. height:30rpx;
  453. margin-bottom:8rpx;
  454. line-height: 30rpx;
  455. }
  456. .catalog .hd .line {
  457. width: 100%;
  458. height: 1px;
  459. background: #d9d9d9;
  460. position: absolute;
  461. z-index: 1;
  462. }
  463. .catalog .bd {
  464. height: auto;
  465. width: 100%;
  466. overflow: hidden;
  467. }
  468. .catalog .bd .item {
  469. display: block;
  470. float: left;
  471. height: 216rpx;
  472. width: 144rpx;
  473. margin-right: 34rpx;
  474. }
  475. .catalog .bd .item.last {
  476. margin-right: 0;
  477. }
  478. .catalog .bd .item .icon {
  479. height: 144rpx;
  480. width: 144rpx;
  481. }
  482. .catalog .bd .item .txt {
  483. display: block;
  484. text-align: center;
  485. font-size: 24rpx;
  486. color: #333;
  487. height: 72rpx;
  488. width: 144rpx;
  489. }
  490. .no-login {
  491. width: 100%;
  492. height: auto;
  493. margin: 0 auto;
  494. background-color: #fff;
  495. }
  496. .no-login .c {
  497. width: 100%;
  498. height: auto;
  499. margin-top: 400rpx;
  500. }
  501. .no-login .c text {
  502. margin: 0 auto;
  503. display: block;
  504. width: 258rpx;
  505. height: 59rpx;
  506. line-height: 29rpx;
  507. text-align: center;
  508. font-size: 35rpx;
  509. }
  510. .no-login button {
  511. width: 90%;
  512. margin: 0 auto;
  513. color: #fff;
  514. font-size: 30rpx;
  515. height: 96rpx;
  516. line-height: 96rpx;
  517. right: 0;
  518. display: flex;
  519. justify-content: center;
  520. align-items: center;
  521. position: flex;
  522. bottom: 0;
  523. left: 0;
  524. border-radius: 0;
  525. padding: 0;
  526. margin-left: 5%;
  527. text-align: center;
  528. border-top-left-radius: 50rpx;
  529. border-bottom-left-radius: 50rpx;
  530. border-top-right-radius: 50rpx;
  531. border-bottom-right-radius: 50rpx;
  532. letter-spacing: 3rpx;
  533. background-image: linear-gradient(to right, #9a9ba1 0%, #9a9ba1 100%);
  534. }
  535. .a-popular {
  536. width: 570rpx;
  537. height: auto;
  538. overflow: hidden;
  539. }
  540. /* .a-popular .b .item {
  541. border-bottom: 1px solid #d9d9d9;
  542. margin: 0 20rpx;
  543. height: 284rpx;
  544. width: 588rpx;
  545. padding-top: 20rpx;
  546. } */
  547. .a-popular .b .img {
  548. width: 170rpx;
  549. height: 174rpx;
  550. border-radius: 10rpx;
  551. margin:0 0 10rpx 0;
  552. }
  553. .a-popular .b .right {
  554. float: left;
  555. height: 264rpx;
  556. width: 336rpx;
  557. display: flex;
  558. flex-flow: row nowrap;
  559. }
  560. .a-popular .b .text {
  561. display: flex;
  562. flex-wrap: nowrap;
  563. flex-direction: column;
  564. /* justify-content: center; */
  565. overflow: hidden;
  566. height: 264rpx;
  567. width: 280rpx;
  568. }
  569. .a-popular .b .name {
  570. width: 280rpx;
  571. display: block;
  572. color: #333;
  573. line-height: 72rpx;
  574. font-size: 36rpx;
  575. }
  576. .a-popular .b .desc {
  577. width: 280rpx;
  578. display: block;
  579. color: #a98f76;
  580. line-height: 50rpx;
  581. font-size: 25rpx;
  582. height: 120rpx;
  583. }
  584. .a-popular .b .price {
  585. width: 280rpx;
  586. display: block;
  587. color: darkred;
  588. /*color: #a81d28;*/
  589. line-height: 50rpx;
  590. font-size: 33rpx;
  591. }
  592. .a-popular .b .price span {
  593. font-size: 24rpx;
  594. color: gray;
  595. }
  596. .a-popular .b .price .btn {
  597. width: 120rpx;
  598. border-radius: 30rpx;
  599. height: 54rpx;
  600. line-height: 54rpx;
  601. font-size: 28rpx;
  602. background-color: #09afff;
  603. color: #fff;
  604. text-align: center;
  605. float: right;
  606. /* margin-right: 10rpx; */
  607. margin-top: -10rpx;
  608. }
  609. .a-popular .b .brand {
  610. font-size: 20rpx;
  611. color: #a98f76;
  612. display: block;
  613. line-height: 30rpx;
  614. padding: 2rpx;
  615. }
  616. .category-line {
  617. display: flex;
  618. flex-wrap: wrap;
  619. }
  620. .product-item{
  621. display: flex;
  622. flex-direction: column;
  623. align-items: center;
  624. width:170rpx;
  625. margin:0 20rpx 40rpx 0;
  626. }
  627. .product-name{
  628. width:166rpx;
  629. display: -webkit-box;
  630. -webkit-box-orient: vertical;
  631. -webkit-line-clamp: 2;
  632. text-overflow: ellipsis;
  633. overflow: hidden;
  634. font-size: 20rpx;
  635. text-align: center;
  636. }
  637. .nav .active-img {
  638. width: 8rpx;
  639. height: 50rpx;
  640. }
  641. .nav .hot-img {
  642. width: 24rpx;
  643. height: 24rpx;
  644. margin: 0 0rpx 0 12rpx;
  645. }
  646. </style>