<%@ 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"  onsubmit="return false" >
        <div class="layui-card">
            <div class="layui-card-header pt-10">
                <h1 class="title">智能识别 <span class="tips">（粘贴整段信息到下面文本框，自动识别用户姓名、性别、联系方式1、用户地址、产品品牌、产品品类、产品型号、购买时间、购买渠道、保修类型、备注）</span>
                </h1>
            </div>
            <div class="layui-card-body">
                <div class="over">
                    <p class="f-l fs-12">
                        例：王依依，女士，18300000000，安徽省，合肥市，经济技术开发区，蔚蓝商务港A座512，美的，空调，DEDED，2019-04-01，京东，保内，请尽快安排安装</p>
                    <button type="button" class="layui-btn f-r distinguish">识别</button>
                </div>

                <textarea id="descDistinguish" placeholder="请输入内容" class="layui-textarea mt-10"></textarea>

            </div>

        </div>
        <div class="layui-card">
            <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" >
                            </div>
                        </div>
                        <div class="layui-col-lg3 layui-col-sm3 layui-col-xs12 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" title="先生">
                                <input type="radio" name="customerSex" value="2" 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|selfPhoneVer" class="layui-input">
                            </div>
                            <button type="button" class="layui-btn f-r chamobi" style="position:absolute;top:2px;right: 0; padding: 0 5px;"><i class="layui-icon fs-16">&#xe615;</i></button>
                        </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">
                            </div>
                        </div>
                        <div class="layui-col-lg9">
                            <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}" 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>

                                        </select>
                                    </div>
                                    <div class="layui-col-lg2 layui-col-sm3 pr-30">
                                        <select name="area" id="area" lay-verify="required" lay-filter="area" lay-search>
                                            <option value="">请选择</option>
                                        </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">
                                    </div>
                                </div>

                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <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" lay-filter="applianceBrand" lay-search>
                                    <option value="">请选择</option>
                                    <c:forEach var="jia" items="${product}">
                                        <option value="${jia.columns.brand}">${jia.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" lay-filter="applianceCategory" lay-search>
                                    <option value="">请选择</option>

                                </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-search lay-filter="applianceModel">
                                    <option value="">请选择</option>

                                </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">
                                <input type="text" name="applianceNum" id="applianceNum" lay-verify="required|amount"  placeholder="" value="1"
                                       autocomplete="off" class="layui-input">
                            </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">
                            </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">
                            </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="pleaseReferMall" lay-search>
                                    <option value=""></option>
                                    <c:forEach items="${mall}" var="mal">
                                        <option value="${mal.columns.mall_name}" >${mal.columns.mall_name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg3 layui-col-sm4 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="保内" checked>
                                <input type="radio" name="warrantyType" value="2" title="保外" >
                            </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" lay-search>
                                    <option value="">请选择</option>
                                    <c:forEach var="jia" items="${jiajis}">
                                        <option value="${jia.columns.complete_limit_length}" title="${jia.columns.complete_extend_cost}">${jia.columns.complete_limit_length} 小时</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm3 lh-30">
                            <input type="hidden" name="completeExtendCost"  id="completeExtendCost" value="0">
                            加急费：<span class="red completeExtendCost">¥0.00</span>元
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-col-sm4">
                                <label class="layui-form-label w-120"><i class="red">*</i>是否已发配件：</label>
                                <div class="layui-input-block ml-120">
                                    <input type="radio" name="fittingFlag" lay-filter="yf" value="0" title="否" checked>
                                    <input type="radio" name="fittingFlag" lay-filter="yf" value="2" title="是">
                                </div>
                            </div>
                            <div class="layui-col-lg12 sureSend layui-hide">
                                <div class="layui-col-lg2 layui-col-sm3 mr-20">
                                    <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="logisticsName" id="logisticsName">
                                            <option value="">请选择</option>
                                            <c:forEach var="logis" items="${logistics}">
                                                <option value="${logis}">${logis}</option>
                                            </c:forEach>
                                            <%--<option value="中通快递" >中通快递</option>
                                            <option value="顺丰速运">顺丰速运</option>
                                            <option value="EMS">EMS</option>
                                            <option value="申通快递">申通快递</option>
                                            <option value="圆通快递">圆通快递</option>
                                            <option value="韵达快递">韵达快递</option>
                                            <option value="百世汇通快递">百世汇通快递</option>
                                            <option value="天天快递">天天快递</option>
                                            <option value="德邦物流">德邦物流</option>
                                            <option value="全一快递">全一快递</option>
                                            <option value="全峰快递">全峰快递</option>
                                            <option value="盛辉物流">盛辉物流</option>
                                            <option value="中铁快运">中铁快运</option>--%>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-lg2 layui-col-sm2">
                                    <div class="layui-input-block ml-0">
                                        <input type="text" name="logisticsNo" id="logisticsNo" placeholder=""
                                               autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                               <%-- <div class="layui-col-lg3">
                                    <label class="layui-form-label w-120">是否返旧：</label>
                                    <div class="layui-input-block ml-120">
                                        <input type="radio" name="oldFittingFlag" lay-filter="fj" value="0" title="否" checked>
                                        <input type="radio" name="oldFittingFlag" lay-filter="fj" value="1" title="是">
                                    </div>
                                </div>--%>
                                <div class="layui-col-lg3 layui-col-sm3">
                                    <button type="button" class="layui-btn fittingUse">备件使用</button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 pl-100" id="fittingApply">

                        </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 remark" lay-verify="required"></textarea>
                            </div>
                        </div>
                        <div class="layui-col-xs12 text-c mt-20">
                            <input type="hidden" name="numb" value="${type}">
                            <input type="hidden" name="serviceType" value="${service_type}">
                            <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1" id="tijiaoBtn">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPlugin}/static/h-ui.admin/js/H-ui.admin.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'layedit', 'laydate','jquery'], function () {
        var $ = layui.$
            , admin = layui.admin
            , element = layui.element
            , form = layui.form
            ,laydate = layui.laydate
            , $= layui.jquery;
        //日期
        laydate.render({
            elem: '#applianceBuyTime'
        });
        form.render(null, 'component-form-element');
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , amount: [
                /^\+?[1-9][0-9]*$/
                , '请输入正整数'
            ]
            , selfPhoneVer: [
                /(^1\d{10}$)|(^(\d{3,4}\-)?\d{5,9}$)/
                , '请输入正确的联系方式'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });
        element.render('breadcrumb', 'breadcrumb');

        form.on('select(applianceBrand)', function(data){
            var brand = data.value
            $("#applianceCategory").empty()
            $("#applianceModel").empty()
            if(isBlank(brand)){
                $("#applianceCategory").append("<option value=''>请选择</option>");
                return "";
            }
            $.ajax({
                type:"POST",
                url:"${ctx}/order/getCategoryByBrandname",
                data:{
                    brand:brand
                },
                success:function(result){
                    if(result =="205"){
                        layer.msg("暂无数据!")
                        return
                    }
                    var html ="<option value=''>请选择</option>";
                    for(var i=0;i<result.length;i++){
                        var cate = result[i];
                        html =html+ '<option value="'+cate.columns.category+'" title="'+cate.columns.model+'">'+cate.columns.category+'</option>';
                    }
                    $("#applianceCategory").append(html);
                    form.render('select');
                }
            });
        });
        form.on('select(applianceCategory)', function(data){
            var model=$(data.elem).find("option:selected").attr("title");
            $("#applianceModel").empty()
            if(isBlank(model)){
                $("#applianceModel").append("<option value=''>请选择</option>");
                return "";
            }
            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');

        });
        form.on('select(completeLimitLength)', function(data){
            var model=$(data.elem).find("option:selected").attr("title");
            if(isBlank(model)){
                $(".completeExtendCost").html("¥0.00");
                $("#completeExtendCost").val(0);
            }else{
                $("#completeExtendCost").val(model);
                $(".completeExtendCost").html("¥"+model);
            }
        });
        form.on('select(province)', function(data){
            var province = $(data.elem).find("option:selected").attr("title");
            $("#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');
                }
            });

        });
        form.on('select(city)', function(data){
            var city = $(data.elem).find("option:selected").attr("title");
            $("#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);
                    form.render('select');
                }
            });

        });
        var checkOrder = false;
        form.on('submit(component-form-demo1)', function (data) {
            $("#tijiaoBtn").attr("disabled","true"); //改变提交按钮上的文字并将按钮设置为不可点击
            if(checkOrder){
                return false;
            }
            //验证不必填项的值格式
           // var shuzi = /[0-9]*[1-9][0-9]*$/;
            var shuzi = /^[1-9]\d*$/;
            var applianceNum = data.field.applianceNum;

                if(!shuzi.test(applianceNum)){
                    layer.msg("家电数量格式不正确!",{icon:2});
                    return false;
                }

            var val=$('input:radio[name="fittingFlag"]:checked').val();
               if(val==2){
                //已发配件需要填写物流信息和备件信息
                    var logisticsName = $("#logisticsName").val();
                    var logisticsNo = $("#logisticsNo").val();
                    if(isBlank(logisticsName) || isBlank(logisticsNo)){
                        layer.msg("请选择物流名称并填写物流单号",{icon:2})
                        return false
                    }
                //获取备件信息
                   var dataDetail = {};
                   var i=1;
                    $(".fitting_name").each(function(){
                        var entity = {}
                    var fitting_name = $(this).val()
                    var fitting_code = $(this).prev('input').val()
                    var apply_num = $(this).next('input').val()
                        entity.fitting_name = fitting_name;
                        entity.fitting_code = fitting_code;
                        entity.apply_num = apply_num;
                        dataDetail[i] = entity;
                        i++;
                    })
                   if(i==1){
                       layer.msg("请添加备件信息",{icon:2})
                       return false
                   }
               }
            if(isBlank($("#province").val())){
                layer.msg("请选择地址",{icon:2})
                return false
            }
            if(isBlank($("#city").val())){
                layer.msg("请选择地址",{icon:2})
                return false
            }
            if(isBlank($("#area").val())){
                layer.msg("请选择地址",{icon:2})
                return false
            }
            if(isBlank($("#applianceBrand").val())){
                layer.msg("请选择品牌",{icon:2})
                return false
            }
            if(isBlank($("#applianceCategory").val())){
                layer.msg("请选择品类",{icon:2})
                return false
            }
            var articleFrom = data.field;
               articleFrom.dataDetail =JSON.stringify(dataDetail);
            checkOrder = true;
            $.ajax({
                type:"POST",
                url:"${ctx}/order/saveOrder",
                data:JSON.stringify(articleFrom),
                contentType:"application/json; charset=utf-8",
                success:function(data){
                    checkOrder = false;
                    $("#tijiao").removeAttr("disabled");
                    if(data.code=='200'){
                        layer.msg('提交成功！', {icon:1,time:1000},function(){
                            window.location.href="${ctx}/order/getcleanOrder?type=W";
                        });
                    }else if(data.code =='506'){
                        layer.msg("保存失败,请联系平台充值!", {icon: 2});
                    }else if(data.code =='507'){
                        layer.msg("保存失败,可用金额不足，请联系平台充值!", {icon: 2});
                    }else{
                        layer.msg("保存失败", {icon: 2});
                    }
                }
            });

            return false;
        });

        $(document).on('click','.chamobi',function(){
            var mobile =  $("input[name='customerMobile']").val();
            if(isBlank(mobile)){
                layer.msg("请输入手机号",{icon:2})
                return
            }
            $.ajax({
                type:"POST",
                url:"${ctx}/order/getOrderByMobile",
                data:{
                    mobile:mobile
                },
                success:function(result){
                    if(result =="205"){
                        layer.msg("数据有误!",{icon:2})
                        return
                    }
                    if(isBlank(result)){
                        layer.msg("查无数据")
                        return
                    }
                    var province =result.columns.province;
                    var city =result.columns.city;
                    var psdId =  $("#province option[value='"+province+"']").attr("title");
                    provinceOrder(psdId)
                    var appliance_brand = result.columns.appliance_brand;
                    CategoryOrder(appliance_brand,result.columns.appliance_category);
                    var modelNew = result.columns.appliance_model;
                    var val = result.columns.appliance_category;
                    setTimeout(function(){
                        var model = $("#applianceCategory option[value='" + val + "']").attr("title");
                        getModel(model,modelNew);
                        var cityId =  $("#city option[value='"+city+"']").attr("title");
                        cityOrder(cityId,result.columns.area);
                        $("#customerName").val(result.columns.customer_name)
                        $("input[name='customerMobile']").val(result.columns.customer_mobile)
                        $("#customerTelephone").val(result.columns.customer_telephone)
                        $("#province").val(province)
                        $("#city").val(city)
                        $("input[name='customerAddress']").val(result.columns.customer_address)
                        var customer_sex = result.columns.customer_sex;
                        $("input[name='customerSex']").eq(customer_sex-1).prop('checked','checked');
                        //$("input[name='customerSex']").eq(customer_sex-1).prop('checked','checked').next().find("i").addClass("layui-anim-scaleSpring").html('&#xe643;');//
                        form.render('radio');
                        form.render('select')
                    },100);



                }
            });
        });

        //识别
        $(document).on('click','.distinguish',function(){
            var descDistinguish = $("#descDistinguish").val();
            if(isBlank(descDistinguish)){
                layer.msg("请输入识别内容",{icon:2})
                return
            }
            var des = descDistinguish.split("，");
            var province;
            var city;
            var orderMo;
            var appliance_brand;
            var catrN;
            $.each(des,function(i,val){  //遍历二维数组
                if("0" == i){
                    $("#customerName").val(val)
                }else if("1" == i){
                    var customer_sex = 1;
                    if("女士" == val){
                        customer_sex = 2;
                    }
                    $("input[name='customerSex']").eq(customer_sex-1).prop('checked','checked');
                   // $("input[name='customerSex']").eq(customer_sex-1).prop('checked','checked').next().find("i").addClass("layui-anim-scaleSpring").html('&#xe643;');//
                    form.render('radio');
                }else if("2" == i){
                    $("input[name='customerMobile']").val(val)
                }else if("3" == i){
                    $("#province").val(val)
                    province = val;
                    var psdId =  $("#province option[value='"+province+"']").attr("title");
                    provinceOrder(psdId)
                } else if ("4" == i) {
                    $("#city").val(val)
                    city = val;
                    var cityId = $("#city option[value='" + city + "']").attr("title");
                    cityOrder(cityId);
                } else if ("5" == i) {
                    $("#area").val(val)
                    form.render('select');
                } else if("6" == i){  $("input[name='customerAddress']").val(val) }else if("7" == i){
                    appliance_brand = val;
                    $("#applianceBrand").val(val)
                }else if("8" == i){
                    CategoryOrder(appliance_brand,val)
                    catrN = val;
                }else if("9" == i){
                    var model = $("#applianceCategory option[value='" + $.trim(catrN) + "']").attr("title");
                    orderModel(model, val)
                }else if("10" == i){
                    $("#applianceBuyTime").val(val);
                }else if("11" == i){
                    $("input[name='pleaseReferMall']").val(val)
                }else if("12" == i){
                    var types = 1;
                    if("保外" == val){
                        types = 2;
                    }
                    $("input[name='warrantyType']").eq(types-1).prop('checked','checked');
                   // $("input[name='warrantyType']").eq(types-1).prop('checked','checked').next().find("i").addClass("layui-anim-scaleSpring").html('&#xe643;');//
                    form.render('radio');
                }else if("13" == i){
                    $(".remark").val(val);
                    $(".remark").text(val);
                }
            })

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



        $(document).on('click','.fittingUse',function(){
            var indess = layer.open({
                type : 2,
                title : '新增备件申请',
                content : '${ctx}/order/getFittingUse',
                maxmin : true,
                area : [ '650px', '498px' ],
                btn : [ '确定', '取消' ],
                yes : function(index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index], submitID = 'LAY-user-front-submit_add', submit = layero.find('iframe').contents().find(
                        '#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
                        var field = data.field; //获取提交的字段
                        var child = layero.find('iframe').contents();
                        var html="";
                        child.find("#detailSet").find("tr").each(function(){
                            var apply_num = $(this).find("input[name='apply_num']").val();
                            var fitting_code = $(this).find("input[name='fitting_code']").val();
                            var fitting_name = $(this).find("input[name='fitting_name']").val();
                            html += '<div class="mr-20 f-l">';
                            html += '<input type="hidden" class="fitting_code" value="'+fitting_code+'"/>';
                            html += '<input type="hidden" class="fitting_name" value="'+fitting_name+'"/>';
                            html += '<input type="hidden" class="apply_num" value="'+apply_num+'"/>';
                            html += ' <span>'+fitting_name+'</span>: <span>'+apply_num+'</span>';
                            html += '<i class="layui-icon red pointer detailDel" >&#xe640;</i>';
                            html += ' </div>';
                        });
                        $("#fittingApply").append(html);
                        layer.close(indess);
                        delectFi()
                    });
                    submit.trigger('click');
                },
                success : function(layero) {
                    layero.find('.layui-layer-btn').css('text-align', 'center');
                    layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                }
            });



        })
        function delectFi() {
            $(".detailDel").on('click', function() {
                $(this).parent("div").remove();

            });
        }



        function orderModel(model,val){
            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);
            $("#applianceModel").val(val);
            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",
                async:false,
                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",
                async:false,
                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');
                }
            });

        }
        function CategoryOrder(brand,cateName){
            $("#applianceCategory").empty()
            $("#applianceModel").empty()
            if(isBlank(brand)){
                $("#applianceCategory").append("<option value=''>请选择</option>");
                return "";
            }
            $.ajax({
                type:"POST",
                url:"${ctx}/order/getCategoryByBrandname",
                async:false,
                data:{
                    brand:brand
                },
                success:function(result){
                    if(result =="205"){
                        layer.msg("暂无数据!")
                        return
                    }
                    var html ="<option value=''>请选择</option>";
                    for(var i=0;i<result.length;i++){
                        var cate = result[i];
                        html =html+ '<option value="'+cate.columns.category+'" title="'+cate.columns.model+'">'+cate.columns.category+'</option>';
                    }
                    $("#applianceCategory").append(html);
                    $("#applianceCategory").val(cateName)
                    form.render('select');
                }
            });

        }

        function getModel(model,modelOne){
            $("#applianceModel").empty();
            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);
            $("#applianceModel").val(modelOne);
            form.render('select');

        }

        //是否已发配件
        var sureSend = document.getElementsByClassName('sureSend')[0];
        form.on('radio(yf)', function (data) {
            if (data.value == '2') {
                sureSend.classList.remove("layui-hide");
            } else {
                sureSend.classList.add("layui-hide");
                //清除已添加得数据
                $("#fittingApply").empty();
                $("#logisticsName").val('');
                $("#logisticsNo").val('');
                form.render('select');
            }
        });
    });


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