fix(goods): 商品一些问题修复

This commit is contained in:
郝先瑞
2022-03-05 12:10:41 +08:00
parent e5433b7194
commit a701d02133
4 changed files with 90 additions and 125 deletions

View File

@@ -4,109 +4,53 @@
<Toolbar <Toolbar
:editorId="editorId" :editorId="editorId"
:defaultConfig="toolbarConfig" :defaultConfig="toolbarConfig"
:mode="mode"
style="border-bottom: 1px solid #ccc" style="border-bottom: 1px solid #ccc"
/> />
<Editor <Editor
:editorId="editorId" :editorId="editorId"
:defaultConfig="editorConfig" :defaultConfig="editorConfig"
:mode="mode"
style="height: 500px" style="height: 500px"
@onCreated="handleCreated"
@onChange="handleChange"
@onDestroyed="handleDestroyed"
@onFocus="handleFocus"
@onBlur="handleBlur"
@customAlert="customAlert"
@customPaste="customPaste"
/> />
</div> </div>
<p v-else>loading</p> <p v-else>loading</p>
</div> </div>
</template> </template>
<script> <script setup>
import {computed, onBeforeUnmount, ref} from 'vue' import {onBeforeUnmount, reactive, ref, toRefs} from 'vue'
import {Editor, Toolbar, getEditor, removeEditor} from '@wangeditor/editor-for-vue' import {Editor, Toolbar, getEditor, removeEditor} from '@wangeditor/editor-for-vue'
import {uploadFile} from "@/api/system/file"; import {uploadFile} from "@/api/system/file";
export default { const state =reactive({
components: {Editor, Toolbar}, editorId : `w-e-${Math.random().toString().slice(-5)}`, //【注意】编辑器 id ,要全局唯一
setup() { toolbarConfig : {},
const editorId = `w-e-${Math.random().toString().slice(-5)}` //【注意】编辑器 id ,要全局唯一 isEditorShow : true,
const toolbarConfig = {} editorConfig : {
const isEditorShow = ref(true) placeholder: '请输入内容...',
const editorConfig = { MENU_CONF: {
placeholder: '请输入内容...', uploadImage: {
MENU_CONF: { // 自定义图片上传
uploadImage: { // @link https://www.wangeditor.com/v5/guide/menu-config.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8A%9F%E8%83%BD
// 自定义图片上传 async customUpload(file, insertFn) {
// @link https://www.wangeditor.com/v5/guide/menu-config.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8A%9F%E8%83%BD uploadFile(file).then(response => {
async customUpload(file, insertFn) { const url = response.data
uploadFile(file).then(response => { insertFn(url)
const url = response.data })
insertFn(url)
})
}
} }
} }
} }
// 组件销毁时,也及时销毁编辑器
onBeforeUnmount(() => {
const editor = getEditor(editorId)
if (editor == null) return
editor.destroy()
removeEditor(editorId)
})
// 编辑器回调函数
const handleCreated = (editor) => {
console.log('created', editor);
}
const handleChange = (editor) => {
console.log('change:', editor.children);
}
const handleDestroyed = (editor) => {
console.log('destroyed', editor)
}
const handleFocus = (editor) => {
console.log('focus', editor)
}
const handleBlur = (editor) => {
console.log('blur', editor)
}
const customAlert = (info, type) => {
alert(`【自定义提示】${type} - ${info}`)
}
const customPaste = (editor, event, callback) => {
console.log('ClipboardEvent 粘贴事件对象', event)
// 自定义插入内容
editor.insertText('xxx')
// 返回值注意vue 事件的返回值,不能用 return
callback(false) // 返回 false ,阻止默认粘贴行为
// callback(true) // 返回 true ,继续默认的粘贴行为
}
const insertText = () => {
const editor = getEditor(editorId)
if (editor == null) return
editor.insertText('hello world')
}
return {
editorId,
mode: 'default',
toolbarConfig,
editorConfig,
isEditorShow,
handleCreated,
handleChange,
handleDestroyed,
handleFocus,
handleBlur,
customAlert,
customPaste,
insertText
};
} }
} })
const {isEditorShow,editorId,toolbarConfig,editorConfig} =toRefs(state)
onBeforeUnmount(() => {
const editor = getEditor(state.editorId)
if (editor == null) return
editor.destroy()
removeEditor(state.editorId)
})
</script> </script>
<style src="@wangeditor/editor/dist/css/style.css"></style> <style src="@wangeditor/editor/dist/css/style.css"></style>

