design.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. var goodsListHtml = '<div style="display:none;"></div>';
  2. Vue.component("goods-list-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. templateList: {
  40. "row1-of1": {
  41. text: "单列",
  42. icon: "iconiPhone86",
  43. styleList: [
  44. {
  45. text: "样式1",
  46. value: "style-1",
  47. cartSupport: true, // 是否支持购物车按钮
  48. saleSupport: true, // 是否支持商品销量
  49. lineSupport: true, // 是否支持划线价
  50. },
  51. ],
  52. },
  53. "row1-of2": {
  54. text: "两列",
  55. icon: "iconyihanglianglie",
  56. styleList: [
  57. {
  58. text: "样式1",
  59. value: "style-1",
  60. cartSupport: false, // 是否支持购物车按钮
  61. saleSupport: true, // 是否支持商品销量
  62. lineSupport: true, // 是否支持划线价
  63. },
  64. {
  65. text: "样式2",
  66. value: "style-2",
  67. cartSupport: true, // 是否支持购物车按钮
  68. saleSupport: true, // 是否支持商品销量
  69. lineSupport: true, // 是否支持划线价
  70. },
  71. {
  72. text: "样式3",
  73. value: "style-3",
  74. cartSupport: false, // 是否支持购物车按钮
  75. saleSupport: true, // 是否支持商品销量
  76. lineSupport: false, // 是否支持划线价
  77. },
  78. ],
  79. },
  80. "row1-of3": {
  81. text: "三列",
  82. icon: "iconyihangsanlie",
  83. styleList: [
  84. {
  85. text: "样式1",
  86. value: "style-1",
  87. cartSupport: false, // 是否支持购物车按钮
  88. saleSupport: false, // 是否支持商品销量
  89. lineSupport: true, // 是否支持划线价
  90. },
  91. {
  92. text: "样式2",
  93. value: "style-2",
  94. cartSupport: true, // 是否支持购物车按钮
  95. saleSupport: false, // 是否支持商品销量
  96. lineSupport: true, // 是否支持划线价
  97. },
  98. ],
  99. },
  100. "horizontal-slide": {
  101. text: "横向滑动",
  102. icon: "iconshangpinliebiaohengxianghuadong",
  103. styleList: [
  104. {
  105. text: "样式1",
  106. value: "style-1",
  107. cartSupport: false, // 是否支持购物车按钮
  108. saleSupport: false, // 是否支持商品销量
  109. lineSupport: true, // 是否支持划线价
  110. },
  111. ],
  112. },
  113. "large-mode": {
  114. text: "大图",
  115. icon: "icondanlieshangpin",
  116. styleList: [
  117. {
  118. text: "样式1",
  119. value: "style-1",
  120. cartSupport: true, // 是否支持购物车按钮
  121. saleSupport: true, // 是否支持商品销量
  122. lineSupport: true, // 是否支持划线价
  123. },
  124. ],
  125. },
  126. },
  127. ornamentList: [
  128. {
  129. type: 'default',
  130. text: '默认',
  131. },
  132. {
  133. type: 'shadow',
  134. text: '投影',
  135. },
  136. {
  137. type: 'stroke',
  138. text: '描边',
  139. },
  140. ],
  141. tagList: [
  142. {
  143. text: "商品标签",
  144. value: "label"
  145. },
  146. {
  147. text: "自定义",
  148. value: "diy"
  149. },
  150. // {
  151. // text: "隐藏",
  152. // value: "hidden"
  153. // },
  154. ],
  155. nameLineModeList: [
  156. {
  157. text: "单行",
  158. value: "single"
  159. },
  160. {
  161. text: "多行",
  162. value: "multiple"
  163. }
  164. ],
  165. goodsDuplicateId: ''
  166. }
  167. },
  168. created: function () {
  169. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  170. this.$parent.data.verify.push(this.verify);//加载验证方法
  171. this.$parent.data.ignore = ['textColor']; //加载忽略内容 -- 其他设置中的属性设置
  172. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  173. var previewList = {};
  174. for (var i = 1; i < 7; i++) {
  175. previewList["goods_id_" + ns.gen_non_duplicate(i)] = {
  176. goods_name: "商品名称",
  177. discount_price: (Math.random() * 10 * i + 10).toFixed(0), // 随机价格
  178. line_price: (Math.random() * 10 * i + 10 + 10).toFixed(0), // 随机价格
  179. sale_num: Math.floor((Math.random() * 10 * i + 10 + 10))
  180. };
  181. }
  182. this.goodsDuplicateId = ns.gen_non_duplicate(10);
  183. // 组件所需的临时数据
  184. this.$parent.data.tempData = {
  185. goodsSources: this.goodsSources,
  186. sortWayList: this.sortWayList,
  187. templateList: this.templateList,
  188. ornamentList: this.ornamentList,
  189. tagList: this.tagList,
  190. nameLineModeList: this.nameLineModeList,
  191. goodsDuplicateId: this.goodsDuplicateId,
  192. previewList: previewList,
  193. methods: {
  194. addGoods: this.addGoods,
  195. selectCategory: this.selectCategory,
  196. selectTemplate: this.selectTemplate,
  197. selectTag: this.selectTag,
  198. iconStyle: this.iconStyle
  199. },
  200. };
  201. this.fetchIconColor();
  202. },
  203. methods: {
  204. verify: function (index) {
  205. var res = {code: true, message: ""};
  206. if (vue.data[index].sources === 'category' && vue.data[index].categoryId === 0) {
  207. res.code = false;
  208. res.message = "请选择商品分类";
  209. }
  210. return res;
  211. },
  212. addGoods: function () {
  213. var self = this;
  214. goodsSelect(function (res) {
  215. self.$parent.data.goodsId = res;
  216. }, self.$parent.data.goodsId, {mode: "spu", disabled: 0, promotion: "module", post: ns.appModule});
  217. },
  218. selectCategory() {
  219. var self = this;
  220. layui.use(['form'], function () {
  221. var form = layui.form;
  222. layer.open({
  223. type: 1,
  224. title: '选择分类',
  225. area: ['630px', '430px'],
  226. btn: ['确定', '返回'],
  227. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .goods-category-layer").html(),
  228. success: function (layero, index) {
  229. $(".js-switch").click(function () {
  230. var category_id = $(this).attr("data-category-id");
  231. var level = $(this).attr("data-level");
  232. var open = parseInt($(this).attr("data-open").toString());
  233. if (open) {
  234. $(".goods-category-list .layui-table tr[data-category-id-" + level + "='" + category_id + "']").hide();
  235. $(this).text("+");
  236. } else {
  237. $(".goods-category-list .layui-table tr[data-category-id-" + level + "='" + category_id + "']").show();
  238. $(this).text("-");
  239. }
  240. $(this).attr("data-open", (open ? 0 : 1));
  241. });
  242. // 勾选分类
  243. form.on('checkbox(category_select_id)', function (data) {
  244. if (data.elem.checked) {
  245. $("input[name='category_select_id']:checked").prop("checked", false);
  246. $(data.elem).prop("checked", true);
  247. form.render();
  248. }
  249. });
  250. $("input[name='category_select_id']:checked").prop("checked", false);
  251. if (self.data.categoryId) {
  252. $('.layui-layer-content [data-category_select_id="' + self.data.categoryId + '"]').prop("checked", true);
  253. }
  254. form.render();
  255. },
  256. yes: function (index, layero) {
  257. var selected = $(".layui-layer-content input[name='category_select_id']:checked");
  258. if (selected.length === 0) {
  259. layer.msg('请选择商品分类');
  260. return;
  261. }
  262. self.data.categoryName = selected.parents('tr').find('.category-name').text();
  263. self.data.categoryId = selected.attr('data-category_select_id');
  264. layer.closeAll()
  265. }
  266. });
  267. });
  268. },
  269. selectTemplate(template, item) {
  270. if (template) {
  271. this.$parent.data.template = template;
  272. item = this.templateList[template].styleList[0];
  273. }
  274. this.$parent.data.style = item.value;
  275. this.$parent.data.btnStyle.support = item.cartSupport;
  276. this.$parent.data.btnStyle.control = item.cartSupport;
  277. this.$parent.data.saleStyle.support = item.saleSupport;
  278. this.$parent.data.saleStyle.control = item.saleSupport;
  279. this.$parent.data.priceStyle.lineSupport = item.lineSupport;
  280. this.$parent.data.priceStyle.lineControl = item.lineSupport;
  281. },
  282. selectTag() {
  283. if (this.$parent.data.tag.value === 'hidden') {
  284. this.$parent.data.tag.text = '商品标签';
  285. this.$parent.data.tag.value = 'label';
  286. } else {
  287. this.$parent.data.tag.text = '隐藏';
  288. this.$parent.data.tag.value = 'hidden';
  289. }
  290. },
  291. /**
  292. * 选择图标风格
  293. * @param event
  294. */
  295. iconStyle(event) {
  296. var self = this;
  297. selectIconStyle({
  298. elem: event.currentTarget,
  299. icon: self.data.btnStyle.iconDiy.icon,
  300. callback: function (data) {
  301. if (data) {
  302. self.data.btnStyle.iconDiy.style = data;
  303. } else {
  304. iconStyleSet({
  305. style: JSON.stringify(self.data.btnStyle.iconDiy.style),
  306. query: {
  307. icon: self.data.btnStyle.iconDiy.icon
  308. }
  309. }, function (style) {
  310. self.data.btnStyle.iconDiy.style = style;
  311. })
  312. }
  313. }
  314. })
  315. },
  316. /**
  317. * 渲染颜色组件
  318. * @param id
  319. * @param color
  320. * @param callback
  321. */
  322. colorRender(id, color, callback) {
  323. setTimeout(function () {
  324. Colorpicker.create({
  325. el: id,
  326. color: color,
  327. change: function (elem, hex) {
  328. callback(elem, hex)
  329. }
  330. });
  331. })
  332. },
  333. /**
  334. * 渲染图标颜色选择器
  335. */
  336. fetchIconColor() {
  337. var self = this;
  338. self.colorRender('goods-list-color-' + this.goodsDuplicateId, '', function (elem, color) {
  339. if (self.data.btnStyle.iconDiy.style.iconBgColor.length || self.data.btnStyle.iconDiy.style.iconBgImg) {
  340. self.data.btnStyle.iconDiy.style.iconBgColor = [color];
  341. } else {
  342. self.data.btnStyle.iconDiy.style.iconColor = [color];
  343. }
  344. self.$forceUpdate();
  345. });
  346. },
  347. }
  348. });