xiaohaizhao 1 год назад
Родитель
Сommit
df875c2d81
5 измененных файлов с 87 добавлено и 35 удалено
  1. 30 6
      components/Yl_ListBox/index.js
  2. 12 1
      components/Yl_ListBox/index.wxml
  3. 18 27
      packageA/work/index.js
  4. 7 0
      project.private.config.json
  5. 20 1
      utils/Http.js

+ 30 - 6
components/Yl_ListBox/index.js

@@ -4,10 +4,10 @@ import {
 Component({
     properties: {
         height: {
-            type:Number
+            type: Number
         }, //组件高度
         getlist: {
-            type:Function
+            type: Function
         },
         pullDown: { //是否开启下拉
             type: Boolean,
@@ -17,6 +17,15 @@ Component({
             type: Boolean,
             value: true
         },
+        automatic: { //自动设置高度
+            type: Boolean,
+            value: true
+        },
+    },
+    lifetimes: {
+        attached: function () {
+            if (this.data.automatic) this.automaticSetHei()
+        },
     },
     data: {
         inRefresh: false, //下拉开启自定义项
@@ -41,11 +50,26 @@ Component({
         loadThePage() {
             this.triggerEvent("getlist", false)
         },
+        automaticSetHei(mode, num) {
+            this.setHeight("#mylisttop", this, mode, num)
+        },
         /* 设置组件高度 */
-        setHeight(element, that) {
-            getHeight(element, that).then(res => {
-                if (this.data.height != res) this.setData({
-                    height: res
+        setHeight(element, that, mode, num) {
+            return new Promise((resolve) => {
+                getHeight(element, that).then(res => {
+                    let height = res;
+                    switch (mode) {
+                        case 'add':
+                            height = (res - 0) + (num - 0);
+                            break;
+                        case 'minus':
+                            height = res - num;
+                            break;
+                    }
+                    this.setData({
+                        height
+                    })
+                    resolve(height)
                 })
             });
         }

+ 12 - 1
components/Yl_ListBox/index.wxml

@@ -1,4 +1,15 @@
-<scroll-view class="scroll-view" scroll-y refresher-enabled='{{pullDown}}' refresher-triggered='{{inRefresh}}' style="height: {{height}}px;" triggered='{{true}}' bindrefresherrefresh='pullToRefresh' lower-threshold='300' bindscrolltolower='loadThePage'>
+<view id="mylisttop" />
+
+<scroll-view class="scroll-view"
+    scroll-y
+    refresher-enabled='{{pullDown}}'
+    refresher-triggered='{{inRefresh}}'
+    style="height: {{height}}px;"
+    triggered='{{true}}'
+    bindrefresherrefresh='pullToRefresh'
+    lower-threshold='300'
+    bindscrolltolower='loadThePage'
+        >
     <slot />
     <view class="safety" wx:if="{{safety}}" />
 </scroll-view>

+ 18 - 27
packageA/work/index.js

@@ -33,7 +33,8 @@ Page({
                 "startdate": "",
                 "enddate": ""
             },
-            "sort": []
+            "sort": [],
+            total: 0,
         },
         classShow: false, //type类型
         filtratelist: [{
@@ -91,7 +92,6 @@ Page({
             url: './add'
         })
     },
-
     /* 筛选状态选择 */
     selectStatus(e) {
         const {
@@ -110,29 +110,23 @@ Page({
         })
     },
     getList(init = false) {
-        //init 用于初始化分页
-        if (init.detail != undefined) init = init.detail;
-        let content = this.data.content;
-        if (init) content.pageNumber = 1;
-        if (content.pageNumber > content.pageTotal) return;
-        _Http.basic({
-            "id": 20220901162901,
-            content
-        }).then(res => {
-            console.log("任务列表", res)
-            this.selectComponent('#ListBox').RefreshToComplete();
-            if (res.msg != '成功') return wx.showToast({
-                title: res.data,
-                icon: "none"
-            })
-            this.setData({
-                'content.pageNumber': res.pageNumber + 1,
-                'content.pageTotal': res.pageTotal,
-                'content.total': res.total,
-                'content.sort': res.sort,
-                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
+        _Http.init(this.data.content, init).then(content => {
+            _Http.basic({
+                "id": 20220901162901,
+                content
+            }).then(res => {
+                console.log("任务列表", res)
+                this.selectComponent('#ListBox').RefreshToComplete();
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.data,
+                    icon: "none"
+                })
+                this.setData({
+                    content: _Http.paging(content, res),
+                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
+                })
+                this.getTags();
             })
-            this.getTags();
         })
     },
     /* 获取列表标签 */
@@ -207,8 +201,5 @@ Page({
         this.classClose();
         this.getList(true)
     },
-    onReady() {
-        this.selectComponent("#ListBox").setHeight(".total", this);
-    },
     onShareAppMessage() {}
 })

+ 7 - 0
project.private.config.json

@@ -8,6 +8,13 @@
     "condition": {
         "miniprogram": {
             "list": [
+                {
+                    "name": "任务列表",
+                    "pathName": "packageA/work/index",
+                    "query": "",
+                    "launchMode": "default",
+                    "scene": null
+                },
                 {
                     "name": "任务新建",
                     "pathName": "packageA/work/add",

+ 20 - 1
utils/Http.js

@@ -14,7 +14,26 @@ class HTTP {
             this.baseUrl = "http://61.164.207.46:8000";
             // this.baseUrl = "https://oms.idcgroup.com.cn:8079";
         }
-        console.log("接口地址:", this.baseUrl)
+
+        this.init = (content, init = false) => {
+            return new Promise((resolve, reject) => {
+                if (init.detail != undefined) init = init.detail;
+                if (init) content.pageNumber = 1;
+                content.pageNumber > content.pageTotal ? reject() : resolve(content)
+            })
+        }
+
+        this.paging = (data, res) => {
+            let content = JSON.parse(JSON.stringify(data))
+            content.pageNumber = res.pageNumber + 1;
+            content.pageTotal = res.pageTotal;
+            content.total = res.total;
+            content.sort = res.sort;
+            if (this.isShowEmpty) this.empty = res.total == 0;
+            return content;
+        }
+
+
     }
     request({
         url,