第一次提交

This commit is contained in:
wangxulei
2024-12-06 22:42:03 +08:00
commit 2e054b0966
535 changed files with 49684 additions and 0 deletions

View File

@@ -0,0 +1,242 @@
<template>
<div>
<el-dialog
:close-on-click-modal="false"
top="3vh"
height="80%"
width="40%"
:visible.sync="dialogVisible"
center
@close="handleCancel"
>
<div class="el-dialog-div">
<el-form
:rules="rules"
ref="dataForm"
:model="temp"
label-position="right"
label-width="120px"
style="height: 90%;"
>
<el-form-item label="分类" prop="categoryId" class="is-required">
<category-select v-model="temp.categoryId" @changeSelect="getCategory"/>
</el-form-item>
<el-form-item label="商品名" prop="productName" class="is-required">
<el-input v-model="temp.productName" placeholder="商品名" />
</el-form-item>
<el-form-item label="商品金额" prop="productAmount" class="is-required">
<el-input v-model="temp.productAmount" placeholder="商品金额" />
</el-form-item>
<el-form-item label="商品会员金额" prop="productMemberAmount" class="is-required">
<el-input v-model="temp.productMemberAmount" placeholder="商品会员金额" />
</el-form-item>
<el-form-item label="商品图片" prop="productImage" class="is-required">
<el-upload
class="avatar-uploader"
:action="''"
:show-file-list="false"
:before-upload="beforeAvatarUpload"
>
<img v-if="imageUrl" :src="imageUrl" class="avatar" style="width: 140px;height: 140px;">
<div style="width: 140px;height: 140px;display: flex;justify-content: center;align-items: center;border: 1px solid #eee;" v-else>
<i class="el-icon-plus avatar-uploader-icon" ></i>
</div>
</el-upload>
<x-cropper ref="iscropper"/>
</el-form-item>
<el-form-item label="库存管理" prop="stockControl" class="is-required">
<el-radio-group v-model="temp.stockControl" size="small">
<el-radio-button label="0">关闭</el-radio-button>
<el-radio-button label="1">开启</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-if="temp.stockControl==1" label="初始化库存数量" prop="productCount" class="is-required">
<el-input v-model="temp.productCount" placeholder="初始化库存数量" />
</el-form-item>
<el-form-item label="提成方式" prop="pushType" class="is-required">
<el-radio-group v-model="temp.pushType" size="small">
<el-radio-button label="0">固定金额</el-radio-button>
<el-radio-button label="1">比例</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="提成金额" v-if="temp.pushType==0" prop="pushAmount" class="is-required">
<el-input v-model="temp.pushAmount" placeholder="提成金额" />
</el-form-item>
<el-form-item label="提成比例" v-if="temp.pushType==1" prop="pushPercent" class="is-required">
<el-input v-model="temp.pushPercent" placeholder="提成比例" />
</el-form-item>
<el-form-item label="状态" prop="productStatus" class="is-required">
<el-radio-group v-model="temp.productStatus" size="small">
<el-radio-button label="0">正常</el-radio-button>
<el-radio-button label="1">禁用</el-radio-button>
</el-radio-group>
</el-form-item>
<!-- <el-form-item label="所属门店" prop="shopId" class="is-required">-->
<!-- <dept-select v-model="temp.shopId" @changeSelect="getDept" style="width: 100%;"/>-->
<!-- </el-form-item>-->
</el-form>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="handleCancel"> </el-button>
<el-button type="primary" @click="submit"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import request from '@/utils/request'
import {addProduct} from "@/api/business/product/product";
import {setRequiredFields} from "@/utils";
import CategorySelect from "@/views/common/business/categorySelect";
import XCropper from "@/views/common/XCropper";
import DeptSelect from "@/views/common/system/deptSelect";
const requiredFields = []
export default {
name: "addForm",
components: {DeptSelect, XCropper, CategorySelect},
data() {
return {
rules: setRequiredFields(requiredFields),
dialogVisible: false,
temp: {
productId:'',
categoryId:'',
categoryName:'',
productName:'',
productAmount:'',
productMemberAmount:'',
productImage:'',
productCount:'',
pushAmount:'',
pushPercent:'',
stockControl:0,
productStatus:0,
shopId:'',
shopName:'',
},
imageUrl: ''
}
},
methods: {
open(categoryId) {
this.dialogVisible = true
this.temp.categoryId = categoryId
},
beforeAvatarUpload(file){
console.log("进入了文件上传")
let _this = this
return new Promise((resolve, reject) => {
let types = ['image/jpeg', 'image/jpg', 'image/png'];
// let width = 140;
// let height = 140;
const isJPG = types.includes(file.type)
const isLt2M = file.size / 1024 / 1024 < 10
if (!isJPG) {
_this.$message.error('上传图片只能是 JPG 或 png格式!')
reject()
return
}
if (!isLt2M) {
_this.$message.error('上传图片大小不能超过 10MB!')
reject()
return
}
let _URL = window.URL || window.webkitURL;
console.log( _this.$refs.iscropper)
//上传前对图片进行裁剪
_this.$refs.iscropper.showModal({
img: _URL.createObjectURL(file) , // 裁剪图片的地址
autoCropWidth: 140, // 默认生成截图框宽度
autoCropHeight: 140, // 默认生成截图框高度
fixedBox:true,
success: res => {
//拿到裁剪后图片没有name 属性
//file的name属性为只读 不能手动设置
//创建一个新的图片对象 设置原始文件名
const cloneFile = new File([res.img], file.name);
const formData = new FormData()
// console.log(param.file)
//通过 append 函数往formdata对象里传参这里传的是后端需求的接口信息
formData.append('file', cloneFile)
formData.append('fileSavePath', "productImage")
//执行上传操作
request({
method: "post",
url: "/upload",
data: formData,
headers: { "Content-Type": "multipart/form-data" },
}).then(response => {
//请求成功
_this.handleAvatarSuccess(response,cloneFile)
})
resolve()
}
})
})
},
handleAvatarSuccess(res,file) {
if(res.code == 200){
this.imageUrl = URL.createObjectURL(file);
this.temp.productImage = res.data.fileId
}else{
this.imageUrl = '';
this.temp.productImg = ''
}
},
submit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
addProduct(this.temp).then(response =>{
this.handleCancel()
this.$emit('ok', response.data)
})
} else {
console.log('error submit!!');
return false;
}
});
},
handleCancel() {
//初始化
this.imageUrl = '';
this.temp = this.$options.data().temp
this.dialogVisible = false
this.$refs['dataForm'].resetFields();
},
getCategory(e){
console.log(e)
this.temp.categoryName = e.categoryName
},
getDept(e){
this.temp.shopName = e.deptName
}
},
}
</script>
<style scoped>
</style>

