<template>
	<div>
		<div style="display: inline-block;">
			<span>状态：</span>
			<el-select v-model="status1" style="width:150px;margin-left: 10px;" @change="select()">
				<el-option v-for="item in statesnum2" :key="item.value" :label="item.label" :value="item.value">
				</el-option>
			</el-select>&nbsp;&nbsp;
			<div style="position: relative;display: inline-block;">
				<span>模板名称：</span>
				<el-input style="width: 200px;" @keydown.enter.native="select" placeholder="请输入模板名称" v-model="templateName1">
				</el-input>&nbsp;&nbsp;
			</div>
			<el-button style='margin-left:15px;' size="mini" type="primary" icon="document" @click="select">查询
			</el-button>
			<el-button style='margin-left:15px;' size="mini" type="primary" icon="document" @click="cleans">重置
			</el-button>
			<!-- <el-button style='margin:0 0 20px 20px;' v-if="isAuth('autonym:tongguo')" size="mini" type="primary"
				icon="document" @click="passClick()" :disabled="checkBoxData.length <= 0">通过</el-button> -->
		</div>
		<div style="float: right;margin-right:2%;">
			<el-button :disabled="!isAuth('duanxinmoban:add')" icon="document" size="mini" style="margin: 10px 0;"
				type="primary" @click="addNotice">添加模板</el-button>
		</div>
		<el-table v-loading="tableDataLoading" :data="duanxinData.list">
		  <el-table-column fixed prop="complaintId" label="编号" width="80">
			 <template slot-scope="scope">
					  <span>{{scope.$index+1}}</span>
				  </template>
		  </el-table-column>
		  <el-table-column prop="id" label="订单id" width="200" align="center">
		  </el-table-column>
		  <el-table-column prop="status" label="状态" width="150">
			<template slot-scope="scope">
					  <div v-if="scope.row.status=='1'">启用</div>
					  <div v-if="scope.row.status=='0'">不启用</div>
				  </template>
		  </el-table-column>
		  <el-table-column prop="templateName" label="模板名称" width="180"></el-table-column>
		  <el-table-column prop="templateContent" label="短信内容" width="180"></el-table-column>
		  <el-table-column prop="platformCode" label="第三方平台模板code" width="120" align="center">
		  </el-table-column>
		  <el-table-column prop="platformType" label="第三方平台类型" width="150">
			<template slot-scope="scope">
					  <div v-if="scope.row.platformType==1">腾讯</div>
				  </template>
		  </el-table-column>
		  <el-table-column label="操作" width="230" fixed="right">
			<template slot-scope="scope">
				<el-button :disabled="!isAuth('duanxinmoban:update')" size="mini" type="primary"
					@click="updates( scope.row)" style="margin: 5px;">修改信息
				</el-button>
				<el-button size="mini" type="danger"
					:disabled="!isAuth('duanxinmoban:delete')" @click="deletes(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="duanxinData.totalCount">
			</el-pagination>
		</div>
		<!-- 添加短信模板 -->
		<el-dialog :visible.sync="dialogFormVisible" center :title="titles">
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">模板名称：</span>
				<el-input v-model="templateName" placeholder="请输入模板名称" style="width:50%;"></el-input>
			</div>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">模板内容：</span>
				<el-input v-model="templateContent" placeholder="请输入模板内容" style="width:50%;"></el-input>
			</div>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">是否启用：</span>
				<el-radio-group v-model="status">
					<el-radio :label="'0'">不启用</el-radio>
					<el-radio :label="'1'">启用</el-radio>
				</el-radio-group>
			</div>
			<div>
				<div id="container1" style="width:80%;height:500px;margin-left: 10%;"></div>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="releasNoticeTo()">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				limit: 10,
				page: 1,
				activeName: 'first',
				tableDataLoading: false,
				dialogFormVisible: false,
				templateName:'',
				templateName1:'',
				platformType:'',
				statesnum2: [{
					label: '全部',
					value: ''
					},
					{
					label: '不启用',
					value: '0'
					},
					{
					label: '启用',
					value: '1'
					},
				],
				platformCode:'',
				status:'',
				status1:'',
				duanxinData:[],
				templateContent:'',
				titles: '添加',
				id:'',
			}
		},
		methods: {
			handleSizeChange(val) {
				this.limit = val;
				this.dataSelect()
			},
			handleCurrentChange(val) {
				this.page = val;
				this.dataSelect()
			},
			// 查询
			select() {
				this.page = 1
				this.limit = 10
				this.dataSelect()
			},
			// 重置
			cleans() {
				this.templateName1 = ''
				this.platformType = ''
				this.status1 = ''
				this.page = 1
				this.dataSelect()
			},
			//添加模板
			addNotice(){
				this.titles = '添加'
				this.platformCode='1400879272'
				this.templateName = ''
				this.platformType = '1'
				this.templateContent=''
				this.status = ''
				this.dialogFormVisible = true
			},
			// 添加模板
			releasNoticeTo() {
				if (this.templateName == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入模板名称',
						type: 'warning'
					})
					return
				}
				if (this.templateContent == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入模板内容',
						type: 'warning'
					})
					return
				}
				var datas = {}
				datas.templateName = this.templateName
				datas.templateContent=this.templateContent
				datas.platformCode = this.platformCode
				datas.platformType = this.platformType
				datas.status = this.status

				var url = 'admin/tb-indent-sms/template'
				if (this.titles == '添加') {
					var zhuang='post'

				}
				if (this.titles == '修改') {
					var zhuang='put'
					datas.id = this.id
				}
				this.$http({
					url: this.$http.adornUrl(url),
					method: zhuang,
					data: this.$http.adornData(datas)
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.dialogFormVisible = false
						this.$message({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.dataSelect()
							}
						})
					} else {
						this.$message({
							message: data.msg,
							type: 'warning',
							duration: 1500,
							onClose: () => {}
						})
					}

				})
			},
			// 修改弹框
			updates( rows) {
				console.log('修改')
				console.log(rows.status)
				this.titles = '修改'
				this.id = rows.id
				this.templateName = rows.templateName
				this.platformCode='1400879272'
				this.platformType = '1'
				this.templateContent=rows.templateContent

				if (rows.status!=null) {
					this.status = rows.status
				}else{
					this.status = '1'
				}
				this.dialogFormVisible = true

			},
			// 删除模板
			deletes(row) {
				let delid = [row.id]
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl('admin/tb-indent-sms/template'),
						method: 'delete',
						data: this.$http.adornData(delid)
					}).then(({
						data
					}) => {
						if (data.code == 0) {
							this.$message({
								message: '删除成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.dataSelect()
								}
							})
						}
					})
				}).catch(() => {})

			},
			// 获取派单数据列表
			dataSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('admin/tb-indent-sms/template'),
					method: 'get',
					params: this.$http.adornParams({
					'page': this.page,
					'limit': this.limit,
					'templateName': this.templateName1,//模板名称
					'platformType': this.platformType,//平台类型
					'status': this.status1,//状态
					})
				}).then(({
					data
				}) => {
					if (data && data.code === 0) {
					this.tableDataLoading = false
					let returnData = data.data
					this.duanxinData = returnData
					}
				})
			}
		},
		mounted() {
			this.dataSelect()
		}
	};
</script>

<style>

</style>
