formatManage.vue 8.88 KB
<template>
	<div class="mallManage-wrapper">
		<el-row class="manage-head-wrapper">
			<el-col :span="18">
				<div class="manage-input-box">
					<el-input class="search-inp" v-model="name_like" placeholder="业态名称" size="mini" clearable @keyup.enter.native="searchFun"></el-input>
				</div>
				<el-button type="primary" class="search-btn" plain size="mini" @click="searchFun">{{$t('button.search')}}</el-button>
			</el-col>
			<el-col :span="6">
				<el-button type="primary" class="manage-add-btn" size="mini" @click="addDialogVisible = true" icon="el-icon-circle-plus-outline">新增业态</el-button>
			</el-col>
		</el-row>
		<el-row class="manage-content">
		  	<el-col :span="24">
				<el-table
				  :data="tableData"
					:empty-text="dataMsg"
				  style="width: 100%"
				  header-row-class-name="manage-tab-head">
					<el-table-column prop="tabOrder" align="center" label="序号">
					</el-table-column>
					<el-table-column prop="name" label="业态名称" align="center">
					</el-table-column>
					<!-- <el-table-column prop="openDate" align="center" label="父级" :formatter="dateFormatter">
					</el-table-column> -->
					<el-table-column prop="level" align="center" label="业态级别">
					</el-table-column>
					 <el-table-column prop="intro" align="center" label="描述">
					</el-table-column>
					<el-table-column label="操作" align="center">
						<template slot-scope="scope">
							<el-button @click="editRow(scope.row)" type="text" size="small" class="tab-btn">编辑</el-button>
                            <el-button @click="delRow(scope.row)" type="text" size="small" class="tab-btn">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
		 	</el-col>
		</el-row>
		<!--新增dialog-->
		<el-dialog title="新增业态" class="manage-dialog" :visible.sync="addDialogVisible" :close-on-click-modal="false" @close="addDialogClose()">
			<!-- :label-width="formLabelWidth" -->
			<el-form :model="addForm" status-icon :rules="rules" ref="addForm">
				<el-form-item label="业态名称" prop="name">
					<el-input v-model.trim="addForm.name"></el-input>
					<i class="error-tip">*</i>
				</el-form-item>
                <el-form-item label="业态级别">
                    <el-input value="一级" disabled></el-input>
                </el-form-item>
				<el-form-item label="描述">
					<el-input type="textarea" v-model.trim="addForm.intro"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="addDialogVisible = false" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
				<el-button type="primary" @click="addSubmit('addForm')" class="dialog-btn dialog-confirm-btn">{{$t('dialog.confirm')}}</el-button>
			</div>
		</el-dialog>
		<!--编辑dialog-->
		<el-dialog title="编辑业态" class="manage-dialog" :visible.sync="editDialogVisible" :close-on-click-modal="false"  @close="editDialogClose()">
			<!-- :label-width="formLabelWidth" -->
			<el-form :model="editForm" status-icon :rules="rules" ref="editForm">
				<el-form-item label="业态名称" prop="name">
					<el-input v-model="editForm.name"></el-input>
					<i class="error-tip">*</i>
				</el-form-item>
                <el-form-item label="业态级别">
                    <el-input value="一级" disabled></el-input>
                </el-form-item>
				<el-form-item label="描述">
					<el-input type="textarea" v-model="editForm.intro"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="editDialogVisible = false" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
				<el-button type="primary" @click="editSubmit('editForm')" class="dialog-btn dialog-confirm-btn">{{$t('dialog.confirm')}}</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
