order-details-controller.js 3.32 KB
/**
 * 维修中页
 */
define(
    "order/order-details-controller",
    [
        'mk7/controller',
        'mk7/url',
        'mk7/utils',
    ],

    function(ctrl, url, utils) {

        var $$ = Dom7;
        var t7 = Template7;
        var ctrl = new ctrl();

        var pageURL = 'order/default/order-details';
        ctrl.run = function () {
            var me = this;
            me.id = me.params.id;
            me.success = true;
            me.setPageTitle("维修单");
            me.loadPage();
        }
        ctrl.bindEvents = function () {
            var me = this;
            console.log("bindEvents");
            me.finishBtnEvent();
            me.popupImageLayer();
        }
        ctrl.beforeRender = function() {
            var me = this;
            console.log('beforeRender')
            if (!me.success) {
                me.view = 'order-details-error';
            }

        }
        ctrl.loadPage = function() {
            var me = this
            var pData = me.csrf({id: me.id});
            utils.httpPost(url.to(pageURL), pData, function(res) {
                var rData = res;
                me.success = res.success
                me.render(rData);
            }, true)

        }
        ctrl.finishBtnEvent = function() {
            var me = this;
            $$('#order-details .finish-submit').click(function(e){
                window.location.href = url.to('order/#cost-list/' + me.id);
            })
        }
        ctrl.agreementEvent = function() {
            //agreement-btn
            /*
            $$('#order-details .agreement-btn').click(function(e){
                $$('#agreement-wrapper').remove();
                var page = $$('#order-details');
                var ele = $$('script#agreement-template');
                var compiled = t7.compile(ele.html());
                var doms = compiled({});
                page.append(doms);
            })

            $$('#order-details').on('click','.agree-btn', function(e){
                $$('#agreement-wrapper').remove();
            })
            */
        }
        ctrl.popupImageLayer = function(){
            $$('#order-details').on('click', '.view-img-cls', function(e) {
                var url = $$(this).attr('data-url');
                $$('#img-mask').remove();
                var imgContent = '<div id="img-mask" style="z-index:2;background:#000;justify-content:center;position: absolute;bottom:0;top:0;width:100%;display:flex;flex-direction: column;align-items: center"><div style="width:100%;"> <img width="100%" src="'+url+'" /></div></div>';
                $$('#order-details').append(imgContent);
            })

            $$('#order-details').on('click', '#img-mask, #img-mask img', function(e) {
                e.preventDefault();
                e.stopPropagation()

                var bh = document.body.clientHeight;
                var ih = $$('#img-mask img').height();
                console.log(bh+'dddd'+ih)
                var interval = Math.abs(ih-bh);
                if (interval >=0 && interval <= 20) {
                    $$('#img-mask').remove();

                } else {
                    var id = $$(e.target).attr('id');
                    if('img-mask' == id) {
                        $$('#img-mask').remove();
                    }
                }

            })
        }

        return ctrl;
    }
);