product.js 2.04 KB
define(['jquery', 'underscore', 'text!../html/templates/product.html'], function($, _, Tpl) {
    var Page = {
        initialize: function(opt) {
            this.opt = opt;
            this.bindEvents();
            this.render();
        },
        bindEvents: function() {

        },
        render: function() {
            var _this = this,
                opt = {
                    data: {
                        // modelCode: "nfyx"
                        modelCode: this.opt.modelCode
                    },
                    success: function(response) {
                        if (response.code == 200) {
                            response.wap = _this.opt.wap;
                            response.banner = _this.opt.banner;
                            response.title = _this.opt.title;
                            $('.m-page').html(_.template(Tpl)(response));
                        } else {
                            alert('请求数据失败,未知错误!');
                        }
                    },
                    error: function() {
                        alert('未知错误!');
                    }
                };
            this.request(opt);
        },
        request: function(opt) {
            $.ajax({
                type: 'POST',
                data: JSON.stringify(opt.data),
                url: 'http://mobapi.nong12.com/mobsiteApp/topic/getTopicProducts.do',
                // url: 'http://10.28.2.183/mobsiteApp/topic/getTopicProducts.do',
                async: true,
                timeout: 15000,
                dataType: 'json',
                contentType: "application/json; charset=utf-8"
            }).done(function(data) {
                opt.success && opt.success(data);
            }).fail(function(xhr, ajaxOptions, thrownError) {
                alert('网络连接超时或失败!');
                console.log('error code: ' + xhr.status + '\n ajaxOptions:' + ajaxOptions + '\n message: ' + thrownError + '\n APIName:' + opt.apiName);
            });
        }
    };
    return Page;
});