common.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * 商品选择器
  3. * @param callback 回调函数
  4. * @param selectId 已选商品id
  5. * @param params mode:模式(spu、sku), max_num:最大数量,min_num 最小数量, is_virtual 是否虚拟 0 1, disabled: 开启禁用已选 0 1,promotion:营销活动标识 pintuan、groupbuy、fenxiao (module 表示组件)
  6. */
  7. function goodsSelect(callback, selectId, params={}) {
  8. layui.use(['layer'], function () {
  9. if (selectId.length) {
  10. params.select_id = selectId.toString();
  11. }
  12. params.mode = params.mode ? params.mode : 'spu';
  13. // params.disabled = params.disabled == 0 ? 0 : 1;
  14. if(!params.post) params.post = 'shop';
  15. if (params.post == 'store') params.post += '://store';
  16. var url = ns.url(params.post + "/goods/goodsselect", params);
  17. //iframe层-父子操作
  18. layer.open({
  19. title: "商品选择",
  20. type: 2,
  21. area: ['1000px', '720px'],
  22. fixed: false, //不固定
  23. btn: ['保存', '返回'],
  24. content: url,
  25. yes: function (index, layero) {
  26. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  27. iframeWin.selectGoods(function (obj) {
  28. if (typeof callback == "string") {
  29. try {
  30. eval(callback + '(obj)');
  31. layer.close(index);
  32. } catch (e) {
  33. console.error('回调函数' + callback + '未定义');
  34. }
  35. } else if (typeof callback == "function") {
  36. callback(obj);
  37. layer.close(index);
  38. }
  39. });
  40. }
  41. });
  42. });
  43. }
  44. /**
  45. * 店铺笔记选择器
  46. * @param callback 回调函数
  47. * @param selectId 已选笔记id
  48. * @param params mode:min_num 最小数量
  49. */
  50. function notesSelect(callback, selectId, params) {
  51. layui.use(['layer'], function () {
  52. if (selectId.length) {
  53. params.select_id = selectId.toString();
  54. }
  55. var url = ns.url("notes://shop/notes/notesSelect", params);
  56. //iframe层-父子操作
  57. layer.open({
  58. title: "店铺笔记选择",
  59. type: 2,
  60. area: ['1000px', '720px'],
  61. fixed: false, //不固定
  62. btn: ['保存', '返回'],
  63. content: url,
  64. yes: function (index, layero) {
  65. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  66. iframeWin.selectNotes(function (obj) {
  67. if (typeof callback == "string") {
  68. try {
  69. eval(callback + '(obj)');
  70. layer.close(index);
  71. } catch (e) {
  72. console.error('回调函数' + callback + '未定义');
  73. }
  74. } else if (typeof callback == "function") {
  75. callback(obj);
  76. layer.close(index);
  77. }
  78. });
  79. }
  80. });
  81. });
  82. }