View File

@@ -2,7 +2,7 @@
<div class="component-container"> <div class="component-container">
<div class="component-container__main"> <div class="component-container__main">
<el-form <el-form
ref="dataForm" ref="dataFormRef"
:rules="rules" :rules="rules"
:model="modelValue" :model="modelValue"
label-width="120px" label-width="120px"
@@ -35,11 +35,12 @@
</el-form-item> </el-form-item>
<el-form-item label="商品简介"> <el-form-item label="商品简介">
<el-input type="textarea" v-model="modelValue.description"/> <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 6 }" v-model="modelValue.description"/>
</el-form-item> </el-form-item>
<el-form-item label="商品相册"> <el-form-item label="商品相册">
<el-card v-for="(item,index) in pictures" style="width: 170px;display: inline-block;margin-left: 10px" :body-style="{ padding: '10px' }"> <el-card v-for="(item,index) in pictures" style="width: 170px;display: inline-block;margin-left: 10px"
:body-style="{ padding: '10px' }">
<single-upload v-model="item.url"/> <single-upload v-model="item.url"/>
@@ -69,14 +70,19 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {listBrands} from "@/api/pms/brand"
import SingleUpload from '@/components/Upload/SingleUpload.vue'
import {onMounted, reactive, ref, toRefs, unref} from "vue" import {onMounted, reactive, ref, toRefs, unref} from "vue"
import {ElForm} from "element-plus" import {ElForm} from "element-plus"
// API 依赖
import {listBrands} from "@/api/pms/brand"
// 自定义组件依赖
import SingleUpload from '@/components/Upload/SingleUpload.vue'
import Editor from '@/components/WangEditor/index.vue' import Editor from '@/components/WangEditor/index.vue'
const emit = defineEmits(['prev', 'next']) const emit = defineEmits(['prev', 'next'])
const dataForm = ref(ElForm) const dataFormRef = ref(ElForm)
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@@ -88,7 +94,13 @@ const props = defineProps({
const state = reactive({ const state = reactive({
brandOptions: [] as Array<any>, brandOptions: [] as Array<any>,
// 商品图册 // 商品图册
pictures: [] as Array<any>, pictures: [
{url: undefined, main: true}, // main = true 代表主图,可切换
{url: undefined, main: false},
{url: undefined, main: false},
{url: undefined, main: false},
{url: undefined, main: false}
] as Array<any>,
rules: { rules: {
name: [{required: true, message: '请填写商品名称', trigger: 'blur'}], name: [{required: true, message: '请填写商品名称', trigger: 'blur'}],
originPrice: [{required: true, message: '请填写原价', trigger: 'blur'}], originPrice: [{required: true, message: '请填写原价', trigger: 'blur'}],
@@ -103,13 +115,15 @@ function loadData() {
listBrands({}).then(response => { listBrands({}).then(response => {
state.brandOptions = response.data state.brandOptions = response.data
}) })
const goodsId = props.modelValue.id const goodsInfo = props.modelValue
console.log('商品信息', goodsInfo)
const goodsId = goodsInfo.id
if (goodsId) { if (goodsId) {
const mainPicUrl = props.modelValue.picUrl const mainPicUrl = goodsInfo.picUrl
if (mainPicUrl) { if (mainPicUrl) {
state.pictures.filter(item => item.main)[0].url = mainPicUrl state.pictures.filter(item => item.main)[0].url = mainPicUrl
} }
const subPicUrls = props.modelValue.subPicUrls const subPicUrls = goodsInfo.subPicUrls
if (subPicUrls && subPicUrls.length > 0) { if (subPicUrls && subPicUrls.length > 0) {
for (let i = 1; i <= subPicUrls.length; i++) { for (let i = 1; i <= subPicUrls.length; i++) {
state.pictures[i].url = subPicUrls[i - 1] state.pictures[i].url = subPicUrls[i - 1]
@@ -120,11 +134,11 @@ function loadData() {
function resetForm() { function resetForm() {
state.pictures = [ state.pictures = [
{url: undefined, main: true}, {url: undefined, main: true}, // main 代表主图,可以切换
{url: undefined, main: false},
{url: undefined, main: false}, {url: undefined, main: false},
{url: undefined, main: false}, {url: undefined, main: false},
{url: undefined, main: false}, {url: undefined, main: false},
{url: undefined, main: false}
] ]
} }
@@ -148,8 +162,7 @@ function handlePrev() {
} }
function handleNext() { function handleNext() {
const form = unref(dataForm) dataFormRef.value.validate((valid: any) => {
form.validate((valid: any) => {
if (valid) { if (valid) {
// 商品图片 // 商品图片
const mainPicUrl = state.pictures.filter(item => item.main == true && item.url).map(item => item.url) const mainPicUrl = state.pictures.filter(item => item.main == true && item.url).map(item => item.url)
@@ -167,7 +180,6 @@ function handleNext() {
onMounted(() => { onMounted(() => {
loadData() loadData()
resetForm()
}) })
</script> </script>

View File

@@ -137,8 +137,8 @@
align="center" align="center"
> >
<template #default="scope"> <template #default="scope">
<el-form-item :prop="'skuList['+scope.$index+'].sn'" :rules="rules.sku.sn"> <el-form-item :prop="'skuList['+scope.$index+'].skuSn'" :rules="rules.sku.skuSn">
<el-input v-model="scope.row.sn"/> <el-input v-model="scope.row.skuSn"/>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
@@ -153,8 +153,8 @@
<el-table-column label="库存" align="center"> <el-table-column label="库存" align="center">
<template #default="scope"> <template #default="scope">
<el-form-item :prop="'skuList['+scope.$index+'].stock'" :rules="rules.sku.stock"> <el-form-item :prop="'skuList['+scope.$index+'].stockNum'" :rules="rules.sku.stockNum">
<el-input v-model="scope.row.stock"/> <el-input v-model="scope.row.stockNum"/>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
@@ -174,16 +174,21 @@
</template> </template>
<script setup> <script setup>
import {computed, getCurrentInstance, nextTick, onMounted, reactive, ref, toRefs, unref, watch} from "vue";
import {useRouter} from "vue-router";
import {Plus, Minus} from '@element-plus/icons-vue'
import {ElNotification, ElMessage, ElTable, ElForm} from "element-plus"
// API 引用
import {listAttributes} from "@/api/pms/attribute"; import {listAttributes} from "@/api/pms/attribute";
import {addGoods, updateGoods} from "@/api/pms/goods";
// 自定义组件引用
import SvgIcon from '@/components/SvgIcon/index.vue'
import SingleUpload from '@/components/Upload/SingleUpload.vue' import SingleUpload from '@/components/Upload/SingleUpload.vue'
// import Sortable from 'sortablejs' // import Sortable from 'sortablejs'
import {addGoods, updateGoods} from "@/api/pms/goods";
import {computed, getCurrentInstance, nextTick, onMounted, reactive, ref, toRefs, unref, watch} from "vue";
import {ElNotification, ElMessage, ElTable, ElForm} from "element-plus"
import {Plus, Minus} from '@element-plus/icons-vue'
import SvgIcon from '@/components/SvgIcon/index.vue'
import {useRouter} from "vue-router";
const categoryId = computed(() => props.modelValue.categoryId);
const emit = defineEmits(['prev', 'next']) const emit = defineEmits(['prev', 'next'])
const proxy = getCurrentInstance() const proxy = getCurrentInstance()
@@ -200,7 +205,6 @@ const props = defineProps({
} }
}) })
const categoryId = computed(() => props.modelValue.categoryId);
const state = reactive({ const state = reactive({
specForm: { specForm: {
@@ -217,9 +221,9 @@ const state = reactive({
value: [{required: true, message: '请输入规格值', trigger: 'blur'}] value: [{required: true, message: '请输入规格值', trigger: 'blur'}]
}, },
sku: { sku: {
sn: [{required: true, message: '请输入商品编号', trigger: 'blur'}], skuSn: [{required: true, message: '请输入商品编号', trigger: 'blur'}],
price: [{required: true, message: '请输入商品价格', trigger: 'blur'}], price: [{required: true, message: '请输入商品价格', trigger: 'blur'}],
stock: [{required: true, message: '请输入商品库存', trigger: 'blur'}], stockNum: [{required: true, message: '请输入商品库存', trigger: 'blur'}],
} }
}, },
colors: ['', 'success', 'warning', 'danger'], colors: ['', 'success', 'warning', 'danger'],
@@ -367,7 +371,7 @@ function generateSkuList() {
skuList.forEach((item) => { skuList.forEach((item) => {
item.specIds = item.specIds.substring(0, item.specIds.length - 1) item.specIds = item.specIds.substring(0, item.specIds.length - 1)
item.name = item.specValues.substring(0, item.specIds.length - 1).replaceAll('_', ' ') item.name = item.specValues.substring(0, item.specValues.length - 1).replaceAll('_', ' ')
const specIdArr = item.specIds.split('|') const specIdArr = item.specIds.split('|')
const skus = props.modelValue.skuList.filter((sku) => const skus = props.modelValue.skuList.filter((sku) =>
sku.specIdArr.length === specIdArr.length && sku.specIdArr.length === specIdArr.length &&
@@ -378,9 +382,9 @@ function generateSkuList() {
if (skus && skus.length > 0) { if (skus && skus.length > 0) {
const sku = skus[0] const sku = skus[0]
item.id = sku.id item.id = sku.id
item.sn = sku.sn item.skuSn = sku.skuSn
item.price = sku.price / 100 item.price = sku.price / 100
item.stock = sku.stock item.stockNum = sku.stockNum
} }
const specValueArr = item.specValues.substring(0, item.specValues.length - 1).split('_') // ['黑','6+128G','官方标配'] const specValueArr = item.specValues.substring(0, item.specValues.length - 1).split('_') // ['黑','6+128G','官方标配']
specValueArr.forEach((v, i) => { specValueArr.forEach((v, i) => {
@@ -527,12 +531,9 @@ function submitForm() {
ElMessage.warning("未添加商品库存") ElMessage.warning("未添加商品库存")
return false; return false;
} }
specFormRef.value.validate((specValid) => {
const specForm = unref(specFormRef)
specForm.validate((specValid) => {
if (specValid) { if (specValid) {
const skuForm = unref(skuFormRef) skuFormRef.value.validate((skuValid) => {
skuForm.validate((skuValid) => {
if (skuValid) { if (skuValid) {
// openFullScreen() // openFullScreen()

View File

@@ -43,7 +43,7 @@
<el-table <el-table
:data="props.row.skuList" :data="props.row.skuList"
border> border>
<el-table-column align="center" label="商品编码" prop="sn"/> <el-table-column align="center" label="商品编码" prop="skuSn"/>
<el-table-column align="center" label="商品规格" prop="name"/> <el-table-column align="center" label="商品规格" prop="name"/>
<el-table-column label="图片" prop="picUrl"> <el-table-column label="图片" prop="picUrl">
<template #default="scope"> <template #default="scope">
@@ -53,21 +53,29 @@
<el-table-column align="center" label="现价" prop="price"> <el-table-column align="center" label="现价" prop="price">
<template #default="scope">{{ moneyFormatter(scope.row.price) }}</template> <template #default="scope">{{ moneyFormatter(scope.row.price) }}</template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="库存" prop="stock"/> <el-table-column align="center" label="库存" prop="stockNum"/>
</el-table> </el-table>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="商品名称" prop="name" min-width="140"/> <el-table-column label="商品名称" prop="name" min-width="140"/>
<el-table-column label="商品图片"> <el-table-column label="商品图片">
<template #default="row"> <template #default="scope">
<img :src="row.picUrl" width="40"> <el-popover
placement="right"
:width="400"
trigger="hover">
<img :src="scope.row.picUrl" width="400" height="400"/>
<template #reference>
<img :src="scope.row.picUrl" style="max-height: 60px;max-width: 60px"/>
</template>
</el-popover>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="商品类目" prop="categoryName" min-width="100"/> <el-table-column label="商品类目" prop="categoryName" min-width="100"/>
<el-table-column label="商品品牌" prop="brandName" min-width="100"/> <el-table-column label="商品品牌" prop="brandName" min-width="100"/>
<el-table-column align="center" label="零售价" prop="originalPrice"> <el-table-column align="center" label="零售价" prop="originalPrice">
<template #default="scope">{{ moneyFormatter(scope.row.price) }}</template> <template #default="scope">{{ moneyFormatter(scope.row.originPrice) }}</template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="促销价" prop="price"> <el-table-column align="center" label="促销价" prop="price">
<template #default="scope">{{ moneyFormatter(scope.row.price) }}</template> <template #default="scope">{{ moneyFormatter(scope.row.price) }}</template>