export default {
	data() {
		return {
			name_like: '',
			noDataText: 'load',
			blocValue: '',
			blocList: [],
			tableHeight: 0,
			addDialogVisible: false,
			editDialogVisible:false,
			tableData: [],
			addForm: {
			},
			editForm:{
			},
			rowId: '',
			mallList: [],
			rules: {
				name: [
					{ required: true, message: '请输入名称', trigger: 'blur' },
				],
			},
			accountList: [],
			dataMsg: ''
		}
	},
	mounted() {
		this.dataMsg = this.$t('echartsTitle.loading')
		this.tableHeight = $(window).height() - 200;
		this.getAccountList();
	},
	methods: {
		searchFun() {
			this.getTableData();
		},
		getTableData() {
			this.dataMsg = this.$t('echartsTitle.loading')
			let tabelParams = {
				name_like: this.name_like ? "%" + this.name_like + "%" : null,
                pid: -1,
				// _t: Date.parse(new Date()) / 1000
			}
			this.$api.base.formatlist(tabelParams)
				.then((data) => {
                    // console.log('data', data)
					let result = data.data;
					result.data.forEach((item, index) => {
						item.tabOrder = ++index;
						item.level = '一级';
					})
					this.tableData = result.data;
					this.tableData.length === 0 && (this.dataMsg = this.$t('echartsTitle.noData'))
				})
				.catch((error) => { })
		},
		//点击编辑弹框
		editRow(row) {
			// console.log('zone row:', row);
			this.editDialogVisible = true;
			this.rowId = row.id;
            let str = JSON.parse(JSON.stringify(row));
			this.editForm = str;
		},
		// 提交新增表单
		addSubmit(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
					this.addForm.createUser = this.$cookie.get('userId');
					this.addForm.modifyUser = this.$cookie.get('userId');
					this.addForm.accountId = this.$cookie.get('accountId');
					this.addForm.pid = -1;
					this.$api.management.addFormat(this.addForm)
						.then((data) => {
							this.addDialogVisible = false
							this.getTableData();
						})
						.catch((error) => { })
				} else {
					return false;
				}
			});
		},
		editSubmit(formName){
			this.$refs[formName].validate((valid) => {
				if (valid) {
					// this.editForm.createUser = this.$cookie.get('userId');
					// this.addForm.modifyUser = this.$cookie.get('userId');
					// this.addForm.accountId = this.$cookie.get('accountId');
					this.$api.management.editFormat(this.rowId, this.editForm)
						.then((data) => {
                            if(data.data.code == 200) {
                                this.editDialogVisible = false;
							    this.getTableData();
                            } else {
                                this.$message({
									showClose: true,
                                    type: 'warning',
                                    message: '修改异常!' + data.data.msg
                                });
                            }
						})
						.catch((error) => { })
				} else {
					return false;
				}
			});
		},
		// 删除表格数据 
		delRow(index, rows) {
            // console.log(rows)
			this.$confirm(this.$t('message.confirDelete'), this.$t('message.prompt'), {
				confirmButtonText: this.$t('message.confirm'),
				cancelButtonText: this.$t('message.cancel'),
				type: 'warning'
			}).then(() => {
				this.$api.management.delFormat(rows.id, {})
					.then((res) => {
                        if(res.data.code == 200) {
                            this.$message({
								showClose: true,
                                type: 'success',
                                message: this.$t('message.node') + this.$t('message.deleteSuccess')
                            })
                            this.tableData.splice(index, 1);
                        } else {
                            this.$message({
								showClose: true,
                                type: 'error',
                                message: this.$t('message.node') + this.$t('message.deleteFailed') + res.data.msg
                            })
                        }
					})
					.catch((error) => { })
			}).catch(() => {
				this.$message({
					showClose: true,
					type: 'info',
					message: this.$t('message.cancelDelete')
				});
			});
		},
		// addDialog关闭时
		addDialogClose() {
			this.addForm.intro = '';
			this.$refs.addForm.resetFields();
		},
		// 编辑dialog关闭时
		editDialogClose() {
			this.$refs.editForm.resetFields();
		},
		getAccountList() {
			// this.$api.base.account({
			// 		// _t: Date.parse(new Date()) / 1000
			// })
			// 	.then((data) => {
			// 		var result = data.data;
			// 		this.accountList = result.data;

			// 		this.blocValue = '';
			// 		this.blocList = result.data;
			// 		this.blocList.forEach((item, index, arr) => {
			// 			if (index == 0) {
			// 				this.blocValue = item.id
			// 			}
			// 		})
			// 		this.getTableData();
			// 	})
			// 	.catch((error) => { })
			this.blocValue = this.$cookie.get('accountId');
			this.getTableData();
		},
	}
}
</script>

<style scoped>
@import url(../public/css/common.css);
.mallManage-wrapper {
	width: 100%;
	font-size: 14px;
}
.manage-input-box .el-input{
	width: 200px;
}
/* .gate-col-left {
	min-width: 150px;
}

.gate-col-middle {
	min-width: 77px; 
}

.gate-col-right {
	min-width: 130px;
} */
</style>