common.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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
  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. var url = ns.url("shop/goods/goodsselect", params);
  15. //iframe层-父子操作
  16. layer.open({
  17. title: "商品选择",
  18. type: 2,
  19. area: ['1000px', '720px'],
  20. fixed: false, //不固定
  21. btn: ['保存', '返回'],
  22. content: url,
  23. yes: function (index, layero) {
  24. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  25. iframeWin.selectGoods(function (obj) {
  26. if (typeof callback == "string") {
  27. try {
  28. eval(callback + '(obj)');
  29. layer.close(index);
  30. } catch (e) {
  31. console.error('回调函数' + callback + '未定义');
  32. }
  33. } else if (typeof callback == "function") {
  34. callback(obj);
  35. layer.close(index);
  36. }
  37. });
  38. }
  39. });
  40. });
  41. }
  42. /**
  43. * 店铺笔记选择器
  44. * @param callback 回调函数
  45. * @param selectId 已选笔记id
  46. * @param params mode:min_num 最小数量
  47. */
  48. function notesSelect(callback, selectId, params) {
  49. layui.use(['layer'], function () {
  50. if (selectId.length) {
  51. params.select_id = selectId.toString();
  52. }
  53. var url = ns.url("notes://shop/notes/notesSelect", params);
  54. //iframe层-父子操作
  55. layer.open({
  56. title: "店铺笔记选择",
  57. type: 2,
  58. area: ['1000px', '720px'],
  59. fixed: false, //不固定
  60. btn: ['保存', '返回'],
  61. content: url,
  62. yes: function (index, layero) {
  63. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  64. iframeWin.selectNotes(function (obj) {
  65. if (typeof callback == "string") {
  66. try {
  67. eval(callback + '(obj)');
  68. layer.close(index);
  69. } catch (e) {
  70. console.error('回调函数' + callback + '未定义');
  71. }
  72. } else if (typeof callback == "function") {
  73. callback(obj);
  74. layer.close(index);
  75. }
  76. });
  77. }
  78. });
  79. });
  80. }