123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <template>
- <view class="place-order">
- <custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
- <AddCart ref="addCart" />
- <view class="content">
- <scroll-view scroll-y :style="{ height: scrollviewHeight + 'px' }">
- <view class="item" v-for="(item, index) in list" :key="index" :class="{ right: index % 2 == 1 }" @tap="tap(index)">
- <image class="img" :src="item.main_img" mode="aspectFill"></image>
- <view class="info">
- <view class="top ellipsis">
-
- </view>
- <view class="mid">¥{{ item.money }}/{{ item.unit }}</view>
- <view class="bot">
- <text>{{ item.size.length }}个尺码可选</text>
- <view class="shopCar" @tap.stop="tapShopCar(item)">
- <view v-if="item.cart.reduce((t, e) => t + e, 0)" class="sizeNum">{{ item.cart.reduce((t, e) => t + e, 0) }}</view>
- <text class="cuIcon-cart"></text>
- </view>
- </view>
- </view>
- </view>
- <view v-if="!goodsList.length" class="loading">{{ status }}</view>
- </scroll-view>
- <navigator open-type="navigate" url="../shop-car1/shop-car1" class="cart">
- 购物车
- <text v-if="cartNum" class="sizeNum">{{ cartNum }}</text>
- </navigator>
- </view>
- </view>
- </template>
- <script>
- import { deepClone } from '@/common/util/index.js'
- import { _API_GoodList } from '@/apis/good.js'
- import AddCart from '@/components/public/add-cart.vue'
- export default {
- components: { AddCart },
- data() {
- return {
- title: '订货下单',
- mode: 'square',
- goodsList: [],
- scrollviewHeight: 0,
- status: '加载中...'
- }
- },
- computed: {
- list() {
- const temp = deepClone(this.goodsList)
- temp.forEach(goodItem => {
- goodItem.cart = Array(goodItem.size.length).fill(0)
- const itemInCart = this.$store.state.cart.list.find(e => e.attr_id === goodItem.attr_id)
- if (itemInCart) {
- Object.assign(goodItem, itemInCart)
- }
- })
- return temp
- },
- cartNum() {
- return this.$store.getters['cart/shopcarNum']
- }
- },
- mounted() { // 获取商品列表
- this.$offset('.content').then(res => this.scrollviewHeight = res.height - uni.upx2px(98)) // 设置scrollview 高
- if (this.$store.state.userinfo.user_type !== 3) {
- uni.navigateBack()
- setTimeout(() => uni.$emit('noopening'))
- return
- }
- this.request()
- },
- onPullDownRefresh() {
- this.request()
- },
- methods: {
- request() {
- uni.showLoading({ mask: true })
- _API_GoodList().then(res => {
- if (res.code === 200) {
- this.goodsList = res.data.list
- console.log(this.goodsList)
- if (!this.goodsList.length) {
- this.status = '暂无商品'
- }
- } else {
- uni.toast('网络好像出了点问题,下拉刷新试试')
- }
- uni.stopPullDownRefresh()
- }).catch(() => setTimeout(() => {
- uni.toast('网络好像出了点问题,下拉刷新试试')
- uni.stopPullDownRefresh()
- }, 123))
- },
- tap(index) { // 查看商品详情
- uni.setStorageSync('ggg', JSON.stringify(this.goodsList[index]))
- uni.navigateTo({ url: `../good-detail1/good-detail1` })
- },
- tapShopCar(item) {
- this.$refs.addCart.show(deepClone(item))
- }
- }
- }
- </script>
- <style lang="scss">
- .place-order {
- @include page();
- .content {
- .cart {
- height: 98rpx;
- @include flex();
- color: $app-base-color;
- font-size: 36rpx;
- // background: $app-base-color;
- border-top: 1rpx solid #C0C0C0;
- background: #FFFFFF;
- position: relative;
- .sizeNum {
- @include flex();
- position: absolute;
- font-size: 20rpx;
- left: 50%;
- margin-left: 48rpx;
- height: 32rpx;
- color: #FFFFFF;
- top: 24rpx;
- padding: 2rpx 8rpx;
- border-radius: 32rpx;
- background: #FF0000;
- }
- }
- .loading {
- text-align: center;
- margin-top: 567rpx;
- }
- .item {
- &.right {
- margin-left: 10rpx;
- }
- float: left;
- height: 380rpx;
- width: 370rpx;
- align-items: flex-end;
- @include flex(column);
- .img {
- height: 240rpx;
- width: 100%;
- }
- .info {
- @include flex(column);
- flex: 1;
- width: 100%;
- margin-left: 23rpx;
- align-items: flex-start;
- }
- }
- }
- }
- </style>
|