2024-12-02 01:49:09 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<el-form ref="resetFormData" :model="form" label-width="auto" style="width: 750px" size="large">
|
|
|
|
<el-form-item label="添加服装图片">
|
|
|
|
<el-upload
|
|
|
|
ref="uploadProductImg"
|
|
|
|
action="#"
|
|
|
|
list-type="picture-card"
|
|
|
|
:auto-upload="false"
|
|
|
|
multiple="true"
|
|
|
|
:on-remove="handleRemove"
|
|
|
|
@change="(event: any) => handleChange(event, 0)"
|
|
|
|
:on-exceed="Exceed_ProductImg"
|
|
|
|
limit="1" >
|
|
|
|
<el-icon>
|
|
|
|
<Plus />
|
|
|
|
</el-icon>
|
|
|
|
</el-upload>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="添加效果图">
|
|
|
|
<el-upload
|
|
|
|
ref="uploadProductDetail"
|
|
|
|
action="#"
|
|
|
|
list-type="picture-card"
|
|
|
|
:auto-upload="false"
|
|
|
|
multiple="true"
|
|
|
|
:on-change="(event: any) => handleChange(event, 1)"
|
|
|
|
:on-exceed="Exceed_ProductDetail"
|
|
|
|
limit="1"
|
|
|
|
:on-remove="handleRemove"
|
|
|
|
>
|
|
|
|
<el-icon>
|
|
|
|
<Plus />
|
|
|
|
</el-icon>
|
|
|
|
</el-upload>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="服装名称" prop="name">
|
2024-12-10 11:27:49 +00:00
|
|
|
<el-input v-model="form.name" maxlength="30" placeholder="30字以内"/>
|
2024-12-02 01:49:09 +00:00
|
|
|
</el-form-item>
|
2024-12-10 11:27:49 +00:00
|
|
|
<el-form-item label="服装价格(元)" prop="price">
|
2024-12-02 01:49:09 +00:00
|
|
|
<el-input v-model="form.price" />
|
|
|
|
</el-form-item>
|
2024-12-10 11:27:49 +00:00
|
|
|
<el-form-item label="服装类别" prop="clothesType">
|
|
|
|
<el-select v-model="clothesType.value" placeholder="请选择" @change="(event:any) => loadForm(event)">
|
|
|
|
<el-option v-for="item in clothesType" :key="item.value" :label="item.label" :value="item.values" />
|
|
|
|
</el-select>
|
2024-12-02 01:49:09 +00:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="服装简介" prop="intro">
|
2024-12-10 11:27:49 +00:00
|
|
|
<el-input v-model="form.intro" maxlength="40" placeholder="40字以内"/>
|
2024-12-02 01:49:09 +00:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
|
|
|
<el-button type="primary" @click="onSubmit">提交</el-button>
|
|
|
|
</el-form-item>
|
2024-12-10 11:27:49 +00:00
|
|
|
<el-form-item>
|
|
|
|
<el-button type="primary" @click="resetForm">重置</el-button>
|
|
|
|
</el-form-item>
|
2024-12-02 01:49:09 +00:00
|
|
|
</el-form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
|
|
import {Plus} from "@element-plus/icons-vue";
|
|
|
|
import {ElMessage, genFileId, type UploadProps, type UploadRawFile} from "element-plus";
|
|
|
|
import myAxios from "@/api/myAxios";
|
2024-12-10 11:27:49 +00:00
|
|
|
import {inject, ref ,onMounted} from "vue";
|
2024-12-02 01:49:09 +00:00
|
|
|
const fileSimple = ref()
|
|
|
|
const uploadProductImg : any = ref()
|
|
|
|
const uploadProductDetail : any = ref()
|
|
|
|
const form = ref({
|
|
|
|
name:'',
|
|
|
|
image:'',
|
|
|
|
effectImg:'',
|
|
|
|
intro:'',
|
|
|
|
price:'',
|
|
|
|
clothesType:''
|
|
|
|
})
|
2024-12-10 11:27:49 +00:00
|
|
|
const clothesType: any = ref([
|
|
|
|
{
|
|
|
|
values: '',
|
|
|
|
label: ''
|
|
|
|
}
|
|
|
|
])
|
|
|
|
onMounted(()=>{
|
|
|
|
getGrade()
|
|
|
|
})
|
|
|
|
const getGrade = async ()=>{
|
|
|
|
const res = await myAxios.post('/clothesGrade/list',{})
|
|
|
|
for(let i in res.data.data){
|
|
|
|
clothesType.value[i] = {
|
|
|
|
values: res.data.data[i].clothesType,
|
|
|
|
label:res.data.data[i].clothesType,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const loadForm = (value: any) => {
|
|
|
|
form.value.clothesType = value
|
|
|
|
}
|
|
|
|
const reload : any = inject("reload")
|
|
|
|
const onSubmit = async () => {
|
|
|
|
const values = Object.values(form.value);
|
|
|
|
if (values.some(value => value === null || value === undefined || value === '')) {
|
|
|
|
ElMessage({
|
|
|
|
type:'warning',
|
|
|
|
message:'请检查表单数据是否完整填写'
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const res = await myAxios.post('/clothesInfo/add', { ...form.value })
|
|
|
|
if (res.data.code === 1) {
|
|
|
|
ElMessage({
|
|
|
|
type: 'success',
|
|
|
|
message: "提交成功"
|
|
|
|
})
|
|
|
|
reload() //上传完后重置表单
|
|
|
|
} else {
|
|
|
|
ElMessage.error("服务错误")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const resetFormData = ref()
|
|
|
|
const resetForm = () =>{
|
|
|
|
resetFormData.value.resetFields()
|
|
|
|
}
|
2024-12-02 01:49:09 +00:00
|
|
|
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
|
|
|
|
console.log(uploadFile, uploadFiles)
|
|
|
|
}
|
|
|
|
const handleChange = async (file: any, flag: number) => {
|
|
|
|
fileSimple.value = file
|
|
|
|
let formData = new FormData()
|
|
|
|
formData.append("file", fileSimple.value.raw)
|
|
|
|
const res = await myAxios({
|
|
|
|
url: '/file/upload/server/not_login',
|
|
|
|
method: 'post',
|
|
|
|
headers: {
|
|
|
|
'content-Type': 'multipart/form-data'
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
biz: "test",
|
|
|
|
file: formData.get("file")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (res.data.code === 1) {
|
|
|
|
flag ? form.value.effectImg = res.data.data : form.value.image = res.data.data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const Exceed_ProductImg: UploadProps['onExceed'] = (files) => { //覆盖商品照片
|
|
|
|
uploadProductImg.value!.clearFiles()
|
|
|
|
const file = files[0] as UploadRawFile
|
|
|
|
file.uid = genFileId()
|
|
|
|
uploadProductImg.value!.handleStart(file)
|
|
|
|
}
|
|
|
|
const Exceed_ProductDetail: UploadProps['onExceed'] = (files) => { //覆盖商品详情图片
|
|
|
|
uploadProductDetail.value!.clearFiles()
|
|
|
|
const file = files[0] as UploadRawFile
|
|
|
|
file.uid = genFileId()
|
|
|
|
uploadProductDetail.value!.handleStart(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|