123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <template>
- <view class="u-waterfall">
- <view id="u-left-column" class="u-column u-left-column">
- <view v-for="(item, index) in leftList" :key="index" class="goods-item" @click="route(item)">
- <view class="demo-img-wrap">
- <image class="demo-image" :src="item.cover_pic" mode="widthFix"></image>
- </view>
- <view class="goods-title t-omit-two">
- {{item.name}}
- </view>
- <view class="goods-vip" v-if="item.is_level == 1 && item.is_negotiable != 1">
- <app-member-price
- :price="item.level_price"
- :theme="themeObject"
- ></app-member-price>
- </view>
- <view class="goods-vip" v-if="item.vip_card_appoint.discount">
- <app-sup-vip
- :discount="item.vip_card_appoint.discount"
- :is_vip_card_user="item.vip_card_appoint.is_vip_card_user"
- ></app-sup-vip>
- </view>
- <view class="goods-content dir-left-nowrap main-between">
- <view>
- <view class="price" :class="theme + '-m-text ' + theme">{{item.price_content}}</view>
- <view class="sales">{{item.sales}}</view>
- </view>
- <view :class="theme + '-m-back app-button-icon ' + theme" v-if="item.goods_stock !== 0" @click.stop="buy(item)">
- </view>
- </view>
- </view>
- </view>
- <view id="u-right-column" class="u-column u-right-column">
- <view v-for="(item, index) in rightList" :key="index" class="goods-item" @click="route(item)" >
- <view class="demo-img-wrap">
- <image class="demo-image" :src="item.cover_pic" mode="widthFix"></image>
- </view>
- <view class="goods-title t-omit-two">
- {{item.name}}
- </view>
- <view class="goods-vip" v-if="item.is_level == 1 && item.is_negotiable != 1">
- <app-member-price
- :price="item.level_price"
- :theme="themeObject"
- ></app-member-price>
- </view>
- <view class="goods-vip" v-if="item.vip_card_appoint.discount">
- <app-sup-vip
- :discount="item.vip_card_appoint.discount"
- :is_vip_card_user="item.vip_card_appoint.is_vip_card_user"
- ></app-sup-vip>
- </view>
- <view class="goods-content dir-left-nowrap main-between">
- <view>
- <view class="price" :class="theme + '-m-text ' + theme">{{item.price_content}}</view>
- <view class="sales">{{item.sales}}</view>
- </view>
- <view :class="theme + '-m-back app-button-icon ' + theme" v-if="item.goods_stock !== 0" @click.stop="buy(item)">
- </view>
- </view>
- </view>
- </view>
- <app-attr :goods="goods" :attrGroupList="goods.attr_groups" :theme="theme" :show="attrShow"></app-attr>
- </view>
- </template>
- <script>
- import appSupVip from '../../components/page-component/app-sup-vip/app-sup-vip.vue';
- import appMemberPrice from '../../components/page-component/app-member-mark/app-member-price.vue';
- import appAttr from '../../components/page-component/app-attr/app-attr.vue';
- import {mapState} from "vuex";
- export default {
- name: "u-waterfall",
- props: {
- value: {
- type: Array,
- required: true,
- default: function() {
- return [];
- }
- },
- addTime: {
- type: [Number, String],
- default: 200
- },
- idKey: {
- type: String,
- default: 'id'
- },
- theme: String,
- themeObject: Object
- },
- provide() {
- return {
- uWaterfall: this
- }
- },
- data() {
- return {
- leftList: [],
- rightList: [],
- tempList: [],
- children: [],
- attrShow: 0,
- goods: null
- }
- },
- watch: {
- copyFlowList(nVal, oVal) {
- let startIndex = Array.isArray(oVal) && oVal.length > 0 ? oVal.length : 0;
- this.tempList = this.tempList.concat(this.cloneData(nVal.slice(startIndex)));
- this.splitData();
- }
- },
- mounted() {
- this.tempList = this.cloneData(this.copyFlowList);
- this.splitData();
- },
- computed: {
- copyFlowList() {
- return this.cloneData(this.value);
- }
- },
- methods: {
- async splitData() {
- if (!this.tempList.length) return;
- let leftRect = await this.uGetRect('#u-left-column');
- let rightRect = await this.uGetRect('#u-right-column');
- let item = this.tempList[0];
- if(!item) return ;
- if (leftRect.height < rightRect.height) {
- this.leftList.push(item);
- } else if (leftRect.height > rightRect.height) {
- this.rightList.push(item);
- } else {
- if (this.leftList.length <= this.rightList.length) {
- this.leftList.push(item);
- } else {
- this.rightList.push(item);
- }
- }
- this.tempList.splice(0, 1);
- if (this.tempList.length) {
- setTimeout(() => {
- this.splitData();
- }, this.addTime);
- }
- },
- cloneData(data) {
- return JSON.parse(JSON.stringify(data));
- },
- uGetRect(element) {
- return new Promise((resolve) => {
- const query = uni.createSelectorQuery().in(this);
- query.select(element).boundingClientRect(data => {
- resolve(data);
- }).exec();
- })
- },
- buy(item) {
- this.goods = item;
- this.attrShow = Math.random();
- },
- route(item) {
- uni.navigateTo({
- url: item.page_url
- });
- },
- emptyList() {
- this.leftList = [];
- this.tempList = [];
- this.rightList = [];
- }
- },
- components: {
- appMemberPrice,
- appSupVip,
- appAttr
- }
- }
- </script>
- <style lang="scss" scoped>
- .u-waterfall {
- display: flex;
- flex-direction: row;
- align-items: flex-start;
- }
- .u-column {
- display: flex;
- flex: 1;
- flex-direction: column;
- height: auto;
- }
- .u-image {
- width: 100%;
- }
- .u-right-column {
- margin-right: 24upx;
- margin-left: 7upx;
- }
- .u-left-column {
- margin-left: 24upx;
- margin-right: 7upx;
- }
- .demo-image {
- width: 344rpx;
- }
- .goods-item {
- width: 344rpx;
- background-color: #fff;
- margin-top: 20upx;
- overflow: hidden;
- border-radius: 16upx;
- }
- .goods-title {
- font-size: 26upx;
- color: #373737;
- padding: 0 20upx;
- }
- .goods-vip {
- padding: 0 20upx;
- margin-top: 12upx;
- }
- .goods-content {
- padding: 0 20upx;
- margin: 12upx 0 28upx 0;
- }
- .price {
- font-size: 22upx;
- }
- .sales {
- font-size: 18upx;
- color: #b0b0b0;
- }
- .app-button-icon {
- width: 40rpx;
- height: 40rpx;
- display: block;
- background-repeat: no-repeat;
- background-size: cover;
- background-position: center;
- background-image: url('../../static/image/icon/goods-cart.png');
- }
- </style>
|