<template>
	<div>
		<el-tabs v-model="activeName" @tab-click="handleClick">
			<el-tab-pane label="评价列表" name="first">

				<div style="margin:6px 0;display: inline-block;">
					<span>用户昵称：</span>
					<el-input style="width: 150px;" @keydown.enter.native="select" clearable placeholder="请输入用户昵称"
						v-model="userName"></el-input>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="margin:6px 0;display: inline-block;">
					<span>手机号：</span>
					<el-input style="width: 150px;" @keydown.enter.native="select" clearable placeholder="请输入手机号"
						v-model="phone"></el-input>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="margin:6px 0;display: inline-block;">
					<span>评价内容/关键字：</span>
					<el-input style="width: 200px;" @keydown.enter.native="select" clearable placeholder="请输入评价内容/关键字"
						v-model="content"></el-input>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="display: inline-block;">
					<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-left:15px;' size="mini" type="primary" icon="document" @click="refresh">刷新
					</el-button>
					<el-button style='margin-left:15px;' size="mini" type="primary" icon="document" @click="handleAdd">新增
					</el-button>
				</div>
				<el-table v-loading="tableDataLoading" :data="tableData.list">
					<el-table-column prop="id" label="编号" width="80">
					</el-table-column>
					<el-table-column prop="userName" label="评论用户" width="150">
						<template slot-scope="scope">
							<span style="color: #4f9dec;cursor: pointer;"
								@click="updates(scope.row.userId)">{{scope.row.userName ? scope.row.userName : '未绑定'}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="avatar" label="头像">
						<template slot-scope="scope">
							<img :src="scope.row.avatar" alt="" width="60" height="60">
						</template>
					</el-table-column>
					<el-table-column prop="artificerName" label="被评论师傅" width="100">
						<template slot-scope="scope">
							<span style="color: #4f9dec;cursor: pointer;"
								@click="updates(scope.row.artificerUserId)">{{scope.row.artificerName ? scope.row.artificerName : '未绑定'}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="title" label="项目">
					</el-table-column>
					<el-table-column prop="content" label="评价内容">
					</el-table-column>
					<!-- <el-table-column label="评价图片" width="150">
				<template slot-scope="scope">
					<div v-if="scope.row.img == null || scope.row.img == ''">
						暂无图片
					</div>
					<div v-else-if="scope.row.img.includes(',')" style="display:flex;flex-wrap: wrap;">
						<div v-for="item in scope.row.img.split(',')" style="margin: 2px;">
							<el-popover placement="top-start" title="" trigger="hover">
								<img style="width: 50px; height: 50px" :src="item" alt="" slot="reference">
								<img style="width: 200px; height: 200px" :src="item" alt="">
							</el-popover>
						</div>
					</div>
					<div v-else>
						<el-popover placement="top-start" title="" trigger="hover">
							<img style="width: 50px; height: 50px" :src="scope.row.img" alt="" slot="reference">
							<img style="width: 200px; height: 200px" :src="scope.row.img" alt="">
						</el-popover>
					</div>
				</template>
			</el-table-column> -->
					<el-table-column prop="score" label="评分">
						<template slot-scope="scope">
							<span>{{scope.row.score?scope.row.score:'暂无评分'}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间" width="180">
					</el-table-column>
					<el-table-column fixed="right" label="操作" width="150">
						<template slot-scope="scope">
							<el-button size="mini" type="danger" :disabled="!isAuth('comment: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, 50, 100]" :page-size="size" :current-page="page"
						layout="total,sizes, prev, pager, next" :total="tableData.totalCount">
					</el-pagination>
				</div>
			</el-tab-pane>

			<!-- <el-tab-pane label="评价标签" name="scond">
				<div style="margin:6px 0;display: inline-block;">
					<span>用户昵称：</span>
					<el-input style="width: 150px;" @keydown.enter.native="selectDt" clearable placeholder="请输入用户昵称"
						v-model="userName"></el-input>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="margin:6px 0;display: inline-block;">
					<span>手机号：</span>
					<el-input style="width: 150px;" @keydown.enter.native="selectDt" clearable placeholder="请输入手机号"
						v-model="phone"></el-input>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="margin:6px 0;display: inline-block;">
					<span>评价内容/关键字：</span>
					<el-input style="width: 200px;" @keydown.enter.native="selectDt" clearable placeholder="请输入评价内容/关键字"
						v-model="content"></el-input>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="display: inline-block;">
					<el-button style='margin-left:15px;' size="mini" type="primary" icon="document" @click="selectDt">查询
					</el-button>
					<el-button style='margin-left:15px;' size="mini" type="primary" icon="document" @click="cleansDt">重置
					</el-button>
					<el-button style='margin-left:15px;' size="mini" type="primary" icon="document" @click="refreshDt">
						刷新
					</el-button>
				</div>
				<el-table v-loading="tableDataLoading" :data="tableData.records">
					<el-table-column prop="commentId" label="编号" width="80">
					</el-table-column>
					<el-table-column prop="nickName" label="用户昵称" width="150">
						<template slot-scope="scope">
							<span style="color: #4f9dec;cursor: pointer;"
								@click="updates(scope.row.userId)">{{scope.row.nickName ? scope.row.nickName : '未绑定'}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="imageUrl" label="头像">
						<template slot-scope="scope">
							<img :src="scope.row.imageUrl" alt="" width="60" height="60">
						</template>
					</el-table-column>
					<el-table-column prop="content" label="评价内容">
					</el-table-column>
					<el-table-column prop="phone" label="手机号">
					</el-table-column>
					<el-table-column prop="score" label="评分">
						<template slot-scope="scope">
							<span>{{scope.row.score?scope.row.score:'暂无评分'}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间" width="180">
					</el-table-column>
					<el-table-column fixed="right" label="操作" width="150">
						<template slot-scope="scope">
							<el-button size="mini" type="danger" :disabled="!isAuth('comment:delete')"
								@click="pldeletes(scope.row)">删除
							</el-button>
						</template>
					</el-table-column>
				</el-table>
				<div style="text-align: center;margin-top: 10px;">
					<el-pagination @size-change="handleSizeChangeDt" @current-change="handleCurrentChangeDt"
						:page-sizes="[10, 20, 30, 50, 100]" :page-size="size" :current-page="page"
						layout="total,sizes, prev, pager, next" :total="tableData.total">
					</el-pagination>
				</div>
			</el-tab-pane> -->

			<!-- 回复 -->
			<el-dialog title="回复" :visible.sync="dialogFormVisible" center>
				<el-form :model="form">
					<el-form-item label="回复内容：" :label-width="formLabelWidth">
						<el-input v-model="form.reply" type="textarea" :rows="4" style="width:65%;"
							placeholder="请输入回复内容">
						</el-input>
					</el-form-item>
				</el-form>
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="replyNoticeTo()">确 定</el-button>
				</div>
			</el-dialog>



			<el-dialog title="新增评论" :visible.sync="dialogSaveVisible" center>
				<el-form :model="saveForm">
						<el-input v-model="saveForm.artificerId" type="text" style="width:65%;" hidden> </el-input>
					<el-form-item label="技师" :label-width="formLabelWidth">
						<el-input v-model="saveForm.artificerName" type="text" style="width:65%;" > </el-input>
						<el-button type="primary" @click="handleCheckJishi()">选择技师</el-button>
					</el-form-item>
					<el-form-item label="内容" :label-width="formLabelWidth">
						<el-input v-model="saveForm.content" type="text" style="width:65%;" > </el-input>
					</el-form-item>
					<el-form-item label="评分" :label-width="formLabelWidth">
						<el-input v-model="saveForm.score" type="number" style="width:65%;" > </el-input>
					</el-form-item>
				</el-form>


				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogSaveVisible = false">取 消</el-button>
					<el-button type="primary" @click="handelQueren()">确 定</el-button>
				</div>
			</el-dialog>


			<el-dialog title="选择师傅" :visible.sync="dialogChkjsVisible" center top="">
				<div>
					<div style="position: relative;  margin: 5px">
						<span style="position: relative; ">
							<span>师傅名称：</span>
							<el-input style="width: 200px" placeholder="请输入师傅名称" v-model="artificerName" ></el-input>&nbsp;&nbsp;
						</span>
						<span style="position: relative; display: inline-block">
							<span>手机号：</span>
							<el-input style="width: 200px" placeholder="请输入手机号" v-model="phoneT" ></el-input>&nbsp;&nbsp;
						</span>
						<el-button style="margin: 10px" size="mini" type="primary" icon="document" @click="handleSelJishi" >查询</el-button>
					</div>
        			<div style="float: right; margin-right: 2%"></div>
					<el-table v-loading="tableDataLoading" :data="choicenData.list">
						<el-table-column prop="artificerId" label="编号" width="80" fixed="left" > </el-table-column>
						<el-table-column prop="classifyName" label="项目类型" width="150"> </el-table-column>
						<el-table-column prop="artificerName" label="师傅名称" fixed="left"></el-table-column>
						<el-table-column prop="phone" width="120" label="手机号">
							<template slot-scope="scope">
							<span>{{ scope.row.phone ? scope.row.phone : "未绑定" }}</span>
							</template>
						</el-table-column>
						<el-table-column label="操作" prop="id" fixed="right">
							<template slot-scope="scope">
								<el-button size="mini" type="warning" style="margin: 5px" @click="handleJsqueren(scope.row)" >确认 </el-button>
							</template>
						</el-table-column>
					</el-table>
					<div style="text-align: center;  float: right">
						<el-pagination
							@size-change="handleSizeChange1"
							@current-change="handleCurrentChange1"
							:page-sizes="[10, 20, 30, 40]"
							:page-size="jishisize"
							:current-page="jishipage"
							layout="total,sizes, prev, pager, next,jumper"
							:total="choicenData.totalCount"
						>
						</el-pagination>
					</div>
				</div>
			</el-dialog>

		</el-tabs>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				size: 10,
				page: 1,
				goodsId: '',
				artificerName: '',
				phoneT: '',
				choicenData: [],
				jishipage:1,
				jishisize:10,
				form: {
					commentId: '',
					reply: ''
				},
				scoreType: 0,
				scoreTypes: [{
						value: 0,
						label: '全部'
					},
					{
						value: 1,
						label: '好评'
					},
					{
						value: 2,
						label: '中评'
					},
					{
						value: 3,
						label: '差评'
					}
				],
				//新增内容
				saveForm:{
					userId: '',
					artificerId: '',
					orderId: '',
					content: '',
					score: ''
				},
				dialogSaveVisible:false,
				dialogChkjsVisible:false,
				formLabelWidth: '200px',
				tableDataLoading: false,
				dialogFormVisible: false,
				tableData: [],
				content: '',
				title: '',
				userName: '',
				phone: '',
				activeName: 'first',

			}
		},
		methods: {
			//新增
			handleAdd(){
				this.dialogSaveVisible = true;
				this.saveForm = {};
			},
			//选择技师
			handleCheckJishi(){
				this.dialogChkjsVisible = true;
				this.handleSelJishi();
			},
			//新增评论保存
			handelQueren(){
				this.$http({
					url: this.$http.adornUrl('takingComment/insertTaking'),
					method: 'post',
					params: this.$http.adornParams({
						'page': 1,
						'limit': this.size,
						'artificerId': this.saveForm.artificerId,
						'content': this.saveForm.content,
						'score': this.saveForm.score
					})
				}).then(({ data }) => {
					this.dialogSaveVisible = false;
					this.dataSelect();
				})
			},
			//技师查询
			handleSelJishi(){
				this.userId = this.$store.state.user.id;
				this.$http({
					url: this.$http.adornUrl(`artificer/selectArtificerList`),
					method: "get",
					params: this.$http.adornParams({
					page: this.jishipage,
					limit: this.jishisize,
					artificerName: this.artificerName,
					massageTypeId: "",
					longitude: "",
					latitude: "",
					city: "",
					classifyId: "",
					phone: this.phoneT,
					authentication: 2,
					}),
				}).then(({ data }) => {
					this.tableDataLoading = false;
					let returnData = data.data;
					this.choicenData = returnData;
					console.log(this.choicenData);
				});
			},
			//技师确认选择
			handleJsqueren(record){
				this.saveForm.artificerId = record.artificerId;
				this.saveForm.artificerName = record.artificerName;
				this.dialogChkjsVisible = false;
			},
			//技师列表更换页数
			handleSizeChange1(val) {
				this.jishisize = val;
				this.handleSelJishi();
			},
			//技师翻页
			handleCurrentChange1(val) {
				this.jishipage = val;
				this.handleSelJishi();
			},
			// 返回上一级
			prev() {
				this.$router.back()
			},
			handleSizeChange(val) {
				this.size = val;
				this.dataSelect()
			},
			handleCurrentChange(val) {
				this.page = val;
				this.dataSelect()
			},
			handleSizeChangeDt(val) {
				this.size = val;
				this.dataSelectDt()
			},
			handleCurrentChangeDt(val) {
				this.page = val;
				this.dataSelectDt()
			},
			// tabs切换
			handleClick(tab, event) {
				this.phone = ''
				this.page = 1
				this.userName = ''
				if (tab._props.label == '评价列表') {
					this.dataSelect()
				}
				if (tab._props.label == '评价标签') {
					this.dataSelectDt()
				}
			},
			// 刷新
			refresh() {
				this.dataSelect()
			},
			//搜索
			select() {
				this.page = 1
				this.dataSelect()
			},
			// 重置
			cleans() {
				this.title = ''
				this.userName = ''
				this.phone = ''
				this.content = ''
				this.page = 1
				this.dataSelect()
			},
			// 刷新
			refreshDt() {
				this.dataSelectDt()
			},
			//搜索
			selectDt() {
				this.page = 1
				this.dataSelectDt()
			},
			// 重置
			cleansDt() {
				this.userName = ''
				this.phone = ''
				this.content = ''
				this.page = 1
				this.dataSelectDt()
			},
			// 回复
			replyClick(row) {
				this.dialogFormVisible = true
				this.form.commentId = row.commentId
				this.form.reply = row.reply
			},
			replyNoticeTo() {
				this.$http({
					url: this.$http.adornUrl('/selfGoodsComment/reply'),
					method: 'get',
					params: this.$http.adornParams({
						'commentId': this.form.commentId,
						'reply': this.form.reply,
					})
				}).then(({
					data
				}) => {
					this.$message({
						message: '回复成功',
						type: 'success',
						duration: 1500,
						onClose: () => {
							this.dataSelect()
						}
					})
					this.dialogFormVisible = false
				})
			},
			// 删除评价
			deletes(row) {
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl(`takingComment/deleteOrderTakingComment/${row.id}`),
						method: 'post',
						params: this.$http.adornParams({})
					}).then(({
						data
					}) => {
						if (data.code == 0) {
							this.$message({
								message: '删除成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.dataSelect()
								}
							})
						} else {
							this.$message({
								message: data.msg,
								type: 'warning',
								duration: 1500,
								onClose: () => {}
							})
						}
					})
				}).catch(() => {})
			},
			// 获取评价列表数据
			dataSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('takingComment/selectOrderTakingComment'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.size,
						'userName': this.userName,
						'content': this.content,
						'phone': this.phone
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data;
					this.tableData = returnData
				})
			},
			// 获取评价标签
			dataSelectDt() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('app/gambit/selectCommentPageAdmin'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.size,
						'userName': this.userName,
						'content': this.content,
						'phone': this.phone
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data;
					this.tableData = returnData
				})
			},
			// 详情跳转
			updates(userId) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: userId
					}
				})
			},
			// 商品跳转
			toGoods(title) {
				this.$router.push({
					path: '/shopAdmin1',
					query: {
						title: title
					}
				})
			},
			// 删除评价标签
			pldeletes(row) {
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl(`gambit/deleteCommentById`),
						method: 'post',
						params: this.$http.adornParams({
							'commentId': row.commentId
						})
					}).then(({
						data
					}) => {
						this.$message({
							message: '删除成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.dataSelectDt()
							}
						})
					})
				})
			},
		},
		activated() {
			this.dataSelect()
		}
	};
</script>

<style>
.el-dialog--center {
	text-align: center;
 	margin-top: 1vh !important;
}
</style>
