<template>
	<div class="order-wrapper">
		<!-- <breadcrumb :item-name="['订单管理', '订单列表']"></breadcrumb> -->
		<el-card>
			<!-- 搜索区域 -->
			<el-col>
				<div class="flex" style="justify-content: flex-end;padding-bottom: 20px;">
					<!-- <el-button type="primary" @click="openBuy">充值</el-button> -->
					<el-button type="primary" icon="el-icon-refresh-right" @click="getList('reload')" >刷新</el-button>
				</div>
			
			</el-col>
			<!-- 订单表格区域 -->
			<el-table :data="list" border style="width: 100%" max-height="620">
				<el-table-column prop="id" label="id" width="50">
				</el-table-column>
				<el-table-column prop="expenses_sum" label="物流费" width="100">
				</el-table-column>
				<el-table-column prop="commission_sum" label="手续费" width="100">
				</el-table-column>
				<el-table-column prop="compensation_sum" label="赔付金额" width="100">
				</el-table-column>
        <el-table-column prop="status" label="审核状态" width="100">
        <template slot-scope="scope">
           <el-tag type="success" v-if="scope.row.status == 1">已通过</el-tag>
           <el-tag type="danger" v-if="scope.row.status == 0">审核中</el-tag>
        </template>
        </el-table-column>
				<el-table-column prop="compensation_10_count" label="赔付金额为10块的单数" >
				</el-table-column>
				<el-table-column prop="compensation_11_count" label="赔付金额为11块的单数" >
				</el-table-column>
				<el-table-column prop="compensation_12_count" label="赔付金额为12块的单数" >
				</el-table-column>
				<el-table-column prop="compensation_13_count" label="赔付金额为13块的单数" >
				</el-table-column>
				<el-table-column prop="compensation_14_count" label="赔付金额为14块的单数" >
				</el-table-column>
			</el-table>
			<div style="height: 20px;"></div>
			<!-- 分页区域 -->
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="queryInfo.page" :page-sizes="[10, 20, 50, 100]" :page-size="queryInfo.pagesize"
				layout="total, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</el-card>
		<!-- 修改地址对话框 -->
		<el-dialog title="充值" :visible.sync="dialogTableVisible">
			<el-form :model="form">
				<el-form-item label="充值金额" :label-width="formLabelWidth">
					<el-input v-model="form.recharge_num" type="number"></el-input>
				</el-form-item>
				<el-form-item label="充值凭证" :label-width="formLabelWidth">
					<el-upload
					  class="avatar-uploader"
					  action="http://www.pingguozhushou.shop/api/common/upload"
					  :show-file-list="false"
					  :headers="headers"
					  :on-success="handleAvatarSuccess"
					  :before-upload="beforeAvatarUpload">
					  <img v-if="form.image" :src="form.image" class="avatar">
					  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
					</el-upload>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogTableVisible = false">取 消</el-button>
				<el-button type="primary" @click="goBuy">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		createCode,
		getCodeList,
		getUserList
	} from '@/request/agent.js'
	import { getMoneyList,rechange,tlement } from '@/request/user.js'
	import { showTime } from '@/assets/js/tools.js'
	export default {
		name: 'Order',
		data() {
			return {
				loading: false,
				formLabelWidth: '80px',
				form: {
					recharge_num: '',
					image: ''
				},
				dialogTableVisible: false,
				queryInfo: {
					keyword: '',
					page: 1,
					limit: 10
				},
				list: [],
				total: 0,
				dataloading: false,
				headers: {}
			}
		},
		created() {
			this.getList()
			this.headers['token'] = window.sessionStorage.getItem('token')
		},
		methods: {
			showTime,
			handleAvatarSuccess(res, file) {
				this.form.image = res.data.fullurl;
				console.log(this.form.image,'this.form.avatar');
			},
			beforeAvatarUpload(file) {
				// const isJPG = file.type === 'image/jpeg/png';
				// const isLt2M = file.size / 1024 / 1024 < 2;
			
				// if (!isJPG) {
				// 	this.$message.error('上传头像图片只能是 JPG 格式!');
				// }
				// if (!isLt2M) {
				// 	this.$message.error('上传头像图片大小不能超过 2MB!');
				// }
				// return isJPG && isLt2M;
				return true
			},
			handleAvatarError() {
				
			},
			openBuy() {
				this.dialogTableVisible = true
			},
			goBuy() {
				let that = this
				if (that.loading) {
					return
				}
				if (!that.form.recharge_num) {
					return that.$msg.error('请输入充值金额')
				}
				if (!that.form.image) {
					return that.$msg.error('请上传充值凭证')
				}
				that.loading = true
				rechange(that.form).then(res => {
					console.log(res);
					that.$msg.success('提交成功，请等待审核')
					that.dialogTableVisible = false
					that.loading = false
					that.getList('reload')
				}).catch(err => {
					that.loading = false
				})
			},
			getList(type) {
				let that = this
				if (type == 'reload') {
					that.queryInfo.page = 1
					that.dataloading = false
				}
				if (that.dataloading) {
					return
				}
				
				that.dataloading = true
				tlement(that.queryInfo).then(res => {
					that.total = res.data.count
					that.list = res.data.data
					that.dataloading = false
				}).catch(err => {
					that.dataloading = false
				})
			},
			handleSizeChange(newPageSize) {
				this.queryInfo.limit = newPageSize
				this.getList()
			},
			handleCurrentChange(newPageNum) {
				this.queryInfo.page = newPageNum
				this.getList()
			},
		},

	}
</script>

<style scoped lang="scss">
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}
	
	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}
	
	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
		border: 1px dashed #d9d9d9;
		border-radius: 10px;
	}
</style>