半成品-产品管理页

This commit is contained in:
祝梦园 2024-02-27 16:51:34 +08:00
parent 7534e7c90b
commit 0faa495d95
2 changed files with 157 additions and 82 deletions

View File

@ -62,7 +62,7 @@ import {mapState} from 'vuex';
import apiConfig from '~/config/api.config'; import apiConfig from '~/config/api.config';
export default { export default {
name: "PostArticle", name: "PostProducts",
middleware: 'auth', middleware: 'auth',
validate({params, store}) { validate({params, store}) {
if (typeof params.product_id === 'undefined') { if (typeof params.product_id === 'undefined') {
@ -379,6 +379,7 @@ export default {
window.onbeforeunload = null; window.onbeforeunload = null;
}, },
async mounted() { async mounted() {
console.log('??')
if (!this.hasPermissions) { if (!this.hasPermissions) {
return return
} }

View File

@ -1,83 +1,125 @@
<template> <template>
<el-row style="margin-top: 20px;"> <div>
<el-col style="margin-bottom: 1rem;"> <el-row style="margin-top: 20px;">
<el-breadcrumb separator-class="el-icon-arrow-right"> <el-col style="margin-bottom: 1rem;">
<el-breadcrumb-item :to="{ path: '/admin/dashboard' }">首页</el-breadcrumb-item> <el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item>产品管理</el-breadcrumb-item> <el-breadcrumb-item :to="{ path: '/admin/dashboard' }">首页</el-breadcrumb-item>
</el-breadcrumb> <el-breadcrumb-item>产品管理</el-breadcrumb-item>
</el-col> </el-breadcrumb>
<el-col> </el-col>
<el-table <el-col>
:data="products.list" <el-table
style="width: 100%"> :data="products.list"
<el-table-column style="width: 100%">
label="#" <el-table-column
width="40" label="#"
prop="idProduct"> width="40"
</el-table-column> prop="idProduct">
<el-table-column </el-table-column>
label="主图" <el-table-column
width="60" label="主图"
prop="productImgUrl"> width="60"
<template slot-scope="scope"> prop="productImgUrl">
<el-avatar size="medium" :src="scope.row.productImgUrl"></el-avatar> <template slot-scope="scope">
</template> <el-avatar size="medium" :src="scope.row.productImgUrl"></el-avatar>
</el-table-column> </template>
<el-table-column </el-table-column>
label="商品名称" <el-table-column
width="140" label="商品名称"
prop="productTitle"> width="140"
<template slot-scope="scope"> prop="productTitle">
<el-link type="primary" :href="'/product/' + scope.row.idProduct" :underline="false"> <template slot-scope="scope">
{{ scope.row.productTitle }} <el-link type="primary" :href="'/product/' + scope.row.idProduct" :underline="false">
</el-link> {{ scope.row.productTitle }}
</template> </el-link>
</el-table-column> </template>
<el-table-column </el-table-column>
label="创建时间" <el-table-column
width="180" label="创建时间"
prop="createdTime"> width="180"
</el-table-column> prop="createdTime">
<el-table-column </el-table-column>
label="状态" <el-table-column
width="180" label="状态"
prop="status"> width="180"
<template slot-scope="scope"> prop="status">
<el-tag type="primary" disable-transitions> <template slot-scope="scope">
{{ scope.row.status === '0' ? '正常' : '禁用' }} <el-tag type="primary" disable-transitions>
</el-tag> {{ scope.row.status === '0' ? '正常' : '禁用' }}
</template> </el-tag>
</el-table-column> </template>
<el-table-column label="操作"> </el-table-column>
<template slot-scope="scope"> <el-table-column label="操作">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)" plain>编辑</el-button> <template slot-scope="scope">
<el-button v-if="scope.row.status == 1" size="mini" type="primary" <el-button size="mini" @click="handleEdit(scope.$index, scope.row)" plain>编辑</el-button>
@click="toggleStatus(scope.$index, scope.row)" plain>上架 <el-button v-if="scope.row.status == 1" size="mini" type="primary"
</el-button> @click="toggleStatus(scope.$index, scope.row)" plain>上架
<el-button v-else size="mini" type="danger" @click="toggleStatus(scope.$index, scope.row)" plain>下架 </el-button>
</el-button> <el-button v-else size="mini" type="danger" @click="toggleStatus(scope.$index, scope.row)" plain>下架
</template> </el-button>
</el-table-column> </template>
</el-table> </el-table-column>
</el-col> </el-table>
<el-col> </el-col>
<el-pagination <el-col>
:hide-on-single-page="true" <el-pagination
@size-change="handleSizeChange" :hide-on-single-page="true"
@current-change="handleCurrentChange" @size-change="handleSizeChange"
:current-page="products.pageNum" @current-change="handleCurrentChange"
:page-sizes="[10, 20, 50, 100]" :current-page="products.pageNum"
:page-size="products.pageSize" :page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper" :page-size="products.pageSize"
:total="products.total"> layout="total, sizes, prev, pager, next, jumper"
</el-pagination> :total="products.total">
</el-col> </el-pagination>
</el-row> </el-col>
</el-row>
<el-dialog :title="`物流公司-${isEdit?'修改':'新增'}项目`" :visible.sync='editVisible'
center width='880px'>
<el-form ref='formStore' :model='formStore' :rules='rules' label-poionsit='right' label-width='110px'>
<div style="margin-bottom:20px">
<img @click="cropperVisible=true" :src="formStore.productImgUrl"
style="width: 120px;height: 120px;margin: 0 auto;display: block">
</div>
<el-form-item label='产品名称' prop='productTitle'>
<el-input v-model='formStore.productTitle' placeholder='请输入产品名称'/>
</el-form-item>
<el-form-item label='产品价格' prop='code'>
<el-input v-model='formStore.productPrice' placeholder='请输入产品价格'/>
</el-form-item>
<el-form-item label='产品描述' prop='type'>
<el-input v-model='formStore.productDescription' placeholder='请输入产品描述'/>
</el-form-item>
<el-form-item label='tags' prop='order'>
<el-input v-model='formStore.tags' placeholder='请输入tags'/>
</el-form-item>
</el-form>
<span slot='footer' class='dialog-footer'>
<el-button @click='cropperVisible = false'> </el-button>
<el-button type='primary' @click='handelStore'> </el-button>
</span>
</el-dialog>
<ImgCropper append-to-body @onSubmit="updateUser" :visible.sync='cropperVisible'
:avatarUrl="formStore.productImgUrl||''"></ImgCropper>
</div>
</template> </template>
<script> <script>
import {mapState} from 'vuex'; import ImgCropper from "~/components/ImgCropper.vue";
import {mapState} from 'vuex';
import VueCropper from "vue-cropper";
const rules = {
productTitle: [
{required: true, message: '请输入公司名称', trigger: 'blur'},
{min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'}
],
productDescription: [{required: true, message: '请输入产品描述', trigger: 'blur'}]
}
export default { export default {
name: "products", name: "products",
middleware: 'auth', middleware: 'auth',
@ -96,9 +138,17 @@ export default {
}, },
data() { data() {
return { return {
order: 'desc' order: 'desc',
editVisible: false,
formStore: {},
rules: rules,
cropperVisible: false,
isEdit: false
} }
}, },
components: {
ImgCropper, VueCropper
},
methods: { methods: {
onRouter(name, data) { onRouter(name, data) {
this.$router.push({ this.$router.push({
@ -155,11 +205,35 @@ export default {
rows: _ts.products.pageSize rows: _ts.products.pageSize
}) })
}, },
handleEdit(index ,row) { handleEdit(index, row) {
this.$router.push({ this.formStore = row
path: `/admin/product/post/${row.idProduct}` this.editVisible = true
}) // this.$router.push({
} // path: `/admin/product/post/${row.idProduct}`
// })
},
handelStore() {
//
},
updateUser(data) {
//
let _ts = this;
if (data) {
// let user = _ts.user;
this.formStore.productImgUrl = data
// user.avatarType = 1
_ts.$axios[this.formStore.idProduct ? '$put' : '$post']('/api/product/post', this.formStore).then(function (res) {
if (res) {
console.log('res')
// _ts.$router.push({
// path: `/product/${res}`
// })
}
})
} else _ts.$message.error('失败,请重试');
},
} }
} }
</script> </script>