{extend name="main"}
{block name="body"}
<div class="bg-white p-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-width="120px" :label-position="labelPosition" size="mini">

	  <el-form-item label="用户ID" prop="uid">
	    <el-input v-model="search.uid" class="col-12 col-sm-2 pl-0 pr-0"></el-input>
	  </el-form-item>
	  <el-form-item label="订单号" prop="otrade">
	    <el-input v-model="search.otrade" class="col-12 col-sm-2 pl-0 pr-0"></el-input>
	  </el-form-item>
	  <el-form-item label="订单类型" prop="type">
	  	<el-select v-model="search.type" clearable filterable multiple placeholder="请选择" class="col-12 col-sm-4 pl-0 pr-0">
		    <el-option
		      v-for="item in OrderType"
		      :key="item.value"
		      :label="item.title"
		      :value="item.value">
		    </el-option>
		</el-select>
	  </el-form-item>
	  <el-form-item label="状态" prop="status">
	    <el-radio-group v-model="search.status">
	      <el-radio :label="'all'">全部</el-radio>
	      <el-radio :label="0">未支付</el-radio>
	      <el-radio :label="1">已支付</el-radio>
	      <el-radio :label="2">已完成</el-radio>
	      <el-radio :label="-1">已取消</el-radio>
	    </el-radio-group>
	  </el-form-item>
	  <el-form-item label="支付方式" prop="pay_type">
	    <el-radio-group v-model="search.pay_type">
	      <el-radio :label="'all'">全部</el-radio>
	      <el-radio :label="1">支付宝</el-radio>
	      <el-radio :label="2">微信</el-radio>
	      <el-radio :label="3">Apple Pay</el-radio>
	      <el-radio :label="4">积分</el-radio>
	      <el-radio :label="5">权益兑换</el-radio>
	      <el-radio :label="6">字节跳动</el-radio>
	      <el-radio :label="7">百度</el-radio>
	    </el-radio-group>
	  </el-form-item>
	  <el-form-item label="时间" prop="time">
	  	<el-date-picker
	      v-model="search.time"
	      type="daterange"
	      align="left"
	      range-separator="至"
	      start-placeholder="开始日期"
	      end-placeholder="结束日期"
	      format="yyyy-M-d"
	      value-format="yyyy-M-d"
	      :picker-options="pickerOptions">
	    </el-date-picker>
	  </el-form-item>

	  <el-form-item>
	    <el-button type="primary" @click="initHtml">查询</el-button>
	    <el-button @click="resetForm('search')">重置</el-button>
	  </el-form-item>
	</el-form>
	<div class="table-responsive py-3">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
	<div class="table-responsive">
		<el-table
	      	:data="tableData"
    		stripe
    		v-loading="search.ajax"
    		style="width: 100%;">
	      <el-table-column
	        prop="oid"
	        label="ID"
	        width="60">
	      </el-table-column>
	      <el-table-column
	        label="用户"
	        width="200">
		      <template slot-scope="scope">
		      	<div class="flex flex-center">
					<el-image
					  	v-if="scope.row.headimg" 
					    style="width: 30px; height: 30px"
					    lazy
					    class="rounded-circle mr-2"
					    :src="scope.row.headimg" 
					    :preview-src-list="[scope.row.headimg]">
					</el-image>
		      		<div>
						{{scope.row.nickname}}
		      		</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	      	prop="type"
	        label="订单类型"
	        width="120">
	      </el-table-column>
	      <el-table-column
	      	prop="otrade"
	        label="订单号"
	        width="200">
	      </el-table-column>
	      <el-table-column
	        prop="otitle"
	        label="名称">
	      </el-table-column>
	      <el-table-column
	      	prop="oprice"
	        label="订单金额"
	        width="100">
	      </el-table-column>
	      <el-table-column
	      	prop="score"
	        label="抵扣积分"
	        width="100">
	      </el-table-column>
	      <el-table-column
	        label="支付方式"
	        width="100">
		      <template slot-scope="scope">
		      	<span class="text-primary" v-if="scope.row.pay_type === 1">支付宝</span>
		      	<span class="text-success" v-else-if="scope.row.pay_type === 2">微信</span>
		      	<span class="text-warning" v-else-if="scope.row.pay_type === 3">Apple Pay</span>
		      	<span class="text-warning" v-else-if="scope.row.pay_type === 4">积分</span>
		      	<span class="text-info" v-else-if="scope.row.pay_type === 5">权益兑换</span>
		      	<span class="text-danger" v-else-if="scope.row.pay_type === 6">字节跳动</span>
		      	<span class="text-primary" v-else-if="scope.row.pay_type === 7">百度</span>
		      	<span class="text-secondary" v-else-if="scope.row.status===1 || scope.row.status===2">未知</span>
		      </template>
	      </el-table-column>
	      <el-table-column
	      	prop="channel_type"
	        label="渠道"
	        width="100">
	      </el-table-column>
	      <el-table-column
	        label="状态"
	        width="100">
		      <template slot-scope="scope">
		      	<span class="text-dark" v-if="scope.row.status===0">待支付</span>
		      	<span class="text-danger" v-if="scope.row.status===1">已支付</span>
		      	<span class="text-success" v-if="scope.row.status===2">已完成</span>
		      	<span class="text-secondary" v-if="scope.row.status===-1">已取消</span>
		      	<span class="text-danger small" v-if="scope.row.delete_time">(删)</span>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="时间线"
	        width="180">
		      <template slot-scope="scope">
		        <el-popover trigger="hover" placement="top">
		          <p>创建时间: {{ scope.row.create_time }}</p>
		          <p>更新时间: {{ scope.row.update_time }}</p>
		          <p v-if="scope.row.status===0">过期时间: {{ scope.row.expire_time }}</p>
		          <p v-if="scope.row.status===1 || scope.row.status===2">支付时间: {{ scope.row.pay_time }}</p>
		          <p v-if="scope.row.status===1 || scope.row.status===2">完成时间: {{ scope.row.finish_time }}</p>
		          <p v-if="scope.row.status===-1">取消时间: {{ scope.row.cancel_time }}</p>
		          <p v-if="scope.row.delete_time">删除时间: {{ scope.row.delete_time }}</p>
		          <div slot="reference" class="name-wrapper">
		            <el-tag size="small" type="info">{{ scope.row.create_time }}</el-tag>
		          </div>
		        </el-popover>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="/"
	        width="80">
		      <template slot-scope="scope">
		      	<el-link v-if="(scope.row.status===1 || scope.row.status===2) && (scope.row.pay_type===1 || scope.row.pay_type===2 || scope.row.pay_type===3 || scope.row.pay_type===6 || scope.row.pay_type===7)" type="primary" :underline="false" @click="getPayInfo(scope.row.pay_type,scope.row.otrade);">支付信息</el-link>
		      </template>
	      </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
