{imp:"cargo/ocar-alay"}<!--模板继承-->

{block:minit}{:parent}<?php 
$tabid = 'coms_coitem';
$title = '订单查询';
$entit = 'Invoce';

if($act=='oadd'){ //提交订单
    $readd = exvOcar::oadd($unqid,$user);
    $ordid = $readd['ordid']; $enc = $readd['enc'];
    die(basMsg::show("添加成功！",'Redir',surl(0)."?$this->mkv&ordid=$ordid&enc=$enc",1));
}elseif($act=='odel'){ //取消订单
    $erow = exvOcar::odel($ordid);
    $msg = "删除".($erow ? '成功！' : '失败！');
    $url = surl(0).($erow ? surl('cargo') : "?$this->mkv&ordid=$ordid&enc=$enc");
    die(basMsg::show("$msg",'Redir',$url,1));
}elseif($act=='oedit'){ //edit订单
    $erow = exvOcar::oedit($ordid);
    $msg = "编辑".($erow ? '成功！' : '失败(可能没有修改项)！');
    die(basMsg::show("$msg",'Redir',surl(0)."?$this->mkv&ordid=$ordid&enc=$enc",1));
}elseif($this->key=='invoce'){
    $ouser = exvOcar::whruser();
    $where = "ordid='$ordid'"; 
}
$msg || $msg = "<b class='c999'>$entit</b>";

$list = exvOcar::ilist($tabid,$where); 
if($list['sum']['acnt']==0){
    die(basMsg::show("订单项为空，返回[商品展销]！",'Redir',surl('cargo'),1));
}
$order = $db->table('coms_corder')->where("cid='$ordid'")->find();
$null = '---';
$ordshto = $order['ordshto'];
$ordstat = $order['ordstat'];
$st_flags = exvOcar::ostat($ouser,$order);
extract($st_flags,EXTR_PREFIX_ALL,'st');

$lpay = glbDBExt::getExtp('paymode_cn'); 
$ldev = glbDBExt::getExtp('logmode_cn');

?>{/block:minit}

{block:mbdstart}{:clear}{/block:mbdstart}
{block:mbdend}{:clear}{/block:mbdend}

{block:mact}

<div class="ocar_logo">
  <div class="logo">
    <p>&nbsp;  </p>
  </div>
  <div class="title">
    <h3>{show(sys_name)}</h3>
    <h1>{=$title}：{=$ordid} ({stime($order['atime'],min)})</h1>
  </div>
  <div class="cleft"></div>
</div>

