zhaoxiaohai 2 лет назад
Родитель
Сommit
6a444145f8

+ 122 - 0
packageA/select/brand/select.js

@@ -0,0 +1,122 @@
+const _Http = getApp().globalData.http;
+
+Page({
+    data: {
+        params: {}, //请求体
+        result: [], //返回结果
+        radio: false, //是否为单选
+        idname: "sa_brandid", //idkey
+        showName: "brandname", //表单用 显示名称
+    },
+    onLoad(options) {
+        console.log(options)
+        if (options.params) {
+            let params = JSON.parse(options.params);
+            if (!params.content.pageNumber || !params.content.pageTotal) {
+                params.content.pageNumber = 1;
+                params.content.pageTotal = 1;
+            }
+            this.setData({
+                params
+            });
+        }
+        if (options.title) wx.setNavigationBarTitle({
+            title: options.title,
+        })
+        this.setData({
+            radio: options.radio ? true : false,
+            idname: options.idname || this.data.idname,
+            showName: options.showName || this.data.showName,
+            result: (!options.result || options.result == 'undefined') ? [] : JSON.parse(options.result)
+        });
+        this.getList()
+    },
+    getList(init = false) {
+        //init 用于初始化分页
+        if (init.detail != undefined) init = init.detail;
+        let params = this.data.params;
+        if (init) params.content.pageNumber = 1;
+        if (params.content.pageNumber > params.content.pageTotal) return;
+        _Http.basic(params).then(res => {
+            console.log("选择客户列表", res)
+            this.selectComponent('#ListBox').RefreshToComplete();
+            if (res.msg != '成功') return wx.showToast({
+                title: res.data,
+                icon: "none"
+            })
+            if (params.excludeid) res.data = res.data.filter(v => v[this.data.idname] != params.excludeid);
+            this.setData({
+                'params.content.pageNumber': res.pageNumber + 1,
+                'params.content.pageTotal': res.pageTotal,
+                'params.content.total': res.total,
+                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
+            })
+        })
+    },
+    /* 删除项 */
+    deteleItem(id) {
+        this.setData({
+            list: this.data.list.filter(v => v[this.data.idname] != id),
+            "params.content.total": this.data.params.content.total - 1
+        })
+    },
+    /* 选中 */
+    changeResult(e) {
+        let {
+            id
+        } = e.currentTarget.dataset, result = this.data.result;
+        if (this.data.radio) {
+            result = [id];
+        } else {
+            result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
+        }
+        this.setData({
+            result
+        });
+        if (this.data.radio) this.submit();
+    },
+    /* 提交 */
+    submit() {
+        let result = this.data.result,
+            obj = this.data.radio ? {
+                id: result,
+                item: this.data.list.find(value => value[this.data.idname] == result),
+                value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
+            } : {
+                result,
+                list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
+                value: [result.map(v => {
+                    let data = this.data.list.find(value => value[this.data.idname] == v);
+                    return data ? data[this.data.showName] : ""
+                }), result]
+            }
+        getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
+    },
+    /* 开始搜索 */
+    startSearch({
+        detail
+    }) {
+        let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
+        if (detail == condition) return;
+        this.setData({
+            'content.where.condition': detail,
+            'params.content.where.condition': detail
+        });
+        this.getList(true);
+    },
+    /* 取消搜索 */
+    onClear() {
+        this.setData({
+            'content.where.condition': "",
+            'params.content.where.condition': ""
+        });
+        this.getList(true);
+    },
+    onReady() {
+        this.selectComponent("#ListBox").setHeight(".total", this);
+    },
+    onUnload() {
+        //回收数据
+        getApp().globalData.handleSelect = null;
+    }
+})

+ 4 - 0
packageA/select/brand/select.json

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

+ 91 - 0
packageA/select/brand/select.scss

@@ -0,0 +1,91 @@
+page {
+	height: 100vw;
+	overflow: hidden;
+}
+
+.box {
+	width: 100vw;
+	box-sizing: border-box;
+
+	.item {
+			display: flex;
+			align-items: center;
+			width: 100%;
+			padding-left: 30rpx;
+			box-sizing: border-box;
+			background-color: #fff;
+
+			.user {
+					display: flex;
+					align-items: center;
+					width: 100%;
+					height: 120rpx;
+					border-bottom: 1px solid #ddd;
+					box-sizing: border-box;
+
+					.portrait {
+							width: 80rpx;
+							height: 80rpx;
+							background: #3874F6;
+							border-radius: 50%;
+							text-align: center;
+							line-height: 80rpx;
+							font-size: 28rpx;
+							font-family: PingFang SC-Regular, PingFang SC;
+							color: #FFFFFF;
+							flex-shrink: 0;
+					}
+
+					.exp {
+							width: 100%;
+							margin-left: 20rpx;
+
+							.line-1 {
+									height: 42rpx;
+									font-size: 30rpx;
+									font-family: PingFang SC-Regular, PingFang SC;
+									color: #333333;
+							}
+
+							.phone {
+									font-size: 24rpx;
+									font-family: PingFang SC-Regular, PingFang SC;
+									color: #999999;
+									margin-top: 4rpx;
+							}
+					}
+			}
+
+	}
+}
+
+.footer {
+	display: flex;
+	justify-content: space-between;
+	align-items: center;
+	padding: 0 30rpx;
+	position: fixed;
+	width: 100vw;
+	height: 130rpx;
+	background: #FFFFFF;
+	box-shadow: 0px -4rpx 16rpx 2rpx rgba(150, 157, 165, 0.16);
+	bottom: 0;
+	box-sizing: border-box;
+
+	.count {
+			font-size: 28rpx;
+			font-family: PingFang SC-Regular, PingFang SC;
+			color: #333333;
+	}
+
+	.but {
+			width: 156rpx;
+			height: 90rpx;
+			background: #3874F6;
+			border-radius: 8rpx;
+			font-size: 28rpx;
+			font-family: PingFang SC-Bold, PingFang SC;
+			font-weight: bold;
+			color: #FFFFFF;
+	}
+}

+ 36 - 0
packageA/select/brand/select.wxml

@@ -0,0 +1,36 @@
+<van-search value="{{ value }}" shape="round" background="#fff" placeholder="搜索姓名、手机号" bind:search='onSearch' bind:clear='onClear' />
+<view class="total" style="height: 20rpx;" />
+<Yl_ListBox id='ListBox' bind:getlist='getList'>
+	<view class="box">
+		<navigator url="#" class="item" wx:for="{{list}}" wx:key="index" data-id="{{item[idname]}}" bindtap="changeResult">
+			<van-checkbox wx:if="{{!radio}}" value="{{ handle.isCheck(item[idname],result) }}" shape="square" icon-size='28rpx' />
+			<view class="user">
+				<view class="exp">
+					<view class="line-1">
+						{{item[showName]}}
+					</view>
+				</view>
+			</view>
+		</navigator>
+		<My_empty wx:if="{{list.length==0}}" />
+	</view>
+</Yl_ListBox>
+<block wx:if="{{!radio}}">
+	<view style="height: 130rpx;" />
+	<view class="footer">
+		<view class="count">
+			已选:{{result.length}}
+		</view>
+		<van-button custom-class='but' disabled='{{result.length==0}}' bind:click="submit">添加</van-button>
+	</view>
+</block>
+
+<wxs module="handle">
+	module.exports = {
+		isCheck: function (id, list) {
+			return list.some(function (v) {
+				return v == id
+			});
+		},
+	}
+</wxs>