Jelajahi Sumber

我的地址

xiaohaizhao 2 tahun lalu
induk
melakukan
e774f35d1d

+ 60 - 0
pages/address/index.js

@@ -0,0 +1,60 @@
+const _Http = getApp().globalData.http;
+Page({
+  data: {
+    "content": {
+      nocache: true,
+      sys_enterpriseid: "",
+      pageNumber: 1,
+      pageTotal: 1,
+      "where": {
+        "condition": "",
+        "workaddress": 1
+      }
+    }
+  },
+  onLoad(options) {
+    this.setData({
+      "content.sys_enterpriseid": options.id
+    })
+    this.getList(true);
+  },
+  /* 获取产品 */
+  getList(init = false) {
+    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": "20221009155803",
+      content
+    }).then(res => {
+      console.log("我的地址列表", res)
+      this.selectComponent('#ListBox').RefreshToComplete();
+      if (res.msg != '成功') return wx.showToast({
+        title: res.msg,
+        icon: "none",
+        mask: true
+      });
+      content.pageNumber = res.pageNumber + 1;
+      content.pageTotal = res.pageTotal;
+      this.setData({
+        list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
+      })
+    })
+  },
+  /* 开始搜索 */
+  onSearch({
+    detail
+  }) {
+    if (detail == this.data.content.where.condition) return;
+    this.data.content.where.condition = detail;
+    this.getList(true);
+  },
+  onClear(e) {
+    this.data.content.where.condition = "";
+    this.getList(true);
+  },
+  onReady() {
+    this.selectComponent("#ListBox").setHeight(".top", this);
+  }
+})

+ 5 - 0
pages/address/index.json

@@ -0,0 +1,5 @@
+{
+  "usingComponents": {
+    "List": "./modules/list/index"
+  }
+}

+ 0 - 0
pages/address/index.scss


+ 7 - 0
pages/address/index.wxml

@@ -0,0 +1,7 @@
+<van-search class="top" value="{{ content.where.condition }}" use-action-slot placeholder="请输入搜索关键词" bind:search="onSearch" bind:clear='onClear'>
+	<navigator url="/pages/address/update?id={{content.sys_enterpriseid}}" slot="action">添加地址</navigator>
+</van-search>
+<Yl_ListBox id='ListBox' bind:getlist='getList'>
+	<view style="height: 20rpx;" />
+	<List list="{{list}}" />
+</Yl_ListBox>

+ 5 - 0
pages/address/modules/list/index.js

@@ -0,0 +1,5 @@
+Component({
+  properties: {
+    list: Array
+  }
+})

+ 4 - 0
pages/address/modules/list/index.json

@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 33 - 0
pages/address/modules/list/index.scss

@@ -0,0 +1,33 @@
+.item {
+    width: 100vw;
+    margin-bottom: 20rpx;
+    background-color: #ffffff;
+
+    .content {
+        position: relative;
+        padding: 20rpx 30rpx;
+        padding-top: 0;
+        box-sizing: border-box;
+
+        .num {
+            font-size: 28rpx;
+            color: #333333;
+            padding: 20rpx 0 10rpx;
+            font-weight: 700;
+        }
+
+        .exp {
+            line-height: 34rpx;
+            font-size: 24rpx;
+            margin-bottom: 8rpx;
+            color: #999999;
+        }
+    }
+}
+
+/* 文本行数限制 */
+.line-1 {
+    overflow: hidden;
+    white-space: nowrap;
+    text-overflow: ellipsis;
+}

+ 15 - 0
pages/address/modules/list/index.wxml

@@ -0,0 +1,15 @@
+<view class="item" wx:for="{{list}}" wx:key="index">
+	<navigator url="#" class="content">
+		<view class="num">
+			{{item.name}} {{item.phonenumber}}
+		</view>
+		<view class="exp">
+			省市县:{{(item.province + item.city + item.county)||" --"}}
+		</view>
+		<view class="exp">
+			地址:{{item.address|| ' --'}}
+		</view>
+	</navigator>
+</view>
+
+<Yl_Empty wx:if="{{list.length==0}}" />

