页面初始化
This commit is contained in:
@@ -1,85 +1,88 @@
|
||||
<template>
|
||||
<view class="edit-container">
|
||||
<!-- 头部 -->
|
||||
<view class="header">
|
||||
<uni-icons type="back" size="28" color="#303133" @click="handleCancel" />
|
||||
<text class="title">修改分销员</text>
|
||||
<view class="header-right"></view>
|
||||
<view class="distributor-edit-container">
|
||||
<!-- 页面标题 -->
|
||||
<view class="page-header">
|
||||
<view class="header-left" @click="goBack">
|
||||
<view class="back-icon">←</view>
|
||||
</view>
|
||||
<view class="header-title">编辑分销员</view>
|
||||
<view class="header-right" @click="saveDistributor">
|
||||
<view class="save-btn">保存</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 表单容器 -->
|
||||
<view class="form-container">
|
||||
<uni-forms :model="formData" ref="formRef" labelWidth="100rpx">
|
||||
<uni-forms-item label="姓名" required name="name">
|
||||
<uni-easyinput
|
||||
v-model="formData.name"
|
||||
placeholder="请输入姓名"
|
||||
class="form-input"
|
||||
/>
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item label="手机号" required name="phone">
|
||||
<uni-easyinput
|
||||
v-model="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
class="form-input"
|
||||
/>
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item label="OpenID" required name="openid">
|
||||
<uni-easyinput
|
||||
v-model="formData.openid"
|
||||
placeholder="请输入OpenID"
|
||||
class="form-input"
|
||||
/>
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item label="父ID" required name="parent_id">
|
||||
<uni-easyinput
|
||||
v-model="formData.parent_id"
|
||||
placeholder="请输入父ID"
|
||||
type="number"
|
||||
class="form-input"
|
||||
/>
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item label="租户ID" required name="tenant_id">
|
||||
<uni-easyinput
|
||||
v-model="formData.tenant_id"
|
||||
placeholder="请输入租户ID"
|
||||
type="number"
|
||||
class="form-input"
|
||||
/>
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item label="苹果URL" name="applet_url">
|
||||
<uni-easyinput
|
||||
v-model="formData.applet_url"
|
||||
placeholder="请输入苹果URL"
|
||||
class="form-input"
|
||||
/>
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item label="状态" name="is_active">
|
||||
<uni-data-checkbox
|
||||
v-model="formData.is_active"
|
||||
:localdata="statusOptions"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</uni-forms-item>
|
||||
</uni-forms>
|
||||
<!-- 表单内容 -->
|
||||
<view class="form-section">
|
||||
<view class="section-title">基本信息</view>
|
||||
<view class="form-card">
|
||||
<view class="form-row">
|
||||
<view class="form-label">姓名</view>
|
||||
<view class="form-control">
|
||||
<input
|
||||
v-model="distributorForm.name"
|
||||
class="form-input"
|
||||
placeholder="请输入姓名"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="form-row">
|
||||
<view class="form-label">手机号</view>
|
||||
<view class="form-control">
|
||||
<input
|
||||
v-model="distributorForm.phone"
|
||||
type="number"
|
||||
class="form-input"
|
||||
placeholder="请输入手机号"
|
||||
maxlength="11"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="form-row">
|
||||
<view class="form-label">角色</view>
|
||||
<view class="form-control">
|
||||
<picker
|
||||
:range="roleOptions"
|
||||
:value="roleIndex"
|
||||
@change="onRoleChange"
|
||||
class="picker"
|
||||
>
|
||||
<view class="picker-text">{{ roleOptions[roleIndex] }}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
<view class="form-row">
|
||||
<view class="form-label">状态</view>
|
||||
<view class="form-control">
|
||||
<picker
|
||||
:range="statusOptions"
|
||||
:value="statusIndex"
|
||||
@change="onStatusChange"
|
||||
class="picker"
|
||||
>
|
||||
<view class="picker-text">{{ statusOptions[statusIndex] }}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
<view class="form-row">
|
||||
<view class="form-label">备注</view>
|
||||
<view class="form-control">
|
||||
<textarea
|
||||
v-model="distributorForm.remark"
|
||||
class="form-textarea"
|
||||
placeholder="请输入备注信息"
|
||||
maxlength="200"
|
||||
></textarea>
|
||||
<view class="textarea-count">{{ distributorForm.remark.length }}/200</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 按钮容器 -->
|
||||
<view class="btn-container">
|
||||
<button class="cancel-btn" @click="handleCancel">
|
||||
<uni-icons type="close" size="20" color="#fff" />
|
||||
<text class="btn-text">取消</text>
|
||||
</button>
|
||||
<button class="submit-btn" @click="handleSubmit">
|
||||
<uni-icons type="checkmark" size="20" color="#fff" />
|
||||
<text class="btn-text">提交</text>
|
||||
</button>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="action-section">
|
||||
<view class="action-btn delete-btn" @click="deleteDistributor">
|
||||
删除分销员
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -87,162 +90,286 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue"
|
||||
|
||||
const formRef = ref(null)
|
||||
const distributorId = ref(uni.getStorageSync('__uni_route_query')?.id || '')
|
||||
|
||||
const formData = ref({
|
||||
// 分销员表单数据
|
||||
const distributorForm = ref({
|
||||
id: '',
|
||||
name: '',
|
||||
phone: '',
|
||||
openid: '',
|
||||
parent_id: '',
|
||||
tenant_id: '',
|
||||
applet_url: '',
|
||||
is_active: 'Y'
|
||||
name: '张三',
|
||||
phone: '13800138001',
|
||||
role: '初级分销员',
|
||||
status: '启用',
|
||||
remark: '默认分销员'
|
||||
})
|
||||
|
||||
const statusOptions = [
|
||||
{ text: '激活', value: 'Y' },
|
||||
{ text: '未激活', value: 'N' }
|
||||
]
|
||||
|
||||
// 初始化加载数据
|
||||
// 角色选项
|
||||
const roleOptions = ['初级分销员', '中级分销员', '高级分销员']
|
||||
const roleIndex = ref(0)
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = ['启用', '禁用']
|
||||
const statusIndex = ref(0)
|
||||
|
||||
onMounted(() => {
|
||||
fetchDistributorDetail()
|
||||
// 实际项目中应从接口获取分销员详情
|
||||
// loadDistributorDetail()
|
||||
})
|
||||
|
||||
// 获取分销员详情
|
||||
function fetchDistributorDetail() {
|
||||
// 这里应该调用后端API获取数据
|
||||
// 模拟数据
|
||||
|
||||
// 返回上一页
|
||||
function goBack() {
|
||||
uni.navigateBack({ delta: 1 })
|
||||
}
|
||||
|
||||
// 保存分销员
|
||||
function saveDistributor() {
|
||||
if (!distributorForm.value.name) {
|
||||
uni.showToast({
|
||||
title: '请输入姓名',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!distributorForm.value.phone || distributorForm.value.phone.length !== 11) {
|
||||
uni.showToast({
|
||||
title: '请输入有效的手机号',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.showLoading({ title: '保存中...' })
|
||||
|
||||
setTimeout(() => {
|
||||
formData.value = {
|
||||
id: distributorId.value,
|
||||
name: '张三',
|
||||
phone: '13800138001',
|
||||
openid: 'openid123456',
|
||||
parent_id: '0',
|
||||
tenant_id: '1',
|
||||
applet_url: 'https://example.com',
|
||||
is_active: 'Y'
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'success'
|
||||
})
|
||||
// 实际项目中应调用接口保存分销员
|
||||
// updateDistributorData()
|
||||
|
||||
// 保存成功后返回上一页
|
||||
setTimeout(() => {
|
||||
goBack()
|
||||
}, 1000)
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
// 删除分销员
|
||||
function deleteDistributor() {
|
||||
uni.showModal({
|
||||
title: '删除分销员',
|
||||
content: '确定要删除该分销员吗?',
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({ title: '删除中...' })
|
||||
|
||||
setTimeout(() => {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'success'
|
||||
})
|
||||
// 实际项目中应调用接口删除分销员
|
||||
// deleteDistributorData()
|
||||
|
||||
// 删除成功后返回上一页
|
||||
setTimeout(() => {
|
||||
goBack()
|
||||
}, 1000)
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 取消
|
||||
function handleCancel() {
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
// 提交
|
||||
function handleSubmit() {
|
||||
formRef.value.validate().then(() => {
|
||||
// 这里应该调用后端API提交数据
|
||||
uni.showToast({ title: '修改成功' })
|
||||
uni.navigateTo({ url: '/pages/distributor/index' })
|
||||
}).catch(err => {
|
||||
console.log('表单验证失败', err)
|
||||
})
|
||||
}
|
||||
|
||||
// 角色变更
|
||||
function onRoleChange(e) {
|
||||
const value = e.detail.value
|
||||
roleIndex.value = value
|
||||
distributorForm.value.role = roleOptions[value]
|
||||
}
|
||||
|
||||
// 状态变更
|
||||
function onStatusChange(e) {
|
||||
const value = e.detail.value
|
||||
statusIndex.value = value
|
||||
distributorForm.value.status = statusOptions[value]
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.edit-container {
|
||||
padding: 20rpx;
|
||||
/* #ifndef APP-NVUE */
|
||||
page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
background-color: #f5f7fa;
|
||||
min-height: 100vh;
|
||||
min-height: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
view {
|
||||
font-size: 14px;
|
||||
line-height: inherit;
|
||||
}
|
||||
/* #endif */
|
||||
|
||||
.distributor-edit-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* 头部样式 */
|
||||
.header {
|
||||
/* 页面头部 */
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 24rpx;
|
||||
padding-bottom: 16rpx;
|
||||
border-bottom: 2rpx solid #ecf5ff;
|
||||
height: 120rpx;
|
||||
background-color: #fff;
|
||||
padding: 0 32rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.title {
|
||||
.header-left {
|
||||
width: 60rpx;
|
||||
}
|
||||
|
||||
.back-icon {
|
||||
font-size: 40rpx;
|
||||
color: #303133;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.header-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
width: 28px;
|
||||
width: 60rpx;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* 表单容器样式 */
|
||||
.form-container {
|
||||
.save-btn {
|
||||
font-size: 24rpx;
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 表单内容 */
|
||||
.form-section {
|
||||
padding: 32rpx;
|
||||
background-color: #fff;
|
||||
margin: 0 16rpx 16rpx;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
margin-bottom: 24rpx;
|
||||
padding-left: 12rpx;
|
||||
border-left: 8rpx solid #409eff;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 12rpx;
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 24rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
/* 表单输入框样式 */
|
||||
.form-row:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-size: 24rpx;
|
||||
color: #606266;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
border-radius: 8rpx !important;
|
||||
border: 1rpx solid #dcdfe6 !important;
|
||||
transition: all 0.3s ease !important;
|
||||
}
|
||||
|
||||
.form-input:focus {
|
||||
border-color: #409eff !important;
|
||||
box-shadow: 0 0 0 2rpx rgba(64, 158, 255, 0.2) !important;
|
||||
}
|
||||
|
||||
/* 按钮容器样式 */
|
||||
.btn-container {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
margin-top: 32rpx;
|
||||
}
|
||||
|
||||
.cancel-btn,
|
||||
.submit-btn {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
padding: 16rpx 0;
|
||||
width: 100%;
|
||||
background-color: #fff;
|
||||
border: 1rpx solid #dcdfe6;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
padding: 16rpx;
|
||||
font-size: 24rpx;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.cancel-btn:active,
|
||||
.submit-btn:active {
|
||||
transform: translateY(2rpx);
|
||||
box-shadow: 0 1rpx 4rpx rgba(0, 0, 0, 0.1);
|
||||
.picker {
|
||||
background-color: #fff;
|
||||
border: 1rpx solid #dcdfe6;
|
||||
border-radius: 8rpx;
|
||||
padding: 16rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
background-color: #909399;
|
||||
color: #fff;
|
||||
.picker-text {
|
||||
font-size: 24rpx;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
background-color: #409eff;
|
||||
color: #fff;
|
||||
.form-textarea {
|
||||
width: 100%;
|
||||
height: 160rpx;
|
||||
background-color: #fff;
|
||||
border: 1rpx solid #dcdfe6;
|
||||
border-radius: 8rpx;
|
||||
padding: 16rpx;
|
||||
font-size: 24rpx;
|
||||
color: #303133;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
margin-left: 8rpx;
|
||||
.textarea-count {
|
||||
position: absolute;
|
||||
bottom: 8rpx;
|
||||
right: 16rpx;
|
||||
font-size: 18rpx;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media screen and (max-width: 750rpx) {
|
||||
.form-container {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.btn-container {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
/* 操作按钮 */
|
||||
.action-section {
|
||||
padding: 32rpx;
|
||||
background-color: #fff;
|
||||
margin: 0 16rpx 16rpx;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
padding: 20rpx;
|
||||
border-radius: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
background-color: #fef0f0;
|
||||
color: #f56c6c;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user