design.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. var goodsListHtml = '<div style="display:none;"></div>';
  2. Vue.component("goods-recommend-sources", {
  3. template: goodsListHtml,
  4. data: function () {
  5. return {
  6. data: this.$parent.data,
  7. goodsSources: {
  8. initial: {
  9. text: "默认",
  10. icon: "iconmofang"
  11. },
  12. category: {
  13. text: "商品分类",
  14. icon: "iconshangpinfenlei"
  15. },
  16. diy: {
  17. text: "手动选择",
  18. icon: "iconshoudongxuanze"
  19. },
  20. },
  21. sortWayList: [
  22. {
  23. text: "综合",
  24. value: "default"
  25. },
  26. {
  27. text: "新品",
  28. value: "news"
  29. },
  30. {
  31. text: "热销",
  32. value: "sales"
  33. },
  34. {
  35. text: "价格",
  36. value: "price"
  37. }
  38. ],
  39. styleList: {
  40. "style-1": {
  41. goodsNameSupport: true, // 是否支持商品名称
  42. saleSupport: true, // 是否支持商品销量
  43. lineSupport: false, // 是否支持划线价
  44. bgUrl: '',
  45. componentBgColor: '',
  46. elementBgColor: '#FFFFFF',
  47. topStyle: {
  48. support: true,
  49. icon: {
  50. value: "icondiy icon-system-tuijian",
  51. color: "#FF3D3D",
  52. bgColor: "",
  53. },
  54. color: "#303133",
  55. subColor: "#999CA7"
  56. },
  57. },
  58. "style-2": {
  59. goodsNameSupport: true, // 是否支持商品名称
  60. saleSupport: true, // 是否支持商品销量
  61. lineSupport: false, // 是否支持划线价
  62. bgUrl: goodsRecommendRelativePath + '/img/bg.png',
  63. componentBgColor: '#1278FE',
  64. elementBgColor: '#FFFFFF',
  65. topStyle: {
  66. support: true,
  67. icon: {
  68. value: "icondiy icon-system-tuijian",
  69. color: "#1278FE",
  70. bgColor: "#FFFFFF",
  71. },
  72. color: "#FFFFFF",
  73. subColor: "#FFFFFF"
  74. },
  75. },
  76. "style-3": {
  77. goodsNameSupport: false, // 是否支持商品名称
  78. saleSupport: false, // 是否支持商品销量
  79. lineSupport: false, // 是否支持划线价
  80. bgUrl: goodsRecommendRelativePath + '/img/style3_bg.png',
  81. componentBgColor: '',
  82. elementBgColor: '',
  83. labelStyle: {
  84. support: true,
  85. bgColor: "#FF504D",
  86. title: "新人专享"
  87. }
  88. },
  89. },
  90. ornamentList: [
  91. {
  92. type: 'default',
  93. text: '默认',
  94. },
  95. {
  96. type: 'shadow',
  97. text: '投影',
  98. },
  99. {
  100. type: 'stroke',
  101. text: '描边',
  102. },
  103. ],
  104. nameLineModeList: [
  105. {
  106. text: "单行",
  107. value: "single"
  108. },
  109. {
  110. text: "多行",
  111. value: "multiple"
  112. }
  113. ]
  114. }
  115. },
  116. created: function () {
  117. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  118. this.$parent.data.verify.push(this.verify);//加载验证方法
  119. this.$parent.data.ignore = ['textColor']; //加载忽略内容 -- 其他设置中的属性设置
  120. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  121. var previewList = {};
  122. for (var i = 1; i < 4; i++) {
  123. previewList["goods_id_" + ns.gen_non_duplicate(i)] = {
  124. goods_name: "商品名称",
  125. discount_price: (Math.random() * 10 * i + 10).toFixed(0), // 随机价格
  126. line_price: (Math.random() * 10 * i + 10 + 10).toFixed(0), // 随机价格
  127. sale_num: Math.floor((Math.random() * 10 * i + 10 + 10))
  128. };
  129. }
  130. // 组件所需的临时数据
  131. this.$parent.data.tempData = {
  132. goodsSources: this.goodsSources,
  133. sortWayList: this.sortWayList,
  134. styleList: this.styleList,
  135. ornamentList: this.ornamentList,
  136. nameLineModeList: this.nameLineModeList,
  137. previewList: previewList,
  138. methods: {
  139. addGoods: this.addGoods,
  140. selectCategory: this.selectCategory,
  141. selectTemplate: this.selectTemplate,
  142. selectStyle: this.selectStyle
  143. },
  144. };
  145. },
  146. methods: {
  147. verify: function (index) {
  148. var res = {code: true, message: ""};
  149. if (vue.data[index].sources === 'category' && vue.data[index].categoryId === 0) {
  150. res.code = false;
  151. res.message = "请选择商品分类";
  152. }
  153. return res;
  154. },
  155. addGoods: function () {
  156. var self = this;
  157. goodsSelect(function (res) {
  158. self.$parent.data.goodsId = res;
  159. }, self.$parent.data.goodsId, {mode: "spu", disabled: 0, promotion: "module", post: ns.appModule});
  160. },
  161. selectCategory() {
  162. var self = this;
  163. layui.use(['form'], function () {
  164. var form = layui.form;
  165. layer.open({
  166. type: 1,
  167. title: '选择分类',
  168. area: ['630px', '430px'],
  169. btn: ['确定', '返回'],
  170. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .goods-category-layer").html(),
  171. success: function (layero, index) {
  172. $(".js-switch").click(function () {
  173. var category_id = $(this).attr("data-category-id");
  174. var level = $(this).attr("data-level");
  175. var open = parseInt($(this).attr("data-open").toString());
  176. if (open) {
  177. $(".goods-category-list .layui-table tr[data-category-id-" + level + "='" + category_id + "']").hide();
  178. $(this).text("+");
  179. } else {
  180. $(".goods-category-list .layui-table tr[data-category-id-" + level + "='" + category_id + "']").show();
  181. $(this).text("-");
  182. }
  183. $(this).attr("data-open", (open ? 0 : 1));
  184. });
  185. // 勾选分类
  186. form.on('checkbox(category_select_id)', function (data) {
  187. if (data.elem.checked) {
  188. $("input[name='category_select_id']:checked").prop("checked", false);
  189. $(data.elem).prop("checked", true);
  190. form.render();
  191. }
  192. });
  193. $("input[name='category_select_id']:checked").prop("checked", false);
  194. if (self.data.categoryId) {
  195. $('.layui-layer-content [data-category_select_id="' + self.data.categoryId + '"]').prop("checked", true);
  196. }
  197. form.render();
  198. },
  199. yes: function (index, layero) {
  200. var selected = $(".layui-layer-content input[name='category_select_id']:checked");
  201. if (selected.length === 0) {
  202. layer.msg('请选择商品分类');
  203. return;
  204. }
  205. self.data.categoryName = selected.parents('tr').find('.category-name').text();
  206. self.data.categoryId = selected.attr('data-category_select_id');
  207. layer.closeAll()
  208. }
  209. });
  210. });
  211. },
  212. selectTemplate(template, item) {
  213. this.$parent.data.goodsNameStyle.support = this.styleList[this.$parent.data.style].goodsNameSupport;
  214. this.$parent.data.goodsNameStyle.control = this.styleList[this.$parent.data.style].goodsNameSupport;
  215. this.$parent.data.saleStyle.support = this.styleList[this.$parent.data.style].saleSupport;
  216. this.$parent.data.saleStyle.control = this.styleList[this.$parent.data.style].saleSupport;
  217. this.$parent.data.priceStyle.lineSupport = this.styleList[this.$parent.data.style].lineSupport;
  218. this.$parent.data.priceStyle.lineControl = this.styleList[this.$parent.data.style].lineSupport;
  219. this.$parent.data.bgUrl = this.styleList[this.$parent.data.style].bgUrl;
  220. this.$parent.data.componentBgColor = this.styleList[this.$parent.data.style].componentBgColor;
  221. this.$parent.data.elementBgColor = this.styleList[this.$parent.data.style].elementBgColor;
  222. // 顶部标题样式
  223. if(this.styleList[this.$parent.data.style].topStyle) {
  224. this.$parent.data.topStyle.support = this.styleList[this.$parent.data.style].topStyle.support;
  225. this.$parent.data.topStyle.color = this.styleList[this.$parent.data.style].topStyle.color;
  226. this.$parent.data.topStyle.subColor = this.styleList[this.$parent.data.style].topStyle.subColor;
  227. this.$parent.data.topStyle.icon.value = this.styleList[this.$parent.data.style].topStyle.icon.value;
  228. this.$parent.data.topStyle.icon.color = this.styleList[this.$parent.data.style].topStyle.icon.color;
  229. this.$parent.data.topStyle.icon.bgColor = this.styleList[this.$parent.data.style].topStyle.icon.bgColor;
  230. }else{
  231. this.$parent.data.topStyle.support = false;
  232. }
  233. if(this.styleList[this.$parent.data.style].labelStyle){
  234. this.$parent.data.labelStyle.support = this.styleList[this.$parent.data.style].labelStyle.support;
  235. this.$parent.data.labelStyle.bgColor = this.styleList[this.$parent.data.style].labelStyle.bgColor;
  236. this.$parent.data.labelStyle.title = this.styleList[this.$parent.data.style].labelStyle.title;
  237. }else{
  238. this.$parent.data.labelStyle.support = false;
  239. }
  240. },
  241. selectStyle: function () {
  242. var self = this;
  243. layer.open({
  244. type: 1,
  245. title: '风格选择',
  246. area: ['920px', '400px'],
  247. btn: ['确定', '返回'],
  248. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .style-list-box-goods-recommend").html(),
  249. success: function (layero, index) {
  250. $(".layui-layer-content input[name='style']").val(self.data.style);
  251. $(".layui-layer-content input[name='style_name']").val(self.data.styleName);
  252. $("body").on("click", ".layui-layer-content .style-list-con-goods-recommend .style-li-goods-recommend", function () {
  253. $(this).addClass("selected border-color").siblings().removeClass("selected border-color bg-color-after");
  254. $(".layui-layer-content input[name='style']").val($(this).attr("data_key"));
  255. $(".layui-layer-content input[name='style_name']").val($(this).find("span").text());
  256. });
  257. },
  258. yes: function (index, layero) {
  259. self.data.style = $(".layui-layer-content input[name='style']").val();
  260. self.data.styleName = $(".layui-layer-content input[name='style_name']").val();
  261. self.selectTemplate();
  262. layer.closeAll()
  263. }
  264. });
  265. }
  266. }
  267. });