2026-04-20 06:23:11 +00:00
|
|
|
<template>
|
|
|
|
|
<view class="apartment-add-page">
|
|
|
|
|
<!-- 自定义导航栏 -->
|
|
|
|
|
<view class="custom-nav safe-area-top">
|
|
|
|
|
<view class="nav-content">
|
|
|
|
|
<view class="nav-back" @click="goBack">
|
|
|
|
|
<uni-icons type="left" size="20" color="#1E293B"></uni-icons>
|
|
|
|
|
</view>
|
|
|
|
|
<text class="nav-title">{{isEdit ? '编辑公寓' : '添加公寓'}}</text>
|
|
|
|
|
<view class="nav-actions">
|
|
|
|
|
<view class="nav-btn" @click="save">
|
|
|
|
|
<text class="save-text">保存</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<scroll-view scroll-y class="page-content">
|
|
|
|
|
<!-- 基本信息 -->
|
|
|
|
|
<view class="form-section">
|
|
|
|
|
<view class="section-title">基本信息</view>
|
|
|
|
|
<view class="form-card">
|
|
|
|
|
<view class="form-item">
|
|
|
|
|
<text class="item-label required">公寓名称</text>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
v-model="form.name"
|
|
|
|
|
placeholder="请输入公寓名称"
|
|
|
|
|
class="item-input"
|
|
|
|
|
/>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="form-item">
|
2026-04-22 06:47:04 +00:00
|
|
|
<text class="item-label">地址</text>
|
2026-04-20 06:23:11 +00:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
v-model="form.address"
|
2026-04-22 06:47:04 +00:00
|
|
|
placeholder="请输入地址"
|
2026-04-20 06:23:11 +00:00
|
|
|
class="item-input"
|
|
|
|
|
/>
|
|
|
|
|
</view>
|
2026-04-22 06:47:04 +00:00
|
|
|
<view class="form-item textarea-item">
|
|
|
|
|
<text class="item-label">描述</text>
|
2026-04-20 06:23:11 +00:00
|
|
|
<textarea
|
2026-04-22 06:47:04 +00:00
|
|
|
v-model="form.description"
|
|
|
|
|
placeholder="请输入描述"
|
2026-04-20 06:23:11 +00:00
|
|
|
class="remark-input"
|
2026-04-22 06:47:04 +00:00
|
|
|
maxlength="500"
|
2026-04-20 06:23:11 +00:00
|
|
|
/>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="safe-area-bottom" style="height: 40rpx;"></view>
|
|
|
|
|
</scroll-view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2026-04-22 06:47:04 +00:00
|
|
|
import { apartmentApi } from '@/api/index.js'
|
2026-04-20 06:23:11 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
isEdit: false,
|
|
|
|
|
apartmentId: null,
|
|
|
|
|
form: {
|
|
|
|
|
name: '',
|
|
|
|
|
address: '',
|
2026-04-22 06:47:04 +00:00
|
|
|
description: ''
|
|
|
|
|
}
|
2026-04-20 06:23:11 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onLoad(options) {
|
2026-04-22 06:47:04 +00:00
|
|
|
// 判断是否为编辑模式
|
|
|
|
|
if (options.mode === 'edit' && options.id) {
|
2026-04-20 06:23:11 +00:00
|
|
|
this.isEdit = true
|
|
|
|
|
this.apartmentId = options.id
|
2026-04-22 06:47:04 +00:00
|
|
|
this.loadApartmentDetail()
|
2026-04-20 06:23:11 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2026-04-22 06:47:04 +00:00
|
|
|
// 加载公寓详情(编辑模式)
|
|
|
|
|
async loadApartmentDetail() {
|
2026-04-20 06:23:11 +00:00
|
|
|
try {
|
|
|
|
|
uni.showLoading({ title: '加载中...' })
|
2026-04-22 06:47:04 +00:00
|
|
|
const res = await apartmentApi.getDetail(this.apartmentId)
|
|
|
|
|
const data = res.data
|
|
|
|
|
|
|
|
|
|
// 填充表单数据
|
2026-04-20 06:23:11 +00:00
|
|
|
this.form = {
|
|
|
|
|
name: data.name || '',
|
|
|
|
|
address: data.address || '',
|
2026-04-22 06:47:04 +00:00
|
|
|
description: data.description || ''
|
2026-04-20 06:23:11 +00:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
uni.showToast({ title: '加载失败', icon: 'none' })
|
|
|
|
|
} finally {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async save() {
|
|
|
|
|
if (!this.form.name.trim()) {
|
|
|
|
|
uni.showToast({ title: '请输入公寓名称', icon: 'none' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
uni.showLoading({ title: '保存中...' })
|
|
|
|
|
|
|
|
|
|
if (this.isEdit) {
|
2026-04-22 06:47:04 +00:00
|
|
|
// 编辑模式
|
2026-04-20 06:23:11 +00:00
|
|
|
await apartmentApi.update(this.apartmentId, this.form)
|
2026-04-22 06:47:04 +00:00
|
|
|
uni.showToast({ title: '修改成功', icon: 'success' })
|
2026-04-20 06:23:11 +00:00
|
|
|
} else {
|
2026-04-22 06:47:04 +00:00
|
|
|
// 添加模式
|
2026-04-20 06:23:11 +00:00
|
|
|
await apartmentApi.create(this.form)
|
|
|
|
|
uni.showToast({ title: '添加成功', icon: 'success' })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.navigateBack()
|
|
|
|
|
}, 1500)
|
|
|
|
|
} catch (error) {
|
2026-04-22 06:47:04 +00:00
|
|
|
const msg = error.data && error.data.message
|
|
|
|
|
uni.showToast({ title: msg || (this.isEdit ? '修改失败' : '添加失败'), icon: 'none' })
|
2026-04-20 06:23:11 +00:00
|
|
|
} finally {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
goBack() {
|
|
|
|
|
uni.navigateBack()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.apartment-add-page {
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
background: #F8FAFC;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 导航栏 */
|
|
|
|
|
.custom-nav {
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
border-bottom: 2rpx solid #F1F5F9;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.nav-content {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 20rpx 32rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.nav-back {
|
|
|
|
|
width: 60rpx;
|
|
|
|
|
height: 60rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.nav-title {
|
|
|
|
|
font-size: 36rpx;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
color: #1E293B;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.nav-actions {
|
|
|
|
|
width: 80rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.save-text {
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
color: #2563EB;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 页面内容 */
|
|
|
|
|
.page-content {
|
|
|
|
|
flex: 1;
|
|
|
|
|
padding: 24rpx 32rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 表单区域 */
|
|
|
|
|
.form-section {
|
|
|
|
|
margin-bottom: 32rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.section-title {
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
color: #94A3B8;
|
|
|
|
|
margin-bottom: 16rpx;
|
|
|
|
|
padding-left: 16rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-card {
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
border-radius: 24rpx;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-item {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: 28rpx 32rpx;
|
|
|
|
|
border-bottom: 2rpx solid #F8FAFC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-item:last-child {
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 06:47:04 +00:00
|
|
|
.textarea-item {
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 06:23:11 +00:00
|
|
|
.item-label {
|
|
|
|
|
width: 160rpx;
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
color: #1E293B;
|
|
|
|
|
font-weight: 500;
|
2026-04-22 06:47:04 +00:00
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.textarea-item .item-label {
|
|
|
|
|
margin-bottom: 16rpx;
|
2026-04-20 06:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.item-label.required::after {
|
|
|
|
|
content: '*';
|
|
|
|
|
color: #EF4444;
|
|
|
|
|
margin-left: 8rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.item-input {
|
|
|
|
|
flex: 1;
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
color: #1E293B;
|
|
|
|
|
text-align: right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.remark-input {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 200rpx;
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
color: #1E293B;
|
|
|
|
|
line-height: 1.6;
|
|
|
|
|
}
|
|
|
|
|
</style>
|