Loading

ThinkPHP关于模板的一些嵌套、IF判断使用

前言,现在有一组数据(涉及到3个数据表,order订单表,order_process办理流程表,process_status流程描述表),根据当前订单,展示相应信息

1.办理流程部分数据:

image

2.流程状态部分数据:

image

3.期望达到效果如下:

image


这里就需要用到几个部分的技巧结合

一般的循环嵌套使用
<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 不恒等于
<eq name="name" value="value">value</eq>

比较标签中的变量可以支持对象的属性或者数组,甚至可以是系统变量,例如: 当vo对象的属性(或者数组,或者自动判断)等于5就输出

<eq name="vo.name" value="5">
   {$vo.name}
</eq>
<!-- 附加说明 判断数组大小-->
<if condition="count($vo['additional']) gt 1">
    附加说明:
    <else /> other Framework
</if>
<!-- 附加说明 判断数组大小-->
<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"
    },
    {
        "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>
posted @ 2017-05-10 15:17  集君  阅读(6702)  评论(0编辑  收藏  举报