<div class="ocar_invoce">
<div class="table-responsive">
    <form id='fmocar' name='fmocar' method="post" action="?{=$this->mkv}&ordid={=$ordid}&enc={=$enc}">
    <input name="act" type="hidden" value="oedit">

    {if empty($st_uexp) }
    <table border="1" class="ocar_items">
        <tr>
            <th nowrap="nowrap" class="tr">No.</th>
            <th nowrap="nowrap">商品名称</th>
            <th nowrap="nowrap" class="tr">价格</th>
            <th nowrap="nowrap"class="tr">数量</td>
            <th nowrap="nowrap" class="tr">重量</th>
            <th nowrap="nowrap" class="tr">金额</th>
            <th nowrap="nowrap" class="tc">添加时间</th>
        </tr>
        <?php foreach($list['data'] as $v){ ?>
        <tr>
            <td class="tr">{=$v[i]}</td>
            <td><a href="{surl("cargo.$v[pid]")}" target="detail">{=$v[title]}</a></td>
            <td class="tr">{=$v[ordprice]}</td>
            <td class="tr">{=$v[ordcnt]}</td>
            <td class="tr">{=$v[ordweight]}</td>
            <td class="tr">{=$v[ifee]}</td>
            <td nowrap="nowrap" class="tc">{stime($v['atime'],dm)}</td>
        </tr>
        <?php } $v=$list['sum']; $ocar_items=count($list['data']); ?>
        <tr>
            <td class="tr">-</td>
            <td>（合计）</td>
            <td class="tr">&nbsp;</td>
            <td class="tr">{=$v[acnt]}</td>
            <td class="tr">{=$v[aweight]}</td>
            <td class="tr">{=$v[afee]}</td>
            <td class="tc">&nbsp;</td>
        </tr>
        <tr>
            <td class="tc">&nbsp;</td>
            <td>运费</td>
            <td colspan="3">&nbsp;</td>
            <td class="tr"><input {=$st_feeship} id="feeship" name="fm[feeship]" type="input" value="{=$order[feeship]}" reg="n+d:" tip="运费" class="w80 tr" /></td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td class="tc">&nbsp;</td>
            <td>折扣（-）</td>
            <td colspan="3">&nbsp;</td>
            <td class="tr"><input {=$st_feedis} id="feedis" name="fm[feedis]" type="input" value="{=$order[feedis]}" reg="n+d:" tip="折扣" class="w80 tr" /></td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td class="tc">&nbsp;</td>
            <td>应付款</td>
            <td colspan="3">&nbsp;</td>
            <td class="tr"><input {=$st_feetotle} id="feetotle" name="fm[feetotle]" type="input" value="{=$order[feetotle]}" reg="n+d:" tip="应付款" class="w80 tr" /></td>
            <td>&nbsp;</td>
        </tr>
        
    </table>
    {/if}

    <table border="1" class="ocar_items">
        <tr>

            <th width="6%" class="tc">No.</th>
            <th width="22%">状态信息</th>
            <th>详情</th>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>订单号</td>
            <td class='tl'>
                <span class="right">状态：
                <select {=$st_ordstat} id='fm_ordstat' name="fm[ordstat]" class="w120"><?php echo basElm::setOption("corder.ordstat",$order['ordstat'],'-请选择-'); ?></select>
                </span>
                <input disabled id='fm[title]' name='fm[title]' value='{=$order['title']}' maxlength='24'  reg='nul:fix:xid'  tip='标题2-60字符' class="text w180" readonly />
                </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>支付方式</td>
            <td class='tl'>
            <span class="right">状态：<span id='st_ordpay'>{sopt($ordstat,corder.ordstat,0,$null)}</span></span>
            <select {=$st_ordpay} name="fm[ordpay]" class="w180"><?php echo basElm::setOption($lpay,$order['ordpay'],'-支付方式-'); ?></select>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>货运方式</td>
            <td class='tl'>
            <span class="right">{=$_cbase[ucfg][city]} → {sopt($ordshto,china,0,$null)}</span>
            <select {=$st_ordship} name="fm[ordship]" class="w180"><?php echo basElm::setOption($ldev,$order['ordship'],'-快递公司-'); ?></select>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>跟踪Url</td>
            <td class='tl'>
            <span class="right">
            <a {if !empty($order['tradeurl'])}href="{=$order['tradeurl']}"{/if} target="_blank">号码</a>：<input {=$st_trakeno} id='fm[trakeno]' name='fm[trakeno]' type='text' value='{=$order['trakeno']}'  maxlength='24' class="txt w150" />
            </span>
            <input {=$st_tradeurl} id='fm[tradeurl]' name='fm[tradeurl]' type='text' value='{=$order['tradeurl']}' maxlength='255' class="txt w240" /></td>
        </tr>
    </table>

    {if empty($st_uexp) }
    <table border="1" class="ocar_items">
        <tr>
            <th width="6%" class="tc">No.</th>
            <th width="22%">收货信息</th>
            <th>详情</th>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>会员名称</td>
            <td class='tl'><input {=$st_uinfos} name='fm[mname]' type='text' class='txt' id='fm[mname]' value="{=$order[mname]}"  maxlength='24'  reg='str:2-24'  tip='2-24字符'  />
                &nbsp;电话
                <input {=$st_uinfos} name='fm[mtel]' type='text' class='txt' id='fm[mtel]' value="{=$order[mtel]}"  maxlength='24'  reg='fix:tel'  tip='2-24字符'  /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>聊天号</td>
            <td class='tl'><input {=$st_uinfos} id='fm[miuid]' name='fm[miuid]' type='text' value='{=$order[miuid]}' class='txt'  maxlength='120'  reg='nul:str:5-120'  tip='聊天号:QQ,MSN等'  />
                &nbsp;邮件
                <input {=$st_uinfos} id='fm[memail]' name='fm[memail]' type='text' value="{=$order[memail]}" class='txt'  maxlength='255'  reg='nul:fix:email'  tip='如:peace@domain.com'  /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>收货地址</td>
            <td class='tl'><input {=$st_uinfos} id='fm[maddr]' name='fm[maddr]' type='text' value="{=$order[maddr]}" maxlength='120' reg='nul:str:5-120'  tip='详细地址' class="txt w450" /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>送货要求</td>
            <td>
            <textarea {=$st_uinfos} id="fm[detail]" name="fm[detail]" rows="2" class="w450" reg='str:10-150'>{=$order[detail]}</textarea>
            </td>
        </tr>

    </table>
    <table border="1" class="ocar_items">
        <tr>
            <td width="15%" class="tc"><input {=$st_btnedit} type="submit" value="+ 保存修改"></td>
            <td width="15%" class="tc"><input {=$st_btndel} type="button" value="- 删除订单" onClick="urlConfirm('?{=$this->mkv}&ordid={=$ordid}&enc={=$enc}&act=odel','确认删除?')"></td>
            <td width="5%" class="">&nbsp;</td>
            <td width="12%" class="tc"><input type="button" value="回首页" onclick="urlConfirm('{surl(0)}','go_url')"></td>
            <td width="12%" class="tc"><input type="button" value="去打印" onclick="urlConfirm('?{=$this->mkv}&ordid={=$ordid}&enc={=$enc}&act=print','go_url')"></td>
            <td>&nbsp;</td>
            <td width="15%" class="tc"><input {=$st_btnpay} type="button" value="¥ 现在支付" onClick="ocar_pay()"></td>
        </tr>
    </table>
    {/if}

    </form>
</div>

<?php
$opay = exvOpay::getParas($order,'Webchn');
$opay['showurl'] = surl(0,'',1)."?$this->mkv&ordid=$ordid&enc=$enc"; 
$oadm = @$opay['a']; unset($opay['a']);
?>
<form id='fmopay' name='fmopay' method="post" action="{=PATH_ROOT}/a3rd/{=$oadm[apidir]}/uapi.php" target="_blank">
<?php foreach($opay as $k=>$v){ ?>
<input name="{=$k}" type="hidden" value="{=$v}">
<?php } ?>
</form>
<script>
function ocar_pay(){
    checkPaied();
    $('#fmopay').submit();
}
function checkPaied(){ 
    var url = '{=PATH_ROOT}/plus/api/ocar.php?act=ordstat&ordid={=$ordid}';
    $.getScript(url, function(){        
        if(typeof(data)=='undefined'){
            alert('服务器返回格式错误。');
            return '';
        }else if(data=='YES'){
            window.location.reload();
            /*$('#st_ordpay').html('已支付');
            $('#fm_ordstat').val('paid');*/
            return '';
        }
        setTimeout("checkPaied()",2000);
    });    
}

</script>

</div>

<?php

$_cbase['tpl']['tplpend'] = 'null';
$_cbase['tpl']['tplpext'] = $act=='print' ? "window.print();" : '';

?>

{/block:mact}
