<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>我的发布</title>
    <link rel="stylesheet" href="../css/main.css" />
    <script src="../js/flexible.js"></script>
    <script src="../js/api.js"></script>
    <script src="../js/checkLanguage.js"></script>
</head>
<body>
<div class="bb ub plr25 ub-ac ptb20 p-te hid" id="otherFn">
    <div class=" ub-pac">
        <label>
            <input class="h-input" type="checkbox">
            <span class="fz26 c3d plr10 nav1">全选</span>
        </label>
        <!--<span class="fz26 c3d">全选</span>-->
    </div>
    <a href="javascript:;" class="fz26 plr20 blue nav2">刷新</a>
    <a href="javascript:;" class="fz26 plr20 blue nav3">下架</a>
    <a href="javascript:;" class="fz26 plr20 blue nav4"><!--删除--></a>
</div>
<div class="bb ub plr25 ub-ac ptb20 p-te fixed hid" id="thisFn">
    <div class=" ub-pac">
        <label>
            <input class="h-input" type="checkbox" id="selAll">
            <span class="fz26 c3d plr10 nav5">全选</span>
        </label>
        <!--<span class="fz26 c3d">全选</span>-->
    </div>
    <a href="javascript:;" class="fz26 plr20 blue nav6" id="reloadBtn">刷新</a>
    <a href="javascript:;" class="fz26 plr20 blue nav7" id="XJArr">下架</a>
    <a href="javascript:;" class="fz26 plr20 blue nav8" id="delArr"><!--删除--></a>
</div>
<ul id="evaluation" class="hid">
    <li class="bb bgff mb20" rel="{{orderid}}">
        <div class="ub p25 ub-pj p-te fz22">
            <p class="fz22 c3d ub ub-pac">
                <label class="ub ub-ac">
                    <input type="checkbox"  class="{{isShow}}"/>
                    <span class="ml10"><span class="list1"></span>：{{tnameCn}}</span>
                </label>
            </p>
            <p class="fz22 c81 plr20"><span class="list2"></span>：{{addDate}}</p>
        </div>
        <div class="bgfa fz24 info-txt ">
            <p class="blue fz24 p-te"><span class="list3"></span>：{{polName}}{{polNamecn}}{{polNameShortCn}}</p>
            <p class="blue fz24 p-te"><span class="list4"></span>：{{podName}}{{podNamecn}}{{podNameShortCn}}</p>
            <div class="clear">{{pricesList}}</div>
            <p class="fz22 fz24 p-te"><span class="list5"></span>:{{dateFrom}} <span class="list6"></span> {{dateTo}}</p>
            <p class="fz22 c98 p-te"><span class="list7"></span>:{{showId}}</p>
            <p class="fz24 c98 p-te"><span class="list8"></span>:{{remark}}</p>
        </div>
        <div class="ptb20 plr25 ub ub-pe">
            <span class="fz24 c65 ub-f1 pt10"><span class="list9"></span>：<span class="list10"></span></span>
            <a href="javascript:;" class="red revise-btn fz24 TJ">{{isTop}}</a>
            <a href="javascript:;" class="delete-btn fz24 ml10 XJ btn3"></a>
        </div>
    </li>
</ul>
<!--<div class="plr25 mt50 mb50">-->
<!--<button type="button" class="release-btn btn-box fz30 cff" id="sureBtn">发布运价</button>-->
<!--</div>-->
<script type="text/javascript">
    try {
        var text=languages.issuePutaway;
        $api.dom(".nav1").innerText=text.nav1;
        $api.dom(".nav2").innerText=text.nav2;
        $api.dom(".nav3").innerText=text.nav3;
        $api.dom(".nav5").innerText=text.nav1;
        $api.dom(".nav6").innerText=text.nav2;
        $api.dom(".nav7").innerText=text.nav3;
        $api.dom(".list1").innerText=text.list1;
        $api.dom(".list2").innerText=text.list2;
        $api.dom(".list3").innerText=text.list3;
        $api.dom(".list4").innerText=text.list4;
        $api.dom(".list5").innerText=text.list5;
        $api.dom(".list6").innerText=text.list6;
        $api.dom(".list7").innerText=text.list7;
        $api.dom(".list8").innerText=text.list8;
        $api.dom(".list9").innerText=text.list9;
        $api.dom(".list10").innerText=text.list10;
        $api.dom(".btn3").innerText=text.btn3;
    }catch (e){
        alert(languages.all.list5)
    }
