<div class="col-sm-24 col-md-24" id="module_regular_customers">
    <h3>老客户</h3>
    <div class="row">
        <div class="col-sm-24 col-md-24">
            <ul class="list-unstyled list-inline">
                <li>
                    <label class="checkbox-inline">
                        网站:
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_ALL" name="website" value="ALL" checked> ALL
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_CHT" name="website" value="CHT"> CH网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_GHKYZG" name="website" value="GHKYZG" > 客运中心中国
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_GHKYHW" name="website" value="GHKYHW" > 客运中心海外
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_AH" name="website" value="AH"> AH网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_GH" name="website" value="GH"> GH网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_JP" name="website" value="JP"> 日语网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_VAC" name="website" value="VAC"> 西语网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_IT" name="website" value="IT"> 意大利语网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_GM" name="website" value="GM"> 德语网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_RU" name="website" value="RU"> 俄语网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_VC" name="website" value="VC"> 法语网站
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_CT" name="website" value="CT"> ChinaTravel
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="website_trippest" name="website" value="trippest"> trippest
                    </label>
                </li>
            </ul>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-24 col-md-24">
            <ul class="list-unstyled list-inline">
                <li>
                    <label class="checkbox-inline">
                        小组:
                    </label>
                </li>
                <li><label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_1" name="DEI_SNList" value="1" checked> CH直销组
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_2" name="DEI_SNList" value="2" checked> CH大客户组
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_28" name="DEI_SNList" value="7" checked> 市场推广
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_28" name="DEI_SNList" value="28" checked> AH亚洲项目组
                    </label>
                </li>

                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_8" name="DEI_SNList" value="8"> 德语市场
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_9" name="DEI_SNList" value="9"> 日语市场
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_11" name="DEI_SNList" value="11"> 法语市场
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_12" name="DEI_SNList" value="12"> 西语市场
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_20" name="DEI_SNList" value="20"> 俄语市场
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_21" name="DEI_SNList"" value="21"> 意语市场
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_10" name="DEI_SNList" value="10"> 商旅市场
                    </label>
                </li>

                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_18" name="DEI_SNList" value="18"> CT市场
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_16" name="DEI_SNList" value="16"> APP移动项目组
                    </label>
                </li>
                <li>
                    <label class="checkbox-inline">
                        <input type="checkbox" id="DEI_SNList_30" name="DEI_SNList" value="30"> Trippest项目组
                    </label>
                </li>
            </ul>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-4 col-md-2">
            <label class="checkbox-inline">
                <input type="checkbox" id="regular_customers_ApplydateCheck" name="regular_customers_ApplydateCheck"
                       checked value="1">预定日期
            </label>
        </div>
        <div class="col-sm-8 col-md-4">
            <input name="regular_customers_ApplydateStart" id="regular_customers_ApplydateStart" type="text"
                   placeholder="开始日期"
                   class="form-control ShowMeTheDatePicker_cn"
                   value="<?php echo date('Y-m-d', strtotime('-1 week last monday')); ?>">
        </div>
        <div class="col-sm-8 col-md-4">
            <input name="regular_customers_ApplydateEnd" id="regular_customers_ApplydateEnd" type="text"
                   placeholder="截至日期"
                   class="form-control ShowMeTheDatePicker_cn"
                   value="<?php echo date('Y-m-d', strtotime('-1 week sunday')); ?>">
        </div>
        <div class="col-sm-4 col-md-2">
            <button class="btn btn-default" type="button" onclick="updateRegularCustomers(0);">统计</button>
        </div>
    </div>
    <br/>
    <div class="row">
        <div class="col-sm-4 col-md-2">
            <label class="checkbox-inline">
                <input type="checkbox" id="regular_customers_EntrancedateCheck"
                       name="regular_customers_EntrancedateCheck" value="1">出发日期
            </label>
        </div>
        <div class="col-sm-8 col-md-4">
            <input name="regular_customers_EntrancedateStart" id="regular_customers_EntrancedateStart" type="text"
                   placeholder="开始日期"
                   class="form-control ShowMeTheDatePicker_cn" value="<?php echo date('Y-m-01', time()); ?>">
        </div>
        <div class="col-sm-8 col-md-4">
            <input name="regular_customers_EntrancedateEnd" id="regular_customers_EntrancedateEnd" type="text"
                   placeholder="截至日期"
                   class="form-control ShowMeTheDatePicker_cn" value="<?php echo date('Y-m-t', time()); ?>">
        </div>
        <div class="col-sm-4 col-md-2">
            <button class="btn btn-default" type="button"
                    onclick="updateRegularCustomers(1);$('#regular_customers_detail_box').show();">显示详情
            </button>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-24 col-md-12">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>统计条目</th>
                        <th>订单数</th>
                        <th>成行数</th>
                        <th>成行率</th>
                        <th>毛利</th>
                        <th>人数（含成人+儿童）</th>
                    </tr>
                    </thead>
                    <tbody id="regular_customers">

                    </tbody>
                </table>
            </div>
        </div>
    </div>


    <label class="text-muted small" onclick="$('#regular_customers_detail_box').toggle();"> 隐藏列表</label>
    |
    <label class="text-muted small" onclick="let table=document.getElementById('regular_customers_detail_box'); let excel=XLSX.utils.table_to_book(table);XLSX.writeFile(excel,'老客户.xlsx'); ">导出excel</label>


    <div class="row" style="display: none;" id="regular_customers_detail_box">
        <div class="col-sm-24 col-md-24">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>订单号</th>
                        <th>预定日期</th>
                        <th>订单状态</th>
                        <th>毛利</th>
                        <th>人数</th>
                        <th>天数</th>
                        <th>人天数</th>
                        <th>走团日期</th>
                        <th>小组</th>
                        <th>老客户</th>
                        <th>老客户推荐</th>
                        <th>网站</th>
                        <th>来源</th>
                        <th>在华</th>
                    </tr>
                    </thead>
                    <tbody id="regular_customers_detail">
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>
<script type="text/javascript">
    function updateRegularCustomers(showDetail) {
        let regular_customers_ApplydateCheck = $('#regular_customers_ApplydateCheck').prop("checked") ? $('#regular_customers_ApplydateCheck').val() : 0;
        let regular_customers_ApplydateStart = $('#regular_customers_ApplydateStart').val();
        let regular_customers_ApplydateEnd = $('#regular_customers_ApplydateEnd').val();
        let regular_customers_EntrancedateCheck = $('#regular_customers_EntrancedateCheck').prop("checked") ? $('#regular_customers_EntrancedateCheck').val() : 0;
        let regular_customers_EntrancedateStart = $('#regular_customers_EntrancedateStart').val();
        let regular_customers_EntrancedateEnd = $('#regular_customers_EntrancedateEnd').val();
        let DEI_SNList = $('#module_regular_customers input[name="DEI_SNList"]:checked').map(function (index, element) {
            return $(element).val();
        }).get().join(',');//将数组元素连接起来转化为字符串
        let websiteList = $('#module_regular_customers input[name="website"]:checked').map(function (index, element) {
            return $(element).val();
        }).get().join(',');//将数组元素连接起来转化为字符串
        if ((regular_customers_ApplydateCheck == 0 && regular_customers_EntrancedateCheck == 0) || DEI_SNList == '') {
            $.modaldialog.error("请检查必填项");
            return false;
        }
        showDetail == 0 ? document.getElementById('regular_customers').innerHTML = '' : document.getElementById('regular_customers_detail').innerHTML = '';
        $.ajax({
            type: "post",
            dataType: "json",
            url: "<?php echo site_url('welcome/show_me_the_data')?>",
            data: {//https://p9axztuwd7x8a7.mycht.cn/service-tourdesign/RegularCusOrder?Website=CHT&ApplydateCheck=1&ApplydateStart=2022-02-01&ApplydateEnd=2022-02-28&EntrancedateCheck=0&EntrancedateStart=2022-02-01&EntrancedateEnd=2022-02-28&IsDetail=0&DEI_SNList=1,8,9,11,12,20,21
                "url": '/service-tourdesign/RegularCusOrder?Website=' + websiteList
                    + '&ApplydateCheck=' + regular_customers_ApplydateCheck
                    + '&ApplydateStart=' + regular_customers_ApplydateStart
                    + '&ApplydateEnd=' + regular_customers_ApplydateEnd+'%2023:59'
                    + '&EntrancedateCheck=' + regular_customers_EntrancedateCheck
                    + '&EntrancedateStart=' + regular_customers_EntrancedateStart
                    + '&EntrancedateEnd=' + regular_customers_EntrancedateEnd+'%2023:59'
                    + '&DEI_SNList=' + DEI_SNList
                    + '&IsDetail=' + showDetail,
            },
            success: function (data, textStatus) {
                if (showDetail == 0) { //显示统计信息
                    for (let key in data) {
                        let tr = document.createElement('tr');
                        let td_ItemName = document.createElement('td');
                        let td_OrderNum = document.createElement('td');
                        let td_SUCOrderNum = document.createElement('td');
                        let td_SUCRate = document.createElement('td');
                        let td_ML = document.createElement('td');
                        let td_PersonNum = document.createElement('td');
                        td_ItemName.innerHTML = data[key].ItemName;
                        td_OrderNum.innerHTML = data[key].OrderNum;
                        td_SUCOrderNum.innerHTML = data[key].SUCOrderNum;
                        td_SUCRate.innerHTML = (data[key].SUCRate * 100).toFixed(1) + '%';
                        td_ML.innerHTML = data[key].ML;
                        td_PersonNum.innerHTML = data[key].PersonNum;
                        tr.appendChild(td_ItemName);
                        tr.appendChild(td_OrderNum);
                        tr.appendChild(td_SUCOrderNum);
                        tr.appendChild(td_SUCRate);
                        tr.appendChild(td_ML);
                        tr.appendChild(td_PersonNum);
                        document.getElementById('regular_customers').appendChild(tr);
                    }
                } else {
                    for (let key in data) {
                        let tr = document.createElement('tr');
                        let td_index = document.createElement('td');
                        let td_COLI_ID = document.createElement('td');
                        let td_COLI_ApplyDate = document.createElement('td');
                        let td_OrderState = document.createElement('td');
                        let td_ML = document.createElement('td');
                        let td_PersonNum = document.createElement('td');
                        let td_COLI_Days = document.createElement('td');
                        let td_CGI_PersonDays = document.createElement('td');
                        let td_COLI_OrderStartDate = document.createElement('td');
                        let td_Department = document.createElement('td');
                        let td_COLI_IsOld = document.createElement('td');
                        let td_COLI_IsCusCommend = document.createElement('td');
                        let td_COLI_WebCode = document.createElement('td');
                        let td_SourceType = document.createElement('td');
                        let td_ZH = document.createElement('td');
                        td_index.innerHTML = parseInt(key) + 1;
                        td_COLI_ID.innerHTML = data[key].COLI_ID;
                        td_COLI_ApplyDate.innerHTML = data[key].COLI_ApplyDate;
                        td_OrderState.innerHTML = data[key].OrderState;
                        td_ML.innerHTML = data[key].ML;
                        td_PersonNum.innerHTML = data[key].PersonNum;
                        td_COLI_Days.innerHTML = data[key].COLI_Days;
                        td_CGI_PersonDays.innerHTML = data[key].CGI_PersonDays;
                        td_COLI_OrderStartDate.innerHTML = data[key].COLI_OrderStartDate;
                        td_Department.innerHTML = data[key].Department;
                        td_COLI_IsOld.innerHTML = data[key].COLI_IsOld;
                        td_COLI_IsCusCommend.innerHTML = data[key].COLI_IsCusCommend;
                        td_COLI_WebCode.innerHTML = data[key].COLI_WebCode;
                        td_SourceType.innerHTML = data[key].SourceType;
                        td_ZH.innerHTML = data[key].ZH;
                        tr.appendChild(td_index);
                        tr.appendChild(td_COLI_ID);
                        tr.appendChild(td_COLI_ApplyDate);
                        tr.appendChild(td_OrderState);
                        tr.appendChild(td_ML);
                        tr.appendChild(td_PersonNum);
                        tr.appendChild(td_COLI_Days);
                        tr.appendChild(td_CGI_PersonDays);
                        tr.appendChild(td_COLI_OrderStartDate);
                        tr.appendChild(td_Department);
                        tr.appendChild(td_COLI_IsOld);
                        tr.appendChild(td_COLI_IsCusCommend);
                        tr.appendChild(td_COLI_WebCode);
                        tr.appendChild(td_SourceType);
                        tr.appendChild(td_ZH);
                        document.getElementById('regular_customers_detail').appendChild(tr);
                    }
                }
            },
            error: function () {
                $.modaldialog.error("\u53d1\u751f\u9519\u8bef\uff0c\u8bf7\u8054\u7cfbYCC")
            }
        })
    }
</script>

