|
|
@@ -0,0 +1,127 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <div class="action-container">
|
|
|
+ <div class="action">
|
|
|
+ <el-button icon="el-icon-plus" size="small" @click="add">添加</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <el-table :data="tableData">
|
|
|
+ <el-table-column prop="name" label="名称"></el-table-column>
|
|
|
+ <el-table-column prop="pic" label="图片">
|
|
|
+ <template slot-scope="{ row }">
|
|
|
+ <el-image
|
|
|
+ style="width: 100px; height: 80px"
|
|
|
+ fit="cover"
|
|
|
+ :src="row.pic"
|
|
|
+ :preview-src-list="[row.pic]"
|
|
|
+ ></el-image>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" fixed="right" width="200" align="center">
|
|
|
+ <template slot-scope="{ row }">
|
|
|
+ <el-button size="mini" type="primary" @click="edit(row)">编辑</el-button>
|
|
|
+ <el-button size="mini" type="danger" @click="del(row)">删除</el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+
|
|
|
+ <el-dialog :visible.sync="showDialog" title="编辑Banner">
|
|
|
+ <el-form :model="formData" ref="form" label-width="80px" size="small">
|
|
|
+ <el-form-item prop="name" label="名称">
|
|
|
+ <el-input v-model="formData.name"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="pic" label="图片">
|
|
|
+ <single-upload v-model="formData.pic"></single-upload>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <span slot="footer" class="dialog-footer">
|
|
|
+ <el-button @click="showDialog = false" size="small">取消</el-button>
|
|
|
+ <el-button type="primary" :loading="loading" @click="save" size="small">保存</el-button>
|
|
|
+ </span>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ tableData: [],
|
|
|
+ formData: {},
|
|
|
+ showDialog: false,
|
|
|
+ loading: false,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getData();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getData() {
|
|
|
+ this.$http
|
|
|
+ .get('/shopBanner/all')
|
|
|
+ .then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ this.tableData = res.data;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ edit(row) {
|
|
|
+ this.formData = { ...row };
|
|
|
+ this.showDialog = true;
|
|
|
+ },
|
|
|
+ add() {
|
|
|
+ this.formData = {};
|
|
|
+ this.showDialog = true;
|
|
|
+ },
|
|
|
+ save() {
|
|
|
+ this.$refs.form.validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ this.loading = true;
|
|
|
+ this.$http
|
|
|
+ .post('/shopBanner/save', this.formData)
|
|
|
+ .then(res => {
|
|
|
+ this.loading = false;
|
|
|
+ this.showDialog = false;
|
|
|
+ if (res.success) {
|
|
|
+ this.$message.success('保存成功');
|
|
|
+ this.getData();
|
|
|
+ } else {
|
|
|
+ this.$message.error(res.error);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ this.loading = false;
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ del(row) {
|
|
|
+ this.$confirm('此操作不可恢复, 是否继续删除?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ return this.$axios.delete(`/shopBanner/${row.id}`);
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ this.$message.success('删除成功');
|
|
|
+ this.getData();
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+</style>
|