123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <template>
- <view class="content">
- <view class="one">
- <uni-search-bar placeholder="搜索" bgColor="#EEEEEE" @confirm="toSearch" @input="input" />
- </view>
- <view class="two">
- <uni-grid :column="4" :show-border="false" :square="false">
- <uni-grid-item v-for="(item, index) in moduleList" :index="index" :key="index" @tap="change(item)">
- <view class="grid">
- <image class="image" :src="item.url&&item.url.length>0?item.url[0].url:''" mode="aspectFill">
- </image>
- <text class="text">{{ item.name }}</text>
- </view>
- </uni-grid-item>
- </uni-grid>
- </view>
- <view class="thr">
- <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
- <view class="list-scroll-view">
- <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(item)">
- <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="aspectFill">
- </image>
- <view class="name textOver">{{item.name}}</view>
- </view>
- <view class="is_bottom" v-if="is_bottom">
- <text>已经到底了!</text>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- moduleList: [],
- list: [],
- total: 0,
- skip: 0,
- limit: 6,
- page: 0,
- // 数据是否触底
- is_bottom: false,
- scrollTop: 0,
- }
- },
- async onLoad() {
- const that = this;
- await that.searchToken();
- await that.search();
- },
- onShow() {
- },
- onPullDownRefresh: async function() {
- const that = this;
- that.clearPage();
- await that.search();
- uni.stopPullDownRefresh();
- },
- methods: {
- async searchToken() {
- const that = this;
- uni.getStorage({
- key: 'token',
- success: async function(res) {
- // 替换底部菜单
- let aee = await that.$api(`/Role/menu`, 'GET', {
- is_use: '0',
- code: res.data.role
- });
- if (aee.errcode == '0') {
- if (aee.data.menu && aee.data.menu.length > 0) {
- for (let val of aee.data.menu) {
- uni.setTabBarItem({
- index: val.index,
- text: val.text,
- pagePath: val.pagePath,
- iconPath: val.iconPath[0].url,
- selectedIconPath: val.selectedIconPath[0].url,
- })
- }
- }
- }
- },
- fail: function(err) {
- uni.showToast({
- title: err.errmsg,
- icon: 'error',
- duration: 2000
- });
- }
- })
- },
- async search() {
- const that = this;
- let res;
- res = await that.$api(`/Module`, 'GET', {
- is_use: '0'
- });
- if (res.errcode == '0') that.$set(that, `moduleList`, res.data);
- let info = {
- skip: that.skip,
- limit: that.limit,
- is_use: '0'
- }
- res = await that.$api(`/Good`, 'GET', {
- ...info
- })
- if (res.errcode == '0') {
- let list = [...that.list, ...res.data];
- that.$set(that, `list`, list)
- that.$set(that, `total`, res.total)
- } else {
- uni.showToast({
- title: res.errmsg,
- });
- }
- },
- async toSearch(res) {
- console.log(res);
- },
- async input(res) {
- console.log(res)
- },
- async change(e) {
- console.log(e);
- },
- // 分页
- toPage(e) {
- const that = this;
- let list = that.list;
- let limit = that.limit;
- if (that.total > list.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- let page = that.page + 1;
- that.$set(that, `page`, page)
- let skip = page * limit;
- that.$set(that, `skip`, skip)
- that.search();
- uni.hideLoading();
- } else that.$set(that, `is_bottom`, true)
- },
- toScroll(e) {
- const that = this;
- let up = that.scrollTop;
- that.$set(that, `scrollTop`, e.detail.scrollTop);
- let num = Math.sign(up - e.detail.scrollTop);
- if (num == 1) that.$set(that, `is_bottom`, false);
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.$set(that, `moduleList`, [])
- that.$set(that, `list`, [])
- that.$set(that, `skip`, 0)
- that.$set(that, `limit`, 6)
- that.$set(that, `page`, 0)
- },
- }
- }
- </script>
- <style lang="scss">
- .content {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- .one {
- width: 100%;
- }
- .two {
- padding: 1vw 2vw;
- background-color: var(--f9Color);
- .grid {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 5px 0 0 0;
- margin: 5px;
- background-color: var(--mainColor);
- border-radius: 10px;
- .image {
- width: 25px;
- height: 25px;
- }
- .text {
- font-size: var(--font14Size);
- margin-top: 5px;
- }
- }
- }
- .thr {
- position: relative;
- flex-grow: 1;
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
- padding: 2vw;
- background-color: var(--f9Color);
- .list {
- position: relative;
- width: 43vw;
- padding: 2vw;
- margin: 0 0 2vw 0;
- border-radius: 10px;
- background-color: var(--mainColor);
- .image {
- width: 100%;
- height: 40vw;
- border-top-right-radius: 10px;
- border-top-left-radius: 10px;
- }
- .name {
- font-size: var(--font14Size);
- }
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- .is_bottom {
- text-align: center;
- text {
- padding: 2vw 0;
- display: inline-block;
- color: var(--f85Color);
- font-size: var(--font14Size);
- }
- }
- </style>
|