style.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /**
  2. * 空的验证组件,后续如果增加业务,则更改组件
  3. */
  4. var goodsListHtml = '<div class="goods-list-edit layui-form">';
  5. goodsListHtml += '<div class="layui-form-item">';
  6. goodsListHtml += '<label class="layui-form-label sm">数据来源</label>';
  7. goodsListHtml += '<div class="layui-input-block">';
  8. goodsListHtml += '<div class="source-selected">';
  9. goodsListHtml += '<div class="source">{{ sourcesText }}</div>';
  10. goodsListHtml += '<template v-for="(item,index) in goodsSources" v-bind:k="index">';
  11. goodsListHtml += '<span class="source-item" :title="item.text" v-on:click="data.sources=item.value" v-bind:class="[(data.sources == item.value) ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\' ]"><img v-bind:src="item.selectedIcon" v-if="data.sources == item.value"><img v-bind:src="item.icon" v-else/></span>';
  12. goodsListHtml += '</template>';
  13. goodsListHtml += '</div>';
  14. goodsListHtml += '</div>';
  15. goodsListHtml += '</div>';
  16. goodsListHtml += '<div class="layui-form-item" v-if="isLoad && data.sources == \'category\'">';
  17. goodsListHtml += '<label class="layui-form-label sm">商品分类</label>';
  18. goodsListHtml += '<div class="layui-input-block align-right">';
  19. goodsListHtml += '<a href="#" class="ns-input-text" @click="selectCategory"><span class="ns-text-color">{{ data.categoryName }}</span><i class="iconfont iconyoujiantou"></i></a>';
  20. goodsListHtml += '</div>';
  21. goodsListHtml += '</div>';
  22. goodsListHtml += '<div class="layui-form-item" v-if="isLoad && data.sources == \'diy\'">';
  23. goodsListHtml += '<label class="layui-form-label sm">手动选择</label>';
  24. goodsListHtml += '<div class="layui-input-block align-right">';
  25. goodsListHtml += '<a href="#" class="ns-input-text" v-on:click="addGoods"><span class="ns-text-color">请选择</span><i class="iconfont iconyoujiantou"></i></a>';
  26. goodsListHtml += '</div>';
  27. goodsListHtml += '</div>';
  28. goodsListHtml += '<slide v-bind:data="{ field : \'goodsCount\', label: \'商品数量\', max: 20}" v-if="data.sources != \'diy\'"></slide>';
  29. goodsListHtml += '</div>';
  30. var select_goods_list = []; //配合商品选择器使用
  31. Vue.component("goods-list", {
  32. template: goodsListHtml,
  33. data: function () {
  34. return {
  35. data: this.$parent.data,
  36. goodsSources: [
  37. {
  38. text: "默认",
  39. value: "default",
  40. icon: goodsListResourcePath + "/goods_list/img/default_icon.png",
  41. selectedIcon: goodsListResourcePath + "/goods_list/img/default_selected_icon.png"
  42. },
  43. {
  44. text: "商品分类",
  45. value: "category",
  46. icon: goodsListResourcePath + "/goods_list/img/category_icon.png",
  47. selectedIcon: goodsListResourcePath + "/goods_list/img/category_selected_icon.png"
  48. },
  49. // {
  50. // text : "手动选择",
  51. // value : "diy",
  52. // icon: goodsListResourcePath + "/goods_list/img/diy_icon.png",
  53. // selectedIcon: goodsListResourcePath + "/goods_list/img/diy_selected_icon.png"
  54. // }
  55. ],
  56. categoryList: [],
  57. isLoad: true,
  58. isShow: false,
  59. selectIndex: 0,//当前选中的下标
  60. goodsCount: [6, 12, 18, 24, 30]
  61. }
  62. },
  63. created:function() {
  64. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  65. this.$parent.data.verify.push(this.verify);//加载验证方法
  66. },
  67. methods: {
  68. shopNum: function(){
  69. if (this.$parent.data.goodsCount.length > 0 && this.$parent.data.goodsCount < 0) {
  70. layer.msg("商品数量不能小于0");
  71. this.$parent.data.goodsCount = 0;
  72. }
  73. if (this.$parent.data.goodsCount > 50){
  74. layer.msg("商品数量最多为50");
  75. this.$parent.data.goodsCount = 50;
  76. }
  77. },
  78. verify : function () {
  79. var res = { code : true, message : "" };
  80. if(this.$parent.data.goodsCount.length===0) {
  81. res.code = false;
  82. res.message = "请输入商品数量";
  83. }
  84. if (this.$parent.data.goodsCount < 0) {
  85. res.code = false;
  86. res.message = "商品数量不能小于0";
  87. }
  88. if (this.$parent.data.goodsCount > 50){
  89. res.code = false;
  90. res.message = "商品数量最多为50";
  91. }
  92. if (this.$parent.data.sources == 'category' && this.$parent.data.categoryId == 0){
  93. res.code = false;
  94. res.message = "请选择商品分类";
  95. }
  96. return res;
  97. },
  98. addGoods: function() {
  99. var self = this;
  100. goodsSelect(function (res) {
  101. self.$parent.data.goodsId = res;
  102. }, self.$parent.data.goodsId, {mode: "spu", disabled: 0, promotion: "module", post: post});
  103. },
  104. selectCategory(){
  105. var self = this;
  106. layer.open({
  107. type: 1,
  108. title: '选择分类',
  109. area:['630px','430px'],
  110. btn: ['确定', '返回'],
  111. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .goods-category-layer").html(),
  112. success: function(layero, index) {
  113. $("body").on("click", ".layui-layer-content .category-wrap .category-item", function () {
  114. $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color");
  115. });
  116. $(".layui-layer-content .category-wrap .category-item[data-id='" + self.data.categoryId + "']").click();
  117. },
  118. yes: function (index, layero) {
  119. self.data.categoryName = $(".layui-layer-content .category-wrap .category-item.selected").text();
  120. self.data.categoryId = $(".layui-layer-content .category-wrap .category-item.selected").attr('data-id');
  121. layer.closeAll()
  122. }
  123. });
  124. }
  125. },
  126. computed:{
  127. sourcesText(){
  128. var sourcesText = '',
  129. _this = this;
  130. this.goodsSources.forEach(function(v){
  131. if (_this.data.sources == v.value) sourcesText = v.text;
  132. })
  133. return sourcesText;
  134. }
  135. }
  136. });
  137. var goodsListStyleHtml = '<div class="layui-form-item">';
  138. goodsListStyleHtml += '<label class="layui-form-label sm">模板样式</label>';
  139. goodsListStyleHtml += '<div class="layui-input-block align-right">';
  140. goodsListStyleHtml += '<a href="#" class="ns-input-text" v-on:click="selectGoodsStyle"><span class="ns-text-color">风格{{ data.style }}</span><i class="iconfont iconyoujiantou"></i></a>';
  141. goodsListStyleHtml += '</div>';
  142. goodsListStyleHtml += '</div>';
  143. Vue.component("goods-list-style", {
  144. template: goodsListStyleHtml,
  145. data: function() {
  146. return {
  147. data: this.$parent.data,
  148. }
  149. },
  150. created:function() {
  151. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  152. this.$parent.data.verify.push(this.verify);//加载验证方法
  153. },
  154. methods: {
  155. verify: function () {
  156. var res = { code: true, message: "" };
  157. return res;
  158. },
  159. selectGoodsStyle: function() {
  160. var self = this;
  161. layer.open({
  162. type: 1,
  163. title: '模板样式',
  164. area:['930px','630px'],
  165. btn: ['确定', '返回'],
  166. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .goods-list-style").html(),
  167. success: function(layero, index) {
  168. $(".layui-layer-content input[name='style']").val(self.data.style);
  169. $("body").on("click", ".layui-layer-content .style-list-con-goods .style-li-goods", function () {
  170. $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color");
  171. $(".layui-layer-content input[name='style']").val($(this).index() + 1);
  172. });
  173. },
  174. yes: function (index, layero) {
  175. self.data.style = $(".layui-layer-content input[name='style']").val();
  176. layer.closeAll()
  177. }
  178. });
  179. },
  180. }
  181. });
  182. // 是否启用更多按钮设置
  183. var carBtnHtml = '<div class="layui-form-item ns-checkbox-wrap">';
  184. carBtnHtml += '<label class="layui-form-label sm">是否启用</label>';
  185. carBtnHtml += '<div class="layui-input-block">';
  186. carBtnHtml += '<span v-if="data.isShowCart == 1">是</span>';
  187. carBtnHtml += '<span v-else>否</span>';
  188. carBtnHtml += '<div v-on:click="changeState()" class="layui-unselect layui-form-checkbox" v-bind:class="{ \'layui-form-checked\': (data.isShowCart==1) }" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>';
  189. carBtnHtml += '</div>';
  190. carBtnHtml += '</div>';
  191. Vue.component("goods-list-more-btn", {
  192. template: carBtnHtml,
  193. data: function () {
  194. return {
  195. data: this.$parent.data,
  196. };
  197. },
  198. created: function () {
  199. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  200. this.$parent.data.verify.push(this.verify);//加载验证方法
  201. },
  202. methods: {
  203. verify : function () {
  204. var res = { code : true, message : "" };
  205. return res;
  206. },
  207. changeState: function() {
  208. this.data.isShowCart = this.data.isShowCart ? 0 : 1;
  209. }
  210. },
  211. });
  212. // 购物车按钮
  213. var cartStyleHtml = '<div class="layui-form-item">';
  214. cartStyleHtml += '<label class="layui-form-label sm">选择风格</label>';
  215. cartStyleHtml += '<div class="layui-input-block align-right">';
  216. cartStyleHtml += '<div class="ns-input-text selected-style" v-on:click="selectTestStyle">请选择<i class="iconfont"></i></div>';
  217. cartStyleHtml += '</div>';
  218. cartStyleHtml += '</div>';
  219. Vue.component("cart-style", {
  220. template: cartStyleHtml,
  221. data: function() {
  222. return {
  223. data: this.$parent.data,
  224. }
  225. },
  226. created:function() {
  227. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  228. this.$parent.data.verify.push(this.verify);//加载验证方法
  229. },
  230. methods: {
  231. verify: function () {
  232. var res = { code: true, message: "" };
  233. return res;
  234. },
  235. selectTestStyle: function() {
  236. var self = this;
  237. layer.open({
  238. type: 1,
  239. title: '风格选择',
  240. area:['930px','630px'],
  241. btn: ['确定', '返回'],
  242. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .cart-list-style").html(),
  243. success: function(layero, index) {
  244. $(".layui-layer-content input[name='cart_style']").val(self.data.style);
  245. $("body").on("click", ".layui-layer-content .cart-list-con .cart-li", function () {
  246. $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color");
  247. $(".layui-layer-content input[name='cart_style']").val($(this).index() + 1);
  248. });
  249. },
  250. yes: function (index, layero) {
  251. self.data.cartStyle = $(".layui-layer-content input[name='cart_style']").val();
  252. layer.closeAll()
  253. }
  254. });
  255. },
  256. }
  257. });
  258. // 多选
  259. var showContentHtml = '<div class="layui-form-item goods-show-box ns-checkbox-wrap">';
  260. showContentHtml += '<div class="layui-input-block">';
  261. showContentHtml += '<div class="layui-input-inline-checkbox">';
  262. showContentHtml += '<span>商品名称</span>';
  263. showContentHtml += '<div v-on:click="changeStatus(\'isShowGoodName\')" class="layui-unselect layui-form-checkbox" v-bind:class="{\'layui-form-checked\': (data.isShowGoodName == 1)}" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>';
  264. showContentHtml += '</div>';
  265. showContentHtml += '<div class="layui-input-inline-checkbox">';
  266. showContentHtml += '<span>副标题</span>';
  267. showContentHtml += '<div v-on:click="changeStatus(\'isShowGoodSubTitle\')" class="layui-unselect layui-form-checkbox" v-bind:class="{\'layui-form-checked\': (data.isShowGoodSubTitle == 1)}" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>';
  268. showContentHtml += '</div>';
  269. showContentHtml += '<div class="layui-input-inline-checkbox">';
  270. showContentHtml += '<span>划线市场价</span>';
  271. showContentHtml += '<div v-on:click="changeStatus(\'isShowMarketPrice\')" class="layui-unselect layui-form-checkbox" v-bind:class="{\'layui-form-checked\': (data.isShowMarketPrice == 1)}" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>';
  272. showContentHtml += '</div>';
  273. showContentHtml += '<div class="layui-input-inline-checkbox">';
  274. showContentHtml += '<span>商品销量</span>';
  275. showContentHtml += '<div v-on:click="changeStatus(\'isShowGoodSaleNum\')" class="layui-unselect layui-form-checkbox" v-bind:class="{\'layui-form-checked\': (data.isShowGoodSaleNum == 1)}" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>';
  276. showContentHtml += '</div>';
  277. showContentHtml += '</div>';
  278. showContentHtml += '</div>';
  279. Vue.component("show-content", {
  280. template: showContentHtml,
  281. data: function () {
  282. return {
  283. data: this.$parent.data,
  284. isShowGoodName: this.$parent.data.isShowGoodName,
  285. isShowMarketPrice: this.$parent.data.isShowMarketPrice,
  286. };
  287. },
  288. created: function () {
  289. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  290. this.$parent.data.verify.push(this.verify);//加载验证方法
  291. },
  292. methods: {
  293. verify :function () {
  294. var res = { code: true, message: "" };
  295. return res;
  296. },
  297. changeStatus: function(field) {
  298. this.$parent.data[field] = this.$parent.data[field] ? 0 : 1;
  299. }
  300. }
  301. });
  302. var goodsTagStyleHtml = '<div class="goods-tag-component">';
  303. goodsTagStyleHtml += '<div class="layui-form-item">';
  304. goodsTagStyleHtml += '<label class="layui-form-label sm">角标</label>';
  305. goodsTagStyleHtml += '<div class="layui-input-block align-right">';
  306. goodsTagStyleHtml += '<template v-for="(item,index) in styleList" v-bind:k="index">';
  307. goodsTagStyleHtml += '<div v-on:click="data.goodsTag=item.value" v-bind:class="{ \'layui-unselect layui-form-radio\' : true,\'layui-form-radioed\' : (data.goodsTag==item.value) }"><i class="layui-anim layui-icon">&#xe63f;</i><div>{{item.text}}</div></div>';
  308. goodsTagStyleHtml += '</template>';
  309. goodsTagStyleHtml += '</div>';
  310. goodsTagStyleHtml += '</div>';
  311. goodsTagStyleHtml += '<div class="layui-form-item goods-tag-img" v-if="data.goodsTag == \'diy\'">';
  312. goodsTagStyleHtml += '<img-sec-upload v-bind:data="{ data : data.tagImg }"></img-sec-upload>';
  313. goodsTagStyleHtml += '<div class="upload-tip"><p>请上传角标的图片</p><p class="ns-text-color">推荐使用 100X100像素的.png的图片</p></div>';
  314. goodsTagStyleHtml += '</div>';
  315. goodsTagStyleHtml += '<div class="error-msg"></div>';
  316. goodsTagStyleHtml += '</div>';
  317. Vue.component("goods-tag-style", {
  318. template: goodsTagStyleHtml,
  319. data: function() {
  320. return {
  321. data: this.$parent.data,
  322. styleList: [
  323. {
  324. text: "默认",
  325. value: "default"
  326. },
  327. {
  328. text: "不显示",
  329. value: "notshow"
  330. },
  331. {
  332. text: "自定义",
  333. value: "diy"
  334. }
  335. ]
  336. }
  337. },
  338. created:function() {
  339. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  340. this.$parent.data.verify.push(this.verify);//加载验证方法
  341. },
  342. methods: {
  343. verify :function () {
  344. var res = {code: true, message: ""};
  345. var _self = this;
  346. if (_self.data.goodsTag == 'diy' && _self.data.tagImg.imageUrl == '') {
  347. res.code = false;
  348. res.message = "请添加图片";
  349. $('.goods-tag-component .error-msg').text("请添加图片").show();
  350. } else {
  351. $('.goods-tag-component .error-msg').text("请添加图片").hide();
  352. }
  353. return res;
  354. }
  355. }
  356. });