index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <app-layout :overflow="false">
  3. <template v-if="hasActivity && activityLoading">
  4. <view class="search dir-left-nowrap main-between cross-center">
  5. <view class="input dir-left-nowrap main-center cross-center" @click="search">
  6. <view class="search-icon"></view>
  7. <view class="text">搜索</view>
  8. </view>
  9. <view class="icon" @click="setSwitch">
  10. <image class="icon-img" :src="style_switch ? '../image/list-2.png' : '../image/list-1.png' "></image>
  11. </view>
  12. </view>
  13. <view class="rule" id="rule" :class="[is_fixed ? 'rule-fixed' : 'rule-no-fixed']" :style="{'background': getTheme.background_gradient_l}">
  14. <view class="rule-top dir-left-nowrap main-between cross-top">
  15. <view class="icon"></view>
  16. <view class="text">
  17. <template v-if="rule_type === 1">
  18. <block v-for="(item, index) in rule"
  19. :key="index">
  20. 满{{item.min_money}}{{item.discount_type === '1' ? '减' + item.cut : '打' + item.discount + '折'}}{{index !== rule.length - 1 ? ', ' : ''}}
  21. </block>
  22. </template>
  23. <template v-else-if="rule_type === 2">
  24. 每满{{rule.min_money}}减{{rule.cut}}
  25. </template>
  26. </view>
  27. </view>
  28. <view class="dir-left-nowrap main-between">
  29. <view class="time dir-left-nowrap cross-center">
  30. <view class="time-icon"></view>
  31. <view class="time-text">距离活动结束仅剩:{{time_str.day}}天{{time_str.hou}}时{{time_str.min}}分</view>
  32. </view>
  33. <view class="rule-text" @click="goRouter">活动规则</view>
  34. </view>
  35. </view>
  36. <scroll-view scroll-x id="cats" class="cats dir-left-nowrap">
  37. <view class="cats-item"
  38. :style="{'background-color': item.active === true ? getTheme.background : ''}"
  39. :class="item.active === true ? 'cats-item-active' : 'cats-item-no'"
  40. v-for="(item, index) in cats"
  41. @click="active(item)"
  42. :key="index">
  43. {{item.name}}
  44. </view>
  45. </scroll-view>
  46. <view>
  47. <template v-if="style_switch">
  48. <u-water-fall v-model="flowList" ref="waterFall" :theme="getTheme">
  49. </u-water-fall>
  50. </template>
  51. <template v-else>
  52. <view class="goods-item dir-left-nowrap " v-for="(item ,index) in flowList" @click="routeGood(item)" :key="index">
  53. <image class="goods-pic" :src="item.cover_pic"></image>
  54. <view class="goods-cont dir-top-nowrap main-between">
  55. <view>
  56. <view class="goods-name t-omit-two"> {{item.name}}</view>
  57. <view class="goods-vip" v-if="item.is_level == 1 && item.is_negotiable != 1">
  58. <app-member-price
  59. :price="item.level_price"
  60. :theme="getTheme"
  61. ></app-member-price>
  62. </view>
  63. <view class="goods-vip" v-if="item.vip_card_appoint.discount">
  64. <app-sup-vip
  65. :discount="item.vip_card_appoint.discount"
  66. :is_vip_card_user="item.vip_card_appoint.is_vip_card_user"
  67. ></app-sup-vip>
  68. </view>
  69. </view>
  70. <view class="dir-left-nowrap main-between">
  71. <view>
  72. <view :style="{'color': getTheme.color}" class="price">{{item.price_content}}</view>
  73. <view class="sales">{{item.sales}}</view>
  74. </view>
  75. <view
  76. v-if="item.goods_stock !== 0"
  77. @click.stop="buyProduct(item)"
  78. :style="{'background-color': getTheme.background}"
  79. :class="'app-button-icon-cart box-grow-0 app-button-icon'"
  80. ></view>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <view class="u-loading-list" v-if="bottomLoading">加载中...</view>
  86. </view>
  87. <view class="no-empty main-center" v-if="!loading && flowList.length === 0">
  88. <app-no-goods title="该分类下无相关内容哦~" background="#f7f7f7"></app-no-goods>
  89. </view>
  90. </template>
  91. <template v-else-if="!hasActivity && activityLoading">
  92. <view class="no-empty main-center" >
  93. <app-no-goods title="暂无满减商品" background="#f7f7f7"></app-no-goods>
  94. </view>
  95. </template>
  96. <app-attr :goods="goods" :attrGroupList="goods.attr_groups" :theme="getTheme" :show="attrShow"></app-attr>
  97. </app-layout>
  98. </template>
  99. <script>
  100. import { mapGetters, mapState } from 'vuex';
  101. import uWaterFall from '../u-waterfall.vue';
  102. import appDiyGoodsList from "../../../components/page-component/app-diy-goods-list/app-diy-goods-list.vue";
  103. import appNoGoods from "../../../components/page-component/app-no-goods/app-no-goods.vue";
  104. import appAttr from '../../../components/page-component/app-attr/app-attr.vue';
  105. export default {
  106. name: "index",
  107. data() {
  108. return {
  109. flowList: [],
  110. page: 1,
  111. page_count: 1,
  112. rule_type: 1,
  113. rule: null,
  114. cats: [],
  115. cat_id: null,
  116. time_str: {
  117. day: '00',
  118. hou: '00',
  119. min: '00'
  120. },
  121. timing: null,
  122. is_fixed: false,
  123. style_switch: false,
  124. loading: false,
  125. hasActivity: true,
  126. activityLoading: false,
  127. is_no_scroll: true,
  128. goods: {},
  129. attrShow: 0,
  130. no_active: false,
  131. bottomLoading: false
  132. }
  133. },
  134. computed: {
  135. ...mapGetters('mallConfig', {
  136. getTheme: 'getTheme'
  137. }),
  138. ...mapState('gConfig', {
  139. windowWidth: state => state.systemInfo.windowWidth
  140. })
  141. },
  142. methods: {
  143. async getListData(status) {
  144. this.loading = true;
  145. const e = await this.$request({
  146. url: this.$api.full_reduce.list,
  147. data: {
  148. page: this.page,
  149. cat_id: this.cat_id
  150. }
  151. });
  152. this.loading = false;
  153. if (e.code === 0) {
  154. this.no_active = false;
  155. let list = e.data.list;
  156. if (status === true) {
  157. this.flowList.push(...list);
  158. } else {
  159. this.flowList = list;
  160. }
  161. this.page_count = e.data.pagination.page_count;
  162. let page = this.page;
  163. if (page++ === this.page_count) {
  164. this.bottomLoading = false;
  165. }
  166. }
  167. },
  168. async getIndex() {
  169. const e = await this.$request({
  170. url: this.$api.full_reduce.index
  171. });
  172. this.activityLoading = true;
  173. if (e.code === 0) {
  174. if (this.$validation.empty(e.data)) {
  175. this.hasActivity = false;
  176. } else {
  177. this.rule = e.data.rule;
  178. this.rule_type = e.data.rule_type;
  179. if (this.$validation.date(e.data.time)) {
  180. this.getTiming(e.data.time);
  181. }
  182. }
  183. }
  184. },
  185. async getCats() {
  186. const e = await this.$request({
  187. url: this.$api.default.cat_list
  188. });
  189. if (e.code === 0) {
  190. this.cats = e.data.list;
  191. this.cat_id = this.cats[0].id;
  192. }
  193. },
  194. active(item) {
  195. this.bottomLoading = false;
  196. if (!this.no_active) {
  197. this.no_active = true;
  198. this.cats.forEach((item) => {
  199. item.active = false;
  200. });
  201. item.active = true;
  202. this.page = 1;
  203. this.cat_id = item.id;
  204. this.flowList = [];
  205. if (this.style_switch) {
  206. this.$refs.waterFall.emptyList();
  207. }
  208. uni.pageScrollTo({
  209. scrollTop: 0,
  210. duration: 500
  211. });
  212. this.getListData();
  213. }
  214. },
  215. getTiming(data) {
  216. clearInterval(this.timing);
  217. let time_str = new Date(data.replace(/-/g, '/'));
  218. this.now_time(time_str);
  219. this.timing = setInterval(() => {
  220. this.now_time(time_str);
  221. }, 1000);
  222. },
  223. now_time(time_str) {
  224. let time = time_str.getTime() - new Date().getTime();
  225. if (time < 0) {
  226. clearInterval(this.timing);
  227. }
  228. let day = parseInt(time/1000/60/60/24);
  229. let hou = parseInt((time/1000/60/60)%24);
  230. let min = parseInt((time/1000/60)%60);
  231. this.time_str.day = day < 10 ? '0' + day : day;
  232. this.time_str.hou = hou < 10 ? '0' + hou : hou;
  233. this.time_str.min = min < 10 ? '0' + min : min;
  234. },
  235. goRouter() {
  236. uni.navigateTo({
  237. url: `/pages/rules/index?url=${encodeURIComponent(this.$api.full_reduce.index)}&key=content`
  238. });
  239. },
  240. routeGood(item) {
  241. uni.navigateTo({
  242. url: item.page_url
  243. });
  244. },
  245. search() {
  246. uni.navigateTo({
  247. url: `/pages/full_reduce/search/search`
  248. })
  249. },
  250. setSwitch() {
  251. this.style_switch = !this.style_switch;
  252. },
  253. buyProduct(item) {
  254. this.goods = item;
  255. this.attrShow = Math.random();
  256. },
  257. },
  258. onReachBottom() {
  259. if (this.page < this.page_count) {
  260. this.page++;
  261. this.bottomLoading = true;
  262. this.getListData(true);
  263. }
  264. },
  265. mounted() {
  266. this.getIndex().then(() => {
  267. this.getCats().then(() => {
  268. this.getListData();
  269. });
  270. });
  271. },
  272. components: {
  273. uWaterFall,
  274. appDiyGoodsList,
  275. appNoGoods,
  276. appAttr
  277. },
  278. onHide() {
  279. clearInterval(this.timing);
  280. },
  281. onUnload() {
  282. clearInterval(this.timing);
  283. },
  284. }
  285. </script>
  286. <style scoped lang="scss">
  287. .search {
  288. height: 88upx;
  289. width: 750upx;
  290. border-bottom: 1upx solid #d6d6db;
  291. position: fixed;
  292. top: 0;
  293. background-color: #efeff4;
  294. z-index: 1000;
  295. padding: 0 24upx;
  296. .icon {
  297. width: 60upx;
  298. height: 60upx;
  299. padding: 15upx;
  300. }
  301. .icon-img {
  302. width: 100%;
  303. height: 100%
  304. }
  305. .input {
  306. width: 620upx;
  307. height: 56upx;
  308. border-radius: 28upx;
  309. background-color: #ffffff;
  310. border: 1upx solid #eaeaef;
  311. .search-icon {
  312. width: 25upx;
  313. height: 25upx;
  314. background-size: 100% 100%;
  315. background-image: url("../../../static/image/icon/search.png");
  316. background-repeat: no-repeat;
  317. margin-right: 5upx;
  318. }
  319. .text {
  320. font-size: 25upx;
  321. color: #b2b2b2;
  322. margin-left: 5upx;
  323. }
  324. }
  325. }
  326. .cats {
  327. height: 100upx;
  328. line-height: 100upx;
  329. width: 750upx;
  330. background-color: #ffffff;
  331. border-top:1upx solid #eaeaef;
  332. border-bottom: 1upx solid #eaeaef;
  333. white-space:nowrap;
  334. padding-left: 20upx;
  335. position: sticky;
  336. top: 88upx;
  337. z-index: 1000;
  338. .cats-item {
  339. display: inline-block;
  340. margin-right: 32upx;
  341. height: 58upx;
  342. line-height: 58upx;
  343. border-radius: 29upx;
  344. font-size: 26upx;
  345. padding: 0 28upx;
  346. }
  347. .cats-item-active {
  348. color: #ffffff;
  349. }
  350. .cats-item-no {
  351. color: #666666;
  352. }
  353. }
  354. .cats-fixed {
  355. position: fixed;
  356. top: 88upx;
  357. z-index: 1000;
  358. }
  359. .rule-fixed {
  360. margin-top: 188upx;
  361. }
  362. .rule-no-fixed {
  363. margin-top: 88upx;
  364. }
  365. .rule {
  366. padding: 36upx 24upx 30upx 24upx;
  367. .rule-top {
  368. margin-bottom: 30upx;
  369. }
  370. .icon {
  371. width: 54upx;
  372. height: 28upx;
  373. background-image: url("../image/icon.png");
  374. background-size: 100% 100%;
  375. background-repeat: no-repeat;
  376. margin-top: 7upx;
  377. }
  378. .text {
  379. width: 648upx;
  380. font-weight: bold;
  381. font-size: 28upx;
  382. color:#FFFFFF;
  383. margin-left: 8upx;
  384. }
  385. .rule-text {
  386. width: 120upx;
  387. height: 40upx;
  388. border-radius: 20upx;
  389. background-color: rgba(0,0,0,.4);
  390. color: #ffffff;
  391. font-size:22upx;
  392. line-height: 40upx;
  393. text-align: center;
  394. }
  395. .time-icon {
  396. width: 26upx;
  397. height: 26upx;
  398. background-image: url("../image/time.png");
  399. background-repeat: no-repeat;
  400. background-size: 100% 100%;
  401. margin-right: 8upx;
  402. }
  403. .time-text {
  404. font-size: 26upx;
  405. color: #ffffff;
  406. line-height: 1;
  407. }
  408. }
  409. .no-empty {
  410. width: 100%;
  411. margin-top: 150upx;
  412. }
  413. .goods-item {
  414. padding: 24upx;
  415. background-color: #ffffff;
  416. border-bottom: 1upx solid #e2e2e2;
  417. .goods-pic {
  418. width: 200upx;
  419. height: 200upx;
  420. border-radius: 13upx;
  421. margin-right: 24upx;
  422. }
  423. .goods-cont {
  424. width: 478upx;
  425. .goods-name {
  426. font-size: 26upx;
  427. color: #353535;
  428. }
  429. .goods-vip {
  430. margin-top: 8upx;
  431. }
  432. .app-button-icon-cart {
  433. background-image: url('../../../static/image/icon/cats.png');
  434. }
  435. .app-button-icon {
  436. width: #{56rpx};
  437. height: #{56rpx};
  438. display: block;
  439. background-repeat: no-repeat;
  440. background-size: cover;
  441. background-position: center;
  442. }
  443. .sales {
  444. font-size: 22upx;
  445. color: #b0b0b0;
  446. }
  447. .price {
  448. font-size: 24upx;
  449. }
  450. }
  451. }
  452. .u-loading-list {
  453. height: 64upx;
  454. line-height: 64upx;
  455. text-align: center;
  456. color: #b0b0b0;
  457. font-size: 24upx;
  458. }
  459. </style>