123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <template>
- <view :class="['qn-page-' + theme]">
- <view class="search-input clearfix">
- <view class="input-box float_left">
- <u-search
- @click="goPage('/pagesT/search/index', 'redirectTo')"
- placeholder="请输入关键字"
- :input-style="input_style"
- :search-icon-color="primaryColor"
- v-model="keyword"
- :show-action="false"
- shape="square"
- :clearabled="true"
- bg-color="#f4f4f4"
- disabled
- ></u-search>
- </view>
- <view class="float_right type-view" @click="changeStyle"><text class="ibonfont" :class="[is_list ? 'ibonfenlei1' : 'ibonfenlei2']"></text></view>
- </view>
- <view class="goods-ul">
- <scroll-view @scrolltolower="lower" scroll-y class="search_list">
- <Aempty text="没有商品哦~~" src="https://onlineimg.qianniao.vip/search.png" v-if="!goods_list.length"></Aempty>
- <block v-if="goods_list.length > 0">
- <u-waterfall v-model="goods_list" ref="uWaterfall" v-if="!is_list">
- <template v-slot:left="{ leftList }">
- <block v-for="(item, index) in leftList" :key="index"><GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem></block>
- </template>
- <template v-slot:right="{ rightList }">
- <block v-for="(item, index) in rightList" :key="index"><GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem></block>
- </template>
- </u-waterfall>
- <view v-else :class="[is_list ? 'goods-li' : 'goods-li-inline']" v-for="(item, index) in goods_list" :key="index">
- <GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem>
- </view>
- </block>
- <u-loadmore margin-top="20" v-if="goods_list.length" :status="load_status" />
- </scroll-view>
- </view>
- <CartFloat />
- <AddCardModel :selAddress="now_sel_address" @close="is_add_show = false" :isShow="is_add_show" @change="cardModelPopChange" :goodsId="goods_id" />
- </view>
- </template>
- <script>
- import AddCardModel from '@/components/AddCardModel';
- import GoodsItem from '@/components/GoodsItem.vue';
- import CartFloat from '../components/CartFloat.vue';
- export default {
- components: {
- AddCardModel,
- GoodsItem,
- CartFloat
- },
- data() {
- return {
- now_sel_address: {},
- show_sku: false,
- is_list: true,
- keyword: '',
- goods_list: [],
- page: 1,
- pageSize: 10,
- pageTotal: 0,
- goods_id: 0,
- load_status: 'loadmore',
- is_add_show: false
- };
- },
- onLoad(options) {
- // 接收传值
- if (options.key) {
- this.keyword = options.key;
- } else {
- const scene = decodeURIComponent(options.scene);
- this.keyword = scene;
- }
- this.searchGoods();
- // #ifdef MP-WEIXIN
- // 小程序的原生菜单中显示分享按钮
- uni.showShareMenu({
- withShareTicket: false,
- menus: ['shareAppMessage', 'shareTimeline']
- });
- // #endif
- },
- methods: {
- // 加入购物车弹窗
- addCard(id) {
- this.goods_id = id;
- this.is_add_show = true;
- },
- cardModelPopChange(obj) {
- if (!obj.show) {
- this.is_add_show = false;
- }
- },
- // 切换商品列表展示样式
- changeStyle() {
- this.is_list = !this.is_list;
- },
- lower(e) {
- if (this.pageTotal / this.pageSize > this.page) {
- this.page += 1;
- this.searchGoods();
- }
- },
- // 商品搜索
- searchGoods() {
- this.load_status = 'loading';
- this.$u.api
- .getGoodsByCategory({
- keyword: this.keyword,
- categoryId: '',
- page: this.page,
- pageSize: this.pageSize
- })
- .then(res => {
- if (this.page === 1) {
- this.goods_list = res.data;
- } else {
- this.goods_list = this.goods_list.concat(res.data);
- }
- this.pageTotal = res.pageTotal;
- this.load_status = this.$_utils.loadStatus(this.page, this.pageSize, this.pageTotal);
- });
- }
- }
- };
- </script>
- <style lang="scss">
- .search-input {
- background-color: #ffffff;
- padding: 22upx;
- .input-box {
- width: 620rpx;
- }
- .type-view {
- width: 80rpx;
- text-align: center;
- line-height: 64upx;
- height: 64upx;
- .ibonfont {
- font-size: 36upx;
- color: #909399;
- }
- }
- }
- // 搜索页
- .search_list {
- height: calc(100vh - 108rpx);
- .goods-li {
- margin: 24rpx 32rpx;
- }
- .goods-li-inline {
- display: inline-block;
- }
- }
- </style>
|