acdr-ui/dist/dev/mp-weixin/pages/address/index.js.map

1 line
6.8 KiB
Plaintext
Raw Normal View History

2024-09-19 07:20:14 +08:00
{"version":3,"file":"index.js","sources":["../../../../../src/pages/address/index.vue","../../../../../uniPage:/cGFnZXMvYWRkcmVzcy9pbmRleC52dWU"],"sourcesContent":["<route lang=\"json5\">\r\n{\r\n style: {\r\n navigationBarTitleText: '新增地址',\r\n },\r\n}\r\n</route>\r\n<template>\r\n <view class=\"address-management\">\r\n <view v-for=\"(address, index) in addresses\" :key=\"index\" class=\"address-cell\">\r\n <view class=\"address-info\">\r\n <view class=\"address-label\">\r\n <view class=\"tag\">{{ address.type }}</view>\r\n <view class=\"address-detail\">\r\n {{ address.name }} {{ address.phone }} -\r\n {{ `${address['province']}-${address['city']}-${address['district']}` }}\r\n </view>\r\n </view>\r\n </view>\r\n <view class=\"address-actions\">\r\n <wd-icon name=\"edit\" size=\"20px\" @click=\"editAddress(index)\" />\r\n <wd-icon name=\"delete\" size=\"20px\" @click=\"deleteAddress(index)\" />\r\n </view>\r\n </view>\r\n <wd-status-tip v-if=\"addresses.length == 0\" image=\"content\" tip=\"暂无内容\" />\r\n <!-- 新增地址按钮 -->\r\n <button class=\"add-address-button\" @click=\"addAddress\">新增地址</button>\r\n\r\n <!-- 弹窗组件 -->\r\n <wd-popup\r\n v-model=\"showPopup\"\r\n position=\"bottom\"\r\n custom-style=\"height: 60%; width: 100%;\"\r\n @close=\"handleClose\"\r\n >\r\n <AddAddress :initialAddress=\"currentAddress\" @save-address=\"saveAddress\" />\r\n </wd-popup>\r\n </view>\r\n</template>\r\n\r\n<script setup>\r\nimport { ref, onMounted } from 'vue'\r\nimport AddAddress from './components/AddAddress.vue'\r\nimport { httpGet, httpPost } from '@/utils/http'\r\n\r\n// 地址列表数据\r\nconst addresses = ref([])\r\n\r\n// 当前操作的地址数据\r\nconst currentAddress = ref({\r\n id: null,\r\n name: '',\r\n phone: '',\r\n address: '',\r\n})\r\n\r\n// 控制弹窗的显示\r\nconst showPopup = ref(false)\r\n\r\n// 获取地址列表\r\nconst fetchAddresses = async () => {\r\n const res = await httpPost('/china-address/page')\r\n addresses.value = res.records\r\n}\r\n\r\n// 页面加载时获取地址列表\r\nonMounted(() => {\r\n fetchAddresses()\r\n})\r\n\r\n// 新增地址\r\nconst addAddress = () => {\r\n currentAddress.value = { id: null, name: '', phone: '', address: '' }\r\n showPopup.value = true\r\n}\r\n\r\n// 编辑地址\r\nconst editAddress = (index) => {\r\n const address = addresses.value[index]\r\n addresses.value[index].address = `${address.province}-${address.city}-${address.district}`\r\n currentAddress.value = { ...addresses.value[index] }\r\n showPopup.value = true\r\n}\r\n\r\n// 保存地址(新增或修改)\r\nconst saveAddress = async (address) => {\r\n let res\r\n if (address.address != '') {\r\n const addressList = address.address.split('-')\r\n address.province = addressList[0]\r\n address.city = addressList[1]\r\n address.district = addressList[2]\r\n }\r\n if (address.id) {\r\n // 修改地址\r\n res = await httpPost('/china-address/modify', address)\r\n } else {\r\n // 新增地址\r\n res = await httpPost('/china-address/add', address)\r\n }\r\n if (res.code == 200) {\r\n uni.showToast({ title: '操作成功', icon: '' })\r\n fetchAddresses() // 刷新地址列表\r\n showPopup.value = false\r\n }\r\n}\r\n\r\n// 删除地址\r\nconst deleteAddress = async (index) => {\r\n const addressId = addresses.value[index].id\r\n uni.showModal({\r\n title: '确认删除',\r\n content: '你确定要删除这个地址吗?',\r\n success: async (res) => {\r\n if (res.confirm) {\r\n const deleteRes = await httpGet(`/china-address/remove/${addressId}`)\r\n if (deleteRes.code === 200) {\r\n uni.showToast({ title: '删除成功', icon: 'success' })\r\n fetchAddresses() // 刷新地址列表\r\n }\r\n }\r\n },\r\n })\r\n}\r\n</script>\r\n\r\n<style scoped>\r\n.address-management {\r\n padd