vue订单列表基本操作
订单列表 翻页功能、切换状态功能
代码如下
<template>
<div id="menu1"></div>
<div style="position: relative; max-width: 640px;">
<router-link to="/user" class="order-back colorff text-center ft22">返回</router-link>
</div>
<div class="course-tab" data-ydui-tab>
<div class="procuct-box layout-column layout-align-space-between-center ft28">
<ul class="procuct-item-tit my-refer-tit tab-nav b-line layout-row layout-align-space-between-end">
<li class="my-refer-li tab-nav-item ft28" @click="status_cat(0)" :class="sid==0?'tab-active':''"><a href="javascript:;">全部</a></li>
<li class="my-refer-li tab-nav-item ft28" @click="status_cat(1)" :class="sid==1?'tab-active':''"><a href="javascript:;">待支付</a></li>
<li class="my-refer-li tab-nav-item ft28" @click="status_cat(3)" :class="sid==3?'tab-active':''"><a href="javascript:;">待发货</a></li>
<li class="my-refer-li tab-nav-item ft28" @click="status_cat(4)" :class="sid==4?'tab-active':''"><a href="javascript:;">待收货</a></li>
<li class="my-refer-li tab-nav-item ft28" @click="status_cat(9)" :class="sid==9?'tab-active':''"><a href="javascript:;">已完成</a></li>
</ul>
</div>
<div class="tab-panel ft28 color5c">
<!-- 全部 -->
<div class="tab-panel-item tab-active">
<div class="order-info" v-for="(item,key,index) in order " :key="index" >
<div class="order-info-top layout-row layout-align-space-between-center">
<div>订单号:{{item.ooid}}</div>
<div class="color-green">{{item.status_v}}</div>
</div>
<div class="order-info-center">
<router-link to="/order_details">
<div class="order-line layout-row layout-align-space-between-center">
<div class="order-img">
<img :src="item.img_s">
</div>
<div class="order-rit layout-column layout-align-space-between-start color5c">
<div>
<div class="coures-title ft26">{{item.title}}</div>
<!-- <div class="order-lable colorb1 layout-row layout-align-start-center">
<span>{{item.know_text}}</span>
</div> -->
</div>
<div class="coures-txt-bot layout-row layout-align-end-center">
<div class="colorb1 ft26">{{item.add_time_v}}</div>
</div>
</div>
</div>
</router-link>
<!-- <div class="order-info-bot layout-row layout-align-end-center">
<router-link to="/purchased_details" class="order-go colorff text-center" style="color:#fff;">去上课</router-link>
</div> -->
</div>
</div>
</div>
<div @click="page()" v-if="jia">
<button class="order-go colorff" style="color:#fff;width:80%;margin-top:30px;margin-left:10%;">加载更多</button>
</div>
</div>
</div>
</template>
<script>
import { reactive, toRefs } from "vue";
import { Userorder } from "../../network/index.js";
export default({
setup() {
const data = reactive({
order:[],
p : 1,
count : 1,
sid:0,
jia : true,
});
//获取订单方法
Userorder().then( (e)=>{
data.order = e.data.data.order;
data.count = e.data.data.num;
console.log( e);
} );
//选择方法
const status_cat = (ee) =>{
data.sid = ee;
Userorder({sid: data.sid}).then( (e)=>{
data.order = e.data.data.order;
data.count = e.data.data.num;
} )
data.jia = true;
data.p = 1;
}
//分页方法
const page = ()=>{
data.p++;
Userorder({p:data.p,sid: data.sid}).then( (e)=>{
data.order = data.order .concat( e.data.data.order);
data.count = e.data.data.num;
if(data.p >= data.count){
data.jia = false;
}
} )
}
return {
...toRefs(data),
status_cat,
page,
}
}
})
</script>
public function userorder(){
$status = input('post.sid',0);
$p = input('post.p',1);
$where = [];
switch ($status){
case 1:
$where[] = ['a.status','=',1];
break;
case 2:
$where[] = ['a.status','=',2];
break;
case 3:
$where[] = ['a.status','=',3];
break;
case 4:
$where[] = ['a.status','=',4];
break;
case 9:
$where[] = ['a.status','=',9];
break;
}
$p = input('post.p',1);
$data = Request::param('token');
$uid= Ticket::get($data,'phpcn');
$num = Db::table('bew_order')->where('uid','=',$uid)->count();
$order= Db::table('bew_order')
->alias('a')
->field('a.ooid,a.status,a.add_time,w.title,w.img,w.know_text')
->leftJoin('bew_course w','a.cou_id = w.id')
->where('a.uid','=',$uid)
->where($where)
->page($p,5)
->select()->toArray();
foreach ( $order as &$order_v){
switch ($order_v['status']){
case 1:
$order_v['status_v']='订单待支付';
break;
case 2:
$order_v['status_v']='订单已支付';
break;
case 3:
$order_v['status_v']='订单已发货';
break;
case 4:
$order_v['status_v']='订单已收货';
break;
case 9:
$order_v['status_v']='订单已完成';
break;
}
$order_v['img_s']= $this->get_url().(explode(';',$order_v['img']))[0];
$order_v['add_time_v']= date('Y-m-d',$order_v['add_time']);
}
$arr= [
'code'=>0,
'msg'=>'成功',
'data'=>[
'order'=>$order,
'num'=>ceil($num/5),
]
];
echo json_encode($arr);
}
效果如下
列表和翻页效果效果