+ 121 - 0
pages/address/update.js

@@ -0,0 +1,121 @@
+const _Http = getApp().globalData.http;
+let sys_enterpriseid = null;
+Page({
+    data: {
+        form: [{
+            label: "联系人",
+            error: false,
+            errMsg: "",
+            type: "text",
+            value: "",
+            placeholder: "请填写",
+            valueName: "name",
+            required: true,
+            checking: "base"
+        }, {
+            label: "手机号",
+            error: false,
+            errMsg: "",
+            type: "number",
+            value: "",
+            placeholder: "联系人手机号码",
+            valueName: "phonenumber",
+            required: true,
+            checking: "phone"
+        }, {
+            label: "省市县",
+            error: false,
+            errMsg: "",
+            type: "region",
+            value: [],
+            placeholder: "省,市,县",
+            valueName: "region",
+            required: true
+        }, {
+            label: "详细地址",
+            error: false,
+            errMsg: "",
+            type: "textarea",
+            value: "",
+            placeholder: "例: 科创园11栋1103室",
+            valueName: "address",
+            required: true,
+            checking: "base"
+        }, {
+            label: "备注",
+            error: false,
+            errMsg: "",
+            type: "textarea",
+            value: "",
+            placeholder: "地址说明",
+            valueName: "remarks",
+            required: false,
+            checking: "base"
+        }],
+        disabled: true
+    },
+    onLoad(options) {
+        sys_enterpriseid = options.id
+    },
+    submit() {
+        let content = Object.assign({
+            "contactsid": 0,
+            sys_enterpriseid,
+            sex: "男",
+            "name": "",
+            "depname": "",
+            "position": "",
+            "isleader": 1,
+            "birthday": "",
+            "phonenumber": "",
+            "email": "",
+            "address": "",
+            "remarks": "",
+            "workaddress": 1,
+            "isdefault": 0
+        }, this.selectComponent("#Form").submit());
+        content.province = content.region[0] || "";
+        content.city = content.region[1] || "";
+        content.county = content.region[2] || "";
+        delete(content.region);
+        _Http.basic({
+            id: 20221009155703,
+            content
+        }).then(res => {
+            console.log("新建地址", res)
+            wx.showToast({
+                title: res.msg != '成功' ? res.msg : "添加成功",
+                icon: "none",
+                mask: true
+            });
+            if (res.msg == '成功') setTimeout(() => {
+                wx.navigateBack();
+                let page = getCurrentPages().find(v => v.route == 'pages/address/index');
+                if (page) {
+                    let content = JSON.parse(JSON.stringify(page.data.content));
+                    content.pageNumber = 1;
+                    content.pageSize = (page.data.content.pageNumber - 1) * (page.data.content.pageSize || 20);
+                    _Http.basic({
+                        "id": "20221009155803",
+                        content
+                    }).then(res => {
+                        if (res.msg == '成功') page.setData({
+                            list: res.data
+                        })
+                    })
+                }
+            }, 500)
+
+
+
+        })
+    },
+    /* 表单是否填写完成 */
+    onConfirm({
+        detail
+    }) {
+        this.setData({
+            disabled: detail
+        })
+    },
+})

+ 3 - 0
pages/address/update.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 26 - 0
pages/address/update.scss

@@ -0,0 +1,26 @@
+.footer {
+	display: flex;
+	justify-content: 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;
+	z-index: 9999;
+	padding-top: 10rpx;
+
+	.but {
+		width: 690rpx;
+		height: 90rpx;
+		background: var(--warning);
+		border-radius: 16rpx;
+		font-size: 28rpx;
+		font-family: PingFang SC-Bold, PingFang SC;
+		font-weight: bold;
+		color: #fff;
+	}
+
+}

+ 5 - 0
pages/address/update.wxml

@@ -0,0 +1,5 @@
+<Yl_Field id='Form' form="{{form}}" bind:onConfirm='onConfirm' />
+
+<view class="footer">
+	<van-button custom-class='but' bind:click="submit" disabled='{{disabled}}'>保存地址</van-button>
+</view>