From 0560eed4a389f806dc3254a526e929e8476c868a Mon Sep 17 00:00:00 2001
From: Liuyi <candymxq888@outlook.com>
Date: 星期日, 29 九月 2024 18:52:51 +0800
Subject: [PATCH] 完成地址管理新增、删除、编辑、设置默认地址,修改navbar组件

---
 unpackage/dist/dev/mp-weixin/pages/address/index.js |   98 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 88 insertions(+), 10 deletions(-)

diff --git a/unpackage/dist/dev/mp-weixin/pages/address/index.js b/unpackage/dist/dev/mp-weixin/pages/address/index.js
index e2f6158..ea55123 100644
--- a/unpackage/dist/dev/mp-weixin/pages/address/index.js
+++ b/unpackage/dist/dev/mp-weixin/pages/address/index.js
@@ -1,6 +1,7 @@
 "use strict";
 const common_vendor = require("../../common/vendor.js");
-const _sfc_main = {};
+const common_assets = require("../../common/assets.js");
+const api_index = require("../../api/index.js");
 if (!Array) {
   const _easycom_navbar2 = common_vendor.resolveComponent("navbar");
   _easycom_navbar2();
@@ -9,12 +10,89 @@
 if (!Math) {
   _easycom_navbar();
 }
-function _sfc_render(_ctx, _cache) {
-  return {
-    a: common_vendor.p({
-      title: "地址管理"
-    })
-  };
-}
-const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
-wx.createPage(MiniProgramPage);
+const _sfc_main = {
+  __name: "index",
+  setup(__props) {
+    const addressList = common_vendor.ref([]);
+    async function getAddressList() {
+      await api_index.searchAddress({ limit: 100, page: 1 }).then((res) => {
+        if (res.code == 200) {
+          res.data.list.forEach((item) => {
+            res.data.list.forEach((item2) => {
+              item2.isDefault = item2.isDefault == 1 ? true : false;
+              item2.addressWhole = item2.regionName.replace(/[,#]/g, " ") + item2.address;
+            });
+          });
+          addressList.value = res.data.list;
+        }
+      });
+    }
+    async function setDefault(isDefault, id, index1) {
+      if (isDefault == true) {
+        console.log("true");
+      } else {
+        console.log("false");
+        await api_index.setAddressDefaultApi(id).then((res) => {
+          if (res.code == 200) {
+            getAddressList();
+          } else {
+            common_vendor.index.showToast({
+              title: "设置失败",
+              image: "../../static/images/other/success.svg",
+              duration: 500
+            });
+          }
+        });
+      }
+    }
+    async function deleteAddress(id) {
+      await api_index.deleteAddressApi(id).then((res) => {
+        if (res.code == 200) {
+          common_vendor.index.showToast({
+            title: "删除成功",
+            image: "../../static/images/other/success.svg",
+            duration: 500
+          });
+          getAddressList();
+        }
+      });
+    }
+    function navToModify(id) {
+      common_vendor.index.navigateTo({
+        url: `/pages/addressAdd/index?id=${id}`
+      });
+    }
+    function navToAdd() {
+      let id = null;
+      common_vendor.index.navigateTo({
+        url: `/pages/addressAdd/index?id=${id}`
+      });
+    }
+    common_vendor.onShow(async () => {
+      getAddressList();
+    });
+    return (_ctx, _cache) => {
+      return {
+        a: common_vendor.p({
+          title: "地址管理"
+        }),
+        b: common_vendor.f(addressList.value, (item, index, i0) => {
+          return {
+            a: common_vendor.t(item.userName),
+            b: common_vendor.t(item.userPhone),
+            c: common_vendor.t(item.addressWhole),
+            d: item.id,
+            e: item.isDefault,
+            f: common_vendor.o(($event) => setDefault(item.isDefault, item.id)),
+            g: common_vendor.o(($event) => navToModify(item.id)),
+            h: common_vendor.o(($event) => deleteAddress(item.id))
+          };
+        }),
+        c: common_assets._imports_0$3,
+        d: common_assets._imports_1$1,
+        e: common_vendor.o(($event) => navToAdd())
+      };
+    };
+  }
+};
+wx.createPage(_sfc_main);

--
Gitblit v1.9.3