Explorar o código

form表单选择自定义分类页面

zhaoxiaohai %!s(int64=2) %!d(string=hai) anos
pai
achega
63cfdb824d

+ 99 - 0
packageA/options/index.js

@@ -0,0 +1,99 @@
+const _Http = getApp().globalData.http;
+Page({
+    data: {
+        paging: {
+            "pageNumber": 1,
+            "pageSize": 20,
+            "pageTotal": 1,
+        },
+        result: [],
+    },
+    onLoad(options) {
+        let item = JSON.parse(options.data);
+        console.log(item)
+        this.setData({
+            item,
+            result: item.value ? Array.isArray(item.value) ? item.value : [item.value] : []
+        })
+        this.getList();
+    },
+    toggle(e) {
+        const {
+            item
+        } = e.currentTarget.dataset;
+        let result = this.data.result;
+        if (this.data.item.optionType == 'checkbox') {
+            let index = result.findIndex(v => v == item.value);
+            if (index == -1) {
+                result.push(item.value)
+            } else {
+                result.splice(index, 1)
+            }
+            this.setData({
+                result
+            })
+        } else {
+            this.setData({
+                result: [item.value]
+            })
+            this.submit();
+        }
+    },
+    getList(init = false) {
+        let {
+            pageNumber,
+            pageTotal,
+            pageSize
+        } = this.data.paging;
+        if (init) {
+            pageNumber = 1;
+            pageTotal = 1;
+        };
+        if (pageNumber > pageTotal) return;
+        _Http.basic({
+            "classname": "sysmanage.develop.optiontype.optiontype",
+            "method": "optiontypeselect",
+            "content": {
+                pageNumber,
+                pageSize,
+                "typename": this.data.item.optionNmae,
+                "parameter": {
+                    "siteid": wx.getStorageSync('siteP').siteid
+                }
+            }
+        }).then(res => {
+            if (res.msg != '成功') {
+                wx.showToast({
+                    title: res.data,
+                    icon: "none"
+                })
+                return;
+            };
+            this.setData({
+                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
+                "paging.pageNumber": res.pageNumber + 1,
+                "paging.pageTotal": res.pageTotal,
+                "paging.total": res.total,
+            })
+            console.log("可选项查询", res)
+        })
+    },
+    submit() {
+        let item = this.data.item;
+        if (item.optionType == 'checkbox') {
+            item.value = this.data.result
+        } else {
+            item.value = this.data.result[0]
+        };
+        const pages = getCurrentPages();
+        pages[pages.length - 2].selectComponent(item.model || "#Form").setOption(item);
+        wx.navigateBack();
+        item.setFun && getApp().globalData.optionFun && getApp().globalData.optionFun({
+            item,
+            list: this.data.result.map(v => this.data.list.find(s => s.value == v))
+        });
+    },
+    onReachBottom() {
+        this.getList();
+    },
+})

+ 4 - 0
packageA/options/index.json

@@ -0,0 +1,4 @@
+{
+    "usingComponents": {},
+    "navigationBarTitleText": "选择"
+}

+ 27 - 0
packageA/options/index.scss

@@ -0,0 +1,27 @@
+.value-class {
+    flex: none !important;
+}
+
+.new-footer {
+    display: flex;
+    align-items: center;
+    justify-content: flex-end;
+    position: fixed;
+    width: 100vw;
+    height: 130rpx;
+    background: #FFFFFF;
+    box-shadow: 0px -4rpx 16rpx 2rpx rgba(150, 157, 165, 0.16);
+    bottom: 0;
+
+    .new-submit {
+        width: 156rpx;
+        height: 90rpx;
+        background: #3874F6;
+        border-radius: 8rpx;
+        font-size: 28rpx;
+        font-family: PingFang SC-Bold, PingFang SC;
+        font-weight: bold;
+        color: #FFFFFF;
+        margin-right: 30rpx;
+    }
+}

+ 15 - 0
packageA/options/index.wxml

@@ -0,0 +1,15 @@
+<van-checkbox-group value="{{ result }}" bind:change="onChange">
+    <van-cell-group>
+        <van-cell wx:for="{{ list }}" wx:key="value" title="{{ item.value }}" label="{{item.remarks}}" value-class="value-class" clickable data-item="{{ item }}" bind:click="toggle">
+            <van-checkbox name="{{ item.value }}" />
+        </van-cell>
+    </van-cell-group>
+</van-checkbox-group>
+<My_empty wx:if="{{list.length==0}}" />
+
+<block wx:if="{{item.optionType == 'checkbox'}}">
+    <view style="height: 130rpx;" />
+    <view class="new-footer">
+        <van-button custom-class='new-submit' disabled='{{!result.length}}' bindclick='submit'>提交</van-button>
+    </view>
+</block>