style.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /**
  2. * 空的验证组件,后续如果增加业务,则更改组件
  3. */
  4. var manyGoodsListHtml = '<div class="many-goods-list-edit layui-form">';
  5. manyGoodsListHtml += '<ul>';
  6. manyGoodsListHtml += '<li v-for="(item, index) in list" v-bind:key="index">';
  7. manyGoodsListHtml += '<div class="content-block">';
  8. manyGoodsListHtml += '<div class="layui-form-item" >';
  9. manyGoodsListHtml += '<label class="layui-form-label sm">分类名称</label>';
  10. manyGoodsListHtml += '<div class="layui-input-block">';
  11. manyGoodsListHtml += '<input type="text" name=\'title\' v-model="item.title" class="layui-input" />';
  12. manyGoodsListHtml += '</div>';
  13. manyGoodsListHtml += '</div>';
  14. manyGoodsListHtml += '<div class="layui-form-item" >';
  15. manyGoodsListHtml += '<label class="layui-form-label sm">副标题</label>';
  16. manyGoodsListHtml += '<div class="layui-input-block">';
  17. manyGoodsListHtml += '<input type="text" name=\'desc\' v-model="item.desc" class="layui-input" />';
  18. manyGoodsListHtml += '</div>';
  19. manyGoodsListHtml += '</div>';
  20. // manyGoodsListHtml += '<nc-link v-bind:data="{ field : $parent.data.list[index].link }"></nc-link>';
  21. // manyGoodsListHtml += '<div class="layui-form-item">';
  22. // manyGoodsListHtml += '<label class="layui-form-label sm">列表风格</label>';
  23. // manyGoodsListHtml += '<div class="layui-input-block align-right">';
  24. // manyGoodsListHtml += '<a href="#" class="ns-input-text" v-on:click="selectGoodsListStyle(index)"><span class="ns-text-color">风格{{ item.goodsStyle }}</span><i class="iconfont iconyoujiantou"></i></a>';
  25. // manyGoodsListHtml += '</div>';
  26. // manyGoodsListHtml += '</div>';
  27. // manyGoodsListHtml += '<div class="layui-form-item">';
  28. // manyGoodsListHtml += '<label class="layui-form-label sm">数据来源</label>';
  29. // manyGoodsListHtml += '<div class="layui-input-block">';
  30. // manyGoodsListHtml += '<div class="source-selected">';
  31. // manyGoodsListHtml += '<template v-for="(sourceItem, sourceIndex) in goodsSources" v-bind:k="index">';
  32. // manyGoodsListHtml += '<div class="source" v-if="sourceItem.value == item.sources">{{ sourceItem.text }}</div>';
  33. // manyGoodsListHtml += '</template>';
  34. // manyGoodsListHtml += '<template v-for="(sourceItem, sourceIndex) in goodsSources" v-bind:k="index">';
  35. // manyGoodsListHtml += '<span class="source-item" :title="sourceItem.text" v-on:click="item.sources=sourceItem.value" v-bind:class="[(item.sources == sourceItem.value) ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\' ]"><img v-bind:src="sourceItem.selectedIcon" v-if="item.sources == sourceItem.value"><img v-bind:src="sourceItem.icon" v-else/></span>';
  36. // manyGoodsListHtml += '</template>';
  37. // manyGoodsListHtml += '</div>';
  38. // manyGoodsListHtml += '</div>';
  39. // manyGoodsListHtml += '</div>';
  40. manyGoodsListHtml += '<div class="layui-form-item" v-if="isLoad && item.sources == \'category\'">';
  41. manyGoodsListHtml += '<label class="layui-form-label sm">商品分类</label>';
  42. manyGoodsListHtml += '<div class="layui-input-block align-right">';
  43. manyGoodsListHtml += '<a href="#" class="ns-input-text" @click="selectCategory(index)"><span class="ns-text-color">{{ item.categoryName }}</span><i class="iconfont iconyoujiantou"></i></a>';
  44. manyGoodsListHtml += '</div>';
  45. manyGoodsListHtml += '</div>';
  46. manyGoodsListHtml += '<div class="layui-form-item" v-if="isLoad && item.sources == \'diy\'">';
  47. manyGoodsListHtml += '<label class="layui-form-label sm">手动选择</label>';
  48. manyGoodsListHtml += '<div class="layui-input-block align-right">';
  49. manyGoodsListHtml += '<a href="#" class="ns-input-text" v-on:click="addGoods(index)">';
  50. manyGoodsListHtml += '<span v-if="item.goodsId.length == 0" class="ns-text-color">请选择</span>';
  51. manyGoodsListHtml += '<span v-if="item.goodsId.length > 0" class="ns-text-color">已选{{item.goodsId.length}}个</span>';
  52. manyGoodsListHtml += '<i class="iconfont iconyoujiantou"></i>';
  53. manyGoodsListHtml += '</a>';
  54. manyGoodsListHtml += '</div>';
  55. manyGoodsListHtml += '</div>';
  56. manyGoodsListHtml += '</div>';
  57. manyGoodsListHtml += '<i class="del" v-on:click="list.splice(index,1)" data-disabled="1">x</i>';
  58. manyGoodsListHtml += '<div class="error-msg"></div>';
  59. manyGoodsListHtml += '</li>';
  60. manyGoodsListHtml += '<div class="add-item ns-text-color" v-on:click="list.push({goodsStyle: 1, title: \'分类\', desc: \'分类描述\', link: {}, sources: \'category\', categoryId: 0, categoryName: \'请选择\', goodsId: []})">';
  61. manyGoodsListHtml += '<i>+</i>';
  62. manyGoodsListHtml += '<span>添加一个商品组</span>';
  63. manyGoodsListHtml += '</div>';
  64. manyGoodsListHtml += '</ul>';
  65. // manyGoodsListHtml += '<slide v-bind:data="{ field : \'goodsCount\', label: \'商品数量\', max: 20}" v-if="data.sources != \'diy\'"></slide>';
  66. manyGoodsListHtml += '</div>';
  67. var select_goods_list = []; //配合商品选择器使用
  68. Vue.component("many-goods-list", {
  69. template: manyGoodsListHtml,
  70. data: function () {
  71. return {
  72. data: this.$parent.data,
  73. list: this.$parent.data.list,
  74. goodsSources: [
  75. // {
  76. // text: "默认",
  77. // value: "default",
  78. // icon: goodsListResourcePath + "/goods_list/img/default_icon.png",
  79. // selectedIcon: goodsListResourcePath + "/goods_list/img/default_selected_icon.png"
  80. // },
  81. {
  82. text: "商品分类",
  83. value: "category",
  84. icon: goodsListResourcePath + "/many_goods_list/img/category_icon.png",
  85. selectedIcon: goodsListResourcePath + "/many_goods_list/img/category_selected_icon.png"
  86. },
  87. {
  88. text : "手动选择",
  89. value : "diy",
  90. icon: goodsListResourcePath + "/many_goods_list/img/diy_icon.png",
  91. selectedIcon: goodsListResourcePath + "/many_goods_list/img/diy_selected_icon.png"
  92. }
  93. ],
  94. categoryList: [],
  95. isLoad: true,
  96. isShow: false,
  97. selectIndex: 0,//当前选中的下标
  98. goodsCount: [6, 12, 18, 24, 30]
  99. }
  100. },
  101. created:function() {
  102. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  103. this.$parent.data.verify.push(this.verify);//加载验证方法
  104. },
  105. methods: {
  106. verify : function () {
  107. var res = { code : true, message : "" };
  108. for (var i=0; i<this.$parent.data.list.length; i++) {
  109. if (this.$parent.data.list[i].title == ''){
  110. res.code = false;
  111. res.message = "请输入分类名称";
  112. }
  113. if (this.$parent.data.list[i].sources == 'category' && this.$parent.data.list[i].categoryId == 0){
  114. res.code = false;
  115. res.message = "请选择商品分类";
  116. }
  117. if (this.$parent.data.list[i].sources == 'diy' && this.$parent.data.list[i].goodsId.length == 0){
  118. res.code = false;
  119. res.message = "请选择商品";
  120. }
  121. }
  122. return res;
  123. },
  124. addGoods: function(index) {
  125. var self = this;
  126. goodsSelect(function (res) {
  127. self.$parent.data.list[index].goodsId = res;
  128. // for (var i = 0; i < res.length; i++) {
  129. // self.$parent.data.goodsId.push(res[i].goods_id);
  130. // }
  131. }, self.$parent.data.list[index].goodsId, {mode: "spu", disabled: 0, promotion: "module", post: post});
  132. },
  133. selectCategory(i){
  134. var self = this;
  135. layer.open({
  136. type: 1,
  137. title: '选择分类',
  138. area:['630px','430px'],
  139. btn: ['确定', '返回'],
  140. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .goods-category-layer").html(),
  141. success: function(layero, index) {
  142. $("body").on("click", ".layui-layer-content .category-wrap .category-item", function () {
  143. $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color");
  144. });
  145. $(".layui-layer-content .category-wrap .category-item[data-id='" + self.data.list[i].categoryId + "']").click();
  146. },
  147. yes: function (index, layero) {
  148. self.data.list[i].categoryName = $(".layui-layer-content .category-wrap .category-item.selected").text();
  149. self.data.list[i].categoryId = $(".layui-layer-content .category-wrap .category-item.selected").attr('data-id');
  150. layer.closeAll()
  151. }
  152. });
  153. },
  154. // selectGoodsListStyle(i) {
  155. // var self = this;
  156. // layer.open({
  157. // type: 1,
  158. // title: '模板样式',
  159. // area:['930px','630px'],
  160. // btn: ['确定', '返回'],
  161. // content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .goods-list-style").html(),
  162. // success: function(layero, index) {
  163. // $(".layui-layer-content .goods-list-style input[name='style']").val(self.data.list[i].style);
  164. // $("body").on("click", ".layui-layer-content .style-list-con-goods .style-li-goods", function () {
  165. // $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color");
  166. // $(".layui-layer-content .goods-list-style input[name='style']").val($(this).index() + 1);
  167. // });
  168. // },
  169. // yes: function (index, layero) {
  170. // self.data.list[i].style = $(".layui-layer-content .goods-list-style input[name='style']").val();
  171. // layer.closeAll()
  172. // }
  173. // });
  174. // }
  175. },
  176. computed:{
  177. sourcesText(){
  178. var sourcesText = '',
  179. _this = this;
  180. this.goodsSources.forEach(function(v){
  181. if (_this.data.sources == v.value) sourcesText = v.text;
  182. })
  183. return sourcesText;
  184. }
  185. }
  186. });
  187. var manyGoodsListStyleHtml = '<div class="">';
  188. manyGoodsListStyleHtml += '<div class="layui-form-item">';
  189. manyGoodsListStyleHtml += '<label class="layui-form-label sm">商品组名称</label>';
  190. manyGoodsListStyleHtml += '<div class="layui-input-block">';
  191. manyGoodsListStyleHtml += '<span>{{data.title}}</span>';
  192. manyGoodsListStyleHtml += '</div>';
  193. // manyGoodsListStyleHtml += '<div style="font-size: 12px; color: #909399; padding-left: 80px; margin-top: 10px;">用来关联商品列表,商品组名称需与要关联的商品列表商品组名称一致</div>';
  194. manyGoodsListStyleHtml += '</div>';
  195. // manyGoodsListStyleHtml += '<div class="layui-form-item">';
  196. // manyGoodsListStyleHtml += '<label class="layui-form-label sm">分组风格</label>';
  197. // manyGoodsListStyleHtml += '<div class="layui-input-block align-right">';
  198. // manyGoodsListStyleHtml += '<a href="#" class="ns-input-text" v-on:click="selectGoodsStyle"><span class="ns-text-color">风格{{ data.style }}</span><i class="iconfont iconyoujiantou"></i></a>';
  199. // manyGoodsListStyleHtml += '</div>';
  200. // manyGoodsListStyleHtml += '</div>';
  201. manyGoodsListStyleHtml += '</div>';
  202. Vue.component("many-goods-list-style", {
  203. template: manyGoodsListStyleHtml,
  204. data: function() {
  205. return {
  206. data: this.$parent.data,
  207. parentList: this.$parent.$parent.data,
  208. goodsGroupNum: 1,
  209. goodsGroupTitle: ''
  210. }
  211. },
  212. created:function() {
  213. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  214. this.$parent.data.verify.push(this.verify);//加载验证方法
  215. },
  216. methods: {
  217. verify: function () {
  218. var res = { code: true, message: "" };
  219. console.log(this.data.title);
  220. var _self = this;
  221. if (_self.data.title.length == 0) {
  222. res.code = false;
  223. res.message = "商品组名称不能为空";
  224. setTimeout(function(){
  225. $("#title_" + _self.data.index).focus();
  226. },10);
  227. } else {
  228. console.log(_self.parentList);
  229. for (var i=0; i<_self.parentList.length; i++) {
  230. if (_self.parentList[i].controller == "ManyGoodsList" && _self.data.title == _self.parentList[i].title && _self.parentList[i].index != _self.data.index) {
  231. res.code = false;
  232. res.message = "商品组名称不能重复";
  233. setTimeout(function(){
  234. $("#title_" + _self.data.index).focus();
  235. },10);
  236. }
  237. }
  238. }
  239. return res;
  240. },
  241. selectGoodsStyle: function() {
  242. var self = this;
  243. layer.open({
  244. type: 1,
  245. title: '模板样式',
  246. area:['930px','630px'],
  247. btn: ['确定', '返回'],
  248. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .goods-cate-style").html(),
  249. success: function(layero, index) {
  250. $(".layui-layer-content .goods-cate-style input[name='style']").val(self.data.style);
  251. $("body").on("click", ".layui-layer-content .style-cate-con-goods .style-li-goods", function () {
  252. $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color");
  253. $(".layui-layer-content .goods-cate-style input[name='style']").val($(this).index() + 1);
  254. });
  255. },
  256. yes: function (index, layero) {
  257. self.data.style = $(".layui-layer-content .goods-cate-style input[name='style']").val();
  258. layer.closeAll()
  259. }
  260. });
  261. },
  262. }
  263. });