common.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /**
  2. * 打开相册
  3. * display_type img-选择图片,icon-选择icon
  4. */
  5. function openAlbum(callback, imgNum = 9999, is_thumb = 0, type = 'img',display_type = "img") {
  6. layui.use(['layer'], function () {
  7. layer.open({
  8. type: 2,
  9. title: '素材管理',
  10. area: ['950px', '600px'],
  11. fixed: false, //不固定
  12. btn: ['保存', '返回'],
  13. content: ns.url("shop/album/album?imgNum=" + imgNum + "&is_thumb=" + is_thumb + '&type=' + type + '&site_id=' + ns_url.siteId + '&app_module=' + ns_url.appModule + '&display_type=' + display_type),
  14. yes: function (index, layero) {
  15. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  16. iframeWin.getCheckItem(function (obj) {
  17. if (typeof callback == "string") {
  18. try {
  19. eval(callback + '(obj)');
  20. layer.close(index);
  21. } catch (e) {
  22. console.error('回调函数' + callback + '未定义');
  23. }
  24. } else if (typeof callback == "function") {
  25. callback(obj);
  26. layer.close(index);
  27. }
  28. });
  29. }
  30. });
  31. });
  32. }
  33. /**
  34. * 商品选择器
  35. * @param callback 回调函数
  36. * @param selectId 已选商品id
  37. * @param params mode:模式(spu、sku), max_num:最大数量,min_num 最小数量, is_virtual 是否虚拟 0 1, disabled: 开启禁用已选 0 1,promotion:营销活动标识 pintuan、groupbuy、fenxiao (module 表示组件) is_disabled_goods_type: 1表示关闭商品类型筛选 0表示开启商品类型筛选 goods_type: 1 实物商品 2虚拟商品 3电子商品 不传查全部
  38. */
  39. function goodsSelect(callback, selectId, params={}) {
  40. layui.use(['layer'], function () {
  41. localStorage.removeItem('goods_select_id'); // 删除选中id 本地缓存
  42. if (selectId.length) {
  43. // params.select_id = selectId.toString();
  44. localStorage.setItem('goods_select_id',selectId.toString());
  45. }
  46. params.mode = params.mode ? params.mode : 'spu';
  47. params.disabled = params.disabled == 0 ? 0 : 1;
  48. params.site_id = ns_url.siteId;
  49. params.app_module = ns_url.appModule;
  50. params.is_disabled_goods_type = params.is_disabled_goods_type || 0;
  51. params.goods_type = params.goods_type || "";
  52. // if(!params.post) params.post = 'shop';
  53. // if (params.post == 'store') params.post += '://store';
  54. var url = ns.url("shop/goods/goodsselect", params);
  55. //iframe层-父子操作
  56. layer.open({
  57. title: "商品选择",
  58. type: 2,
  59. area: ['1000px', '720px'],
  60. fixed: false, //不固定
  61. btn: ['保存', '返回'],
  62. content: url,
  63. yes: function (index, layero) {
  64. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  65. iframeWin.selectGoods(function (obj) {
  66. if (typeof callback == "string") {
  67. try {
  68. eval(callback + '(obj)');
  69. layer.close(index);
  70. } catch (e) {
  71. console.error('回调函数' + callback + '未定义');
  72. }
  73. } else if (typeof callback == "function") {
  74. callback(obj);
  75. layer.close(index);
  76. }
  77. });
  78. }
  79. });
  80. });
  81. }
  82. /**
  83. * 店铺笔记选择器
  84. * @param callback 回调函数
  85. * @param selectId 已选笔记id
  86. * @param params mode:min_num 最小数量
  87. */
  88. function notesSelect(callback, selectId, params) {
  89. layui.use(['layer'], function () {
  90. localStorage.removeItem('note_select_id'); // 删除选中id 本地缓存
  91. if (selectId.length) {
  92. // params.select_id = selectId.toString();
  93. localStorage.setItem('note_select_id',selectId.toString()); // 删除选中id 本地缓存
  94. }
  95. var url = ns.url("notes://shop/notes/notesSelect", params);
  96. //iframe层-父子操作
  97. layer.open({
  98. title: "店铺笔记选择",
  99. type: 2,
  100. area: ['1000px', '720px'],
  101. fixed: false, //不固定
  102. btn: ['保存', '返回'],
  103. content: url,
  104. yes: function (index, layero) {
  105. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  106. iframeWin.selectNotes(function (obj) {
  107. if (typeof callback == "string") {
  108. try {
  109. eval(callback + '(obj)');
  110. layer.close(index);
  111. } catch (e) {
  112. console.error('回调函数' + callback + '未定义');
  113. }
  114. } else if (typeof callback == "function") {
  115. callback(obj);
  116. layer.close(index);
  117. }
  118. });
  119. }
  120. });
  121. });
  122. }
  123. function tipsShow() {
  124. var prompt_tips_box = 0;
  125. // 处理鼠标划上提示问题
  126. setTimeout(function () {
  127. $('body .js-prompt-top').unbind('mouseover').unbind('mouseout').unbind('mousemove');
  128. $('body .js-prompt-top').mouseover(function () {
  129. var prompt_tips_data;
  130. prompt_tips_data = $(this).data('tips');
  131. if (!prompt_tips_data) {
  132. prompt_tips_data = $('.js-prompt-top-' + $(this).data('tipsbox')).html();
  133. }
  134. prompt_tips_box = layer.tips(prompt_tips_data, $(this), {
  135. tips: [1, '#fff'],//还可配置颜色
  136. time: 0
  137. });
  138. }).mouseleave(function () {
  139. layer.close(prompt_tips_box)
  140. })
  141. }, 1000) //延迟执行为解决某些页面渲染问题
  142. }
  143. tipsShow();
  144. /**
  145. * 图标库选择器
  146. * @param callback 回调函数
  147. * @param params icon:选中的icon
  148. */
  149. function iconSelect(callback, params={}) {
  150. layui.use(['layer'], function () {
  151. //iframe层-父子操作
  152. layer.open({
  153. title: "图标选择器",
  154. type: 2,
  155. area: ['950px', '550px'],
  156. fixed: false, //不固定
  157. btn: ['保存', '返回'],
  158. content: ns.url("shop/diy/iconfont",{icon: params.icon, site_id: ns_url.siteId, app_module: ns_url.appModule}),
  159. yes: function (index, layero) {
  160. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  161. iframeWin.selectIcon(function (obj) {
  162. if (typeof callback == "string") {
  163. try {
  164. eval(callback + '(obj)');
  165. layer.close(index);
  166. } catch (e) {
  167. console.error('回调函数' + callback + '未定义');
  168. }
  169. } else if (typeof callback == "function") {
  170. callback(obj);
  171. layer.close(index);
  172. }
  173. });
  174. }
  175. });
  176. });
  177. }
  178. /**
  179. * 图标风格设置
  180. * @param params
  181. * @param callback
  182. */
  183. function iconStyleSet(params, callback) {
  184. if (params.style != undefined) localStorage.setItem('iconStyle', params.style);
  185. layer.open({
  186. title: "图标风格设置",
  187. type: 2,
  188. area: ['1000px', '720px'],
  189. fixed: false, //不固定
  190. btn: ['保存', '取消'],
  191. content: ns.url("shop/diy/iconstyleset", params.query ? params.query : {}),
  192. yes: function (index, layero) {
  193. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  194. iframeWin.iconStyle(function (obj) {
  195. if (typeof callback == "string") {
  196. try {
  197. eval(callback + '(obj)');
  198. layer.close(index);
  199. } catch (e) {
  200. console.error('回调函数' + callback + '未定义');
  201. }
  202. } else if (typeof callback == "function") {
  203. callback(obj);
  204. layer.close(index);
  205. }
  206. });
  207. }
  208. });
  209. }
  210. // icon预览
  211. $(function () {
  212. $('body').on('click', '.icon-box .js-preview', function () {
  213. var h = `<div class="icon-preview">
  214. <div class="icon-preview-block">
  215. `+ $(this).parents('.icon-box').html() +`
  216. </div>
  217. </div>`;
  218. $('body').append(h);
  219. $('.icon-preview-block .operation').remove();
  220. $('.icon-preview').click(function () {
  221. $(this).remove();
  222. })
  223. })
  224. });
  225. /**
  226. * 选择图标风格
  227. * @param option
  228. */
  229. function selectIconStyle(option) {
  230. var _w = option.width ? option.width : 340,
  231. _h = option.height ? option.height : 200,
  232. _x = $(option.elem).offset().left + $(option.elem).width() - _w,
  233. _y = $(option.elem).offset().top + $(option.elem).height();
  234. option.pagex -= _w;
  235. window.onmessage = function(e) {
  236. if (e.data.event && e.data.event == 'selectIconStyle') {
  237. $('.select-icon-style').remove();
  238. typeof option.callback == 'function' && option.callback(e.data.data);
  239. }
  240. };
  241. var h = `
  242. <div class="select-icon-style">
  243. <div class="icon-style-wrap" style="width: `+ _w +`px;height: `+ _h +`px;left:`+ _x +`px;top:`+ _y +`px">
  244. <iframe src="`+ ns.url('shop/diy/selecticonstyle', {icon: option.icon}) +`" frameborder="0"></iframe>
  245. </div>
  246. </div>
  247. `;
  248. $('body').append(h);
  249. // 点击任意位置关闭弹窗
  250. $('.select-icon-style').click(function () {
  251. $(this).remove();
  252. })
  253. }
  254. /**
  255. * 商品品牌选择器
  256. * @param callback 回调函数
  257. * @param params select_id 已选商品id
  258. */
  259. function goodsBrandSelect(callback, params={}) {
  260. layui.use(['layer'], function () {
  261. localStorage.removeItem('goods_brand_select_id'); // 删除选中id 本地缓存
  262. if (params.select_id) {
  263. localStorage.setItem('goods_brand_select_id', params.select_id);
  264. }
  265. var url = ns.url("shop/goodsbrand/brandselect", params);
  266. //iframe层-父子操作
  267. layer.open({
  268. title: "商品品牌选择",
  269. type: 2,
  270. area: ['800px', '600px'],
  271. fixed: false, //不固定
  272. btn: ['保存', '返回'],
  273. content: url,
  274. yes: function (index, layero) {
  275. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  276. iframeWin.selectGoodsBrand(function (obj) {
  277. if (typeof callback == "string") {
  278. try {
  279. eval(callback + '(obj)');
  280. layer.close(index);
  281. } catch (e) {
  282. console.error('回调函数' + callback + '未定义');
  283. }
  284. } else if (typeof callback == "function") {
  285. callback(obj);
  286. layer.close(index);
  287. }
  288. });
  289. }
  290. });
  291. });
  292. }
  293. /**
  294. * 文章选择器
  295. * @param callback 回调函数
  296. * @param params select_id 已选商品id
  297. */
  298. function articleSelect(callback, params={}) {
  299. layui.use(['layer'], function () {
  300. localStorage.removeItem('article_select_id'); // 删除选中id 本地缓存
  301. if (params.select_id) {
  302. localStorage.setItem('article_select_id', params.select_id);
  303. }
  304. var url = ns.url("shop/article/articleselect", params);
  305. //iframe层-父子操作
  306. layer.open({
  307. title: "文章选择",
  308. type: 2,
  309. area: ['800px', '600px'],
  310. fixed: false, //不固定
  311. btn: ['保存', '返回'],
  312. content: url,
  313. yes: function (index, layero) {
  314. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  315. iframeWin.selectArticle(function (obj) {
  316. if (typeof callback == "string") {
  317. try {
  318. eval(callback + '(obj)');
  319. layer.close(index);
  320. } catch (e) {
  321. console.error('回调函数' + callback + '未定义');
  322. }
  323. } else if (typeof callback == "function") {
  324. callback(obj);
  325. layer.close(index);
  326. }
  327. });
  328. }
  329. });
  330. });
  331. }
  332. function storeSelect(callback, params={}) {
  333. layui.use(['layer'], function () {
  334. //iframe层-父子操作
  335. layer.open({
  336. title: "选择门店",
  337. type: 2,
  338. area: ['950px', '550px'],
  339. fixed: false, //不固定
  340. btn: ['保存', '返回'],
  341. content: ns.url("shop/store/selectstore", params),
  342. yes: function (index, layero) {
  343. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  344. iframeWin.selectStore(function (obj) {
  345. if (typeof callback == "string") {
  346. try {
  347. eval(callback + '(obj)');
  348. layer.close(index);
  349. } catch (e) {
  350. console.error('回调函数' + callback + '未定义');
  351. }
  352. } else if (typeof callback == "function") {
  353. callback(obj);
  354. layer.close(index);
  355. }
  356. });
  357. }
  358. });
  359. });
  360. }
  361. function showNotify(option){
  362. var node = {};
  363. if (option.icon && ['success', 'fail', 'info', 'warning'].indexOf(option.icon) != -1) node.icon = '<div class="icon"><i class="'+ option.icon +'"></i></div>';
  364. if (option.title) node.title = '<div class="title">'+ option.title +'</div>';
  365. if (option.content) node.content = '<div class="content">'+ option.content +'</div>';
  366. var h = `<div class="notify-item">
  367. `+ (node.icon ? node.icon : '') +`
  368. <span class="iconfont iconclose_light"></span>
  369. <div class="box">
  370. `+ (node.title ? node.title : '') +`
  371. `+ (node.content ? node.content : '') +`
  372. </div>
  373. </div>`;
  374. if ($('.notify-wrap').length) {
  375. $('.notify-wrap').append(h);
  376. } else {
  377. $('body').append('<div class="notify-wrap">' + h + '</div>');
  378. }
  379. let elem = $('.notify-wrap .notify-item:last-child');
  380. // 手动关闭
  381. elem.find('.iconclose_light').click(function () {
  382. $(this).parents('.notify-item').remove();
  383. })
  384. // 自动关闭
  385. let duration = option.duration != undefined ? option.duration : 4500;
  386. if (duration) {
  387. setTimeout(function () {
  388. elem.remove();
  389. }, duration)
  390. }
  391. }