Browse Source

商学院列表

zhaoxiaohai 3 years ago
parent
commit
d08b89febc
2 changed files with 75 additions and 23 deletions
  1. 72 19
      pages/college/index.js
  2. 3 4
      pages/college/index.wxml

+ 72 - 19
pages/college/index.js

@@ -9,9 +9,19 @@ Page({
         scrollHeight: 0, //滚动区域高度
         searchContent: "", //搜索内容
         mainActiveIndex: 0, //分类选择器打开分类的下标
-        activeId: null, //分类选择器选择id
+        activeId: "", //分类选择器选择id
         showText: null, //左上显示文本
         items: [], //分类列表
+        list: [], //列表
+        content: {
+            pageNumber: 1,
+            pageSize: 20,
+            pageTotal: 1,
+            where: {
+                condition: "",
+                sorttype: 2
+            }
+        }
     },
 
     /**
@@ -19,22 +29,7 @@ Page({
      */
     onLoad(options) {
         this.selectMenu(0);
-        _Http.basic({
-            "classname": "saletool.courseware.courseware",
-            "method": "selectList",
-            "content": {
-                "pageNumber": 1,
-                "pageSize": 10,
-                "where": {
-                    "condition": "",
-                    "sorttype": 2,
-                    "sat_courseware_classid": 31
-                }
-            }
-        }).then(res => {
-            console.log(res)
-        })
-
+        this.selectList();
     },
     /* 查询菜单分类 */
     selectMenu(index) {
@@ -47,7 +42,7 @@ Page({
             "method": "selectMenu",
             "content": {}
         }).then(res => {
-            console.log(res)
+            console.log("商学院分类", res)
             if (res.msg != '成功') return this.selectMenu(index + 1)
             let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_courseware_classid/g, 'id');
             this.setData({
@@ -56,6 +51,63 @@ Page({
         })
     },
 
+    /* 获取列表 */
+    selectList(init = false) {
+        if (init.detail != undefined) init = init.detail;
+        if (init) this.setData({
+            ['content.pageNumber']: 1
+        })
+        if (this.data.content.pageNumber > this.data.content.pageTotal) return;
+        let content = this.data.content;
+        content.where.sat_courseware_classid = this.data.activeId;
+        _Http.basic({
+            "classname": "saletool.courseware.courseware",
+            "method": "selectList",
+            content
+        }).then(res => {
+            console.log("列表", res)
+
+            this.selectComponent('#ListBox').RefreshToComplete();
+            if (res.msg != '成功') return wx.showToast({
+                title: res.data,
+                icon: "none"
+            })
+
+            this.setData({
+                list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
+                ['content.pageNumber']: res.pageNumber + 1,
+                ['content.pageTotal']: res.pageTotal
+            })
+        })
+    },
+
+    /* 开始搜索 */
+    startSearch({
+        detail
+    }) {
+        this.setData({
+            "content.where.condition": detail.trim()
+        })
+        this.selectList(true);
+    },
+
+    /* 关闭搜索 */
+    closeSearch() {
+        this.setData({
+            "content.where.condition": ""
+        })
+        this.selectList(true);
+    },
+
+    switchChange({
+        detail
+    }) {
+        this.setData({
+            'content.where.sorttype': detail == '最新' ? 2 : 1
+        })
+        this.selectList(true);
+    },
+
     onClickNav({
         detail = {}
     }) {
@@ -67,12 +119,13 @@ Page({
     onClickItem({
         detail = {}
     }) {
-        const activeId = this.data.activeId === detail.id ? null : detail.id,
+        const activeId = this.data.activeId === detail.id ? "" : detail.id,
             showText = this.data.showText === detail.text ? null : detail.text;
         this.setData({
             activeId,
             showText
         });
+        this.selectList(true);
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 3 - 4
pages/college/index.wxml

@@ -1,16 +1,15 @@
-<van-search value="{{ value }}" shape="round" background="var(--primary)" placeholder="请输入搜索关键词" />
-
+<van-search value="{{ content.where.condition }}" shape="round" background="var(--primary)" bindchange='startSearch' bind:clear='closeSearch' placeholder="请输入搜索关键词" />
 <!-- 下拉菜单 -->
 <van-dropdown-menu class="menu" activeColor='var(--assist)'>
     <van-dropdown-item id="item" title="{{showText||'默认'}}">
         <van-tree-select items="{{ items }}" main-active-class='main-active' content-active-class='content-active' main-active-index="{{ mainActiveIndex }}" active-id="{{activeId}}" bind:click-nav="onClickNav" bind:click-item="onClickItem" />
     </van-dropdown-item>
     <view class="switch">
-        <My_switch></My_switch>
+        <My_switch bind:change="switchChange" />
     </view>
 </van-dropdown-menu>
 <!-- 列表 -->
-<My_listBox height='{{scrollHeight}}'>
+<My_listBox id='ListBox' height='{{scrollHeight}}' bind:getlist='selectList'>
     <view class="unread">总共15个,有1个更新</view>
     <navigator url="/pages/college/detail" class="course my-card" wx:for="{{5}}">
         <van-image width="230rpx" height="120rpx" custom-class='cover-img' lazy-load fit='cover' src="https://img.yzcdn.cn/vant/cat.jpeg" />