<template>
	<div>
		<div style="float: right;margin-right:2%;">
			<el-button style="margin: 10px 0;" :disabled="!isAuth('serviceType:add')" size="mini" type="primary"
				icon="document" @click="advertNotice">添加</el-button>
		</div>
		<el-table v-loading="tableDataLoading" :data="guangaoData">
			<el-table-column fixed prop="id" label="编号" width="80"></el-table-column>
			<el-table-column prop="serviceName" label="名称">
			</el-table-column>
			<el-table-column label="操作" width="180">
				<template slot-scope="scope">
					<el-button size="mini" type="primary" :disabled="!isAuth('serviceType:update')"
						@click="advertUpdates(scope.row)">修改</el-button>
					<el-button size="mini" type="danger" :disabled="!isAuth('serviceType:delete')"
						@click="advertdeletes(scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!-- <div style="text-align: center;margin-top: 10px;">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page"
				layout="total,sizes, prev, pager, next,jumper" :total="guangaoData.totalCount">
			</el-pagination>
		</div> -->
		<!-- 添加素材 -->
		<el-dialog title="添加" :visible.sync="dialogFormVisible" center>

			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">名称：</span>
				<el-input style="width:50%;" v-model="serviceName" placeholder="请输入名称" type="text">
				</el-input>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="advertNoticeTo()">确 定</el-button>
			</div>
		</el-dialog>
		<!-- 修改素材 -->
		<el-dialog title="修改" :visible.sync="dialogFormVisible1" center>
			<el-form :model="form">
				<el-form-item label="名称：" :label-width="formLabelWidth">
					<el-input style="width:90%;" v-model="form.serviceName" placeholder="请输入名称" type="text"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible1 = false">取 消</el-button>
				<el-button type="primary" @click="amendadvertTo()">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		quillEditor
	} from 'vue-quill-editor'
	import 'quill/dist/quill.core.css'
	import 'quill/dist/quill.snow.css'
	import 'quill/dist/quill.bubble.css'
	import quillConfig from '../runErrands/quill-config.js'
	export default {
		components: {
			quillEditor
		},
		data() {
			return {
				page: 1,
				limit: 10,
				message: '',
				serviceName: '',
				type: 3,
				form: {
					id: '',
					serviceName: '',
				},
				formLabelWidth: '200px',
				tableDataLoading: false,
				dialogFormVisible1: false,
				dialogFormVisible: false,
				guangaoData: [],
				quillOption: quillConfig,
			}
		},
		methods: {
			handleAvatarSuccess(file) {
				this.imgUrl = file.data
				this.linkUrl = this.imgUrl
			},
			handleAvatarSuccess1(file) {
				this.form.imgUrl = file.data
				this.form.linkUrl = this.form.imgUrl
			},
			handleSizeChange(val) {
				this.limit = val
				this.guangaoSelect()
			},
			handleCurrentChange(val) {
				this.page = val
				this.guangaoSelect()
			},
			// 刷新
			refresh() {
				this.choicenSelect()
				this.handpick()
			},
			// 添加素材弹框
			advertNotice() {
				this.serviceName = ''
				this.dialogFormVisible = true
			},
			// 添加
			advertNoticeTo() {
				if (this.serviceName == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入名称',
						type: 'warning'
					})
					return
				}
				this.$http({
					url: this.$http.adornUrl(`admin/servicetype/insertServiceType`),
					method: 'post',
					data: this.$http.adornData({
						'serviceName': this.serviceName
					})
				}).then(({
					data
				}) => {
					this.dialogFormVisible = false
					this.$message({
						message: '操作成功',
						type: 'success',
						duration: 1500,
						onClose: () => {

							this.guangaoSelect()
						}
					})
				})
			},
			// 点击修改
			advertUpdates(rows) {
				this.form.id = rows.id
				this.form.serviceName = rows.serviceName
				this.dialogFormVisible1 = true
			},
			// 确定修改
			amendadvertTo() {
				if (this.form.serviceName == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入名称',
						type: 'warning'
					})
					return
				}
				this.$http({
					url: this.$http.adornUrl('admin/servicetype/updateServiceType'),
					method: 'post',
					data: this.$http.adornData({
						'id': this.form.id,
						'serviceName': this.form.serviceName,
					})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.$message({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.guangaoSelect()
								this.dialogFormVisible1 = false
							}
						})
					} else {
						this.$notify({
							title: '提示',
							duration: 1800,
							message: data.msg,
							type: 'warning'
						})
					}

				})
			},
			// 删除广告
			advertdeletes(row) {
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl(`admin/servicetype/deleteServiceType`),
						method: 'get',
						params: this.$http.adornParams({
							'id': row.id
						})
					}).then(({
						data
					}) => {
						if (data.code == 0) {
							this.$message({
								message: '删除成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.guangaoSelect()
								}
							})
						} else {
							this.$notify({
								title: '提示',
								duration: 1800,
								message: data.msg,
								type: 'warning'
							})
						}

					})
				})
			},
			// 获取素材数据
			guangaoSelect() {
				let page = this.page
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('admin/servicetype/selectServiceTypeList'),
					method: 'get',
					params: this.$http.adornParams({
						// 'page': this.page,
						// 'limit': this.limit
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data
					this.guangaoData = returnData
				})
			},
		},
		mounted() {
			this.guangaoSelect()
		}
	}
</script>

<style>
	.customWidth {
		width: 80% !important;
	}
</style>