</div>
<el-dialog title="支付信息" :visible.sync="dialogTableVisible">
	<table class="table">
		<tr v-for="(v,index) in payInfo">
			<td width="180">{{index}}</td>
			<td>{{v}}</td>
		</tr>
	</table>
</el-dialog>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="OrderType"}
	var OrderType=[];
	{else/}
	var OrderType={:json_encode($OrderType,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			OrderType:OrderType,
			dialogTableVisible:false,
	        payInfo: {},
			labelPosition:'right',
	        pickerOptions: {
	          shortcuts: [{
	            text: '最近一周',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近一个月',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近三个月',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近半年',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
	              picker.$emit('pick', [start, end]);
	            }
	          }]
	      	},
			search:{
				uid:'',
				otrade:'{:request()->get('otrade','')}',
				status:'all',
				pay_type:'all',
				type:[],
				time:[],
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				this.search.page=val;
	          	this.initHtml();
			},
			getPayInfo:function(pay_type,otrade){
				var _this=this;
				var loadingEl=XYBase.openloading();
				$.getJSON('/orders/getPayInfo/'+pay_type+'/'+otrade,function(ret){
					loadingEl.close();
					if(ret){
						if(ret.code === 0){
							_this.payInfo=ret.data;
							_this.dialogTableVisible=true;
						}else XYBase.msg(ret.msg);
					}else XYBase.error(XYBase.config.system_network_error);
				});
			},
	      	initHtml() {
	      		var _this=this;
	      		_this.search.ajax=true;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
	      				_this.search.ajax=false;
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
	      				_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								_this.search.total=ret.data.total;
								_this.tableData=ret.data.data;
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			}
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{/block}