</script>
<script src="../js/publicData.js"></script>
<script>
    var pageIndex=1,isReload=false,isClick=false;
    var modelTxt=$api.dom("#evaluation").innerHTML;
    var priceTxt='<p class="fz24 c98">'+languages.issuePutaway.list11+'：{{nameOfboard}} &nbsp;'+languages.issuePutaway.list12+'：{{day}}{{hour}}</p><p class="fz24 c98">'+languages.issuePutaway.list13+'：{{dateOfStart}} &nbsp;'+languages.issuePutaway.list14+'：{{dateOfEndGate}}</p> <p class="fz24 c28 clear">{{prices}}</p><p class="fz24 c98">'+languages.issuePutaway.list15+'：{{additionalPrice}} </p>';
    var priceListTxt='<span class="fl pr20 " style="white-space: nowrap">{{code}}{{price}}/{{theCode}}</span>';
    apiready=function () {
        var otherFn = $api.dom("#otherFn"), thisFn = $api.dom("#thisFn"), selAll = $api.dom("#selAll"), reloadBtn = $api.dom("#reloadBtn"), XJArr = $api.dom("#XJArr"), delArr = $api.dom("#delArr");
//        var sureBtn=$api.dom("#sureBtn");
//        sureBtn.onclick=function () {
//            api.openWin({
//                name: 'issueFare',
//                url: 'issueFare.html',
//                pageParam: {winName: 'issuePutaway'}
//            });
//        }
        getData(true);
        api.addEventListener({
            name:"loginInit"
        },function (ret,err) {
            api.closeFrame({
                name: 'issuePutaway'
            });
        })
        api.setRefreshHeaderInfo({
            loadingImg: 'widget://image/refresh.png',
            bgColor: '#efefef',
            textColor: '#818181',
            textDown: languages.all.list34+'...',
            textUp: languages.all.list35+'...'
        }, function (ret, err) {
            //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
            pageIndex = 1;
            if(otherFn.className.indexOf("hid")==-1){
                otherFn.className = otherFn.className + " hid";
            }
            if(thisFn.className.indexOf("hid")==-1){
                thisFn.className = thisFn.className + " hid";
            }
            getData(true);
            api.refreshHeaderLoadDone();
        });
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0            //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function (ret, err) {
            if (isReload) {
                return;
            }
            getData(false);
        });
        api.addEventListener({
            name: 'showPutaway'
        }, function (ret, err) {
            var evaluation = $api.dom("#evaluation"), liList = $api.domAll(evaluation, "li"), total = false;
            if (otherFn.className.indexOf("hid") != -1) {
                otherFn.className = otherFn.className.replace("hid", "");
                thisFn.className = thisFn.className.replace("hid", "");
                for (var i = 0, len = liList.length; i < len; i++) {
                    $api.dom(liList[i], "[type=checkbox]").className = "h-input";
                    !function (i) {
                        $api.dom(liList[i], "[type=checkbox]").onclick = function () {
                            for (var j = 0; j < len; j++) {
                                if (!$api.dom(liList[j], "[type=checkbox]").checked) {
                                    total = true;
                                }
                            }
                            if (!total) {
                                selAll.checked=true;
                            } else {
                                selAll.checked=false;
                            }
                            total = false;
                        }
                    }(i)
                }
            } else {
                otherFn.className = otherFn.className + " hid";
                thisFn.className = thisFn.className + " hid";
                for (var i = 0, len = liList.length; i < len; i++) {
                    $api.dom(liList[i], "[type=checkbox]").className = "";
                }
            }
        });
        selAll.onclick = function () {
            var evaluation = $api.dom("#evaluation"), liList = $api.domAll(evaluation, "li");
            if (this.checked) {
                for (var i = 0, len = liList.length; i < len; i++) {
                    $api.dom(liList[i], "[type=checkbox]").setAttribute("checked", true);
                }
            } else {
                for (var i = 0, len = liList.length; i < len; i++) {
                    $api.dom(liList[i], "[type=checkbox]").removeAttribute("checked");
                }
            }

        }
        reloadBtn.onclick = function () {
            if(isReload) return;
            if(otherFn.className.indexOf("hid")==-1){
                otherFn.className = otherFn.className + " hid";
            }
            if(thisFn.className.indexOf("hid")==-1){
                thisFn.className = thisFn.className + " hid";
            }
            selAll.checked=false;
            getData(true,1);
        }
        XJArr.onclick = function () {
            if(isClick) return;
            var evaluation = $api.dom("#evaluation"), liList = $api.domAll(evaluation, "li"), postArr = [], list = [];
            for (var i = 0, len = liList.length; i < len; i++) {
                if ($api.dom(liList[i], "[type=checkbox]").checked) {
                    postArr.push({id: liList[i].getAttribute("rel"), state: 0});
                    list.push(liList[i])
                }
            }
            if(list.length){
                api.showProgress({
                    title: languages.all.list21+'...',
                    text: languages.issuePutaway.remind3+'...',
                    modal: true
                });
                isClick=true;
            }else {
                api.toast({
                    msg: languages.issuePutaway.remind2,
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            api.ajax({
                url: pageUrl + 'Price/set_state',
                method: 'post',
                timeout: 30,
                headers: {
                    "content-type": "application/json"
                },
                dataType: 'json',
                returnAll: false,
                data: {
                    body: postArr
                }
            }, function (ret, err) {
                isClick = false;
                if (ret.status == "200") {
                    for (var i = 0, len = list.length; i < len; i++) {
                        list[i].parentNode.removeChild(list[i]);
                    }
                    selAll.checked=false;
                    api.toast({
                        msg: languages.issuePutaway.remind4,
                        duration: 2000,
                        location: 'bottom'
                    });
                    //在名为winName的window中执行jsfun脚本
                    var jsfun2 = 'getData(true,1);';
                    api.execScript({
                        name: 'root',
                        frameName: 'issueSoldOut',
                        script: jsfun2
                    });
                } else {
                    api.toast({
                        msg: languages.all.list48,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
                api.hideProgress();
            });
        }
        delArr.onclick = function () {
            if(isClick) return;
            var evaluation = $api.dom("#evaluation"), liList = $api.domAll(evaluation, "li"), postArr = [], list = [];
            for (var i = 0, len = liList.length; i < len; i++) {
                if ($api.dom(liList[i], "[type=checkbox]").checked) {
                    postArr.push({id: liList[i].getAttribute("rel")});
                    list.push(liList[i])
                }
            }
            if(!list.length){
                api.toast({
                    msg: languages.issuePutaway.remind2,
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            popups(languages.all.list22, function (ret, dialogBox) {
                if (ret.eventType == 'right') {
                    isClick=true;
                    api.showProgress({
                        title: languages.all.list21+'...',
                        text: languages.all.list32+'...',
                        modal: true
                    });
                    api.ajax({
                        url: pageUrl + 'Price/del_price',
                        method: 'post',
                        timeout: 30,
                        headers: {
                            "content-type": "application/json"
                        },
                        dataType: 'json',
                        returnAll: false,
                        data: {
                            body: postArr
                        }
                    }, function (ret, err) {
                        isClick = false;
                        if (ret.status == "200") {
                            for (var i = 0, len = list.length; i < len; i++) {
                                list[i].parentNode.removeChild(list[i]);
                            }
                            selAll.checked=false;
                            api.toast({
                                msg: languages.all.list23,
                                duration: 2000,
                                location: 'bottom'
                            });
                            getData(true, 1)
                        } else {
                            api.toast({
                                msg: languages.all.list47,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                        api.hideProgress();
                    });
                    dialogBox.close({
                        dialogName: 'alert'
                    });
                } else if (ret.eventType == 'left') {
                    dialogBox.close({
                        dialogName: 'alert'
                    });
                }
            })
        }
        function popups(val,fn) {
            var dialogBox = api.require('dialogBox');
            dialogBox.alert({
                texts: {
                    title: languages.all.list18,
                    content: val,
                    leftBtnTitle:  languages.all.list2,
                    rightBtnTitle:  languages.all.list18
                },
                styles: {
                    bg: '#fff',
                    w: 300,
                    title: {
                        marginT: 20,
                        icon: 'widget://res/gou.png',
                        iconSize: 40,
                        titleSize: 13,
                        titleColor: '#000'
                    },
                    content: {
                        color: '#000',
                        size: 16
                    },
                    left: {
                        marginB: 0,
                        marginL: 0,
                        w: 150,
                        h: 60,
                        corner: 2,
                        bg: '#f9f9f9',
                        color: '#818181',
                        size: 12
                    },
                    right: {
                        marginB: 0,
                        marginL: 0,
                        w: 150,
                        h:60,
                        corner: 2,
                        bg: '#51c4d4',
                        color: '#fff',
                        size: 12
                    }
                }
            }, function(ret) {
                fn(ret,dialogBox)
            });
        }
    }
        function getData(bl,thisPage) {
            isReload=true;
            api.ajax({
                url: pageUrl+"Price/get_price_list",
                method: 'get',
                timeout: 30,
                dataType: 'json',
                returnAll: false,
                headers:{
                    "content-type":"application/json"
                },
                data: {
                    body:{
                        "type":{
                            "state":1,
                            "adminIsOk":1
                        },
                        "page":thisPage||pageIndex
                    }
                }
            }, function (ret, err) {
                console.log(JSON.stringify(ret))
                var that=$api.dom("#evaluation"),thisFn = $api.dom("#thisFn");
                var jsfun1 = 'getNum('+JSON.stringify(ret['data']["total"])+');';
                if(thisPage)  pageIndex = thisPage;
                api.execScript({
                    name: 'root',
                    frameName:"issueNav",
                    script: jsfun1
                });
                if(ret.status!="200"){
                    if(bl){
                        that.innerHTML=" <p style='padding-top: 5.3rem;font-size: .5rem;text-align: center;color: #818181'>"+ languages.issuePutaway.remind1+"</p>";
                        that.className=that.className.replace("hid","");
                    }else {
                        api.toast({
                            msg: languages.all.list19,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                    api.refreshHeaderLoadDone();
                    isReload=false;
                    return;
                }
                var data=ret.data['datas'],str="",str2="",str3="";
                for(var i in data){
                    str+=modelTxt.replace("{{orderid}}",data[i]['id']).replace("{{isShow}}",thisFn.className.indexOf("hid")==-1?"h-input":"").replace("{{isTop}}",data[i]['isbegTop']&&data[i]['isbegTop']=="1"?languages.issuePutaway.btn2:languages.issuePutaway.btn1).replace("{{showId}}",data[i]['showId']).replace("{{addDate}}",data[i]['addDate']).replace("{{tnameCn}}",data[i]['tnameCn'])
                    for(var j in data[i]['pol']){
                        str=str.replace("{{polName}}",data[i]['pol'][j]['polName']?data[i]['pol'][j]['polName']+"&nbsp;·&nbsp;":"").replace("{{polNamecn}}",data[i]['pol'][j]['nameCn']?data[i]['pol'][j]['nameCn']+"&nbsp;·&nbsp;":"").replace("{{polNameShortCn}}",data[i]['pol'][j]['nameShortCn']?data[i]['pol'][j]['nameShortCn']:"")
                    }
                    for(var n in data[i]['pod']){
                        str=str.replace("{{podName}}",data[i]['pod'][n]['podName']?data[i]['pod'][n]['podName']+"&nbsp;·&nbsp;":"").replace("{{podNamecn}}",data[i]['pod'][n]['nameCn']?data[i]['pod'][n]['nameCn']+"&nbsp;·&nbsp;":"").replace("{{podNameShortCn}}",data[i]['pod'][n]['nameShortCn']?data[i]['pod'][n]['nameShortCn']:"")
                    }
                    for(var x in data[i]['detail']){
                        str2=priceTxt.replace("{{additionalPrice}}",languages.issuePutaway.list16).replace("{{day}}",data[i]['detail'][x]['timeSpendDay']!=0?data[i]['detail'][x]['timeSpendDay']+languages.all.list26:"").replace("{{hour}}",data[i]['detail'][x]['timeSpendHour']!=0?data[i]['detail'][x]['timeSpendHour']+languages.all.list27:"").replace("{{dateOfEndGate}}",data[i]['detail'][x]['dateOfEndGate']).replace("{{dateOfStart}}",data[i]['detail'][x]['dateOfStart']).replace("{{nameOfboard}}",data[i]['tcnameCn'])
                        for(var s in data[i]['detail'][x]['child']){
                            str3+=priceListTxt.replace("{{code}}",data[i]['detail'][x]['child'][s]['code']).replace("{{theCode}}",data[i]['detail'][x]['child'][s]['theCode']).replace("{{price}}",data[i]['detail'][x]['child'][s]['price'])
                        }
                    }
                    str2=str2.replace("{{prices}}",str3);
                    str3="";
                    str=str.replace("{{pricesList}}",str2).replace("{{remark}}",data[i]['detail'][0]['remark']).replace("{{dateTo}}",data[i]['detail'][0]['dateTo'].split(" ")[0]).replace("{{dateFrom}}",data[i]['detail'][0]['dateFrom'].split(" ")[0]);
                    str2="";
                }
                if(bl){
                    that.innerHTML=str;
                    that.className=that.className.replace("hid","");
                }else {
                    that.insertAdjacentHTML("beforeend",str);
                }
                setTJ();
                setXJ();
                pageIndex++;
                str="";
                isReload=false;
            })
            function setTJ() {
                var evaluation=$api.dom("#evaluation"),TJS=$api.domAll(evaluation,".TJ"),isClick=false;
                for(var num=0,len=TJS.length;num<len;num++){
                    !function (i) {
                        TJS[i].onclick=function () {
                            if(isClick) return;
                            isClick=true;
                            api.showProgress({
                                title: languages.all.list21+'...',
                                text: languages.all.list25+'...',
                                modal: true
                            });
                            var id=this.parentNode.parentNode.getAttribute("rel"),isTop=0,that=this;
                            if(this.innerText==languages.issuePutaway.btn1){
//                              if($api.getStorage("serviceStatus").assurance=="0"){
//                                  api.openWin({
//                                      name: 'paidService',
//                                      url: 'paidService.html',
//                                      pageParam: {index: 0}
//                                  });
//                                  api.hideProgress();
//                                  isClick=false;
//                                  return;
//                              }
                                isTop=1;
                            }else {
                                isTop=0;
                            }
                            api.ajax({
                                url: pageUrl+'Price/set_top',
                                method: 'post',
                                timeout: 30,
                                dataType: 'json',
                                returnAll: false,
                                data: {
                                    values: {
                                        id: id,
                                        isbegTop:isTop
                                    }
                                }
                            }, function (ret, err) {
                                var txt="";
                                isClick=false;
                                api.hideProgress();
                                if(ret.status=="200"){
                                    if(isTop){
                                        that.innerText=languages.issuePutaway.btn2;
                                        txt=languages.issuePutaway.remind5;
                                    }else {
                                        that.innerText=languages.issuePutaway.btn1;
                                        txt=languages.issuePutaway.remind6;
                                    }
                                    api.toast({
                                        msg: txt,
                                        duration: 2000,
                                        location: 'bottom'
                                    });
                                }else {
                                    api.toast({
                                        msg: languages.all.list48,
                                        duration: 2000,
                                        location: 'bottom'
                                    });
                                }
                            });
                        }
                    }(num)
                }
            }
            function setXJ() {
                var evaluation=$api.dom("#evaluation"),XJS=$api.domAll(evaluation,".XJ"),isClick=false;
                for(var num=0,len=XJS.length;num<len;num++){
                    !function (i) {
                        XJS[i].onclick=function () {
                            if(isClick) return;
                            isClick=true;
                            var id=this.parentNode.parentNode.getAttribute("rel"),that=this;
                            var arr=[{id:id,state:0}];
                            api.showProgress({
                                title: languages.all.list21+'...',
                                text: languages.issuePutaway.remind3+'...',
                                modal: true
                            });
                            api.ajax({
                                url: pageUrl+'Price/set_state',
                                method: 'post',
                                timeout: 30,
                                headers:{
                                    "content-type":"application/json"
                                },
                                dataType: 'json',
                                returnAll: false,
                                data: {
                                    body: arr
                                }
                            }, function (ret, err) {
                                api.hideProgress();
                                isClick=false;
                                if(ret.status=="200"){
                                    api.toast({
                                        msg: languages.issuePutaway.remind4,
                                        duration: 2000,
                                        location: 'bottom'
                                    });
                                    that.parentNode.parentNode.parentNode.removeChild(that.parentNode.parentNode);
                                    //在名为winName的window中执行jsfun脚本
                                    var jsfun2 = 'getData(true,1);';
                                    api.execScript({
                                        name: 'root',
                                        frameName: 'issueSoldOut',
                                        script: jsfun2
                                    });
                                }else {
                                    api.toast({
                                        msg: languages.all.list48,
                                        duration: 2000,
                                        location: 'bottom'
                                    });
                                }
                            });
                        }
                    }(num)
                }
            }
        }
</script>
</body>
</html>
