From 98a835cc45adbe5ef8ee3cca5ad478f7df673b80 Mon Sep 17 00:00:00 2001 From: Liuyi <candymxq888@outlook.com> Date: 星期三, 27 十一月 2024 17:20:33 +0800 Subject: [PATCH] 添加设备管理列表 --- pages/addressAdd/index.vue | 116 ++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 81 insertions(+), 35 deletions(-) diff --git a/pages/addressAdd/index.vue b/pages/addressAdd/index.vue index aa462c1..3276ff9 100644 --- a/pages/addressAdd/index.vue +++ b/pages/addressAdd/index.vue @@ -1,12 +1,87 @@ <script setup> - import { onMounted, ref } from 'vue'; - import { getRegionApi,creatUserArchive } from '../../api/index.js'; + import { onMounted, ref, watchEffect } from 'vue'; + import { getRegionApi,creatUserArchive,getAddressApi,editAddressApi } from '../../api/index.js'; + import { onLoad } from "@dcloudio/uni-app" + + const addressId = ref() + const pageTitle = ref('新增地址') + const isCheckedDefault =ref(false) + const form = ref({ + id:'', + userName:'', + userPhone:'', + listRegion:[], + userAddress:'', + isDefault:null, + }) + //获取地址 + async function getAddress(){ + if(addressId.value){ + pageTitle.value = "编辑地址" + await getAddressApi(addressId.value).then((res) =>{ + form.value.id = res.data.id + form.value.userName = res.data.userName + form.value.userPhone = res.data.userPhone + form.value.listRegion = res.data.region.replace(/#/g,'').split(',') + form.value.userAddress = res.data.address + form.value.isDefault = res.data.isDefault + regionName.value = res.data.regionName.replace(/[#,]/g,' ') + isCheckedDefault.value = form.value.isDefault == 1 ? true : false + console.log('form',form.value) + }) + }else{ + console.log('xiznzeng') + } + } + onLoad(async(option)=>{ + addressId.value = option.id + console.log('1') + }) + onMounted(()=>{ + getAddress() + }) + function change(e){ + form.value.isDefault = e.detail.value ? 1 : 0 + } + //提交表单数据 + async function submit(){ + //修改地址 + if(form.value.id){ + await editAddressApi(form.value).then((res) =>{ + if(res.code == 200){ + uni.showToast({ + title: '修改成功', + duration:500 + }) + setTimeout(() =>{ + uni.navigateBack() + form.value = {} + },500) + } + }) + }else{ + //新增地址 + form.value.id = JSON.parse(uni.getStorageSync('userInfo')).id + await creatUserArchive(form.value).then((res) =>{ + if(res.code == 200){ + uni.showToast({ + title: '新增成功', + duration:1000 + }) + setTimeout(() =>{ + uni.navigateBack() + form.value = {} + },1000) + } + }) + } + } const DaTreeRef = ref() const treeListData = ref([]) - const selectRegionName = ref() const isExpandIcon = ref(false) const regionName = ref('') + //展开关闭选择框 function expandRegion(){ if(isExpandIcon.value){ isExpandIcon.value = false @@ -40,8 +115,7 @@ nodeList.forEach((item)=>{ nameList.push(item.label) }) - selectRegionName.value = nameList - regionName.value = selectRegionName.value.join() + regionName.value = nameList.join() } //选中区域 function handleTreeChange(e,e2){ @@ -86,42 +160,14 @@ DaTreeRef.value.setExpandedKeys([item.key],true) } } - const isCheckedDefault =ref(false) - const form = ref({ - userName:'', - userPhone:'', - listRegion:[], - userAddress:'', - isDefault:null, - }) - //提交表单数据 - async function submit(){ - console.log('form',form.value) - await creatUserArchive(form.value).then((res) =>{ - if(res.code == 200){ - uni.showToast({ - title: '新增成功', - image: '../../static/images/other/success.svg', - duration:500 - }) - setTimeout(() =>{ - uni.navigateBack() - form.value = {} - },500) - } - }) - } - function change(e){ - console.log('e',e) - form.value.isDefault = e.detail.value ? 1 : null - } + onMounted(async() =>{ await getRegion() }) </script> <template> <view class="container"> - <navbar title ='新增地址'></navbar> + <navbar :title ='pageTitle'></navbar> <view class="content"> <view class="main"> <view class="item"> -- Gitblit v1.9.3