biz.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. define(['jquery'], function($) {
  2. var biz = {};
  3. biz.url = function(routes, params, merch) {
  4. if (merch) {
  5. var url = './merchant.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=' + routes.replace(/\//ig, '.')
  6. } else {
  7. var url = './index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=' + routes.replace(/\//ig, '.')
  8. }
  9. if (params) {
  10. if (typeof(params) == 'object') {
  11. url += "&" + $.toQueryString(params)
  12. } else if (typeof(params) == 'string') {
  13. url += "&" + params
  14. }
  15. }
  16. return url
  17. };
  18. biz.selector = {
  19. select: function(params) {
  20. params = $.extend({}, params || {});
  21. var name = params.name === undefined ? 'default' : params.name;
  22. var modalid = name + "-selector-modal";
  23. modalObj = $('#' + modalid);
  24. if (modalObj.length <= 0) {
  25. var modal = '<div id="' + modalid + '" class="modal fade" tabindex="-1">';
  26. modal += '<div class="modal-dialog" style="width: 920px;">';
  27. modal += '<div class="modal-content">';
  28. modal += '<div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>数据选择器</h3></div>';
  29. modal += '<div class="modal-body" >';
  30. modal += '<div class="row">';
  31. modal += '<div class="input-group">';
  32. modal += '<input type="text" class="form-control" name="keyword" id="' + name + '_input" placeholder="' + (params.placeholder === undefined ? '' : params.placeholder) + '" />';
  33. modal += '<span class="input-group-btn"><button type="button" class="btn btn-default" onclick="biz.selector.search(this, \'' + name + '\');">搜索</button></span>';
  34. modal += '</div>';
  35. modal += '</div>';
  36. modal += '<div class="content" style="padding-top:5px;" data-name="' + name + '"></div>';
  37. modal += '</div>';
  38. modal += '<div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>';
  39. modal += '</div>';
  40. modal += '</div>';
  41. modal += '</div>';
  42. modalObj = $(modal);
  43. modalObj.on('show.bs.modal', function() {
  44. if (params.autosearch == '1') {
  45. $.get(params.url, {
  46. keyword: ''
  47. }, function(dat) {
  48. $('.content', modalObj).html(dat)
  49. })
  50. }
  51. })
  52. };
  53. modalObj.modal('show')
  54. },
  55. search: function(searchbtn, name) {
  56. var input = $(searchbtn).closest('.modal').find('#' + name + '_input');
  57. var selector = $("#" + name + '_selector');
  58. var needkeywords = true;
  59. if (selector.data('nokeywords') == '1') {
  60. needkeywords = false
  61. };
  62. var keyword = $.trim(input.val());
  63. if (keyword == '' && needkeywords) {
  64. input.focus();
  65. return
  66. }
  67. var modalObj = $('#' + name + "-selector-modal");
  68. $('.content', modalObj).html("正在搜索....");
  69. $.get(selector.data('url'), {
  70. keyword: keyword
  71. }, function(dat) {
  72. $('.content', modalObj).html(dat)
  73. })
  74. },
  75. remove: function(obj, name) {
  76. var selector = $("#" + name + '_selector');
  77. var css = selector.data('type') == 'image' ? '.multi-item' : '.multi-audio-item';
  78. if (selector.data('type') == 'image') {
  79. css = ".multi-item"
  80. } else if (selector.data('type') == 'coupon') {
  81. css = ".multi-product-item"
  82. } else if (selector.data('type') == 'coupon_cp') {
  83. css = ".multi-product-item"
  84. } else if (selector.data('type') == 'coupon_share') {
  85. css = ".multi-product-item"
  86. } else if (selector.data('type') == 'coupon_shares') {
  87. css = ".multi-product-item"
  88. } else {
  89. css = ".multi-audio-item"
  90. }
  91. $(obj).closest(css).remove();
  92. biz.selector.refresh(name)
  93. },
  94. set: function(obj, data) {
  95. var name = $(obj).closest('.content').data('name');
  96. var modalObj = $('#' + name + "-selector-modal");
  97. var selector = $('#' + name + "_selector");
  98. var container = $('.container', selector);
  99. var key = selector.data('key') || 'id',
  100. text = selector.data('text') || 'title',
  101. thumb = selector.data('thumb') || 'thumb',
  102. multi = selector.data('multi') || 0,
  103. type = selector.data('type') || 'image',
  104. callback = selector.data('callback') || '',
  105. css = type == 'image' ? '.multi-item' : '.multi-audio-item';
  106. if ($(css + '[data-' + key + '="' + data[key] + '"]', container).length > 0) {
  107. if (multi === 0) {
  108. modalObj.modal('hide')
  109. }
  110. return
  111. }
  112. if (type == 'coupon_cp') {
  113. if ($(".setticket").length >= 3) {
  114. tip.msgbox.err('您已经选择了三张优惠券,若要更换请删除其他优惠券!');
  115. return
  116. }
  117. }
  118. if (type == 'coupon_share') {
  119. if ($(".shareticket").length >= 3) {
  120. tip.msgbox.err('您已经选择了三张优惠券,若要更换请删除其他优惠券!');
  121. return
  122. }
  123. }
  124. if (type == 'coupon_shares') {
  125. if ($(".sharesticket").length >= 3) {
  126. tip.msgbox.err('您已经选择了三张优惠券,若要更换请删除其他优惠券!');
  127. return
  128. }
  129. }
  130. var id = multi === 0 ? name : name + "[]";
  131. var html = "";
  132. if (type == 'image') {
  133. html += '<div class="multi-item" data-' + key + '="' + data[key] + '" data-name="' + name + '">';
  134. html += '<img class="img-responsive img-thumbnail" src="' + data[thumb] + '" >';
  135. html += '<div class="img-nickname">' + data[text] + '</div>';
  136. html += '<input type="hidden" value="' + data[key] + '" name="' + id + '">';
  137. html += '<em onclick="biz.selector.remove(this,\'' + name + '\')" class="close">×</em>';
  138. html += '</div>'
  139. } else if (type == 'coupon') {
  140. html += "<tr class='multi-product-item' data-" + key + "='" + data[key] + "'>";
  141. html += "<input type='hidden' class='form-control img-textname' readonly='' value='" + data[text] + "'>";
  142. html += "<input type='hidden' value='" + data[key] + "' name='couponid[]'>";
  143. html += "<td style='width:80px;'><img src='" + data[thumb] + "' style='width:70px;border:1px solid #ccc;padding:1px'></td>";
  144. html += "<td style='width:220px;'>" + data[text] + "</td>";
  145. html += "<td><input class='form-control valid' type='text' value='' name='coupontotal" + data[key] + "'></td>";
  146. html += "<td><input class='form-control valid' type='text' value='' name='couponlimit" + data[key] + "'></td>";
  147. html += "<td style='width:80px;'><button class='btn btn-default' onclick='biz.selector.remove(this,\"" + name + "\")' type='button'><i class='fa fa-remove'></i></button></td></tr>"
  148. } else if (type == 'coupon_cp') {
  149. html += "<tr class='multi-product-item setticket' data-" + key + "='" + data[key] + "'>";
  150. html += "<input type='hidden' class='form-control img-textname' readonly='' value='" + data[text] + "'>";
  151. html += "<input type='hidden' value='" + data[key] + "' name='couponid[]'>";
  152. html += "<td style='width:80px;'><img src='" + data[thumb] + "' style='width:70px;border:1px solid #ccc;padding:1px'></td>";
  153. html += "<td style='width:220px;'>" + data[text] + "</td>";
  154. html += "<td></td>";
  155. html += "<td></td>";
  156. html += "<td style='width:80px;'><button class='btn btn-default' onclick='biz.selector.remove(this,\"" + name + "\")' type='button'><i class='fa fa-remove'></i></button></td></tr>"
  157. } else if (type == 'coupon_share') {
  158. html += "<tr class='multi-product-item shareticket' data-" + key + "='" + data[key] + "'>";
  159. html += "<input type='hidden' class='form-control img-textname' readonly='' value='" + data[text] + "'>";
  160. html += "<input type='hidden' value='" + data[key] + "' name='couponid[]'>";
  161. html += "<td style='width:80px;'><img src='" + data[thumb] + "' style='width:70px;border:1px solid #ccc;padding:1px'></td>";
  162. html += "<td style='width:220px;'>" + data[text] + "</td>";
  163. html += "<td></td>";
  164. html += "<td><input class='form-control valid' type='text' value='1' name='couponnum" + data[key] + "'></td>";
  165. html += "<td style='width:80px;'><button class='btn btn-default' onclick='biz.selector.remove(this,\"" + name + "\")' type='button'><i class='fa fa-remove'></i></button></td></tr>"
  166. } else if (type == 'coupon_shares') {
  167. html += "<tr class='multi-product-item sharesticket' data-" + key + "='" + data[key] + "'>";
  168. html += "<input type='hidden' class='form-control img-textname' readonly='' value='" + data[text] + "'>";
  169. html += "<input type='hidden' value='" + data[key] + "' name='couponids[]'>";
  170. html += "<td style='width:80px;'><img src='" + data[thumb] + "' style='width:70px;border:1px solid #ccc;padding:1px' class='img_share'></td>";
  171. html += "<td style='width:220px;'>" + data[text] + "</td>";
  172. html += "<td></td>";
  173. html += "<td><input class='form-control valid' type='text' value='1' name='couponsnum" + data[key] + "'></td>";
  174. html += "<td style='width:80px;'><button class='btn btn-default' onclick='biz.selector.remove(this,\"" + name + "\")' type='button'><i class='fa fa-remove'></i></button></td></tr>"
  175. } else {
  176. html += "<div class='multi-audio-item' data-" + key + "='" + data[key] + "' data-name='" + name + "'>";
  177. html += "<div class='input-group'><input type='hidden' name='" + id + "' value='" + data[key] + "'> ";
  178. html += "<input type='text' class='form-control img-textname' readonly='' value='" + data[text] + "'>";
  179. html += "<div class='input-group-btn'><button class='btn btn-default' onclick='biz.selector.remove(this,\"" + name + "\")' type='button'><i class='fa fa-remove'></i></button></div></div></div>"
  180. }
  181. if (multi === 0) {
  182. container.html(html);
  183. modalObj.modal('hide')
  184. } else {
  185. container.append(html)
  186. }
  187. biz.selector.refresh(name);
  188. if (callback !== '') {
  189. var callfunc = eval(callback);
  190. if (callfunc !== undefined) {
  191. callfunc(data, obj)
  192. }
  193. }
  194. },
  195. refresh: function(name) {
  196. var titles = '';
  197. var selector = $('#' + name + '_selector');
  198. var type = selector.data('type') || 'image';
  199. if (type == 'image') {
  200. $('.multi-item', selector).each(function() {
  201. titles += " " + $(this).find('.img-nickname').html();
  202. if ($('.multi-item', selector).length > 1) {
  203. titles += "; "
  204. }
  205. })
  206. } else if (type == 'coupon') {
  207. $('.multi-product-item', selector).each(function() {
  208. titles += " " + $(this).find('.img-textname').val();
  209. if ($('.multi-product-item', selector).length > 1) {
  210. titles += "; "
  211. }
  212. })
  213. } else if (type == 'coupon_cp') {
  214. $('.multi-product-item', selector).each(function() {
  215. titles += " " + $(this).find('.img-textname').val();
  216. if ($('.multi-product-item', selector).length > 1) {
  217. titles += "; "
  218. }
  219. })
  220. } else if (type == 'coupon_share') {
  221. $('.multi-product-item', selector).each(function() {
  222. titles += " " + $(this).find('.img-textname').val();
  223. if ($('.multi-product-item', selector).length > 1) {
  224. titles += "; "
  225. }
  226. })
  227. } else if (type == 'coupon_shares') {
  228. $('.multi-product-item', selector).each(function() {
  229. titles += " " + $(this).find('.img-textname').val();
  230. if ($('.multi-product-item', selector).length > 1) {
  231. titles += "; "
  232. }
  233. })
  234. } else {
  235. $('.multi-audio-item', selector).each(function() {
  236. titles += " " + $(this).find('.img-textname').val();
  237. if ($('.multi-audio-item', selector).length > 1) {
  238. titles += "; "
  239. }
  240. })
  241. }
  242. $('#' + name + "_text", selector).val(titles)
  243. }
  244. };
  245. biz.selector_new = {
  246. select: function(params) {
  247. params = $.extend({}, params || {});
  248. var name = params.name === undefined ? 'default' : params.name;
  249. var modalid = name + "-selector-modal";
  250. modalObj = $('#' + modalid);
  251. if (modalObj.length <= 0) {
  252. var modal = '<div id="' + modalid + '" class="modal fade" tabindex="-1">';
  253. modal += '<div class="modal-dialog" style="width: 920px;">';
  254. modal += '<div class="modal-content">';
  255. modal += '<div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>数据选择器</h3></div>';
  256. modal += '<div class="modal-body" >';
  257. modal += '<div class="row">';
  258. modal += '<div class="input-group">';
  259. modal += '<input type="text" class="form-control" name="keyword" id="' + name + '_input" placeholder="' + (params.placeholder === undefined ? '' : params.placeholder) + '" />';
  260. modal += '<span class="input-group-btn"><button type="button" class="btn btn-default" onclick="biz.selector_new.search(this, \'' + name + '\');">搜索</button></span>';
  261. modal += '</div>';
  262. modal += '</div>';
  263. modal += '<div class="content" style="padding-top:5px;" data-name="' + name + '"></div>';
  264. modal += '</div>';
  265. modal += '<div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>';
  266. modal += '</div>';
  267. modal += '</div>';
  268. modal += '</div>';
  269. modalObj = $(modal);
  270. modalObj.on('show.bs.modal', function() {
  271. if (params.autosearch == '1') {
  272. $.get(params.url, {
  273. keyword: ''
  274. }, function(dat) {
  275. $('.content', modalObj).html(dat)
  276. })
  277. }
  278. })
  279. };
  280. modalObj.modal('show')
  281. },
  282. search: function(searchbtn, name) {
  283. var input = $(searchbtn).closest('.modal').find('#' + name + '_input');
  284. var selector = $("#" + name + '_selector');
  285. var needkeywords = true;
  286. if (selector.data('nokeywords') == '1') {
  287. needkeywords = false
  288. };
  289. var keyword = $.trim(input.val());
  290. if (keyword == '' && needkeywords) {
  291. input.focus();
  292. return
  293. }
  294. var modalObj = $('#' + name + "-selector-modal");
  295. $('.content', modalObj).html("正在搜索....");
  296. $.get(selector.data('url'), {
  297. keyword: keyword
  298. }, function(dat) {
  299. $('.content', modalObj).html(dat)
  300. })
  301. },
  302. remove: function(obj, name) {
  303. var selector = $("#" + name + '_selector');
  304. var css = selector.data('type') == 'image' ? '.multi-item' : '.multi-product-item';
  305. $(obj).closest(css).remove();
  306. biz.selector_new.refresh(name)
  307. },
  308. set: function(obj, data) {
  309. var name = $(obj).closest('.content').data('name');
  310. var modalObj = $('#' + name + "-selector-modal");
  311. var selector = $('#' + name + "_selector");
  312. var key = selector.data('key') || 'id',
  313. text = selector.data('text') || 'title',
  314. thumb = selector.data('thumb') || 'thumb',
  315. multi = selector.data('multi') || 0,
  316. type = selector.data('type') || 'image',
  317. callback = selector.data('callback') || '',
  318. css = type == 'image' ? '.multi-item' : '.multi-product-item',
  319. optionurl = selector.data('optionurl') || '',
  320. selectorid = selector.data('selectorid') || '';
  321. var container = $('.container', selector);
  322. if ($(css + '[data-' + key + '="' + data[key] + '"]', container).length > 0) {
  323. if (multi === 0) {
  324. modalObj.modal('hide')
  325. }
  326. return
  327. }
  328. var id = multi === 0 ? name : name + "[]";
  329. var html = "";
  330. if (type == 'image') {
  331. html += '<div class="multi-item" data-' + key + '="' + data[key] + '" data-name="' + name + '">';
  332. html += '<img class="img-responsive img-thumbnail" src="' + data[thumb] + '" >';
  333. html += '<div class="img-nickname">' + data[text] + '</div>';
  334. html += '<input type="hidden" value="' + data[key] + '" name="' + id + '">';
  335. html += '<em onclick="biz.selector_new.remove(this,\'' + name + '\')" class="close">×</em>';
  336. html += '</div>'
  337. } else if (type == 'product') {
  338. var optionurl = optionurl == '' ? 'sale.package.hasoption' : optionurl;
  339. var url = "index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=" + optionurl + "&goodsid=" + data[key] + "&selectorid=" + selectorid;
  340. html += '<tr class="multi-product-item" data-' + key + '="' + data[key] + '" data-name="' + name + '">';
  341. html += "<input type='hidden' name='" + id + "' value='" + data[key] + "'> ";
  342. html += "<input type='hidden' class='form-control img-textname' value='" + data[text] + "'>";
  343. html += '<td style="width:80px;"><img src="' + data[thumb] + '" style="width:70px;border:1px solid #ccc;padding:1px" /></td>';
  344. html += '<td style="width:220px;">' + data[text] + '</td>';
  345. html += "<td><a class='btn btn-default btn-sm' data-toggle='ajaxModal' href='" + url + "' id='" + selectorid + "optiontitle" + data[key] + "'>设置</a>" + "<input type='hidden' id='" + selectorid + "packagegoods" + data[key] + "' value='' name='" + selectorid + "packagegoods[" + data[key] + "]'></td>";
  346. html += '<td><a href="javascript:void(0);" class="btn btn-default btn-sm" onclick="biz.selector_new.remove(this,\'' + name + '\')" title="删除">';
  347. html += '<i class="fa fa-times"></i></a></td></tr>'
  348. } else if (type == 'fullback') {
  349. var optionurl = optionurl == '' ? 'sale.fullback.hasoption' : optionurl;
  350. var url = "index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=" + optionurl + "&goodsid=" + data[key] + "&selectorid=" + selectorid;
  351. html += '<tr class="multi-product-item" data-' + key + '="' + data[key] + '" data-name="' + name + '">';
  352. html += "<input type='hidden' name='" + id + "' value='" + data[key] + "'> ";
  353. html += "<input type='hidden' class='form-control img-textname' value='" + data[text] + "'>";
  354. html += '<td style="width:80px;"><img src="' + data[thumb] + '" style="width:70px;border:1px solid #ccc;padding:1px" /></td>';
  355. html += '<td style="width:220px;">' + data[text] + '</td>';
  356. html += "<td><a class='btn btn-default btn-sm' data-toggle='ajaxModal' href='" + url + "' id='" + selectorid + "optiontitle" + data[key] + "'>设置</a>" + "<input type='hidden' id='" + selectorid + "fullbackgoods" + data[key] + "' value='' name='" + selectorid + "fullbackgoods[" + data[key] + "]'></td>";
  357. html += '<td><a href="javascript:void(0);" class="btn btn-default btn-sm" onclick="biz.selector_new.remove(this,\'' + name + '\')" title="删除">';
  358. html += '<i class="fa fa-times"></i></a></td></tr>'
  359. } else if (type == 'live') {
  360. var optionurl = optionurl == '' ? 'live.room.hasoption' : optionurl;
  361. var url = "index.php?c=site&a=entry&m=lionfish_comshop&do=admin&controller=" + optionurl + "&goodsid=" + data[key] + "&selectorid=" + selectorid;
  362. html += '<tr class="multi-product-item" data-' + key + '="' + data[key] + '" data-name="' + name + '">';
  363. html += "<input type='hidden' name='" + id + "' value='" + data[key] + "'> ";
  364. html += "<input type='hidden' class='form-control img-textname' value='" + data[text] + "'>";
  365. html += '<td style="width:80px;"><img src="' + data[thumb] + '" style="width:70px;border:1px solid #ccc;padding:1px" /></td>';
  366. html += '<td style="width:220px;">' + data[text] + '</td>';
  367. html += "<td><a class='btn btn-default btn-sm' data-toggle='ajaxModal' href='" + url + "' id='" + selectorid + "optiontitle" + data[key] + "'>设置</a>" + "<input type='hidden' id='" + selectorid + "livegoods" + data[key] + "' value='' name='" + selectorid + "livegoods[" + data[key] + "]'></td>";
  368. html += '<td><a href="javascript:void(0);" class="btn btn-default btn-sm" onclick="biz.selector_new.remove(this,\'' + name + '\')" title="删除">';
  369. html += '<i class="fa fa-times"></i></a></td></tr>'
  370. } else {
  371. html += "<div class='111 multi-audio-item' data-" + key + "='" + data[key] + "' data-name='" + name + "'>";
  372. html += "<div class='input-group'><input type='hidden' name='" + id + "' value='" + data[key] + "'> ";
  373. html += "<input type='text' class='form-control img-textname' readonly='' value='" + data[text] + "'>";
  374. html += "<div class='input-group-btn'><button class='btn btn-default' onclick='biz.selector_new.remove(this,\"" + name + "\")' type='button'>" + "<i class='fa fa-remove'></i></button></div></div></div>"
  375. }
  376. if (multi === 0) {
  377. container.html(html);
  378. modalObj.modal('hide')
  379. } else {
  380. $("#param-items" + selectorid).append(html)
  381. }
  382. biz.selector_new.refresh(name);
  383. if (callback !== '') {
  384. var callfunc = eval(callback);
  385. if (callfunc !== undefined) {
  386. callfunc(data, obj)
  387. }
  388. }
  389. },
  390. refresh: function(name) {
  391. var titles = '';
  392. var selector = $('#' + name + '_selector');
  393. var type = selector.data('type') || 'image';
  394. if (type == 'image') {
  395. $('.multi-item', selector).each(function() {
  396. titles += " " + $(this).find('.img-nickname').html();
  397. if ($('.multi-item', selector).length > 1) {
  398. titles += "; "
  399. }
  400. })
  401. } else {
  402. $('.multi-product-item', selector).each(function() {
  403. titles += " " + $(this).find('.img-textname').val();
  404. if ($('.multi-product-item', selector).length > 1) {
  405. titles += "; "
  406. }
  407. })
  408. }
  409. $('#' + name + "_text", selector).val(titles)
  410. }
  411. };
  412. biz.selector_open = {
  413. callback: function() {},
  414. select: function(params) {
  415. params = $.extend({}, params || {});
  416. biz.selector_open.callback = typeof(params.callback) === 'undefined' ? false : params.callback;
  417. biz.selector_open.params = params;
  418. var name = params.name === undefined ? 'default' : params.name;
  419. var modalid = name + "-selector-modal";
  420. modalObj = $('#' + modalid);
  421. if (modalObj.length <= 0) {
  422. var modal = '<div id="' + modalid + '" class="modal fade" tabindex="-1">';
  423. modal += '<div class="modal-dialog" style="width: 920px;">';
  424. modal += '<div class="modal-content">';
  425. modal += '<div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>数据选择器</h3></div>';
  426. modal += '<div class="modal-body" >';
  427. modal += '<div class="row">';
  428. modal += '<div class="input-group">';
  429. modal += '<input type="text" class="form-control" name="keyword" id="' + name + '_input" placeholder="' + (params.placeholder === undefined ? '' : params.placeholder) + '" />';
  430. modal += '<span class="input-group-btn"><button type="button" class="btn btn-default" onclick="biz.selector_open.search(this, \'' + name + '\');">搜索</button></span>';
  431. modal += '</div>';
  432. modal += '</div>';
  433. modal += '<div class="content" style="padding-top:5px;" data-name="' + name + '"></div>';
  434. modal += '</div>';
  435. modal += '<div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>';
  436. modal += '</div>';
  437. modal += '</div>';
  438. modal += '</div>';
  439. modalObj = $(modal);
  440. modalObj.on('show.bs.modal', function() {
  441. if (params.autosearch == '1') {
  442. $.get(params.url, {
  443. keyword: ''
  444. }, function(dat) {
  445. $('.content', modalObj).html(dat)
  446. })
  447. }
  448. })
  449. };
  450. modalObj.modal('show')
  451. },
  452. search: function(searchbtn, name) {
  453. var input = $(searchbtn).closest('.modal').find('#' + name + '_input');
  454. var selector = $("#" + name + '_selector');
  455. var needkeywords = true;
  456. var params = biz.selector_open.params;
  457. if (params.nokeywords == '1') {
  458. needkeywords = false
  459. };
  460. var keyword = $.trim(input.val());
  461. if (keyword == '' && needkeywords) {
  462. input.focus();
  463. return
  464. }
  465. var modalObj = $('#' + name + "-selector-modal");
  466. $('.content', modalObj).html("正在搜索....");
  467. $.get(params.url, {
  468. keyword: keyword
  469. }, function(dat) {
  470. $('.content', modalObj).html(dat)
  471. })
  472. },
  473. remove: function(obj, name) {
  474. var params = biz.selector_open.params;
  475. var css = params.type == 'image' ? '.multi-item' : '.multi-audio-item';
  476. $(obj).closest(css).remove();
  477. biz.selector_open.refresh(name)
  478. },
  479. set: function(obj, data) {
  480. var name = $(obj).closest('.content').data('name');
  481. var modalObj = $('#' + name + "-selector-modal");
  482. var selector = $('#' + name + "_selector");
  483. var params = biz.selector_open.params;
  484. var multi = params.multi || 0;
  485. if (multi === 0) {
  486. modalObj.modal('hide')
  487. }
  488. if (typeof(biz.selector_open.callback) === 'function') {
  489. biz.selector_open.callback(data, obj)
  490. }
  491. }
  492. };
  493. biz.map = function(val, callback, tpl) {
  494. var modalobj = $('#map-dialog');
  495. if (modalobj.length === 0) {
  496. var content = '<div class="embed-responsive embed-responsive-16by9">' + '<iframe class="embed-responsive-item" src="' + tpl + '" scrolling="no"></iframe>' + '</div>';
  497. var footer = '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' + '<button type="button" class="btn btn-primary">确认</button>';
  498. modalobj = util.dialog('请选择地点', content, footer, {
  499. containerName: 'map-dialog'
  500. });
  501. modalobj.find('.modal-dialog').css('width', '80%');
  502. modalobj.modal({
  503. 'keyboard': false
  504. });
  505. modalobj.find('.input-group :text').keydown(function(e) {
  506. if (e.keyCode == 13) {
  507. var kw = $(this).val();
  508. searchAddress(kw)
  509. }
  510. });
  511. modalobj.find('.input-group button').click(function() {
  512. var kw = $(this).parent().prev().val();
  513. searchAddress(kw)
  514. })
  515. }
  516. modalobj.find('button.btn-primary').off('click');
  517. modalobj.find('button.btn-primary').on('click', function() {
  518. if ($.isFunction(callback)) {
  519. var $point = modalobj.find("iframe").contents().find("#poi_json").val();
  520. if ($.isEmpty($point)) {
  521. tip.msgbox.err('尚未选择坐标!');
  522. return
  523. }
  524. var point = JSON.parse(modalobj.find("iframe").contents().find("#poi_json").val());
  525. var address = modalobj.find("iframe").contents().find("#addr_cur").val();
  526. var val = {
  527. lng: point.lng,
  528. lat: point.lat,
  529. label: address
  530. };
  531. callback(val)
  532. }
  533. modalobj.modal('hide')
  534. });
  535. modalobj.modal('show')
  536. };
  537. biz.TxMapToBdMap = function(gg_lat, gg_lon) {
  538. var point = new Object();
  539. var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  540. var x = new Number(gg_lon);
  541. var y = new Number(gg_lat);
  542. var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
  543. var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
  544. var bd_lon = z * Math.cos(theta) + 0.0065;
  545. var bd_lat = z * Math.sin(theta) + 0.006;
  546. point.lng = bd_lon;
  547. point.lat = bd_lat;
  548. return point
  549. };
  550. biz.BdMapToTxMap = function(bd_lat, bd_lon) {
  551. var point = new Object();
  552. var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  553. var x = new Number(bd_lon - 0.0065);
  554. var y = new Number(bd_lat - 0.006);
  555. var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  556. var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  557. var Mars_lon = z * Math.cos(theta);
  558. var Mars_lat = z * Math.sin(theta);
  559. point.lng = Mars_lon;
  560. point.lat = Mars_lat;
  561. return point
  562. };
  563. window.biz = biz;
  564. return biz
  565. });