member_index.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. var vue = new Vue({
  2. el: "#diyView",
  3. data: {
  4. currentIndex: 0,// 当前编辑的位置
  5. bgColorList: ["#ff454f", "#1e9fff", "#ff547b", "#c3a769", "#ff8d17", "#b2b2b2", "#98cb71", "#333333", "#0adb9a", "#5fb878"],
  6. topStyleList: [
  7. {
  8. text: "系统风格",
  9. value: "default"
  10. },
  11. {
  12. text: "自定义风格",
  13. value: "diy"
  14. }
  15. ],
  16. menuStyleList: [
  17. {
  18. text: "宫格式",
  19. value: "palace"
  20. },
  21. {
  22. text: "列表式",
  23. value: "list"
  24. }
  25. ],
  26. tempLink: {},
  27. repeat_flag: false,
  28. data: {
  29. textColor: "#ffffff",
  30. bgImg: 'upload/uniapp/member/index/member_bg.png',
  31. bgColor: "#ff454f",
  32. topStyle: 'default',
  33. menuStyle: "palace",
  34. level:1,
  35. insertGap: 0, // 插入间隔
  36. menuList: [
  37. {
  38. tag: 'membersignin',
  39. text: '签到',
  40. img: 'upload/uniapp/member/index/menu/default_sign.png',
  41. link: {
  42. "name": "SIGN_IN",
  43. "title": "签到",
  44. "wap_url": "/otherpages/member/signin/signin",
  45. },
  46. isShow: 1,
  47. isSystem: 1
  48. },
  49. {
  50. text: '个人资料',
  51. img: 'upload/uniapp/member/index/menu/default_person.png',
  52. link: {
  53. "name": "MEMBER_INFO",
  54. "title": "个人资料",
  55. "wap_url": "/pages/member/info/info",
  56. },
  57. isShow: 1,
  58. isSystem: 1
  59. },
  60. {
  61. text: '收货地址',
  62. img: 'upload/uniapp/member/index/menu/default_address.png',
  63. link: {
  64. "name": "SHIPPING_ADDRESS",
  65. "title": "收货地址",
  66. "wap_url": "/otherpages/member/address/address",
  67. },
  68. isShow: 1,
  69. isSystem: 1
  70. },
  71. {
  72. tag: 'memberwithdraw',
  73. text: '账户列表',
  74. img: 'upload/uniapp/member/index/menu/default_cash.png',
  75. link: {
  76. "name": "ACCOUNT",
  77. "title": "账户列表",
  78. "wap_url": "/otherpages/member/account/account",
  79. },
  80. isShow: 1,
  81. isSystem: 1
  82. },
  83. {
  84. tag: 'coupon',
  85. text: '优惠券',
  86. img: 'upload/uniapp/member/index/menu/default_discount.png',
  87. link: {
  88. "name": "COUPON",
  89. "title": "优惠券",
  90. "wap_url": "/otherpages/member/coupon/coupon",
  91. },
  92. isShow: 1,
  93. isSystem: 1
  94. },
  95. {
  96. tag: 'pintuan',
  97. text: '我的拼单',
  98. img: 'upload/uniapp/member/index/menu/default_store.png',
  99. link: {
  100. "name": "MY_PINTUAN",
  101. "title": "我的拼团",
  102. "wap_url": "/promotionpages/pintuan/my_spell/my_spell",
  103. },
  104. isShow: 1,
  105. isSystem: 1
  106. },
  107. {
  108. text: '我的关注',
  109. img: 'upload/uniapp/member/index/menu/default_like.png',
  110. link: {
  111. "name": "ATTENTION",
  112. "title": "我的关注",
  113. "wap_url": "/otherpages/member/collection/collection",
  114. },
  115. isShow: 1,
  116. isSystem: 1
  117. },
  118. {
  119. text: '我的足迹',
  120. img: 'upload/uniapp/member/index/menu/default_toot.png',
  121. link: {
  122. "name": "FOOTPRINT",
  123. "title": "我的足迹",
  124. "wap_url": "/otherpages/member/footprint/footprint",
  125. },
  126. isShow: 1,
  127. isSystem: 1
  128. },
  129. {
  130. tag: 'pointexchange',
  131. text: '积分兑换',
  132. img: 'upload/uniapp/member/index/menu/default_point_recond.png',
  133. link: {
  134. "name": "INTEGRAL_CONVERSION",
  135. "title": "积分兑换",
  136. "wap_url": "/promotionpages/point/order_list/order_list",
  137. },
  138. isShow: 1,
  139. isSystem: 1
  140. },
  141. {
  142. tag: 'verifier',
  143. text: '核销台',
  144. img: 'upload/uniapp/member/index/menu/default_verification.png',
  145. link: {
  146. "name": "VERIFICATION_PLATFORM",
  147. "title": "核销台",
  148. "wap_url": "/otherpages/verification/index/index",
  149. },
  150. isShow: 1,
  151. isSystem: 1,
  152. remark: '成为核销员时显示'
  153. },
  154. {
  155. tag: 'fenxiao',
  156. text: '分销中心',
  157. img: 'upload/uniapp/member/index/menu/default_fenxiao.png',
  158. link: {
  159. "name": "DISTRIBUTION_CENTRE",
  160. "title": "分销中心",
  161. "wap_url": "/otherpages/fenxiao/index/index",
  162. },
  163. isShow: 1,
  164. isSystem: 1
  165. },
  166. {
  167. tag: 'bargain',
  168. text: '我的砍价',
  169. img: 'upload/uniapp/member/index/menu/default_bargain.png',
  170. link: {
  171. "name": "MY_BARGAIN",
  172. "title": "我的砍价",
  173. "wap_url": "/promotionpages/bargain/my_bargain/my_bargain",
  174. },
  175. isShow: 1,
  176. isSystem: 1
  177. }
  178. ],
  179. }
  180. },
  181. created: function () {
  182. var info = JSON.parse($("#info").val().toString());
  183. for (var k in info) {
  184. if (this.data[k] != undefined) this.data[k] = info[k];
  185. }
  186. },
  187. methods: {
  188. //转换图片路径
  189. changeImgUrl: function (url) {
  190. if (url == null || url == "") return '';
  191. else return ns.img(url);
  192. },
  193. editMenu: function (i) {
  194. var self = this;
  195. var data = JSON.parse(JSON.stringify(self.data.menuList[i]));
  196. data.i = i;
  197. this.openEditMenu('edit', data, i);
  198. },
  199. addMenu: function () {
  200. this.openEditMenu("add");
  201. },
  202. deleteMenu: function (i) {
  203. this.data.menuList.splice(i, 1);
  204. },
  205. openEditMenu: function (tag, data, i) {
  206. var self = this;
  207. if (tag == 'add') data = {};
  208. laytpl($("#editMenuHtml").html()).render(data, function (html) {
  209. layer.open({
  210. title: '编辑菜单',
  211. btn: ['保存', '取消'],
  212. type: 1,
  213. area: ['400px'],
  214. content: html,
  215. success: function (layero, index) {
  216. var $parent = $("#menuImgUpload").parent();
  217. $("#menuImgUpload").click(function () {
  218. openAlbum(function (data) {
  219. $parent.find("input[type='hidden']").val(data[0].pic_path);
  220. $parent.find(".del").addClass("show");
  221. $parent.find(".upload-img-box").html("<img src=" + ns.img(data[0].pic_path) + " >");
  222. }, 1);
  223. });
  224. $parent.find(".del").click(function () {
  225. var path = $parent.find("input[type='hidden']").val();
  226. if (!path) return;
  227. $parent.find("input[type='hidden']").val("");
  228. $(this).removeClass("show");
  229. $parent.find(".upload-img-box").html(`<div class="ns-upload-default"><img src="${ns_url.SHOPIMG}/upload_img.png" /></div>`);
  230. });
  231. if (self.data.menuList[i]) self.tempLink = self.data.menuList[i].link;
  232. },
  233. yes: function (index, layero) {
  234. if ($("input[name='menu_text']").val().length == 0) {
  235. layer.msg("请输入菜单名称");
  236. $("input[name='menu_text']").focus();
  237. return;
  238. }
  239. if ($("input[name='menu_img']").val().length == 0) {
  240. layer.msg("请上传菜单图标");
  241. return;
  242. }
  243. if (tag == 'add') {
  244. if (!self.tempLink.title) {
  245. layer.msg("请选择跳转链接");
  246. return;
  247. }
  248. self.data.menuList.push({
  249. text: $("input[name='menu_text']").val(),
  250. img: $("input[name='menu_img']").val(),
  251. link: self.tempLink,
  252. isShow: 1,
  253. isSystem: 0
  254. });
  255. self.tempLink = {};
  256. } else {
  257. self.data.menuList[i].link = self.tempLink;
  258. if (!self.data.menuList[i].link.title) {
  259. layer.msg("请选择跳转链接");
  260. return;
  261. }
  262. self.data.menuList[i].text = $("input[name='menu_text']").val();
  263. self.data.menuList[i].img = $("input[name='menu_img']").val();
  264. }
  265. layer.closeAll();
  266. }
  267. });
  268. });
  269. },
  270. //刷新数据排序
  271. refresh: function () {
  272. var self = this;
  273. //vue框架执行,异步操作组件列表的排序
  274. setTimeout(function () {
  275. $(".menu-list>ul li").each(function (i) {
  276. $(this).attr("data-sort", i);
  277. });
  278. for (var i = 0; i < self.data.menuList.length; i++) {
  279. self.data.menuList[i].index = $(".menu-list>ul li[data-index=" + i + "]").attr("data-index");
  280. self.data.menuList[i].sort = $(".menu-list>ul li[data-index=" + i + "]").attr("data-sort");
  281. }
  282. //触发变异方法,进行视图更新。不能用sort()方法,会改变组件的顺序,导致显示的顺序错乱
  283. self.data.menuList.push({});
  284. self.data.menuList.pop();
  285. // console.log("触发变异方法,进行视图更新。不能用sort()方法,会改变组件的顺序,导致显示的顺序错乱");
  286. }, 50);
  287. },
  288. save: function () {
  289. var self = this;
  290. if (this.repeat_flag) return;
  291. this.repeat_flag = true;
  292. //组件属性
  293. var data = JSON.parse(JSON.stringify(vue.data));
  294. //重新排序
  295. data.menuList.sort(function(a,b){
  296. return a.sort-b.sort;
  297. });
  298. for (var i=0;i<data.menuList.length;i++){
  299. delete data.menuList[i].index;
  300. delete data.menuList[i].sort;
  301. }
  302. $.ajax({
  303. type: 'POST',
  304. url: ns.url("shop/diy/memberindex"),
  305. data: {data: data},
  306. dataType: 'JSON',
  307. success: function (res) {
  308. layer.msg(res.message);
  309. self.repeat_flag = false;
  310. if (res.code == 0) {
  311. location.reload();
  312. }
  313. }
  314. });
  315. },
  316. },
  317. computed:{
  318. handleMenuList:function () {
  319. var data = JSON.parse(JSON.stringify(this.data.menuList));
  320. for (var i=0;i<data.length;i++){
  321. if(data[i].isShow == 0) data.splice(i,1);
  322. }
  323. data.sort(function(a,b){
  324. return a.sort-b.sort;
  325. });
  326. return data;
  327. }
  328. }
  329. });
  330. function selectLink(i) {
  331. var d = {};
  332. if (i == undefined) d = vue.tempLink;
  333. else d = vue.data.menuList[i].link;
  334. ns.select_link(d, '', function (data) {
  335. vue.tempLink = data;
  336. $('.js-select-link-text').text(data.title).show();
  337. }, post, 0);
  338. }
  339. /**
  340. * 绑定拖拽事件
  341. * 创建时间:2018年7月3日18:50:11
  342. */
  343. $('.menu-list>ul').DDSort({
  344. //拖拽数据源
  345. target: 'li',
  346. //拖拽时显示的样式
  347. floatStyle: {
  348. 'border': '1px solid #FF6A00',
  349. 'background-color': '#ffffff'
  350. },
  351. //设置可拖拽区域
  352. draggableArea: "info-wrap",
  353. //拖拽中,隐藏右侧编辑属性栏
  354. move: function (index) {
  355. },
  356. //拖拽结束后,选择当前拖拽,并且显示右侧编辑属性栏,刷新数据
  357. up: function (index) {
  358. vue.refresh();
  359. }
  360. });