123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- <template>
- <view class="center">
- <view class="input-box flex" @click="clickSearch">
- <view class=" input-content flex">
- <view class="iconfont iconsearch"></view>
- <view class="input"><input type="text" disabled value="商品搜索" /></view>
- </view>
- </view>
- <view class="mp-height"></view>
- <scroll-view scroll-x="true" class="class-box flex" :scroll-left="scrollLeft" :scroll-with-animation="true">
- <view @click="tabClass(item, idx)" class="item" v-for="(item, idx) in indexList" :key="idx">
- <view class="time" :class="{ action: idx == classIndex }">{{ item }}</view>
- </view>
- </scroll-view>
- <view class="line"></view>
- <swiper class="list-Box" :current="classIndex" @change="swiperChange" duration="500">
- <swiper-item class="list-item" v-for="(ls, idx) in indexList">
- <!-- 空白页 -->
- <scroll-view scroll-y="true" class="list">
- <view class="goodsList-item flex" v-for="(lss, ind) in ls.dataList" @click="check('item', ind, idx)">
- <view class="iconfont iconroundcheckfill checkbox" :class="{ checked: lss.checked }"></view>
- <view class="img"><image :src="lss.image" mode="scaleToFill"></image></view>
- <view class="text">
- <view class="spname">{{ lss.store_name }}</view>
- <view class="price">
- <text>¥</text>
- {{ lss.price }}
- </view>
- </view>
- <view class="yishou">已售{{ lss.sales }}</view>
- </view>
- </scroll-view>
- </swiper-item>
- </swiper>
- <view class="btn flex">
- <view class="checkAllbox" @click="check('all')">
- <view class="iconfont iconroundcheckfill checkalls" :class="{ checked: allChecked }"></view>
- <view class="quanxuan">全选</view>
- </view>
- <view class="btn-box flex"><view class="button" style="margin-left: 20rpx;" @click="submit()">添加</view></view>
- </view>
- </view>
- </template>
- <script>
- import { getProducts, choseProducts } from '@/api/product.js';
- import { getList } from '@/api/category.js';
- import { mapState, mapMutations } from 'vuex';
- import empty from '@/components/empty';
- export default {
- components: {
- empty
- },
- data() {
- return {
- chose: [], //选择的商品id,
- allChecked: false,
- indexList: ['家居','服装','首饰','食品'],
- topNavWidth: '12%', //设置导航默认宽度
- classIndex: 0, //当前进行中的活动
- itemWidht: 0, //顶部分类宽度
- loadingType: 'more', //加载更多状态
- actionClassInd: 0,
- page: 1,
- limit: 10
- };
- },
- computed: {
- ...mapState(['hasLogin', 'userInfo', 'baseURL', 'urlFile']),
- // 计算左侧距离
- scrollLeft() {
- if (this.classIndex > 1) {
- return this.itemWidht * (this.classIndex - 1.5);
- } else {
- return 0;
- }
- }
- },
- onLoad() {
- // 载入分类
- this.loadData();
- },
- methods: {
- async loadData(type = 'add', loading) {
- // let obj = this;
- // let data = {
- // page: obj.page,
- // limit: obj.limit
- // };
- // //没有更多直接返回
- // if (type === 'add') {
- // if (obj.loadingType === 'nomore') {
- // return;
- // }
- // obj.loadingType = 'loading';
- // } else {
- // obj.loadingType = 'more';
- // }
- // if (type === 'refresh') {
- // // 清空数组
- // obj.page = 1;
- // }
- // getList({})
- // .then(({ data }) => {
- // console.log('------',data);
- // obj.indexList = data.map(e => {
- // e.dataList = [];
- // e.loadingType = 'more';
- // e.page = 1;
- // e.limit = 10;
- // return e;
- // });
- // obj.classIndex = 0;
- // obj.getDataList(obj.indexList[obj.classIndex]);
- // if (obj.indexList.length <= 4) {
- // // 当数量小于等于4的时候自适应宽度
- // obj.topNavWidth = 100 / obj.indexList.length + '%';
- // } else {
- // // 页面渲染完毕后加载scroll-view左侧距离
- // obj.$nextTick(() => {
- // obj.numClassWidht();
- // });
- // }
- // })
- // .catch(err => {
- // console.log(err);
- // })
- },
- getDataList(item, type = 'add') {
- const obj = this;
- const requestData = {
- page: item.page,
- limit: item.limit,
- cid: item.id,
- can_chose: 1
- };
- // 判断数据是否加载中
- if (item.loadingType == 'nomore' || item.loadingType == 'loading') {
- return;
- }
- // 判断是否重新加载数据
- if (type == 'refresh') {
- item.dataList = [];
- }
- // 设置数据加载中
- item.loadingType = 'loading';
- return new Promise((ok, erro) => {
- getProducts(requestData)
- .then(({ data }) => {
- console.log(item.dataList);
- if (item.limit == data.length) {
- item.page++;
- item.loadingType = 'more';
- } else {
- item.loadingType = 'nomore';
- }
- if (type === 'refresh') {
- if (loading == 1) {
- uni.hideLoading();
- } else {
- uni.stopPullDownRefresh();
- }
- }
- this.$set(item.dataList, 'loaded', true);
- })
- .catch(err => {
- console.log(err);
- });
- });
- },
- swiperChange(e) {
- const obj = this;
- obj.classIndex = e.target.current;
- obj.getDataList(obj.indexList[obj.classIndex], 'tabChange');
- obj.allChecked = true;
- if (obj.indexList[obj.classIndex].dataList.length > 0) {
- let list = obj.indexList[obj.classIndex].dataList;
- for (let i = 0; i < list.length; i++) {
- if (!list[i].checked) {
- obj.allChecked = false;
- break;
- }
- }
- } else {
- obj.allChecked = false;
- }
- },
- tabClass(item, index) {
- const obj = this;
- obj.classIndex = index;
- obj.actionClassInd = index;
- let ls = obj.indexList[obj.actionClassInd];
- obj.allChecked = true;
- if (obj.indexList[obj.classIndex].dataList.length > 0) {
- let list = obj.indexList[obj.classIndex].dataList;
- for (let i = 0; i < list.length; i++) {
- if (!list[i].checked) {
- obj.allChecked = false;
- break;
- }
- }
- } else {
- obj.allChecked = false;
- }
- // 判断当前数据是否已经加载完毕
- if (ls.loadingType == 'more') {
- // this.getDataList(ls);
- }
- },
- check(type, index, erindex) {
- const obj = this;
- if (type === 'item') {
- const list = obj.indexList[erindex].dataList;
- list[index].checked = !list[index].checked;
- if (list[index].checked) {
- if (!obj.chose.includes(list[index].id)) {
- obj.chose.push(list[index].id);
- }
- } else {
- if (obj.chose.includes(list[index].id)) {
- // console.log(list[index].id);
- let aid = list[index];
- console.log(aid);
- let index = obj.chose.indexOf(aid);
- obj.chose.splice(index, 1);
- }
- }
- this.allChecked = true;
- for (let i = 0; i < list.length; i++) {
- if (!list[i].checked) {
- this.allChecked = false;
- }
- }
- } else {
- const checked = !obj.allChecked;
- const list = obj.indexList[obj.classIndex].dataList;
- list.forEach(item => {
- item.checked = checked;
- });
- obj.allChecked = checked;
- if (obj.allChecked) {
- list.forEach(item => {
- if (!obj.chose.includes(item.id)) {
- obj.chose.push(item.id);
- }
- });
- } else {
- list.forEach(item => {
- if (obj.chose.includes(item.id)) {
- let index = obj.chose.indexOf(item.id);
- obj.chose.splice(index, 1);
- }
- });
- }
- }
- },
- numClassWidht() {
- uni.createSelectorQuery()
- .select('.center')
- .fields(
- {
- size: true
- },
- data => {
- // 设置项目宽度
- // console.log(data);
- this.itemWidht = Math.floor((data.width / 750) * 187.5);
- }
- )
- .exec();
- },
- // clickSearch() {
- // uni.navigateTo({
- // url: '/pages/product/search'
- // });
- // },
- navTo(url) {
- uni.navigateTo({
- url
- });
- },
- submit() {
- const obj = this;
- // obj.chose = [];
- // let indexCd = obj.indexList.length;
- // for(let i = 0; i < indexCd; i++){
- // let dataCd = obj.indexList[i].dataList.length;
- // for(let j = 0; j < dataCd; j++){
- // if(obj.indexList[i].dataList[j].checked){
- // obj.chose=obj.chose.concat(obj.indexList[i].dataList[j].id);
- // }
- // }
- // }
- console.log(obj.chose);
- if (obj.chose.length != 0) {
- choseProducts({ ids: obj.chose })
- .then(() => {
- obj.$api.msg('添加商品成功');
- this.loadData();
- })
- .catch(err => {
- console.log(err);
- });
- } else {
- obj.$api.msg('请选择要添加的数据');
- }
- }
- }
- };
- </script>
- <style lang="scss">
- page {
- height: 100%;
- margin: 0;
- padding: 0;
- background-color: #ffffff;
- }
- .center {
- height: 100%;
- }
- .class-box {
- background: #ffffff;
- white-space: nowrap;
- height: 78rpx;
- .item {
- text-align: center;
- display: inline-block;
- color: $font-color-base;
- margin: 26rpx 34rpx 15rpx 29rpx;
- background-color: #fff;
- line-height: 1;
- .time {
- font-family: PingFang SC;
- font-weight: bold;
- font-size: 30rpx;
- padding-bottom: 19rpx;
- &.action {
- border-bottom: 4rpx solid #52C696;
- }
- }
- }
- }
- .input-box {
- margin-top: -5px;
- padding: 25rpx;
- background-color: #ffffff;
- height: 100rpx;
- .input-content {
- border-radius: 99rpx;
- flex-grow: 1;
- padding: 5rpx 30rpx;
- background: #ebebeb;
- .iconsearch {
- font-size: 50rpx;
- color: #999999;
- }
- .input {
- margin-left: 19rpx;
- flex-grow: 1;
- color: #999999;
- input {
- font-size: 26rpx;
- color: #999999;
- }
- }
- }
- .input-button {
- padding-left: 20rpx;
- font-size: $font-base;
- height: 100%;
- }
- }
- .line {
- width: 100%;
- height: 24rpx;
- background-color: #f8f8f8;
- }
- .list-Box {
- height: calc(100vh - 200px);
- .list-item {
- height: 100%;
- .list {
- height: 100%;
- }
- }
- }
- .goodsList-item {
- position: relative;
- justify-content: flex-start;
- width: 100%;
- padding: 30rpx;
- .checkbox {
- display: flex;
- flex-shrink: 0;
- font-size: 32rpx;
- color: #eeeeee;
- background: #eeeeee;
- border-radius: 50px;
- }
- .img {
- margin-left: 28rpx;
- width: 146rpx;
- height: 146rpx;
- background: #f0f0f0;
- border-radius: 10px;
- image {
- width: 146rpx;
- height: 146rpx;
- }
- }
- .text {
- position: relative;
- padding-left: 35rpx;
- height: 146rpx;
- text-overflow: ellipsis;
- overflow: hidden;
- white-space: nowrap;
- .spname {
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #333333;
- text-overflow: ellipsis;
- overflow: hidden;
- }
- .earning {
- width: 275rpx;
- padding: 7rpx;
- margin-top: 12rpx;
- background: #fee1d7;
- border-radius: 5rpx;
- text-align: center;
- font-size: 20rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #fc4141;
- line-height: 1;
- }
- .price {
- margin-top: 19rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #ff0000;
- font-size: 36rpx;
- text {
- font-size: 24rpx;
- }
- }
- }
- .yishou {
- position: absolute;
- right: 29rpx;
- bottom: 40rpx;
- }
- }
- .btn {
- position: fixed;
- bottom: 0;
- width: 100%;
- height: 100rpx;
- justify-content: space-between;
- padding: 0 39rpx 0 54rpx;
- line-height: 1;
- border-top: 1rpx solid #f0f0f0;
- .checkAllbox {
- display: flex;
- .checkalls {
- font-size: 32rpx;
- color: #eeeeee;
- background: #eeeeee;
- border-radius: 50px;
- }
- .quanxuan {
- margin-left: 16rpx;
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #1d2023;
- }
- }
- .button {
- width: 160rpx;
- height: 64rpx;
- background: #52C696;
- border-radius: 32rpx;
- color: #ffffff;
- text-align: center;
- line-height: 64rpx;
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: bold;
- }
- }
- .checkAllbox .checkalls.checked,
- .goodsList-item .checkbox.checked {
- color: #52C696;
- background: #ffffff;
- }
- </style>
|