View File

@@ -0,0 +1,243 @@
<template>
<div>
<el-dialog
:close-on-click-modal="false"
top="3vh"
height="80%"
width="40%"
:visible.sync="dialogVisible"
center
@close="handleCancel"
>
<div class="el-dialog-div">
<el-form
:rules="rules"
ref="dataForm"
:model="temp"
label-position="right"
label-width="120px"
style="height: 90%;"
>
<el-form-item label="分类" prop="categoryId" class="is-required">
<category-select v-model="temp.categoryId" @changeSelect="getCategory"/>
</el-form-item>
<el-form-item label="商品名" prop="productName" class="is-required">
<el-input v-model="temp.productName" placeholder="商品名" />
</el-form-item>
<el-form-item label="商品金额" prop="productAmount" class="is-required">
<el-input v-model="temp.productAmount" placeholder="商品金额" />
</el-form-item>
<el-form-item label="商品会员金额" prop="productMemberAmount" class="is-required">
<el-input v-model="temp.productMemberAmount" placeholder="商品会员金额" />
</el-form-item>
<el-form-item label="商品图片" prop="productImage" class="is-required">
<el-upload
class="avatar-uploader"
:action="''"
:show-file-list="false"
:before-upload="beforeAvatarUpload"
>
<img v-if="imageUrl" :src="imageUrl" class="avatar" style="width: 140px;height: 140px;">
<div style="width: 140px;height: 140px;display: flex;justify-content: center;align-items: center;border: 1px solid #eee;" v-else>
<i class="el-icon-plus avatar-uploader-icon" ></i>
</div>
</el-upload>
<x-cropper ref="iscropper"/>
</el-form-item>
<el-form-item label="库存管理" prop="stockControl" class="is-required">
<el-radio-group v-model="temp.stockControl" size="small">
<el-radio-button label="0">关闭</el-radio-button>
<el-radio-button label="1">开启</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-if="temp.stockControl==1" label="库存数量" prop="productCount" class="is-required">
<el-input v-model="temp.productCount" readonly placeholder="库存数量" />
</el-form-item>
<el-form-item label="提成方式" prop="pushType" class="is-required">
<el-radio-group v-model="temp.pushType" size="small">
<el-radio-button label="0">固定金额</el-radio-button>
<el-radio-button label="1">比例</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="提成金额" v-if="temp.pushType==0" prop="pushAmount" class="is-required">
<el-input v-model="temp.pushAmount" placeholder="提成金额" />
</el-form-item>
<el-form-item label="提成比例" v-if="temp.pushType==1" prop="pushPercent" class="is-required">
<el-input v-model="temp.pushPercent" placeholder="提成比例" />
</el-form-item>
<el-form-item label="状态" prop="productStatus" class="is-required">
<el-radio-group v-model="temp.productStatus" size="small">
<el-radio-button label="0">正常</el-radio-button>
<el-radio-button label="1">禁用</el-radio-button>
</el-radio-group>
</el-form-item>
<!-- <el-form-item label="所属门店" prop="shopId" class="is-required">-->
<!-- <dept-select v-model="temp.shopId" @changeSelect="getDept" style="width: 100%;"/>-->
<!-- </el-form-item>-->
</el-form>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="handleCancel"> </el-button>
<el-button type="primary" @click="submit"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import request from '@/utils/request'
import { editProduct } from "@/api/business/product/product";
import {setRequiredFields} from "@/utils";
import CategorySelect from "@/views/common/business/categorySelect";
import XCropper from "@/views/common/XCropper";
import DeptSelect from "@/views/common/system/deptSelect";
const requiredFields = []
export default {
name: "editForm",
components: {DeptSelect, XCropper, CategorySelect},
data() {
return {
rules: setRequiredFields(requiredFields),
dialogVisible: false,
temp: {
productId:'',
categoryId:'',
categoryName:'',
productName:'',
productAmount:'',
productMemberAmount:'',
productImage:'',
productCount:'',
pushAmount:'',
pushPercent:'',
productStatus:0,
shopId:'',
shopName:'',
pushType:0
},
imageUrl:''
}
},
methods: {
open(row) {
this.temp = this.$options.data().temp
this.temp = row
if(this.temp.productImageUrl){
this.imageUrl = this.baseUrl + this.temp.productImageUrl
}
this.dialogVisible = true
},
beforeAvatarUpload(file){
console.log("进入了文件上传")
let _this = this
return new Promise((resolve, reject) => {
let types = ['image/jpeg', 'image/jpg', 'image/png'];
// let width = 140;
// let height = 140;
const isJPG = types.includes(file.type)
const isLt2M = file.size / 1024 / 1024 < 2
if (!isJPG) {
_this.$message.error('上传图片只能是 JPG 或 png格式!')
reject()
}
if (!isLt2M) {
_this.$message.error('上传图片大小不能超过 2MB!')
reject()
}
let _URL = window.URL || window.webkitURL;
console.log( _this.$refs.iscropper)
//上传前对图片进行裁剪
_this.$refs.iscropper.showModal({
img: _URL.createObjectURL(file) , // 裁剪图片的地址
autoCropWidth: 140, // 默认生成截图框宽度
autoCropHeight: 140, // 默认生成截图框高度
fixedBox:true,
success: res => {
//拿到裁剪后图片没有name 属性
//file的name属性为只读 不能手动设置
//创建一个新的图片对象 设置原始文件名
const cloneFile = new File([res.img], file.name);
const formData = new FormData()
// console.log(param.file)
//通过 append 函数往formdata对象里传参这里传的是后端需求的接口信息
formData.append('file', cloneFile)
formData.append('fileSavePath', "productImage")
//执行上传操作
request({
method: "post",
url: "/upload",
data: formData,
headers: { "Content-Type": "multipart/form-data" },
}).then(response => {
//请求成功
_this.handleAvatarSuccess(response,cloneFile)
})
resolve()
}
})
})
},
handleAvatarSuccess(res,file) {
if(res.code == 200){
this.imageUrl = URL.createObjectURL(file);
this.temp.productImage = res.data.fileId
}else{
this.imageUrl = '';
this.temp.productImg = ''
}
},
submit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
editProduct(this.temp).then(response => {
this.handleCancel()
this.$emit('ok', response.data)
})
} else {
console.log('error submit!!');
return false;
}
});
},
handleCancel() {
//初始化
this.temp = this.$options.data().temp
this.dialogVisible = false
this.$refs['dataForm'].resetFields()
},
getCategory(e){
console.log(e)
this.temp.categoryName = e.categoryName
},
getDept(e){
this.temp.shopName = e.deptName
}
},
}
</script>
<style scoped>
</style>

