style.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /**
  2. * 空的验证组件,后续如果增加业务,则更改组件
  3. */
  4. var couponListHtml = '<div class="goods-list-edit layui-form">';
  5. // couponListHtml += '<div class="layui-form-item ns-icon-radio">';
  6. // couponListHtml += '<label class="layui-form-label sm">优惠券来源</label>';
  7. // couponListHtml += '<div class="layui-input-block">';
  8. // couponListHtml += '<template v-for="(item, index) in goodsSources" v-bind:k="index">';
  9. // couponListHtml += '<span :class="[item.value == data.sources ? \'\' : \'layui-hide\']">{{item.text}}</span>';
  10. // couponListHtml += '</template>';
  11. // couponListHtml += '<ul class="ns-icon">';
  12. // couponListHtml += '<li v-for="(item, index) in goodsSources" v-bind:k="index" :class="[item.value == data.sources ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" @click="data.sources=item.value">';
  13. // couponListHtml += '<img v-if="item.value == data.sources" :src="item.selectedSrc" />'
  14. // couponListHtml += '<img v-else :src="item.src" />'
  15. // couponListHtml += '</li>';
  16. // couponListHtml += '</ul>';
  17. // couponListHtml += '</div>';
  18. // couponListHtml += '</div>';
  19. // couponListHtml += '<div class="layui-form-item" v-if="data.sources == \'diy\'">';
  20. // couponListHtml += '<label class="layui-form-label sm">手动选择</label>';
  21. // couponListHtml += '<div class="layui-input-block">';
  22. // couponListHtml += '<a href="#" class="ns-input-text selected-style" v-on:click="addCoupon">选择 <i class="layui-icon layui-icon-right"></i></a>';
  23. // couponListHtml += '</div>';
  24. // couponListHtml += '</div>';
  25. couponListHtml += '<slide v-if="data.sources == \'default\'" v-bind:data="{ field : \'couponCount\', label : \'优惠券数量\', max: 9, min: 1 }"></slide>';
  26. couponListHtml += '</div>';
  27. Vue.component("coupon-list", {
  28. template: couponListHtml,
  29. data: function () {
  30. return {
  31. data: this.$parent.data,
  32. goodsSources: [
  33. {
  34. text: "默认",
  35. value: "default",
  36. src: couponResourcePath + "/coupon/img/goods.png",
  37. selectedSrc: couponResourcePath + "/coupon/img/goods_1.png"
  38. },
  39. {
  40. text : "手动选择",
  41. value : "diy",
  42. src: couponResourcePath + "/coupon/img/manual.png",
  43. selectedSrc: couponResourcePath + "/coupon/img/manual_1.png"
  44. }
  45. ],
  46. isLoad: false,
  47. isShow: false,
  48. couponCount: [6, 12, 18, 24, 30],
  49. }
  50. },
  51. created:function() {
  52. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  53. this.$parent.data.verify.push(this.verify);//加载验证方法
  54. },
  55. methods: {
  56. shopNum: function(){
  57. if (this.$parent.data.couponCount > 50){
  58. layer.msg("优惠券数量最多为50");
  59. this.$parent.data.couponCount = 50;
  60. }
  61. if (this.$parent.data.couponCount.length > 0 && this.$parent.data.couponCount < 1) {
  62. layer.msg("优惠券数量不能小于0");
  63. this.$parent.data.couponCount = 1;
  64. }
  65. },
  66. verify : function () {
  67. var res = { code : true, message : "" };
  68. /* if(this.data.couponCount.length===0) {
  69. res.code = false;
  70. res.message = "请输入优惠券数量";
  71. }
  72. if (this.data.goodsCount < 0) {
  73. res.code = false;
  74. res.message = "优惠券数量不能小于0";
  75. }
  76. if(this.data.couponCount > 50){
  77. res.code = false;
  78. res.message = "优惠券数量最多为50";
  79. } */
  80. return res;
  81. },
  82. addCoupon: function(){
  83. var self = this;
  84. self.couponSelect(function (res) {
  85. self.$parent.data.couponIds = [];
  86. for (var i=0; i<res.length; i++) {
  87. self.$parent.data.couponIds.push(res[i].coupon_type_id);
  88. }
  89. }, self.$parent.data.couponIds);
  90. },
  91. couponSelect: function(callback, selectId) {
  92. var self = this;
  93. layui.use(['layer'], function () {
  94. var url = ns.url("coupon://shop/coupon/couponselect", {select_id : selectId.toString()});
  95. //iframe层-父子操作
  96. layer.open({
  97. title: "优惠券选择",
  98. type: 2,
  99. area: ['1000px', '600px'],
  100. fixed: false, //不固定
  101. btn: ['保存', '返回'],
  102. content: url,
  103. yes: function (index, layero) {
  104. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  105. iframeWin.selectGoods(function (obj) {
  106. if (typeof callback == "string") {
  107. try {
  108. eval(callback + '(obj)');
  109. layer.close(index);
  110. } catch (e) {
  111. console.error('回调函数' + callback + '未定义');
  112. }
  113. } else if (typeof callback == "function") {
  114. callback(obj);
  115. layer.close(index);
  116. }
  117. });
  118. }
  119. });
  120. });
  121. }
  122. }
  123. });
  124. /**
  125. * 优惠券·组件
  126. */
  127. var couponHtml = '<div class="layui-form-item">';
  128. couponHtml += '<label class="layui-form-label sm">选择风格</label>';
  129. couponHtml += '<div class="layui-input-block">';
  130. // couponHtml += '<span>{{data.styleName}}</span>';
  131. couponHtml += '<div v-if="data.styleName" class="ns-input-text ns-text-color selected-style" v-on:click="selectCouponStyle">{{data.styleName}} <i class="layui-icon layui-icon-right"></i></div>';
  132. couponHtml += '<div v-else class="ns-input-text selected-style" v-on:click="selectCouponStyle">选择 <i class="layui-icon layui-icon-right"></i></div>';
  133. couponHtml += '</div>';
  134. couponHtml += '</div>';
  135. Vue.component("coupon-style", {
  136. template : couponHtml,
  137. data : function(){
  138. return {
  139. data : this.$parent.data,
  140. };
  141. },
  142. methods:{
  143. selectCouponStyle: function() {
  144. var self = this;
  145. layer.open({
  146. type: 1,
  147. title: '风格选择',
  148. area:['930px','630px'],
  149. btn: ['确定', '返回'],
  150. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .coupon-list-style").html(),
  151. success: function(layero, index) {
  152. $(".layui-layer-content input[name='style']").val(self.data.style);
  153. $(".layui-layer-content input[name='style_name']").val(self.data.styleName);
  154. $("body").on("click", ".layui-layer-content .style-list-con-coupon .style-li-coupon", function () {
  155. $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color");
  156. $(".layui-layer-content input[name='style']").val($(this).index() + 1);
  157. $(".layui-layer-content input[name='style_name']").val($(this).find("span").text());
  158. });
  159. },
  160. yes: function (index, layero) {
  161. self.data.style = $(".layui-layer-content input[name='style']").val();
  162. self.data.styleName = $(".layui-layer-content input[name='style_name']").val();
  163. layer.closeAll()
  164. }
  165. });
  166. },
  167. }
  168. });
  169. // 优惠券领取状态开关
  170. var moreBtnHtml = '<div class="layui-form-item">';
  171. moreBtnHtml += '<label class="layui-form-label sm">{{data.label}}</label>';
  172. moreBtnHtml += '<div class="layui-input-block">';
  173. moreBtnHtml += '<template v-for="(item,index) in list" v-bind:k="index">';
  174. moreBtnHtml += '<div v-on:click="parent[data.field]=item.value" v-bind:class="{ \'layui-unselect layui-form-radio\' : true,\'layui-form-radioed\' : (parent[data.field]==item.value) }"><i class="layui-anim layui-icon">&#xe643;</i><div>{{item.label}}</div></div>';
  175. moreBtnHtml += '</template>';
  176. moreBtnHtml += '</div>';
  177. moreBtnHtml += '</div>';
  178. Vue.component("coupon-status", {
  179. props: {
  180. data: {
  181. type: Object,
  182. default: function () {
  183. return {
  184. field: "status",
  185. label: "优惠券领取状态"
  186. };
  187. }
  188. }
  189. },
  190. created: function () {
  191. if (this.data.label == undefined) this.data.label = "启用";
  192. if (this.data.field == undefined) this.data.field = "status";
  193. },
  194. watch: {
  195. data: function (val, oldVal) {
  196. if (val.field == undefined) val.field = oldVal.field;
  197. if (val.label == undefined) val.label = "启用";
  198. },
  199. },
  200. template: moreBtnHtml,
  201. data: function () {
  202. return {
  203. list: [
  204. {label: "开启", value: 1},
  205. {label: "关闭", value: 0},
  206. ],
  207. parent: this.$parent.data,
  208. };
  209. }
  210. });