| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- /**
- * 打开相册
- * display_type img-选择图片,icon-选择icon
- */
- function openAlbum(callback, imgNum = 9999, is_thumb = 0, type = 'img',display_type = "img") {
- layui.use(['layer'], function () {
- layer.open({
- type: 2,
- title: '素材管理',
- area: ['950px', '600px'],
- fixed: false, //不固定
- btn: ['保存', '返回'],
- 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),
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
- iframeWin.getCheckItem(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
- });
- }
- });
- });
- }
- /**
- * 商品选择器
- * @param callback 回调函数
- * @param selectId 已选商品id
- * @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电子商品 不传查全部
- */
- function goodsSelect(callback, selectId, params={}) {
- layui.use(['layer'], function () {
- localStorage.removeItem('goods_select_id'); // 删除选中id 本地缓存
- if (selectId.length) {
- // params.select_id = selectId.toString();
- localStorage.setItem('goods_select_id',selectId.toString());
- }
- params.mode = params.mode ? params.mode : 'spu';
- params.disabled = params.disabled == 0 ? 0 : 1;
- params.site_id = ns_url.siteId;
- params.app_module = ns_url.appModule;
- params.is_disabled_goods_type = params.is_disabled_goods_type || 0;
- params.goods_type = params.goods_type || "";
- // if(!params.post) params.post = 'shop';
- // if (params.post == 'store') params.post += '://store';
- var url = ns.url("shop/goods/goodsselect", params);
- //iframe层-父子操作
- layer.open({
- title: "商品选择",
- type: 2,
- area: ['1000px', '720px'],
- fixed: false, //不固定
- btn: ['保存', '返回'],
- content: url,
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
-
- iframeWin.selectGoods(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
-
- });
- }
- });
- });
- }
- /**
- * 店铺笔记选择器
- * @param callback 回调函数
- * @param selectId 已选笔记id
- * @param params mode:min_num 最小数量
- */
- function notesSelect(callback, selectId, params) {
- layui.use(['layer'], function () {
- localStorage.removeItem('note_select_id'); // 删除选中id 本地缓存
- if (selectId.length) {
- // params.select_id = selectId.toString();
- localStorage.setItem('note_select_id',selectId.toString()); // 删除选中id 本地缓存
- }
-
- var url = ns.url("notes://shop/notes/notesSelect", params);
- //iframe层-父子操作
- layer.open({
- title: "店铺笔记选择",
- type: 2,
- area: ['1000px', '720px'],
- fixed: false, //不固定
- btn: ['保存', '返回'],
- content: url,
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
-
- iframeWin.selectNotes(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
-
- });
- }
- });
- });
- }
- function tipsShow() {
- var prompt_tips_box = 0;
- // 处理鼠标划上提示问题
- setTimeout(function () {
- $('body .js-prompt-top').unbind('mouseover').unbind('mouseout').unbind('mousemove');
- $('body .js-prompt-top').mouseover(function () {
- var prompt_tips_data;
- prompt_tips_data = $(this).data('tips');
- if (!prompt_tips_data) {
- prompt_tips_data = $('.js-prompt-top-' + $(this).data('tipsbox')).html();
- }
- prompt_tips_box = layer.tips(prompt_tips_data, $(this), {
- tips: [1, '#fff'],//还可配置颜色
- time: 0
- });
- }).mouseleave(function () {
- layer.close(prompt_tips_box)
- })
- }, 1000) //延迟执行为解决某些页面渲染问题
- }
- tipsShow();
- /**
- * 图标库选择器
- * @param callback 回调函数
- * @param params icon:选中的icon
- */
- function iconSelect(callback, params={}) {
- layui.use(['layer'], function () {
- //iframe层-父子操作
- layer.open({
- title: "图标选择器",
- type: 2,
- area: ['950px', '550px'],
- fixed: false, //不固定
- btn: ['保存', '返回'],
- content: ns.url("shop/diy/iconfont",{icon: params.icon, site_id: ns_url.siteId, app_module: ns_url.appModule}),
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
-
- iframeWin.selectIcon(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
-
- });
- }
- });
- });
- }
- /**
- * 图标风格设置
- * @param params
- * @param callback
- */
- function iconStyleSet(params, callback) {
- if (params.style != undefined) localStorage.setItem('iconStyle', params.style);
- layer.open({
- title: "图标风格设置",
- type: 2,
- area: ['1000px', '720px'],
- fixed: false, //不固定
- btn: ['保存', '取消'],
- content: ns.url("shop/diy/iconstyleset", params.query ? params.query : {}),
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
- iframeWin.iconStyle(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
- });
- }
- });
- }
- // icon预览
- $(function () {
- $('body').on('click', '.icon-box .js-preview', function () {
- var h = `<div class="icon-preview">
- <div class="icon-preview-block">
- `+ $(this).parents('.icon-box').html() +`
- </div>
- </div>`;
- $('body').append(h);
- $('.icon-preview-block .operation').remove();
- $('.icon-preview').click(function () {
- $(this).remove();
- })
- })
- });
- /**
- * 选择图标风格
- * @param option
- */
- function selectIconStyle(option) {
- var _w = option.width ? option.width : 340,
- _h = option.height ? option.height : 200,
- _x = $(option.elem).offset().left + $(option.elem).width() - _w,
- _y = $(option.elem).offset().top + $(option.elem).height();
- option.pagex -= _w;
- window.onmessage = function(e) {
- if (e.data.event && e.data.event == 'selectIconStyle') {
- $('.select-icon-style').remove();
- typeof option.callback == 'function' && option.callback(e.data.data);
- }
- };
- var h = `
- <div class="select-icon-style">
- <div class="icon-style-wrap" style="width: `+ _w +`px;height: `+ _h +`px;left:`+ _x +`px;top:`+ _y +`px">
- <iframe src="`+ ns.url('shop/diy/selecticonstyle', {icon: option.icon}) +`" frameborder="0"></iframe>
- </div>
- </div>
- `;
- $('body').append(h);
- // 点击任意位置关闭弹窗
- $('.select-icon-style').click(function () {
- $(this).remove();
- })
- }
- /**
- * 商品品牌选择器
- * @param callback 回调函数
- * @param params select_id 已选商品id
- */
- function goodsBrandSelect(callback, params={}) {
- layui.use(['layer'], function () {
- localStorage.removeItem('goods_brand_select_id'); // 删除选中id 本地缓存
- if (params.select_id) {
- localStorage.setItem('goods_brand_select_id', params.select_id);
- }
- var url = ns.url("shop/goodsbrand/brandselect", params);
- //iframe层-父子操作
- layer.open({
- title: "商品品牌选择",
- type: 2,
- area: ['800px', '600px'],
- fixed: false, //不固定
- btn: ['保存', '返回'],
- content: url,
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
- iframeWin.selectGoodsBrand(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
- });
- }
- });
- });
- }
- /**
- * 文章选择器
- * @param callback 回调函数
- * @param params select_id 已选商品id
- */
- function articleSelect(callback, params={}) {
- layui.use(['layer'], function () {
- localStorage.removeItem('article_select_id'); // 删除选中id 本地缓存
- if (params.select_id) {
- localStorage.setItem('article_select_id', params.select_id);
- }
- var url = ns.url("shop/article/articleselect", params);
- //iframe层-父子操作
- layer.open({
- title: "文章选择",
- type: 2,
- area: ['800px', '600px'],
- fixed: false, //不固定
- btn: ['保存', '返回'],
- content: url,
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
- iframeWin.selectArticle(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
- });
- }
- });
- });
- }
- function storeSelect(callback, params={}) {
- layui.use(['layer'], function () {
- //iframe层-父子操作
- layer.open({
- title: "选择门店",
- type: 2,
- area: ['950px', '550px'],
- fixed: false, //不固定
- btn: ['保存', '返回'],
- content: ns.url("shop/store/selectstore", params),
- yes: function (index, layero) {
- var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
- iframeWin.selectStore(function (obj) {
- if (typeof callback == "string") {
- try {
- eval(callback + '(obj)');
- layer.close(index);
- } catch (e) {
- console.error('回调函数' + callback + '未定义');
- }
- } else if (typeof callback == "function") {
- callback(obj);
- layer.close(index);
- }
- });
- }
- });
- });
- }
- function showNotify(option){
- var node = {};
- if (option.icon && ['success', 'fail', 'info', 'warning'].indexOf(option.icon) != -1) node.icon = '<div class="icon"><i class="'+ option.icon +'"></i></div>';
- if (option.title) node.title = '<div class="title">'+ option.title +'</div>';
- if (option.content) node.content = '<div class="content">'+ option.content +'</div>';
- var h = `<div class="notify-item">
- `+ (node.icon ? node.icon : '') +`
- <span class="iconfont iconclose_light"></span>
- <div class="box">
- `+ (node.title ? node.title : '') +`
- `+ (node.content ? node.content : '') +`
- </div>
- </div>`;
- if ($('.notify-wrap').length) {
- $('.notify-wrap').append(h);
- } else {
- $('body').append('<div class="notify-wrap">' + h + '</div>');
- }
- let elem = $('.notify-wrap .notify-item:last-child');
- // 手动关闭
- elem.find('.iconclose_light').click(function () {
- $(this).parents('.notify-item').remove();
- })
- // 自动关闭
- let duration = option.duration != undefined ? option.duration : 4500;
- if (duration) {
- setTimeout(function () {
- elem.remove();
- }, duration)
- }
- }
|