View File

@@ -0,0 +1,360 @@
<template>
<div class="app-container">
<div class="filter-container">
<el-input
v-model="listQuery.keyword"
size="small"
placeholder="请输入关键词"
clearable
class="filter-item"
style="width: 200px;margin-left: 10px;"
/>
<el-button-group style="margin-left: 10px;">
<el-button
size="small"
class="filter-item"
type="primary"
icon="el-icon-search"
@click="search"
>
搜索
</el-button>
<el-button
size="small"
class="filter-item"
type="primary"
icon="el-icon-refresh"
@click="refresh"
>
重置
</el-button>
</el-button-group>
<el-button
size="small"
class="filter-item"
type="primary"
icon="el-icon-plus"
style="margin-left: 10px;"
@click="add"
>
新增
</el-button>
</div>
<el-row :gutter="24" class="row-container">
<el-col :span="4" style="height: 100%;">
<el-tree
default-expand-all
:data="categoryList"
node-key="categoryId"
:props="defaultProps"
@node-click="handleNodeClick"
>
<span class="custom-tree-node" slot-scope="{ node, data }">
<span :class="listQuery.categoryId==data.categoryId?'info-text':''" > {{ node.label }}</span>
</span>
</el-tree>
</el-col>
<el-col :span="20" style="height: 100%;">
<el-table
v-loading="listLoading"
:data="list"
element-loading-text="Loading"
border
fit
height="100%"
class="table-container"
highlight-current-row
>
<el-table-column
label="序号"
width="150"
align="center"
>
<template slot-scope="scope">
{{ scope.$index+1 }}
</template>
</el-table-column>
<el-table-column
label="分类名"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.categoryName }}
</template>
</el-table-column>
<el-table-column
label="商品名"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.productName }}
</template>
</el-table-column>
<el-table-column
label="商品金额"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.productAmount }}
</template>
</el-table-column>
<el-table-column
label="商品会员金额"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.productMemberAmount }}
</template>
</el-table-column>
<el-table-column
label="商品图片"
width="160"
align="center"
>
<template slot-scope="scope">
<img v-if="scope.row.productImage" :src=" baseUrl + scope.row.productImageUrl" class="avatar" style="width: 40px;height: 40px;">
</template>
</el-table-column>
<el-table-column
label="库存数量"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.productCount }}
</template>
</el-table-column>
<el-table-column
label="提成金额"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.pushAmount }}
</template>
</el-table-column>
<el-table-column
label="提成比例"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.pushPercent }}
</template>
</el-table-column>
<el-table-column
label="0正常 1下架"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.productStatus }}
</template>
</el-table-column>
<el-table-column
label="门店名"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.shopName }}
</template>
</el-table-column>
<el-table-column
label="创建人"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.createName }}
</template>
</el-table-column>
<el-table-column
label="创建时间"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.createTime }}
</template>
</el-table-column>
<el-table-column
label="修改人"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.updateName }}
</template>
</el-table-column>
<el-table-column
label="修改时间"
width="160"
align="center"
>
<template slot-scope="scope">
{{ scope.row.updateTime }}
</template>
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="200"
align="center"
>
<template slot-scope="scope">
<el-button-group>
<el-button
type="primary"
icon="el-icon-edit"
size="mini"
@click="edit(scope)"
>
修改
</el-button>
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
@click="del(scope)"
v-hasPerms="'product:del'"
>
删除
</el-button>
</el-button-group>
</template>
</el-table-column>
</el-table>
<pagination
:total="total"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="fetchData"
/>
</el-col>
</el-row>
<add-form ref="addForm" @ok="addOk" />
<edit-form ref="editForm" @ok="editOk" />
</div>
</template>
<script>
import {getCategoryList} from "@/api/business/category/category";
import {getProductPage,deleteProduct} from "@/api/business/product/product";
import {deepClone,success} from "@/utils";
import confirm from "@/utils/confirm";
import Pagination from '@/components/Pagination'
import addForm from "@/views/business/product/addProduct";
import editForm from "@/views/business/product/editProduct";
export default {
name: 'product',
components: {addForm,editForm,Pagination},
data() {
return {
total: 0,
list: [],
listLoading: true,
listQuery: {
page: 1,
limit: 50,
categoryId: '',
keyword: ''
},
defaultProps: {
id: 'categoryId',
label: 'categoryName',
},
temp: {},
categoryList: []
}
},
created() {
this.fetchData()
this.getCategoryList()
},
methods: {
getCategoryList(){
getCategoryList().then(res => {
this.categoryList = res.data
})
},
handleNodeClick(e){
this.listQuery.categoryId = e.categoryId
this.fetchData()
},
search() {
this.fetchData()
},
refresh() {
this.listQuery = this.$options.data().listQuery
this.fetchData()
},
fetchData() {
this.listLoading = true
getProductPage(this.listQuery).then(response => {
const { records, total } = response.data
this.list = records
this.total = total
this.listLoading = false
})
},
add(){
this.$refs.addForm.open(this.listQuery.categoryId)
},
addOk(){
this.fetchData()
},
edit(scope) {
const temp = deepClone(scope.row)
this.$refs.editForm.open(temp)
},
editOk(){
this.fetchData()
},
del(scope) {
confirm("确定要删除吗?").then(res=>{
if(res){
deleteProduct(scope.row.productId).then(response => {
console.log(response)
success('删除成功')
this.fetchData()
})
}
})
},
}
}
</script>
<style scoped>
</style>