cat.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <template>
  2. <view class="app-layout">
  3. <app-layout>
  4. <template v-if="cat_style === `1`">
  5. <view class="app-body dir-top-nowrap">
  6. <view class="app-item" v-for="(item, index) in list" :key="index">
  7. <app-jump-button
  8. form
  9. open_type="navigate"
  10. :url="item.page_url"
  11. >
  12. <view class="app-image"
  13. :style="{backgroundImage: `url(${item.big_pic_url})`}"
  14. ></view>
  15. </app-jump-button>
  16. </view>
  17. </view>
  18. </template>
  19. <template v-else-if="cat_style === `2`">
  20. <view class="app-left-right dir-left-nowrap">
  21. <app-category-list
  22. @click="activeThree"
  23. :windowHeight="windowHeight"
  24. :windowWidth="windowWidth"
  25. :botHeight="botHeight"
  26. :height="height"
  27. :noSetHeight="setHeight"
  28. :list="list"
  29. ></app-category-list>
  30. <scroll-view scroll-y class="app-right" :style="{height: `${setHeight}`}" style="padding-top:20rpx">
  31. <image class="app-background" :src="list[activeIndex].advert_pic"
  32. v-if="list[activeIndex].advert_pic"></image>
  33. <view class="app-item" v-for="(item, index) in list[activeIndex].child" :key="index">
  34. <app-jump-button form open_type="navigate" :url="item.page_url">
  35. <image :src="item.big_pic_url" class="app-image"></image>
  36. </app-jump-button>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. </template>
  41. <template v-else-if="cat_style === `3`">
  42. <view class="app-small dir-left-wrap">
  43. <view class="app-item" v-for="(item, index) in list" :key="index">
  44. <app-jump-button arrangement="column" form open_type="navigate" :url="item.page_url">
  45. <image class="app-image" :src="item.pic_url"></image>
  46. <text class="app-name" style="text-align: center">{{item.name}}</text>
  47. </app-jump-button>
  48. </view>
  49. </view>
  50. </template>
  51. <template v-else-if="cat_style === `4`">
  52. <view class="app-left-right-t dir-left-nowrap">
  53. <app-category-list :windowHeight="windowHeight" :windowWidth="windowWidth" :botHeight="botHeight"
  54. @click="activeThree" :height="height" :noSetHeight="setHeight"
  55. :list="list"></app-category-list>
  56. <scroll-view scroll-y class="app-right" :style="{height: `${setHeight}`}"
  57. style="padding-top: 20rpx">
  58. <image class="app-background" :src="list[activeIndex].advert_pic"
  59. v-if="list[activeIndex].advert_pic"></image>
  60. <view class="app-item" v-for="(item, index) in list[activeIndex].child" :key="index">
  61. <app-jump-button arrangement="column" form open_type="navigate" :url="item.page_url">
  62. <image :src="item.pic_url" class="app-image"></image>
  63. <text class="app-name">{{item.name}}</text>
  64. </app-jump-button>
  65. </view>
  66. </scroll-view>
  67. </view>
  68. </template>
  69. <template v-else-if="cat_style === `6`">
  70. <view class="app-left-right-f dir-left-nowrap">
  71. <app-category-list :windowHeight="windowHeight" :windowWidth="windowWidth" :botHeight="botHeight"
  72. @click="activeThree" :height="height" :noSetHeight="setHeight"
  73. :list="list"></app-category-list>
  74. <scroll-view scroll-y class="app-right" :style="{height: `${setHeight}`}">
  75. <image class="app-background" :src="list[activeIndex].advert_pic"
  76. v-if="list[activeIndex].advert_pic"></image>
  77. <view class="app-item" v-for="(item, index) in list[activeIndex].child" :key="index">
  78. <view class="app-top">
  79. <app-jump-button arrangement="left" form open_type="navigate" :url="item.page_url">
  80. <text class="app-text">{{item.name}}</text>
  81. <view class="app-icon dir-left-nowrap cross-center">
  82. <text>更多</text>
  83. <icon type></icon>
  84. </view>
  85. </app-jump-button>
  86. </view>
  87. <view v-for="(a, i) in item.child" :key="i">
  88. <app-jump-button form open_type="navigate" :url="a.page_url">
  89. <image :src="a.big_pic_url" class="app-image"></image>
  90. </app-jump-button>
  91. </view>
  92. </view>
  93. </scroll-view>
  94. </view>
  95. </template>
  96. <template v-else-if="cat_style === `7`">
  97. <view class="app-left-right-s dir-left-nowrap">
  98. <app-category-list
  99. :windowHeight="windowHeight"
  100. :windowWidth="windowWidth"
  101. :botHeight="botHeight"
  102. @click="activeThree"
  103. :height="height"
  104. :noSetHeight="setHeight"
  105. :list="list"
  106. ></app-category-list>
  107. <scroll-view
  108. scroll-y
  109. class="app-right"
  110. :style="{height: `${setHeight}`}"
  111. style="padding-top: 20rpx"
  112. >
  113. <image lazy-load class="app-background"
  114. :src="list[activeIndex].advert_pic"
  115. v-if="list[activeIndex].advert_pic"
  116. ></image>
  117. <view class="app-item" v-for="(item, index) in list[activeIndex].child" :key="index">
  118. <view class="app-top">
  119. <app-jump-button arrangement="left" form open_type="navigate" :url="item.page_url">
  120. <text class="app-text">{{item.name}}</text>
  121. <view class="app-icon dir-left-nowrap cross-center">
  122. <text>更多</text>
  123. <icon type></icon>
  124. </view>
  125. </app-jump-button>
  126. </view>
  127. <view class="app-item-child" v-for="(a, i) in item.child" :key="i">
  128. <app-jump-button arrangement="column" form open_type="navigate" :url="a.page_url">
  129. <image :src="a.pic_url" class="app-image"></image>
  130. <text class="app-text">{{a.name}}</text>
  131. </app-jump-button>
  132. </view>
  133. </view>
  134. </scroll-view>
  135. </view>
  136. </template>
  137. </app-layout>
  138. </view>
  139. </template>
  140. <script>
  141. import {mapGetters, mapState} from 'vuex';
  142. import appCategoryList from '../../../components/page-component/app-category-list/app-category-list.vue';
  143. export default {
  144. components: {
  145. 'app-category-list': appCategoryList,
  146. },
  147. data() {
  148. return {
  149. scrollTop: 0,
  150. list: [],
  151. goods: [],
  152. request: true,
  153. page: 1,
  154. classId: 0,
  155. activeIndex: 0,
  156. activeIndexTwo: 0,
  157. height: 0,
  158. over: false,
  159. scrollHeight: 0,
  160. mch_id: 0,
  161. cat_style: 0,
  162. cat_id: 0,
  163. }
  164. },
  165. computed: {
  166. ...mapGetters('mallConfig', {
  167. tabBarNavs: 'getNavBar'
  168. }),
  169. ...mapState('gConfig', {
  170. windowHeight: state => state.systemInfo.windowHeight,
  171. windowWidth: state => state.systemInfo.windowWidth,
  172. }),
  173. ...mapGetters('iPhoneX', {
  174. botHeight: 'getBotHeight'
  175. }),
  176. setHeight() {
  177. return this.windowHeight + 'px';
  178. }
  179. },
  180. onReachBottom() {
  181. },
  182. /**
  183. * 生命周期函数--监听页面加载
  184. */
  185. onLoad(options) { this.$commonLoad.onload(options);
  186. const self = this;
  187. self.mch_id = options.mch_id;
  188. self.$request({
  189. url: self.$api.mch.cat_style,
  190. data: {
  191. mch_id: self.mch_id,
  192. }
  193. }).then(info => {
  194. if (info.code === 0) {
  195. self.cat_style = info.data.setting.cat_style;
  196. self.loadData();
  197. }
  198. });
  199. },
  200. methods: {
  201. loadData: function () {
  202. const self = this;
  203. self.$showLoading();
  204. self.$request({
  205. url: self.$api.mch.cats_list,
  206. data: {
  207. mch_id: self.mch_id,
  208. cat_id: self.cat_id
  209. }
  210. }).then(info => {
  211. self.$hideLoading();
  212. if (info.code === 0) {
  213. self.list = info.data.list
  214. }
  215. }).catch(info => {
  216. self.$hideLoading();
  217. })
  218. },
  219. // 点击导航栏
  220. active(item) {
  221. this.page = 1;
  222. uni.showLoading({
  223. text: '加载中...',
  224. mask: true
  225. });
  226. for (let i = 0; i < this.list.length; i++) {
  227. if (this.list[i].active !== item.active) {
  228. this.list[i].active = false;
  229. }
  230. if (this.list[i].id === item.id) {
  231. this.list[i].active = true;
  232. }
  233. }
  234. this.$request({
  235. url: `${this.$api.default.goods_list}&page=${this.page}&cat_id=${item.id}`
  236. }).then(response => {
  237. uni.hideLoading();
  238. this.goods = response.data.list;
  239. this.page = 1;
  240. this.classId = item.id;
  241. this.over = false;
  242. });
  243. this.over = false;
  244. },
  245. // 下拉分页请求
  246. req() {
  247. this.$request({
  248. url: `${this.$api.default.goods_list}&page=${this.page}&cat_id=${this.classId}`
  249. }).then(response => {
  250. if (response.data.list.length > 0) {
  251. this.goods.push(...response.data.list);
  252. } else {
  253. this.over = true;
  254. }
  255. uni.hideLoading();
  256. });
  257. },
  258. activeThree(item) {
  259. for (let i = 0; i < this.list.length; i++) {
  260. if (this.list[i].active !== item.active) {
  261. this.list[i].active = false;
  262. }
  263. if (this.list[i].id === item.id) {
  264. this.list[i].active = true;
  265. this.activeIndex = i;
  266. }
  267. }
  268. }
  269. },
  270. }
  271. </script>
  272. <style lang="scss" scoped>
  273. .app-layout {
  274. background: white;
  275. min-height: 100vh;
  276. }
  277. .app-body {
  278. width: #{750rpx};
  279. background-color: white;
  280. padding: 0 #{24rpx} #{24rpx} #{24rpx};
  281. .app-item {
  282. width: #{702rpx};
  283. height: #{212rpx};
  284. margin-top: #{20rpx};
  285. .app-image {
  286. background-size: 100% 100%;
  287. background-repeat: no-repeat;
  288. width: 100%;
  289. height: 100%;
  290. }
  291. }
  292. }
  293. .app-small {
  294. width: $screen-width;
  295. padding: 0 #{27rpx};
  296. background-color: white;
  297. .app-item {
  298. width: #{120rpx};
  299. margin: #{64rpx} #{27rpx} 0 #{27rpx};
  300. .app-image {
  301. width: #{120rpx};
  302. height: #{120rpx};
  303. margin-bottom: #{20rpx};
  304. }
  305. .app-name {
  306. color: #353535;
  307. font-size: #{26rpx};
  308. width: 100%;
  309. word-break: break-all;
  310. text-overflow: ellipsis;
  311. display: -webkit-box;
  312. -webkit-box-orient: vertical;
  313. -webkit-line-clamp: 1;
  314. overflow: hidden;
  315. }
  316. }
  317. }
  318. .app-top {
  319. width: $screen-width;
  320. }
  321. .app-top-t {
  322. width: $screen-width;
  323. background: white;
  324. .app-t {
  325. width: 100%;
  326. padding-top: #{24rpx};
  327. padding-left: #{24rpx};
  328. > text {
  329. margin-bottom: #{20rpx};
  330. }
  331. .app-text {
  332. border: #{1rpx} solid #cccccc;
  333. font-size: #{28rpx};
  334. color: #666666;
  335. padding: 0 #{28rpx};
  336. display: inline-block;
  337. height: #{54rpx};
  338. line-height: #{54rpx};
  339. margin-right: #{24rpx};
  340. border-radius: #{28rpx};
  341. }
  342. .app-active-color {
  343. color: #ff4544;
  344. border: #{1rpx} solid #ff4544;
  345. }
  346. }
  347. }
  348. .app-left-right {
  349. width: $screen-width;
  350. background: #ffffff;
  351. .app-right {
  352. width: #{524rpx};
  353. margin-left: #{22rpx};
  354. .app-background {
  355. width: #{500rpx};
  356. height: #{184rpx};
  357. margin: #{20rpx} #{24rpx} #{20rpx} 0;
  358. }
  359. .app-item {
  360. margin-left: #{2rpx};
  361. height: #{158rpx};
  362. width: #{524rpx};
  363. margin-bottom: #{20rpx};
  364. .app-image {
  365. height: #{158rpx};
  366. width: #{524rpx};
  367. }
  368. }
  369. }
  370. }
  371. .app-left-right-t {
  372. width: $screen-width;
  373. background: white;
  374. .app-right {
  375. width: #{546rpx};
  376. .app-background {
  377. width: #{500rpx};
  378. height: #{184rpx};
  379. margin: #{20rpx} #{24rpx} #{20rpx} #{24rpx};
  380. }
  381. .app-item {
  382. width: #{182rpx};
  383. height: #{138rpx};
  384. display: inline-block;
  385. margin-bottom: #{40rpx};
  386. .app-image {
  387. height: #{104rpx};
  388. width: #{104rpx};
  389. }
  390. .app-name {
  391. font-size: #{26rpx};
  392. margin-top: #{8rpx};
  393. color: #353535;
  394. word-break: break-all;
  395. text-overflow: ellipsis;
  396. display: -webkit-box;
  397. -webkit-box-orient: vertical;
  398. -webkit-line-clamp: 1;
  399. overflow: hidden;
  400. }
  401. }
  402. }
  403. }
  404. .app-left-right-f {
  405. width: $screen-width;
  406. background: white;
  407. .app-right {
  408. width: #{524rpx};
  409. margin-left: #{22rpx};
  410. .app-background {
  411. width: #{500rpx};
  412. height: #{184rpx};
  413. margin: #{20rpx} #{24rpx} #{20rpx} 0;
  414. }
  415. .app-item {
  416. margin-left: #{2rpx};
  417. width: #{524rpx};
  418. .app-image {
  419. width: #{524rpx};
  420. height: #{158rpx};
  421. margin-bottom: #{20rpx};
  422. }
  423. .app-top {
  424. position: relative;
  425. width: #{524rpx};
  426. margin: #{20rpx} 0 #{40rpx} 0;
  427. }
  428. .app-text {
  429. font-size: #{28rpx};
  430. color: #353535;
  431. }
  432. .app-icon {
  433. position: absolute;
  434. right: #{24rpx};
  435. text {
  436. font-size: #{26rpx};
  437. color: #999999;
  438. margin-left: #{16rpx};
  439. }
  440. icon {
  441. width: #{13rpx};
  442. height: #{22rpx};
  443. background-image: url("../../../static/image/icon/arrow-right.png");
  444. background-size: 100% 100%;
  445. background-repeat: no-repeat;
  446. margin-left: #{24rpx};
  447. }
  448. }
  449. }
  450. }
  451. }
  452. .app-left-right-s {
  453. width: $screen-width;
  454. background: white;
  455. .app-right {
  456. width: #{546rpx};
  457. background-color: white;
  458. .app-background {
  459. width: #{500rpx};
  460. height: #{184rpx};
  461. margin: #{20rpx} #{24rpx} #{40rpx} #{24rpx};
  462. }
  463. .app-item {
  464. width: #{546rpx};
  465. .app-top {
  466. width: 100%;
  467. padding-left: #{24rpx};
  468. margin-bottom: #{40rpx};
  469. .app-text {
  470. font-size: #{28rpx};
  471. color: #353535;
  472. }
  473. .app-icon {
  474. position: absolute;
  475. right: #{24rpx};
  476. text {
  477. font-size: #{26rpx};
  478. color: #999999;
  479. margin-left: #{16rpx};
  480. }
  481. icon {
  482. width: #{13rpx};
  483. height: #{22rpx};
  484. background-image: url("../../../static/image/icon/arrow-right.png");
  485. background-size: 100% 100%;
  486. background-repeat: no-repeat;
  487. margin-left: #{24rpx};
  488. }
  489. }
  490. }
  491. .app-item-child {
  492. display: inline-block;
  493. height: #{138rpx};
  494. width: #{182rpx};
  495. margin-bottom: #{40rpx};
  496. .app-image {
  497. width: #{104rpx};
  498. height: #{104rpx};
  499. }
  500. .app-text {
  501. font-size: #{26rpx};
  502. color: #353535;
  503. margin-top: #{8rpx};
  504. }
  505. }
  506. }
  507. }
  508. }
  509. </style>