ThinkPHP关于模板的⼀些嵌套、IF判断使⽤
前⾔,现在有⼀组数据(涉及到3个数据表,order订单表,order_process办理流程表,process_status流程描述表),根据当前订单,展⽰相应信息
1.办理流程部分数据:
2.流程状态部分数据:
3.期望达到效果如下:
这⾥就需要⽤到⼏个部分的技巧结合
⼀般的循环嵌套使⽤
<volist name="list" id="vo">
<volist name="vo['sub']" id="sub">
{$sub.name}
</volist>
</volist>
其中第⼆个volist的name属性,也可以写作name="vo.sub"
IF判断使⽤
常⽤的判断中,不允许使⽤<,>,=之类的符号,改为:
标签含义
eq或者equal等于
neq或者notequal不等于
gt⼤于
egt⼤于等于
lt⼩于
elt⼩于等于
heq恒等于
nheq不恒等于
1. <eq name="name" value="value">value</eq>
⽐较标签中的变量可以⽀持对象的属性或者数组,甚⾄可以是系统变量,例如:当vo对象的属性(或者数组,或者⾃动判断)等于5就输出
2 .<eq name="vo.name" value="5">
{$vo.name}
</eq>
3. <!-- 附加说明判断数组⼤⼩-->
<if condition="count($vo['additional']) gt 1">
附加说明:
<else /> other Framework
</if>
4. <!-- 附加说明判断数组⼤⼩-->
<if condition="strlen($vo['additional']['0']) gt 1">
附加说明:
<else /> other Framework
</if>
参考php
public function orderDetail($id, $userId) {
$param['id'] = $id;
$order = M('reorder')->where($param)->find();
//0.更新订单被查看的信息:查看⼈、查看时间
$watch['userId'] = $userId;
$watch['posttime2'] = time();
M('reorder')->where($param)->save($watch);
//获取当前项⽬的默认办理流程
$where['projectid'] = $order['projectid'];
$immiprogram = M('reimmiprogram')->where($where)->find();
$orderStatus = M('reorderstatus')->where($where)->find();
$orderStatus['status'] = explode('|',$orderStatus['status']);
//查已经完成的办理流程
$param_process['orderid'] = $order['orderid'];
$param_process['isfinish'] = 'true';
$status1 = M('reorderprocess')->where($param_process)->order('posttime')->select();
//根据当前订单状态,分割orderStatus
$param_process['isfinish'] = 'false';
$status2 = M('reorderprocess')->where($param_process)->order('posttime')->select();
//$this->ajaxJSON($status2);
/
/判断附加说明,是否含分隔符
foreach ($status1 as $key => &$value) {
$value['additional'] = explode("|",$value['additional']);
}
foreach ($status2 as $key => &$item) {
$item['additional'] = explode("|",$item['additional']);
}
//$this->ajaxJSON($status1);
$status3 = array();
$least = count($status1)+count($status2);
foreach ($orderStatus['status'] as $key => $value) {
/
/当前正在办理的事项
if($key > $least){
array_push($status3,$value);
}
}
//查最新的流程附加信息
$param_newest['orderid'] = $order['orderid'];
$process_newest = M('reorderprocess')->where($param_newest)->order('posttime desc')->find(); $counts = array();
array_push($counts,0);
array_push($counts,count($status1));
array_push($counts,count($status1)+count($status2));
$this->assign('order',$order);
$this->assign('immiprogram',$immiprogram);
$this->assign('orderStatus',$orderStatus);
$this->assign('process_newest',$process_newest);
$this->assign('status1',$status1);
$this->assign('status2',$status2);
$this->assign('status3',$status3);
$this->assign('counts',$counts);
$this->display();
}
参考json数据status1
[
{
"id": "135",
"orderid": "2017YH1001",
"status": "签约",
"isfinish": "true",
"additional": [
"客户上门拜访签约的"
],
"posttime": "1491321600",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-05-10 14:37:08",
"create_time": "2017-04-05 00:00:00"
},
{
"id": "136",
"orderid": "2017YH1001",
"status": "缴纳服务费",
"isfinish": "true",
"additional": [
""
]
,
"posttime": "1491321600",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-04-05 00:00:00",
"create_time": "2017-04-05 00:00:00"
},
{
"id": "137",
"orderid": "2017YH1001",
"status": "提交移民信息表",
"isfinish": "true",
"additional": [
""
],
"posttime": "1491408000",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-04-06 00:00:00",
"create_time": "2017-04-06 00:00:00"
},
{
"id": "138",
"orderid": "2017YH1001",
"status": "收集材料",
"isfinish": "true",
"additional": [
""
],
"posttime": "1491408000",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-04-06 00:00:00",
"create_time": "2017-04-06 00:00:00"
},
{
"id": "139",
"orderid": "2017YH1001",
"status": "材料制作",
"isfinish": "true",
"additional": [
""
],
"posttime": "1491408000",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-04-06 00:00:00", "create_time": "2017-04-06 00:00:00" },
{
"id": "149",
"orderid": "2017YH1001",
"status": "递交申请",
"isfinish": "true",
"additional": [
""
],
"posttime": "1491753600",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-04-10 00:00:00", "create_time": "2017-04-10 00:00:00" },
{
"id": "150",
"orderid": "2017YH1001",
"status": "获得档案编号",
"isfinish": "true",
"additional": [
""
]
,
"posttime": "1492012800",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-04-13 00:00:00", "create_time": "2017-04-13 00:00:00" },
{
"id": "151",
"orderid": "2017YH1001",
"status": "已补件到⾹港⼊境处",
"isfinish": "true",
"additional": [
"2017.02.27 补录资料",
"2017.03.24 补录资料 "
],
"posttime": "1493827200",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-05-10 13:45:48", "create_time": "2017-05-04 00:00:00" },
{
"id": "152",
"orderid": "2017YH1001",
"status": "已补⼊资料",
"isfinish": "true",
"additional": [
""
],
"posttime": "1494432000",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-05-11 00:00:00", "create_time": "2017-05-11 00:00:00" },
thinkphp3{
"id": "153",
"orderid": "2017YH1001",
"status": "获得原则性批准信",
"isfinish": "true",
"additional": [
""
],
"posttime": "1502208000",
"recorder": "Candy",
"checkinfo": "true",
"update_time": "2017-05-10 14:43:03", "create_time": "2017-08-09 00:00:00" }
]
参考html
<li class="descriptionDetailList">
<ul class="descriptionUl1">
<volist name="status1" id="vo">
<li class="clearfix">
<h5 class="finishedH5">{$counts['0']+$key+1}</h5>
<div class="finishedSchedule">
<p>{$vo.status}</p>
<span>完成时间:{$vo.posttime|date="Y-m-d",###}</span> <!-- 附加说明判断数组⼤⼩-->
<if condition="strlen($vo['additional']['0']) gt 1">
<p><span>附加说明:</span></p>
<else />
</if>
<volist name="vo.additional" id="vo2">
<span>{$vo2}</span> <br/>
</volist>
</div>
<span class="finished">【完成】</span>
</li>
</volist>
<volist name="status2" id="vo">
<li class="clearfix">
<h5 class="underwayH5">{$counts['1']+$key+1}</h5>
<div class="underwaySchedule">
<p>{$vo.status}</p>
<span>进⾏中......</span>
<!-- 附加说明判断数组⼤⼩-->
<if condition="strlen($vo['additional']['0']) gt 1">
<p><span>附加说明:</span></p>
<else />
</if>
<volist name="vo.additional" id="vo2">
<span>{$vo2}</span> <br/>
</volist>
</div>
<span class="underway">【详情】</span>
</li>
</volist>
<volist name="status3" id="vo">
<li class="clearfix">
<h5 class="beforeH5">{$counts['2']+$key+1}</h5>
<div class="beforeSchedule">
<p>{$vo}</p>
<span>未开始</span>
</div>
<span class="before">......</span>
</li>
</volist>
</ul>
</li>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论