This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<text class="category-desc">{{ cat.description || '暂无描述' }}</text>
|
||||
</view>
|
||||
<view class="category-actions">
|
||||
<text class="action-btn attr" @click="editAttributes(cat)">属性配置</text>
|
||||
<text class="action-btn edit" @click="editCategory(cat)">编辑</text>
|
||||
<text class="action-btn delete" @click="deleteCategory(cat)">删除</text>
|
||||
</view>
|
||||
@@ -51,6 +52,33 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 属性配置弹窗 -->
|
||||
<view class="dialog-mask" v-if="showAttrDialog" @click="closeAttrDialog">
|
||||
<view class="dialog dialog-wide" @click.stop>
|
||||
<view class="dialog-header">
|
||||
<text class="dialog-title">{{ currentCategory.name }} - 属性配置</text>
|
||||
</view>
|
||||
<view class="dialog-body">
|
||||
<view v-for="(attr, index) in attributes" :key="index" class="attr-item">
|
||||
<input class="input attr-name" v-model="attr.name" placeholder="属性名称" />
|
||||
<select class="input attr-type" v-model="attr.attrType">
|
||||
<option value="number">数字</option>
|
||||
<option value="text">文本</option>
|
||||
</select>
|
||||
<input class="input attr-unit" v-model="attr.unit" placeholder="单位" />
|
||||
<text class="attr-delete" @click="removeAttr(index)">×</text>
|
||||
</view>
|
||||
<view class="add-attr-btn" @click="addAttr">
|
||||
<text>+ 添加属性</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="dialog-footer">
|
||||
<text class="btn-cancel" @click="closeAttrDialog">取消</text>
|
||||
<text class="btn-confirm" @click="saveAttributes">保存</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -67,7 +95,11 @@ export default {
|
||||
categoryId: '',
|
||||
name: '',
|
||||
description: ''
|
||||
}
|
||||
},
|
||||
// 属性配置相关
|
||||
showAttrDialog: false,
|
||||
currentCategory: {},
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
@@ -149,6 +181,48 @@ export default {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '检查失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
// ============ 属性配置 ============
|
||||
async editAttributes(cat) {
|
||||
this.currentCategory = cat
|
||||
this.showAttrDialog = true
|
||||
try {
|
||||
const attrs = await productApi.getCategoryAttributes(cat.categoryId)
|
||||
this.attributes = (attrs || []).map(a => ({
|
||||
name: a.name,
|
||||
attrType: a.attrType || 'number',
|
||||
unit: a.unit || '',
|
||||
attrId: a.attrId
|
||||
}))
|
||||
if (this.attributes.length === 0) {
|
||||
this.attributes.push({ name: '', attrType: 'number', unit: '', attrId: '' })
|
||||
}
|
||||
} catch (e) {
|
||||
this.attributes = [{ name: '', attrType: 'number', unit: '', attrId: '' }]
|
||||
}
|
||||
},
|
||||
addAttr() {
|
||||
this.attributes.push({ name: '', attrType: 'number', unit: '', attrId: '' })
|
||||
},
|
||||
removeAttr(index) {
|
||||
this.attributes.splice(index, 1)
|
||||
},
|
||||
closeAttrDialog() {
|
||||
this.showAttrDialog = false
|
||||
},
|
||||
async saveAttributes() {
|
||||
const validAttrs = this.attributes.filter(a => a.name.trim())
|
||||
if (validAttrs.length === 0) {
|
||||
uni.showToast({ title: '请至少添加一个属性', icon: 'none' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
await productApi.saveCategoryAttributes(this.currentCategory.categoryId, validAttrs)
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
this.closeAttrDialog()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,6 +294,11 @@ export default {
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.action-btn.attr {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.action-btn.delete {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
@@ -330,4 +409,60 @@ export default {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 属性配置弹窗 */
|
||||
.dialog-wide {
|
||||
width: 90%;
|
||||
max-height: 80vh;
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.attr-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.attr-name {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
.attr-type {
|
||||
flex: 1;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
padding: 0 10rpx;
|
||||
height: 70rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.attr-unit {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.attr-delete {
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
text-align: center;
|
||||
font-size: 36rpx;
|
||||
color: #ff4d4f;
|
||||
background: #fff1f0;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.add-attr-btn {
|
||||
padding: 20rpx;
|
||||
text-align: center;
|
||||
color: #667eea;
|
||||
font-size: 28rpx;
|
||||
border: 2rpx dashed #667eea;
|
||||
border-radius: 12rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user