<template>
	<div>
		<!-- <el-tabs v-model="activeName" @tab-click="handleClick">
			<el-tab-pane label="信用分明细" name="first"> -->
			<el-row>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">转化率</div>
							<div class="text_color"><span>{{zhuanhualv ?zhuanhualv : 0}}</span>
							</div>
						</div>
					</div>
				</el-col>
			</el-row>
			<div>
				<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="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>
				</div>
			</div>
				
				<el-table v-loading="tableDataLoading" :data="tableData.records">
					<el-table-column prop="userId" label="编号">
					</el-table-column>
					<el-table-column prop="nickName" label="用户名">
						<template slot-scope="scope">
							<span style="color: #4f9dec;cursor: pointer;"
								@click="updates(scope.row)">{{scope.row.userName ? scope.row.userName : '未绑定'}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="phone" label="手机号">
					</el-table-column>
					<el-table-column prop="counts" label="次数">
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间">
					</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.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-tabs> -->
	</div>
</template>

<script>
	export default {
		data() {
			return {
				size: 10,
				page: 1,
				goodsId: '',
				form: {
					commentId: '',
					reply: ''
				},
				scoreType: 0,
				scoreTypes: [{
						value: 0,
						label: '全部'
					},
					{
						value: 1,
						label: '好评'
					},
					{
						value: 2,
						label: '中评'
					},
					{
						value: 3,
						label: '差评'
					}
				],
				formLabelWidth: '200px',
				tableDataLoading: false,
				dialogFormVisible: false,
				tableData: [],
				content: '',
				title: '',
				userName: '',
				phone: '',
				activeName: 'first',
				zhuanhualv:0,

			}
		},
		methods: {
			// 返回上一级
			prev() {
				this.$router.back()
			},
			handleSizeChange(val) {
				this.size = val;
				this.dataSelect()
			},
			handleCurrentChange(val) {
				this.page = val;
				this.dataSelect()
			},
			
			// tabs切换
			handleClick(tab, event) {
				this.phone = ''
				this.page = 1
				this.userName = ''
				if (tab._props.label == '评价列表') {
					this.dataSelect()
				}
				
			},
			// 刷新
			refresh() {
				this.dataSelect()
			},
			//搜索
			select() {
				this.page = 1
				this.dataSelect()
			},
			// 重置
			cleans() {
				this.title = ''
				this.userName = ''
				this.phone = ''
				this.content = ''
				this.page = 1
				this.dataSelect()
				this.dataSelectLv()
			},
			
			// 回复
			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('artificer/selectNewUserOrdersCount'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.size,
						'userName': this.userName,
						'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
					}
				})
			},
			// 转化率
			dataSelectLv() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('artificer/selectNewUserOrdersRate'),
					method: 'get',
					params: this.$http.adornParams({
						
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data;
					if(returnData>0){
						this.zhuanhualv = ((Number(returnData)*100).toFixed(2))+'%'
					}else{
						this.zhuanhualv =0
					}
				})
			},
		},
		activated() {
			this.dataSelect()
			this.dataSelectLv()
		}
	};
</script>

<style>
	.Chart1 {
		width: 100%;
		height: 300px;
	}
	.box {
		padding: 44px;
		border: 1px solid #eee;
		margin: 15px 10px;
	}
	
	.box_num {
		font-size: 14px;
		color: #66b1ff;
	}
	
	.box_num .box_color {
		color: #333;
		font-size: 14px;
		margin-bottom: 15px;
	}
	
	.box_num div span {
		font-size: 20px;
		margin-left: 5px;
	}
	
	.text_color {
		color: #4f9dec;
	}
	
	.text_color span {
		margin-right: 5px;
	}
</style>
