catalog.vue 16 KB

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