<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
</head>
<body class="">
<div class="layui-fluid">
    <form class="layui-form" action="" lay-filter="component-form-group" id="orderForm">
        <div class="">
            <input type="hidden" name="id" id="orderId" value="${order.id}">
            <input type="hidden" id="logisticName" name="logisticName" value="${order.logisticsName}">
            <input type="hidden" id="logisticNo" name="logisticNo" value="${order.logisticsNo}">
            <div class="layui-card-header pt-10">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label>服务类型：${order.serviceType}</label>
                </div>
                <div class="layui-col-lg2 layui-col-sm3 layui-form" lay-filter="component-form-element">
                    <label >下单时间：<fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm"/></label>
                </div>

                <div class="layui-col-lg2 layui-col-sm3" style="position: relative">
                    <label >冻结金额：${order.frozenCost}</label>
                </div>
                <div  class="layui-col-lg2 layui-col-sm3  f-r">
                    <button  type="button" class="layui-btn layui-btn-primary layui-btn-sm submitBtn">保存</button>
                    <button type="button"  class="layui-btn layui-btn-primary layui-btn-sm closeBtn">取消</button>
                </div>

            </div>
           <%-- <fieldset class="layui-elem-field " >--%>
                <div class="site-demo-button siteOrderButten">
                    <button type="button" class="layui-btn <c:if test="${type ne 2}">layui-btn-primary</c:if> ">基本信息</button>
                    <button type="button" class="layui-btn <c:if test="${type eq 2}">layui-btn-primary</c:if> ">过程信息</button>
                 <%--   <button type="button" class="layui-btn ">物流信息</button>--%>
                </div>
          <%--  </fieldset>--%>
        </div>
        <div class="layui-card jibenxinxi">
            <div class="layui-card-header pt-10">
                <h1 class="title">用户信息</h1>
            </div>
            <div class="layui-card-body">
                <div class="layui-form" action="" lay-filter="component-form-element">
                    <div class="layui-row layui-col-space12 layui-form-item">
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label"><i class="mark">*</i>用户姓名：</label>
                            <div class="layui-input-block">
                                <input type="text" name="customerName" id="customerName" lay-verify="required" placeholder=""
                                       autocomplete="off" class="layui-input" value="${order.customerName}">
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3 layui-form" lay-filter="component-form-element">
                            <label class="layui-form-label">性别：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="customerSex" value="1" <c:if test="${order.customerSex eq 1}">checked</c:if> title="先生">
                                <input type="radio" name="customerSex" value="2" <c:if test="${order.customerSex eq 2}">checked</c:if>  title="女士" >
                            </div>
                        </div>

                        <div class="layui-col-lg2 layui-col-sm3" style="position: relative">
                            <label class="layui-form-label"><i class="mark">*</i>联系方式1：</label>
                            <div class="layui-input-block pr-30">
                                <input type="text" name="customerMobile" lay-verify="required|phone" class="layui-input" value="${order.customerMobile}">
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label">联系方式2：</label>
                            <div class="layui-input-block">
                                <input type="text" name="customerTelephone" id="customerTelephone"  placeholder=""
                                       autocomplete="off" class="layui-input " value="${order.customerTelephone}">
                            </div>
                        </div>
                        <div class="layui-col-lg8">
                            <div class="layui-col-xs12 layui-form-item">
                                <label class="layui-form-label"><i class="mark">*</i>用户地址：</label>
                                <div class="layui-input-block">
                                    <div class="layui-col-lg2 layui-col-sm3 pr-30">
                                        <select name="province" id="province" lay-verify="required" lay-filter="province" lay-search >
                                            <option value=""></option>
                                            <c:forEach items="${pros}" var="pro">
                                                <option value="${pro.columns.ProvinceName}" <c:if test="${order.province eq pro.columns.ProvinceName}">selected</c:if> title="${pro.columns.ProvinceID }">${pro.columns.ProvinceName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="layui-col-lg2 layui-col-sm3 pr-30">
                                        <select name="city" id="city" lay-verify="required" lay-filter="city" lay-search >
                                            <option value="">请选择</option>
                                            <c:forEach items="${faccitys}" var="city">
                                                <option value="${city.columns.CityName}" <c:if test="${order.city eq city.columns.CityName}">selected</c:if> title="${city.columns.CityID}">${city.columns.CityName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="layui-col-lg2 layui-col-sm3 pr-30">
                                        <select name="area" id="area" lay-verify="required" lay-filter="aihao" lay-search >
                                            <option value="">请选择</option>
                                            <c:forEach items="${areas}" var="area">
                                                <option value="${area.columns.DistrictName}" <c:if test="${order.area eq area.columns.DistrictName}">selected</c:if> title="${area.columns.DistrictID}">${area.columns.DistrictName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="layui-col-lg6 layui-col-sm3">
                                        <input type="text" name="customerAddress" lay-verify="required" placeholder=""
                                               autocomplete="off" class="layui-input layui-col-lg2 " value="${order.customerAddress}">
                                    </div>
                                </div>

                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card jibenxinxi">
            <div class="layui-card-header pt-10">
                <h1 class="title">服务信息</h1>
            </div>
            <div class="layui-card-body">
                <div class="layui-form" action="" lay-filter="component-form-element">
                    <div class="layui-row layui-col-space12 layui-form-item">

                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label"><i class="mark">*</i>产品品牌：</label>
                            <div class="layui-input-block">
                                <select name="applianceBrand" id="applianceBrand" lay-verify="required" disabled>
                                       <c:forEach items="${brands}" var="brandList">
                                        <option value="${brandList.columns.brand}" <c:if test="${brandList.columns.brand == order.applianceBrand}">selected</c:if>>${brandList.columns.brand}</option>
                                       </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label"><i class="mark">*</i>产品品类：</label>
                            <div class="layui-input-block">
                                <select name="applianceCategory" id="applianceCategory" lay-verify="required" disabled>
                                        <c:forEach items="${categorys}" var="categoryList">
                                            <option value="${categoryList.columns.category}" <c:if test="${categoryList.columns.category == order.applianceCategory}">selected</c:if>>${categoryList.columns.category}</option>
                                        </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label">产品型号：</label>
                            <div class="layui-input-block">
                                <select name="applianceModel" id="applianceModel" lay-verify="required" lay-search>
                                    <option value="">请选择</option>
                                        <c:forEach items="${models}" var="modelList">
                                            <option value="${modelList}" <c:if test="${modelList == order.applianceModel}">selected</c:if>>${modelList}</option>
                                        </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label">产品数量：</label>
                            <div class="layui-input-block">
                                <input type="text" name="applianceNum" id="applianceNum"  placeholder=""
                                       autocomplete="off" class="layui-input layui-bg-gray" readonly value="${order.applianceNum}">
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label">机身条码：</label>
                            <div class="layui-input-block">
                                <input type="text" name="applianceBarcode"  placeholder=""
                                       autocomplete="off" class="layui-input " value="${order.applianceBarcode}">
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label">购买时间：</label>
                            <div class="layui-input-block">
                                <input type="text" name="applianceBuyTime" id="applianceBuyTime"   placeholder=""
                                       autocomplete="off" class="layui-input " value="<fmt:formatDate value="${order.applianceBuyTime}" pattern="yyyy-MM-dd" />">
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label">购买渠道：</label>
                            <div class="layui-input-block">
                                <select  name="pleaseReferMall"  lay-filter="aihao" id="pleaseReferMall" lay-search>
                                    <option value="">请选择</option>
                                    <c:forEach items="${mall}" var="mal">
                                        <option value="${mal.columns.mall_name}" <c:if test="${order.pleaseReferMall== mal.columns.mall_name}">selected</c:if>>${mal.columns.mall_name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg3 layui-col-sm3 layui-form" lay-filter="component-form-element">
                            <label class="layui-form-label"><i class="mark">*</i>保修类型：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="warrantyType" value="1" title="保内" disabled <c:if test="${order.warrantyType eq 1}">checked</c:if>>
                                <input type="radio" name="warrantyType" value="2" title="保外" disabled <c:if test="${order.warrantyType eq 2}">checked</c:if>>
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3">
                            <label class="layui-form-label"><i class="layui-icon vertical-tb"
                                                               style="font-size: 20px; color: red;">&#xe60b;</i>
                                工单加急：</label>
                            <div class="layui-input-block">
                                <select name="completeLimitLength"  lay-filter="completeLimitLength" class="layui-bg-gray" disabled>
                                    <option value="${order.completeLimitLength}" >${order.completeLimitLength}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3 lh-30">
                            <input type="hidden" name="completeExtendCost"  id="completeExtendCost" value="${order.completeExtendCost}">
                            加急费：<span class="red completeExtendCost">¥${order.completeExtendCost}</span>元
                        </div>
                        <div class="layui-col-xs12">
                            <label class="layui-form-label"><i class="red">*</i>故障描述：</label>
                            <div class="layui-input-block">
                                <textarea name="remarks" placeholder="" class="layui-textarea " lay-verify="required">${order.remarks}</textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="layui-card processInformation layui-hide">
        <ul class="layui-timeline guoChen">



        </ul>
    </div>
    <div class="layui-card over pl-10 logsticInfoNew layui-hide">
        <div class="layui-col-xs6 pr-20">
            <h1 class="title mt-10">寄件物流</h1>
            <div class="mt-5">
                <div class="layui-collapse" lay-accordion="">
                    <c:choose>
                        <c:when test="${order.fittingFlag eq '2'}">

                        </c:when>
                        <c:otherwise>
                            <div class="layui-colla-item">
                                <h2 class="layui-colla-title productInfo">${order.applianceBrand}${order.applianceCategory}</h2>
                                <div class="layui-colla-content">
                                    <ul class="layui-timeline logisticInfor" style="max-height: 200px;overflow-y: auto">
                                    </ul>
                                </div>
                            </div>
                        </c:otherwise>
                    </c:choose>
                    <c:choose>
                        <c:when test="${order.fittingFlag eq '2'}">
                            <div class="layui-colla-item">
                                <h2 class="layui-colla-title fitRefundInfo">已发备件</h2>
                                <div class="layui-colla-content">
                                    <ul class="layui-timeline logisticInfor" style="max-height: 200px;overflow-y: auto">

                                    </ul>
                                </div>
                            </div>
                        </c:when>
                        <c:otherwise>
                        </c:otherwise>
                    </c:choose>

                    <c:forEach items="${applyInfo}" var="info">
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title fitApplyInfo" data-logName="${info.columns.logistics_names}" data-logNumber="${info.columns.logistics_number}" >${info.columns.fitting_name}</h2>
                            <div class="layui-colla-content">
                                <ul class="layui-timeline logisticInfor" style="max-height: 200px;overflow-y: auto">

                                </ul>
                            </div>
                        </div>
                    </c:forEach>
                </div>

            </div>
        </div>
        <div class="layui-col-xs6 pr-20">
            <h1 class="title mt-10">返件物流</h1>
            <div class="mt-5">
                <div class="layui-collapse" lay-accordion="">
                    <c:forEach items="${rd}" var="rdList">
                        <c:choose>
                            <c:when test="${rdList.columns.fitting_name eq ''}">

                            </c:when>
                            <c:when test="${rdList.columns.fitting_name eq null}">

                            </c:when>
                            <c:otherwise>
                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title returnFactoryInfo" data-logName="${rdList.columns.logistics_names}" data-logNum="${rdList.columns.logistics_number}">${rdList.columns.fitting_name}</h2>
                                    <div class="layui-colla-content">
                                        <ul class="layui-timeline returnFactory" style="max-height: 200px;overflow-y: auto">

                                        </ul>
                                    </div>
                                </div>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-card">
        <div class="site-demo-button fuwufankuiorder">
            <c:if test="${order.status ne 1}">
                <button type="button" class="layui-btn layui-btn-primary" >服务反馈</button>
                <button type="button" class="layui-btn " >备件信息</button>
            </c:if>
            <c:if test="${order.status eq 1}"> <button type="button" class="layui-btn layui-btn-primary" disabled>备件信息</button></c:if>
        </div>
        <div class="layui-card-body  <c:if test="${order.status eq 1}">layui-hide</c:if> fuwufankui">
            <div class="layui-form" action="" lay-filter="component-form-element">
                <div class="layui-row layui-col-space12 layui-form-item">
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">工单状态：</label>
                        <div class="layui-input-block">
                            <c:if test="${order.status eq 1}"><input type="text"  class="layui-input layui-bg-gray layui-disabled" disabled value="待派工"></c:if>
                            <c:if test="${order.status eq 2}"><input type="text"  class="layui-input layui-bg-gray layui-disabled" disabled value="服务中"></c:if>
                            <c:if test="${order.status eq 3}"><input type="text"  class="layui-input layui-bg-gray layui-disabled" disabled value="待回访"></c:if>
                            <c:if test="${order.status eq 4}"><input type="text"  class="layui-input layui-bg-gray layui-disabled" disabled value="待结算"></c:if>
                            <c:if test="${order.status eq 5}"><input type="text"  class="layui-input layui-bg-gray layui-disabled" disabled value="已完成"></c:if>
                            <c:if test="${order.status eq 6}"><input type="text"  class="layui-input layui-bg-gray layui-disabled" disabled value="无效工单"></c:if>
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">服务商：</label>
                        <div class="layui-input-block">
                            <input type="text"  placeholder=""
                                   autocomplete="off" class="layui-input layui-bg-gray" value="${order.siteName}">
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">服务工程师：</label>
                        <div class="layui-input-block">
                            <input type="text"  placeholder=""
                                   autocomplete="off" class="layui-input layui-bg-gray" value="${order.employeName}">
                        </div>
                    </div>
                    <div class="layui-col-xs12">
                        <label class="layui-form-label">反馈内容：</label>
                        <div class="layui-input-block">
                            <c:forEach var="fbItems" items="${feedbackInfo.feedbackResults}">
                                <p class="processItem">
                                    <span class="time">${fbItems.feedbackTime} </span>
                                    <span>${fbItems.feedbackName }：${fbItems.feedbackResults }</span>
                                </p>
                            </c:forEach>
                        </div>
                    </div>
                    <div class="layui-col-xs12">
                        <label class="layui-form-label">过程图片：</label>
                        <div class="layui-input-block">
                            <c:forEach var="fbImgItems" items="${feedbackInfo.feedbackImgs}">
                                <c:if test="${not empty fbImgItems.fbImgPath }">
                                    <c:forEach var="fbImgItem" items="${fbImgItems.fbImgPath}">
                                        <div class="imgWrap1 f-l" id="img${da.index}">
                                            <div class="imgWrap text-c">
                                                <img src="${commonStaticImgPath}${fbImgItem}" class="w-80 h-80" style="width:150px;">
                                                <p class="hei">${fbImgItems.fbImgTime}</p>
                                            </div>
                                        </div>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <table class="layui-table <c:if test="${order.status ne 1}">layui-hide</c:if> beijianxinxi" style="table-layout:fixed;">
            <thead>
            <tr>
                <th width="10%">备件名称</th>
                <th width="10%">备件条码</th>
                <th width="15%">备件描述</th>
                <th width="10%">备件状态</th>
                <th width="10%">使用数量</th>
                <%--<th width="10%">是否返旧</th>--%>
                <th width="10%">有无返旧</th>
                <th width="10%">收货人</th>
                <th width="12%">联系方式</th>
                <th width="25%">收货地址</th>
            </tr>
            </thead>
            <tbody>


            </tbody>
        </table>


    </div>

</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/static/js/orderCommon.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'layedit', 'laydate'], function () {
        var $ = layui.$
            , admin = layui.admin
            , element = layui.element
            , form = layui.form
            ,laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#applianceBuyTime'
            ,trigger: 'click'
        });
        form.render(null, 'component-form-element');
        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        element.render('breadcrumb', 'breadcrumb');

        form.on('select(applianceBrand)', function(data){
            var brand = data.value
            CategoryOrder(brand)
        });
        form.on('select(applianceCategory)', function(data){
            var model=$(data.elem).find("option:selected").attr("title");
            $("#applianceModel").empty()
            if(isBlank(model)){
                $("#applianceCategory").append("<option value=''>请选择</option>");
                return "";
            }
            orderModel(model);
        });

        form.on('select(province)', function(data){
            var province = $(data.elem).find("option:selected").attr("title");
            provinceOrder(province);
        });
        form.on('select(city)', function(data){
            var city = $(data.elem).find("option:selected").attr("title");
            cityOrder(city);

        });

        $(".closeBtn").on('click',function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        })

        $(".submitBtn").on('click', function () {

            //验证不必填项的值格式
            var shuzi = /[0-9]*[1-9][0-9]*$/;
            var customerName = $("input[name=customerName]").val();//用户姓名
            if(isBlank(customerName)){
                layer.msg("请输入用户姓名!",{icon:2});
                return false
            }
            var customerMobile = $("input[name=customerMobile]").val();//联系方式1
            var customerSex = $('input[name="customerSex"]:checked').val();//用户性别
            var customerTelephone = $("input[name=customerTelephone]").val();//联系方式2
            var province = $("#province").find("option:selected").text();//省
            var city = $("#city").find("option:selected").text();//市
            var area = $("#area").find("option:selected").text();//区
            var applianceModel = $("select[name=applianceModel]").val();//型号
            var applianceBarcode = $("input[name=applianceBarcode]").val();//机身条码
            var applianceBuyTime = $("input[name=applianceBuyTime]").val();//购买时间
            var pleaseReferMall = $("#pleaseReferMall").find("option:selected").text();//购买渠道  1

            var remarks = $("textarea[name=remarks]").val();//故障描述
            var customerAddress = $("input[name=customerAddress]").val();//用户地址
            if (isBlank(customerMobile)) {
                layer.msg("请输入联系方式",{icon:2});
                return
            } else if (!isPhoneNo($.trim(customerMobile))) {
                layer.msg("联系方式格式不正确",{icon:2});
                return
            } else if (isBlank(province)) {
                layer.msg("请选择地址",{icon:2});
                return
            }else if (isBlank(city)) {
                layer.msg("请选择地址",{icon:2});
                return
            }else if (isBlank(area)) {
                layer.msg("请选择区县",{icon:2});
                return
            }else if (isBlank(customerAddress)) {
                layer.msg("请输入详细地址",{icon:2});
                return
            }

            if (isBlank(remarks)) {
                layer.msg("请输入故障描述",{icon:2});
                return
            }

            var applianceNum = $("#applianceNum").val();//产品数量
            if(!shuzi.test(applianceNum)){
                layer.msg("家电数量格式不正确!",{icon:2})
                return false
            }

            var orderId = "${order.id}";//工单id
            $.ajax({
                type:"POST",
                url:"${ctx}/order/updateOrder",
                data:{
                    id:orderId,
                    customerName:customerName,
                    customerMobile:customerMobile,
                    customerSex:customerSex,
                    customerTelephone:customerTelephone,
                    province:province,
                    city:city,
                    area:area,
                    applianceModel:applianceModel,
                    applianceBarcode:applianceBarcode,
                    applianceBuyTime:applianceBuyTime,
                    pleaseReferMall:pleaseReferMall,
                    remarks:remarks,
                    customerAddress:customerAddress
                },
                success:function(data){
                    console.log(data)
                    if(data.code=='200'){
                        layer.msg('编辑成功！', {icon:1,time:1000},function(){
                            window.location.reload();
                        });
                    }else if(data.code =='506'){
                        layer.msg("保存失败,请联系平台充值!", {icon: 2});
                    }else if(data.code =='506'){
                        layer.msg("保存失败,可用金额不足，请联系平台充值!", {icon: 2});
                    }else{
                        layer.msg("提交失败！", {icon: 2});
                    }
                },
                error:function(data){
                    console.log(data)
                }
            });

        });

        // 验证手机号
        function isPhoneNo(phone) {
            var tel = /(^1\d{10}$)|(^(\d{3,4}\-)?\d{5,9}$)/;
            return tel.test($.trim(phone));
        }

        function orderModel(model){
            if(isBlank(model)){
                return
            }
            var mode = model.split(",");
            var html ="<option value=''>请选择</option>";
            for(var i=0;i<mode.length;i++){
                var mod = $.trim(mode[i]);
                html =html+ '<option value="'+mod+'" >'+mod+'</option>';
            }
            $("#applianceModel").append(html);
            form.render('select');

        }

        function provinceOrder(province){
            $("#city").empty();
            $("#area").empty();
            if(isBlank(province)){
                $("#city").append("<option value=''>请选择</option>");
                return "";
            }
            $.ajax({
                type:"POST",
                url:"${ctx}/main/redirect/getCitysByProId",
                data:{
                    province:province
                },
                success:function(result){
                    if(result =="205"){
                        layer.msg("暂无数据!")
                        return
                    }
                    var html =" <option value=''>请选择</option>";
                    for(var i=0;i<result.length;i++){
                        var city = result[i];
                        html =html+ '<option value="'+city.columns.CityName+'" title="'+city.columns.CityID+'">'+city.columns.CityName+'</option>';
                    }
                    $("#city").append(html);
                    form.render('select');
                }
            });

        }

        function cityOrder(city,arean){
            $("#area").empty()
            if(isBlank(city)){
                $("#area").append("<option value=''>请选择</option>");
                return "";
            }
            $.ajax({
                type:"POST",
                url:"${ctx}/main/redirect/getAreaByCityId",
                data:{
                    city:city
                },
                success:function(result){
                    if(result =="205"){
                        layer.msg("暂无数据!")
                        return
                    }
                    var html ="<option value=''>请选择</option>";
                    for(var i=0;i<result.length;i++){
                        var area = result[i];
                        html =html+ '<option value="'+area.columns.DistrictName+'" >'+area.columns.DistrictName+'</option>';
                    }
                    $("#area").append(html);
                    if(!isBlank(arean)){
                        $("#area").val(arean)
                    }

                    form.render('select');
                }
            });

        }
    });
    var siteId = "${order.siteId}";
    layui.use(['jquery',], function(args){
        var $= layui.jquery;
        var aa = $('.siteOrderButten button');
        var orderId = $("#orderId").val();
        aa.click(function () {
            aa.removeClass("layui-btn-primary");
            $(this).addClass("layui-btn-primary");
            var index=aa.index(this);
           if(index == 1){
               //过程信息
               $(".processInformation").removeClass("layui-hide");
               $(".jibenxinxi").addClass("layui-hide");
               $(".logsticInfoNew").addClass("layui-hide");
               var html = $.trim($(".layui-timeline").html()) ;
               if(isBlank(html)){
                   guocheng(orderId);
               }

           }else if(index == 2){
               //物流信息
               $(".processInformation").addClass("layui-hide");
               $(".jibenxinxi").addClass("layui-hide");
               $(".logsticInfoNew").removeClass("layui-hide");//物流信息
           }else{
               $(".jibenxinxi").removeClass("layui-hide");
               $(".processInformation").addClass("layui-hide");
               $(".logsticInfoNew").addClass("layui-hide");
           }
        })


        //却换服务反馈按钮
        var fuwu = $('.fuwufankuiorder button');
        fuwu.click(function () {
            fuwu.removeClass("layui-btn-primary");
            $(this).addClass("layui-btn-primary");
            var index=fuwu.index(this);
           if(index == 1){
               //备件信息
               $(".beijianxinxi").removeClass("layui-hide");
               $(".fuwufankui").addClass("layui-hide");
               orderFitting(orderId);
           }else{
               $(".fuwufankui").removeClass("layui-hide");
               $(".beijianxinxi").addClass("layui-hide");
           }
        })

       if("${type}" == 2){
           $(".processInformation").removeClass("layui-hide");
           $(".jibenxinxi").addClass("layui-hide");
           $(".logsticInfoNew").addClass("layui-hide");
           guocheng(orderId)
       }


       if(${order.status == 1}){
           orderFitting(orderId);
       }
       //过程信息
        function guocheng(orderId){

            $.ajax({
                type:"POST",
                url:"${ctx}/order/getOrderDetail",
                data:{
                    orderId:orderId
                },
                success:function(data){
                    if(data!=null){
                        var deatil ="";
                        for(var i =0;i<data.length;i++){
                            deatil += '<li class="layui-timeline-item"><i class="layui-icon layui-timeline-axis"></i>';
                            deatil += '<div class="layui-timeline-content layui-text">';
                            deatil +=' <h4 class="layui-timeline-title">'+data[i].d+'</h4> <p>';
                            deatil += data[i].c+ '</p> </div> </li>';
                        }
                        $(".guoChen").html(deatil);
                    }else{
                        layer.msg("数据有误！", {icon: 2});
                    }
                }
            });
        }

        //查看物流信息
        $(".productInfo").click(function(){
            var logisticName = $("#logisticName").val();
            var logisticNo = $("#logisticNo").val();
            var orderId = $("#orderId").val();
            addLogisticInfo(logisticName,logisticNo,orderId);
        })

        //查看已发备件信息
        $(".fitRefundInfo").click(function(){
            var logisticName = $("#logisticName").val();
            var logisticNo = $("#logisticNo").val();
            var orderId = $("#orderId").val();
            addLogisticInfo(logisticName,logisticNo,orderId);
        })

        //查看添加备件申请获取的物流信息
        $(".fitApplyInfo").click(function(){
            var logisticName = $(this).attr("data-logName");
            var logisticNo = $(this).attr("data-logNumber");
            var orderId = $("#orderId").val();
            addLogisticInfo(logisticName,logisticNo,orderId);
        })

        //查看新建，旧件返厂物流信息
        $(".returnFactoryInfo").click(function(){
            var logisticName = $(this).attr("data-logName");
            var logisticNo = $(this).attr("data-logNum");
            var orderId = $("#orderId").val();
            $.ajax({
                type:"POST",
                url:"${ctx}/main/order/logisticsDetail",
                data:{
                    orderId:orderId,
                    logisticName:logisticName,
                    logisticNo:logisticNo
                },
                success:function(data){
                    if(data!=null){
                        var deatil ="";
                        for(var i =0;i<data.length;i++){
                            deatil += '<li class="layui-timeline-item">';
                            deatil += '<i class="layui-icon layui-timeline-axis"></i>';
                            deatil += '<div class="layui-timeline-content layui-text">';
                            deatil += '<div class="layui-timeline-title">'+data[i].AcceptTime+" "+data[i].AcceptStation+'</div>';
                            deatil += '</div>';
                            deatil += '</li>';
                        }
                        $(".returnFactory").html(deatil);
                    }else{
                        layer.msg("数据有误！", {icon: 2});
                    }

                }
            })
        })

        function addLogisticInfo(logisticName,logisticNo,orderId){
            $(".logisticInfor").empty()
            $.ajax({
                type:"POST",
                url:"${ctx}/main/order/logisticsDetail",
                data:{
                    orderId:orderId,
                    logisticName:logisticName,
                    logisticNo:logisticNo
                },
                success:function(data){
                    if(data!=null){
                        var deatil ="";
                        for(var i =0;i<data.length;i++){
                            deatil += '<li class="layui-timeline-item">';
                            deatil += '<i class="layui-icon layui-timeline-axis"></i>';
                            deatil += '<div class="layui-timeline-content layui-text">';
                            deatil += '<div class="layui-timeline-title">'+data[i].AcceptTime+" "+data[i].AcceptStation+'</div>';
                            deatil += '</div>';
                            deatil += '</li>';
                        }
                        $(".logisticInfor").html(deatil);
                    }else{
                        layer.msg("数据有误！", {icon: 2});
                    }

                }
            })
        }

        function orderFitting(orderId){
            $("tbody").empty();
            $.ajax({
                type:"POST",
                url:"${ctx}/order/getOrderFittingByorderId",
                data:{
                    orderId:orderId,
                    siteId:siteId
                },
                success:function(data){
                    if(data!=null){
                        var deatil ="";
                        for(var i =0;i<data.length;i++){
                            var status = data[i].columns.status;
                            var stname ="";
                            if(status == 1){
                                stname = "待发货";
                            }else if(status == 2){
                                stname = "备件在途";
                            }else if(status == 3){
                                stname = "已完成";
                            }
                            var fitting_code= data[i].columns.fitting_code;
                            if(isBlank(fitting_code)){
                                fitting_code="";
                            }
                            deatil +=' <tr>';
                            deatil += ' <td style="overflow:hidden;" class="text-over" title="'+data[i].columns.fitting_name+'">' + data[i].columns.fitting_name + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + fitting_code + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + data[i].columns.apply_marks + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + stname + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + data[i].columns.apply_num + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + returOldFit(data[i].columns.old_fitting_flag) + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + returnedOldFit(data[i].columns.return_fitting) + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + data[i].columns.delivery_name + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over">' + data[i].columns.delivery_mobile + '</td>';
                            deatil += ' <td style="overflow:hidden;" class="text-over" title="'+data[i].columns.delivery_address+'">' + data[i].columns.delivery_address + '</td>';
                            deatil +=' </tr>';
                        }
                        $("tbody").html(deatil);
                    }else{
                       // layer.msg("数据有误！", {icon: 2});
                    }
                }
            });
        }
    });


    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
</script>
</body>
</html>