design.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /**
  2. * 空的验证组件,后续如果增加业务,则更改组件
  3. */
  4. var couponSetHtml = '<div class="layui-hide"></div>';
  5. Vue.component("coupon-set", {
  6. template: couponSetHtml,
  7. data: function () {
  8. return {
  9. data: this.$parent.data,
  10. goodsSources: {
  11. initial: {
  12. text: "默认",
  13. src: "iconshangpinfenlei"
  14. },
  15. diy: {
  16. text: "手动选择",
  17. src: "iconshoudongxuanze"
  18. }
  19. },
  20. couponList: [
  21. {
  22. "ifNeedBg": true,
  23. "couponBgColor": "",
  24. "couponBgUrl": "",
  25. "couponType": "img",
  26. "isName": false,
  27. "nameColor": "",
  28. "moneyColor": "#FFFFFF",
  29. "limitColor": "#FFFFFF",
  30. "btnStyle": {
  31. "textColor": "#FFFFFF",
  32. "bgColor": "",
  33. "text": "立即领取",
  34. "aroundRadius": 0,
  35. "isBgColor": false,
  36. "isAroundRadius": false,
  37. "maxLen": 4
  38. },
  39. "bgColor": ""
  40. },
  41. {
  42. "ifNeedBg": true,
  43. "couponBgColor": "",
  44. "couponBgUrl": "",
  45. "couponType": "img",
  46. "isName": false,
  47. "nameColor": "",
  48. "moneyColor": "#FF8143",
  49. "limitColor": "#FF8143",
  50. "btnStyle": {
  51. "textColor": "#FF8143",
  52. "bgColor": "",
  53. "text": "领取",
  54. "aroundRadius": 0,
  55. "isBgColor": false,
  56. "isAroundRadius": false,
  57. "maxLen": 2
  58. },
  59. "bgColor": ""
  60. },
  61. {
  62. "ifNeedBg": true,
  63. "couponBgColor": "#FFFFFF",
  64. "couponBgUrl": couponRelativePath + "/img/style3-bg-1.png",
  65. "couponType": "img",
  66. "isName": false,
  67. "nameColor": "",
  68. "moneyColor": "#FF4544",
  69. "limitColor": "#FF4544",
  70. "btnStyle": {
  71. "textColor": "#FFFFFF",
  72. "bgColor": "#FF4544",
  73. "text": "立即抢",
  74. "aroundRadius": 20,
  75. "isBgColor": true,
  76. "isAroundRadius": true,
  77. "maxLen": 4
  78. },
  79. "bgColor": ""
  80. },
  81. {
  82. "ifNeedBg": true,
  83. "couponBgColor": "",
  84. "couponBgUrl": "",
  85. "couponType": "img",
  86. "isName": false,
  87. "nameColor": "",
  88. "moneyColor": "#FFFFFF",
  89. "limitColor": "#FFFFFF",
  90. "btnStyle": {
  91. "textColor": "#FFFFFF",
  92. "bgColor": "",
  93. "text": "立即领取",
  94. "aroundRadius": 0,
  95. "isBgColor": false,
  96. "isAroundRadius": false,
  97. "maxLen": 4
  98. },
  99. "bgColor": ""
  100. },
  101. {
  102. "ifNeedBg": true,
  103. "couponBgColor": "",
  104. "couponBgUrl": "",
  105. "couponType": "img",
  106. "isName": true,
  107. "nameColor": "#303133",
  108. "moneyColor": "#FF0000",
  109. "limitColor": "#999999",
  110. "btnStyle": {
  111. "textColor": "#FFFFFF",
  112. "bgColor": "#303133",
  113. "text": "立即领取",
  114. "aroundRadius": 5,
  115. "isBgColor": true,
  116. "isAroundRadius": true,
  117. "maxLen": 5
  118. },
  119. "bgColor": ""
  120. },
  121. {
  122. "ifNeedBg": true,
  123. "couponBgColor": "",
  124. "couponBgUrl": "",
  125. "couponType": "img",
  126. "isName": true,
  127. "nameColor": "#303133",
  128. "moneyColor": "#FF0000",
  129. "limitColor": "#303133",
  130. "btnStyle": {
  131. "textColor": "#FFFFFF",
  132. "bgColor": "#303133",
  133. "text": "领取",
  134. "aroundRadius": 20,
  135. "isBgColor": true,
  136. "isAroundRadius": true,
  137. "maxLen": 3
  138. },
  139. "bgColor": ""
  140. },
  141. {
  142. "ifNeedBg": true,
  143. "couponBgColor": "",
  144. "couponBgUrl": "",
  145. "couponType": "img",
  146. "isName": true,
  147. "nameColor": "",
  148. "moneyColor": "#FD463E",
  149. "limitColor": "#FD463E",
  150. "btnStyle": {
  151. "textColor": "#FF3D3D",
  152. "bgColor": "",
  153. "text": "立即领取",
  154. "aroundRadius": 0,
  155. "isBgColor": false,
  156. "isAroundRadius": false,
  157. "maxLen": 4
  158. },
  159. "bgColor": ""
  160. }
  161. ]
  162. }
  163. },
  164. created:function() {
  165. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  166. this.$parent.data.verify.push(this.verify);//加载验证方法
  167. this.$parent.data.ignore = ['textColor', 'elementAngle', 'componentAngle', 'componentBgColor']; //加载忽略内容 -- 其他设置中的属性设置
  168. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  169. this.$parent.data.tempData = {
  170. goodsSources: this.goodsSources,
  171. methods:{
  172. moneyConduct: this.moneyConduct,
  173. addCoupon: this.addCoupon,
  174. delCoupon: this.delCoupon,
  175. selectCouponStyle: this.selectCouponStyle
  176. }
  177. }
  178. },
  179. methods: {
  180. // 金额处理
  181. moneyConduct(value){
  182. var arr = value.split(".");
  183. var str = parseInt(arr[1].split("").reverse().join("")) + '';
  184. str = str.split("").reverse().join("");
  185. if(str == 0) return arr[0];
  186. else return arr[0] + '.' + str;
  187. },
  188. verify : function (index) {
  189. var res = { code : true, message : "" };
  190. if (vue.data[index].sources == 'diy' && vue.data[index].couponIds.length == 0){
  191. res.code = false;
  192. res.message = "请选择优惠券";
  193. }
  194. return res;
  195. },
  196. addCoupon: function(){
  197. var self = this;
  198. self.couponSelect(function (res) {
  199. self.$parent.data.couponIds = [];
  200. self.$parent.data.previewList = [];
  201. for (var i=0; i<res.length; i++) {
  202. self.$parent.data.couponIds.push(res[i].coupon_type_id);
  203. self.$parent.data.previewList.push(res[i]);
  204. }
  205. }, self.$parent.data.couponIds);
  206. },
  207. delCoupon: function (index){
  208. var self = this;
  209. self.$parent.data.couponIds.splice(index, 1);
  210. self.$parent.data.previewList.splice(index, 1);
  211. },
  212. couponSelect: function(callback, selectId) {
  213. var self = this;
  214. layui.use(['layer'], function () {
  215. var url = ns.url("coupon://shop/coupon/couponselect", {select_id : selectId.toString(),app_module:ns.appModule,site_id:ns.siteId});
  216. //iframe层-父子操作
  217. layer.open({
  218. title: "优惠券选择",
  219. type: 2,
  220. area: ['1000px', '600px'],
  221. fixed: false, //不固定
  222. btn: ['保存', '返回'],
  223. content: url,
  224. yes: function (index, layero) {
  225. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  226. iframeWin.selectCoupon(function (obj) {
  227. if (typeof callback == "string") {
  228. try {
  229. eval(callback + '(obj)');
  230. layer.close(index);
  231. } catch (e) {
  232. console.error('回调函数' + callback + '未定义');
  233. }
  234. } else if (typeof callback == "function") {
  235. callback(obj);
  236. layer.close(index);
  237. }
  238. });
  239. }
  240. });
  241. });
  242. },
  243. selectCouponStyle: function() {
  244. var self = this;
  245. layer.open({
  246. type: 1,
  247. title: '风格选择',
  248. area:['930px','470px'],
  249. btn: ['确定', '返回'],
  250. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .coupon-list-style").html(),
  251. success: function(layero, index) {
  252. $(".layui-layer-content input[name='style']").val(self.data.style);
  253. $(".layui-layer-content input[name='style_name']").val(self.data.styleName);
  254. $("body").on("click", ".layui-layer-content .style-list-con-coupon .style-li-coupon", function () {
  255. $(this).addClass("selected border-color").siblings().removeClass("selected border-color");
  256. $(".layui-layer-content input[name='style']").val($(this).index() + 1);
  257. $(".layui-layer-content input[name='style_name']").val($(this).find("span").text());
  258. });
  259. },
  260. yes: function (index, layero) {
  261. self.data.style = $(".layui-layer-content input[name='style']").val();
  262. self.data.styleName = $(".layui-layer-content input[name='style_name']").val();
  263. self.data.ifNeedBg = self.couponList[self.data.style-1].ifNeedBg;
  264. self.data.couponBgColor = self.couponList[self.data.style-1].couponBgColor;
  265. self.data.couponBgUrl = self.couponList[self.data.style-1].couponBgUrl;
  266. self.data.couponType = self.couponList[self.data.style-1].couponType;
  267. self.data.isName = self.couponList[self.data.style-1].isName;
  268. self.data.nameColor = self.couponList[self.data.style-1].nameColor;
  269. self.data.moneyColor = self.couponList[self.data.style-1].moneyColor;
  270. self.data.limitColor = self.couponList[self.data.style-1].limitColor;
  271. self.data.bgColor = self.couponList[self.data.style-1].bgColor;
  272. self.data.btnStyle.textColor = self.couponList[self.data.style-1].btnStyle.textColor;
  273. self.data.btnStyle.bgColor = self.couponList[self.data.style-1].btnStyle.bgColor;
  274. self.data.btnStyle.text = self.couponList[self.data.style-1].btnStyle.text;
  275. self.data.btnStyle.aroundRadius = self.couponList[self.data.style-1].btnStyle.aroundRadius;
  276. self.data.btnStyle.isBgColor = self.couponList[self.data.style-1].btnStyle.isBgColor;
  277. self.data.btnStyle.isAroundRadius = self.couponList[self.data.style-1].btnStyle.isAroundRadius;
  278. self.data.btnStyle.maxLen = self.couponList[self.data.style-1].btnStyle.maxLen;
  279. layer.closeAll()
  280. }
  281. });
  282. }
  283. }
  284. });