EditFun.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div id="app">
  3. <common ref="common" @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle" :rightLink="rightLink" :doRightLink="doRightLink"></top-header>
  5. <div class="mui-content vongi-icons">
  6. <div class="vongi-all">
  7. <h4 class="vongi-center">您可以将常用的应用添加到主页</h4>
  8. <ul class="mui-table-view mui-grid-view mui-grid-9">
  9. <draggable element="ul" v-model="menuList" :options="{draggable:'.mui-table-view-cell'}">
  10. <li draggable="true" v-for="(item,index) in menuList" class="mui-table-view-cell mui-media mui-col-xs-3">
  11. <!-- <router-link :to="{name:item.iconRoute,query:item.iconParam}"> -->
  12. <img :src="requirePic(item.iconPic)" />
  13. <div class="mui-media-body" v-text="item.iconName"></div>
  14. <!-- </router-link> -->
  15. <span @click="del(item.id,index)" class="mui-icon mui-icon-closeempty vongi-close"></span>
  16. </li>
  17. </draggable>
  18. </ul>
  19. </div>
  20. <div class="vongi-all">
  21. <h2>全部服务</h2>
  22. <div v-if="iten.cun_num" v-for="(iten,indey) in allFunList">
  23. <h4 v-text="iten.name"></h4>
  24. <ul class="mui-table-view mui-grid-view mui-grid-9">
  25. <li v-show="item.is_show" v-for="(item,index) in iten.list" :class="'mui-table-view-cell mui-media mui-col-xs-3 '+(item.iconRoute?'':'kfz')">
  26. <!-- <router-link :to="{name:item.iconRoute,query:item.iconParam}"> -->
  27. <img :src="requirePic(item.iconPic)" />
  28. <div class="mui-media-body" v-text="item.iconName"></div>
  29. <!-- </router-link> -->
  30. <span @click="add(indey,index)" class="mui-icon mui-icon-plusempty vongi-add"></span>
  31. </li>
  32. </ul>
  33. </div>
  34. </div>
  35. </div>
  36. <loading :visible="isLoading"></loading>
  37. </div>
  38. </template>
  39. <script>
  40. import draggable from 'vuedraggable'
  41. import * as API_User from '$project/apis/user'
  42. import Common from '$project/components/Common.vue'
  43. import Loading from '$project/components/Loading.vue'
  44. import TopHeader from '$project/components/TopHeader.vue'
  45. import NavMenu from '@/components/NavMenu.vue'
  46. import {
  47. mapGetters,
  48. mapMutations
  49. } from 'vuex'
  50. export default {
  51. name: 'MasterEditFun',
  52. components: {
  53. Common,
  54. Loading,
  55. TopHeader,
  56. NavMenu,
  57. draggable,
  58. },
  59. data() {
  60. return {
  61. isLoading: false,
  62. pageTitle: '管理常用服务',
  63. rightLink: {
  64. show: true,
  65. icon: 'mui-btn mui-btn-primary',
  66. style: 'width: 55px;height: 25px;margin-top:5px;margin-right: 0px;line-height: 5px;color: #fff;font-size:16px;',
  67. title: '完成'
  68. },
  69. allFunList: [],
  70. menuList: [],
  71. idList: [],
  72. }
  73. },
  74. created() {
  75. this.menuList = this.menu_list;
  76. this.resetIdList();
  77. },
  78. methods: {
  79. //引入图片
  80. requirePic(file) {
  81. if (file) {
  82. if (file.indexOf('http') == 0) {
  83. return file;
  84. } else {
  85. return require('$project/assets/img/' + file);
  86. }
  87. }
  88. },
  89. //获取所有的功能列表包括常用功能
  90. getAllFunList() {
  91. this.isLoading = true;
  92. API_User.getAllFunList().then(response => {
  93. this.isLoading = false;
  94. this.allFunList = this.resetAllFunList(response.allIcon);
  95. }).catch(error => {
  96. mui.toast(error);
  97. })
  98. },
  99. //重置数组
  100. resetAllFunList(list) {
  101. for (var i = 0; i < list.length; i++) {
  102. var num = 0;
  103. for (var j = 0; j < list[i]['list'].length; j++) {
  104. if (this.idList.indexOf(list[i]['list'][j]['id']) > -1) {
  105. list[i]['list'][j]['is_show'] = 0;
  106. } else {
  107. list[i]['list'][j]['is_show'] = 1;
  108. num++;
  109. }
  110. }
  111. list[i]['cun_num'] = num;
  112. }
  113. return list;
  114. },
  115. resetIdList() {
  116. var list = [];
  117. for (var i = 0; i < this.menuList.length; i++) {
  118. list.push(this.menuList[i]['id']);
  119. }
  120. this.idList = list;
  121. },
  122. //添加图标
  123. add(indy, index) {
  124. this.menuList.push(this.allFunList[indy]['list'][index])
  125. this.allFunList[indy]['list'][index]['is_show'] = 0;
  126. this.allFunList[indy]['cun_num']--;
  127. },
  128. //减少图标
  129. del(id, index) {
  130. for (var i = 0; i < this.menuList.length; i++) {
  131. if (this.menuList[i]['id'] == id) {
  132. this.menuList.splice(i, 1);
  133. }
  134. }
  135. var allFunList = this.allFunList;
  136. for (var i = 0; i < allFunList.length; i++) {
  137. var item = allFunList[i];
  138. for (var j = 0; j < item['list'].length; j++) {
  139. if (item['list'][j]['id'] == id) {
  140. item['list'][j]['is_show'] = 1;
  141. item['cun_num']++;
  142. this.$set(this.allFunList, i, item)
  143. }
  144. }
  145. }
  146. },
  147. //保存常用图片
  148. doRightLink() {
  149. this.isLoading = true;
  150. this.resetIdList();
  151. API_User.saveFun(this.idList.join(',')).then(response => {
  152. this.isLoading = false;
  153. mui.toast('保存成功');
  154. this.$router.go(-1);
  155. }).catch(error => {
  156. mui.toast(error);
  157. })
  158. },
  159. asynCallBack() {
  160. },
  161. },
  162. mounted() {
  163. this.getAllFunList()
  164. },
  165. destroyed() {
  166. },
  167. computed: {
  168. ...mapGetters({
  169. openId: 'wx_openid',
  170. token: 'token',
  171. person_data: 'person_data',
  172. person_popedom: 'person_popedom',
  173. menu_list: 'menu_list'
  174. })
  175. }
  176. }
  177. </script>
  178. <style src="$project/assets/css/iconfont.css"></style>
  179. <style scoped src="$project/assets/css/xpgj.css"></style>
  180. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  181. <style scoped>
  182. .mui-table-view ul {
  183. padding-left: 0;
  184. }
  185. </style>