define(['jquery'], function($) { var biz = {}; biz.url = function(routes, params, merch) { if (merch) { var url = './merchant.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=' + routes.replace(/\//ig, '.') } else { var url = './index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=' + routes.replace(/\//ig, '.') } if (params) { if (typeof(params) == 'object') { url += "&" + $.toQueryString(params) } else if (typeof(params) == 'string') { url += "&" + params } } return url }; biz.selector = { select: function(params) { params = $.extend({}, params || {}); var name = params.name === undefined ? 'default' : params.name; var modalid = name + "-selector-modal"; modalObj = $('#' + modalid); if (modalObj.length <= 0) { var modal = ''; modalObj = $(modal); modalObj.on('show.bs.modal', function() { if (params.autosearch == '1') { $.get(params.url, { keyword: '' }, function(dat) { $('.content', modalObj).html(dat) }) } }) }; modalObj.modal('show') }, search: function(searchbtn, name) { var input = $(searchbtn).closest('.modal').find('#' + name + '_input'); var selector = $("#" + name + '_selector'); var needkeywords = true; if (selector.data('nokeywords') == '1') { needkeywords = false }; var keyword = $.trim(input.val()); if (keyword == '' && needkeywords) { input.focus(); return } var modalObj = $('#' + name + "-selector-modal"); $('.content', modalObj).html("正在搜索...."); $.get(selector.data('url'), { keyword: keyword }, function(dat) { $('.content', modalObj).html(dat) }) }, remove: function(obj, name) { var selector = $("#" + name + '_selector'); var css = selector.data('type') == 'image' ? '.multi-item' : '.multi-audio-item'; if (selector.data('type') == 'image') { css = ".multi-item" } else if (selector.data('type') == 'coupon') { css = ".multi-product-item" } else if (selector.data('type') == 'coupon_cp') { css = ".multi-product-item" } else if (selector.data('type') == 'coupon_share') { css = ".multi-product-item" } else if (selector.data('type') == 'coupon_shares') { css = ".multi-product-item" } else { css = ".multi-audio-item" } $(obj).closest(css).remove(); biz.selector.refresh(name) }, set: function(obj, data) { var name = $(obj).closest('.content').data('name'); var modalObj = $('#' + name + "-selector-modal"); var selector = $('#' + name + "_selector"); var container = $('.container', selector); var key = selector.data('key') || 'id', text = selector.data('text') || 'title', thumb = selector.data('thumb') || 'thumb', multi = selector.data('multi') || 0, type = selector.data('type') || 'image', callback = selector.data('callback') || '', css = type == 'image' ? '.multi-item' : '.multi-audio-item'; if ($(css + '[data-' + key + '="' + data[key] + '"]', container).length > 0) { if (multi === 0) { modalObj.modal('hide') } return } if (type == 'coupon_cp') { if ($(".setticket").length >= 3) { tip.msgbox.err('您已经选择了三张优惠券,若要更换请删除其他优惠券!'); return } } if (type == 'coupon_share') { if ($(".shareticket").length >= 3) { tip.msgbox.err('您已经选择了三张优惠券,若要更换请删除其他优惠券!'); return } } if (type == 'coupon_shares') { if ($(".sharesticket").length >= 3) { tip.msgbox.err('您已经选择了三张优惠券,若要更换请删除其他优惠券!'); return } } var id = multi === 0 ? name : name + "[]"; var html = ""; if (type == 'image') { html += '
'; html += ''; html += '
' + data[text] + '
'; html += ''; html += '×'; html += '
' } else if (type == 'coupon') { html += ""; html += ""; html += ""; html += ""; html += "" + data[text] + ""; html += ""; html += ""; html += "" } else if (type == 'coupon_cp') { html += ""; html += ""; html += ""; html += ""; html += "" + data[text] + ""; html += ""; html += ""; html += "" } else if (type == 'coupon_share') { html += ""; html += ""; html += ""; html += ""; html += "" + data[text] + ""; html += ""; html += ""; html += "" } else if (type == 'coupon_shares') { html += ""; html += ""; html += ""; html += ""; html += "" + data[text] + ""; html += ""; html += ""; html += "" } else { html += "
"; html += "
"; html += ""; html += "
" } if (multi === 0) { container.html(html); modalObj.modal('hide') } else { container.append(html) } biz.selector.refresh(name); if (callback !== '') { var callfunc = eval(callback); if (callfunc !== undefined) { callfunc(data, obj) } } }, refresh: function(name) { var titles = ''; var selector = $('#' + name + '_selector'); var type = selector.data('type') || 'image'; if (type == 'image') { $('.multi-item', selector).each(function() { titles += " " + $(this).find('.img-nickname').html(); if ($('.multi-item', selector).length > 1) { titles += "; " } }) } else if (type == 'coupon') { $('.multi-product-item', selector).each(function() { titles += " " + $(this).find('.img-textname').val(); if ($('.multi-product-item', selector).length > 1) { titles += "; " } }) } else if (type == 'coupon_cp') { $('.multi-product-item', selector).each(function() { titles += " " + $(this).find('.img-textname').val(); if ($('.multi-product-item', selector).length > 1) { titles += "; " } }) } else if (type == 'coupon_share') { $('.multi-product-item', selector).each(function() { titles += " " + $(this).find('.img-textname').val(); if ($('.multi-product-item', selector).length > 1) { titles += "; " } }) } else if (type == 'coupon_shares') { $('.multi-product-item', selector).each(function() { titles += " " + $(this).find('.img-textname').val(); if ($('.multi-product-item', selector).length > 1) { titles += "; " } }) } else { $('.multi-audio-item', selector).each(function() { titles += " " + $(this).find('.img-textname').val(); if ($('.multi-audio-item', selector).length > 1) { titles += "; " } }) } $('#' + name + "_text", selector).val(titles) } }; biz.selector_new = { select: function(params) { params = $.extend({}, params || {}); var name = params.name === undefined ? 'default' : params.name; var modalid = name + "-selector-modal"; modalObj = $('#' + modalid); if (modalObj.length <= 0) { var modal = ''; modalObj = $(modal); modalObj.on('show.bs.modal', function() { if (params.autosearch == '1') { $.get(params.url, { keyword: '' }, function(dat) { $('.content', modalObj).html(dat) }) } }) }; modalObj.modal('show') }, search: function(searchbtn, name) { var input = $(searchbtn).closest('.modal').find('#' + name + '_input'); var selector = $("#" + name + '_selector'); var needkeywords = true; if (selector.data('nokeywords') == '1') { needkeywords = false }; var keyword = $.trim(input.val()); if (keyword == '' && needkeywords) { input.focus(); return } var modalObj = $('#' + name + "-selector-modal"); $('.content', modalObj).html("正在搜索...."); $.get(selector.data('url'), { keyword: keyword }, function(dat) { $('.content', modalObj).html(dat) }) }, remove: function(obj, name) { var selector = $("#" + name + '_selector'); var css = selector.data('type') == 'image' ? '.multi-item' : '.multi-product-item'; $(obj).closest(css).remove(); biz.selector_new.refresh(name) }, set: function(obj, data) { var name = $(obj).closest('.content').data('name'); var modalObj = $('#' + name + "-selector-modal"); var selector = $('#' + name + "_selector"); var key = selector.data('key') || 'id', text = selector.data('text') || 'title', thumb = selector.data('thumb') || 'thumb', multi = selector.data('multi') || 0, type = selector.data('type') || 'image', callback = selector.data('callback') || '', css = type == 'image' ? '.multi-item' : '.multi-product-item', optionurl = selector.data('optionurl') || '', selectorid = selector.data('selectorid') || ''; var container = $('.container', selector); if ($(css + '[data-' + key + '="' + data[key] + '"]', container).length > 0) { if (multi === 0) { modalObj.modal('hide') } return } var id = multi === 0 ? name : name + "[]"; var html = ""; if (type == 'image') { html += '
'; html += ''; html += '
' + data[text] + '
'; html += ''; html += '×'; html += '
' } else if (type == 'product') { var optionurl = optionurl == '' ? 'sale.package.hasoption' : optionurl; var url = "index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=" + optionurl + "&goodsid=" + data[key] + "&selectorid=" + selectorid; html += ''; html += " "; html += ""; html += ''; html += '' + data[text] + ''; html += "设置" + ""; html += ''; html += '' } else if (type == 'fullback') { var optionurl = optionurl == '' ? 'sale.fullback.hasoption' : optionurl; var url = "index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=" + optionurl + "&goodsid=" + data[key] + "&selectorid=" + selectorid; html += ''; html += " "; html += ""; html += ''; html += '' + data[text] + ''; html += "设置" + ""; html += ''; html += '' } else if (type == 'live') { var optionurl = optionurl == '' ? 'live.room.hasoption' : optionurl; var url = "index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=" + optionurl + "&goodsid=" + data[key] + "&selectorid=" + selectorid; html += ''; html += " "; html += ""; html += ''; html += '' + data[text] + ''; html += "设置" + ""; html += ''; html += '' } else { html += "
"; html += "
"; html += ""; html += "
" } if (multi === 0) { container.html(html); modalObj.modal('hide') } else { $("#param-items" + selectorid).append(html) } biz.selector_new.refresh(name); if (callback !== '') { var callfunc = eval(callback); if (callfunc !== undefined) { callfunc(data, obj) } } }, refresh: function(name) { var titles = ''; var selector = $('#' + name + '_selector'); var type = selector.data('type') || 'image'; if (type == 'image') { $('.multi-item', selector).each(function() { titles += " " + $(this).find('.img-nickname').html(); if ($('.multi-item', selector).length > 1) { titles += "; " } }) } else { $('.multi-product-item', selector).each(function() { titles += " " + $(this).find('.img-textname').val(); if ($('.multi-product-item', selector).length > 1) { titles += "; " } }) } $('#' + name + "_text", selector).val(titles) } }; biz.selector_open = { callback: function() {}, select: function(params) { params = $.extend({}, params || {}); biz.selector_open.callback = typeof(params.callback) === 'undefined' ? false : params.callback; biz.selector_open.params = params; var name = params.name === undefined ? 'default' : params.name; var modalid = name + "-selector-modal"; modalObj = $('#' + modalid); if (modalObj.length <= 0) { var modal = ''; modalObj = $(modal); modalObj.on('show.bs.modal', function() { if (params.autosearch == '1') { $.get(params.url, { keyword: '' }, function(dat) { $('.content', modalObj).html(dat) }) } }) }; modalObj.modal('show') }, search: function(searchbtn, name) { var input = $(searchbtn).closest('.modal').find('#' + name + '_input'); var selector = $("#" + name + '_selector'); var needkeywords = true; var params = biz.selector_open.params; if (params.nokeywords == '1') { needkeywords = false }; var keyword = $.trim(input.val()); if (keyword == '' && needkeywords) { input.focus(); return } var modalObj = $('#' + name + "-selector-modal"); $('.content', modalObj).html("正在搜索...."); $.get(params.url, { keyword: keyword }, function(dat) { $('.content', modalObj).html(dat) }) }, remove: function(obj, name) { var params = biz.selector_open.params; var css = params.type == 'image' ? '.multi-item' : '.multi-audio-item'; $(obj).closest(css).remove(); biz.selector_open.refresh(name) }, set: function(obj, data) { var name = $(obj).closest('.content').data('name'); var modalObj = $('#' + name + "-selector-modal"); var selector = $('#' + name + "_selector"); var params = biz.selector_open.params; var multi = params.multi || 0; if (multi === 0) { modalObj.modal('hide') } if (typeof(biz.selector_open.callback) === 'function') { biz.selector_open.callback(data, obj) } } }; biz.map = function(val, callback, tpl) { var modalobj = $('#map-dialog'); if (modalobj.length === 0) { var content = '
' + '' + '
'; var footer = '' + ''; modalobj = util.dialog('请选择地点', content, footer, { containerName: 'map-dialog' }); modalobj.find('.modal-dialog').css('width', '80%'); modalobj.modal({ 'keyboard': false }); modalobj.find('.input-group :text').keydown(function(e) { if (e.keyCode == 13) { var kw = $(this).val(); searchAddress(kw) } }); modalobj.find('.input-group button').click(function() { var kw = $(this).parent().prev().val(); searchAddress(kw) }) } modalobj.find('button.btn-primary').off('click'); modalobj.find('button.btn-primary').on('click', function() { if ($.isFunction(callback)) { var $point = modalobj.find("iframe").contents().find("#poi_json").val(); if ($.isEmpty($point)) { tip.msgbox.err('尚未选择坐标!'); return } var point = JSON.parse(modalobj.find("iframe").contents().find("#poi_json").val()); var address = modalobj.find("iframe").contents().find("#addr_cur").val(); var val = { lng: point.lng, lat: point.lat, label: address }; callback(val) } modalobj.modal('hide') }); modalobj.modal('show') }; biz.TxMapToBdMap = function(gg_lat, gg_lon) { var point = new Object(); var x_pi = 3.14159265358979324 * 3000.0 / 180.0; var x = new Number(gg_lon); var y = new Number(gg_lat); var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); var bd_lon = z * Math.cos(theta) + 0.0065; var bd_lat = z * Math.sin(theta) + 0.006; point.lng = bd_lon; point.lat = bd_lat; return point }; biz.BdMapToTxMap = function(bd_lat, bd_lon) { var point = new Object(); var x_pi = 3.14159265358979324 * 3000.0 / 180.0; var x = new Number(bd_lon - 0.0065); var y = new Number(bd_lat - 0.006); var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi); var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi); var Mars_lon = z * Math.cos(theta); var Mars_lat = z * Math.sin(theta); point.lng = Mars_lon; point.lat = Mars_lat; return point }; window.biz = biz; return biz });