index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div>
  3. <div class="i-layout-page-header" style="padding: 18px 32px;border-bottom: 1px solid #f2f2f2;">
  4. <span class="ivu-page-header-title">{{ $route.meta.title }}</span>
  5. </div>
  6. <div class="article-manager">
  7. <Card :bordered="false" dis-hover class="ivu-mt fromBox">
  8. <Tabs v-model="currentTab" @on-click="changeTab" v-if="headerList.length">
  9. <TabPane
  10. :icon="item.icon"
  11. :label="item.label"
  12. :name="item.value.toString()"
  13. v-for="(item, index) in headerList"
  14. :key="index"
  15. />
  16. </Tabs>
  17. <Tabs type="card" v-model="childrenId" v-if="headerChildrenList.length" @on-click="changeChildrenTab">
  18. <TabPane
  19. :label="item.label"
  20. :name="item.id.toString()"
  21. v-for="(item, index) in headerChildrenList"
  22. :key="index"
  23. ></TabPane>
  24. </Tabs>
  25. <form-create :option="option" :rule="rules" @submit="onSubmit" v-if="rules.length !== 0"></form-create>
  26. <Spin size="large" fix v-if="spinShow"></Spin>
  27. </Card>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import formCreate from '@form-create/iview';
  33. import { headerListApi, dataFromApi } from '@/api/setting';
  34. import request from '@/libs/request';
  35. import { getLogo } from '@/api/common';
  36. export default {
  37. name: 'setting_setSystem',
  38. components: { formCreate: formCreate.$form() },
  39. data() {
  40. return {
  41. rules: [],
  42. option: {
  43. form: {
  44. labelWidth: 185,
  45. },
  46. submitBtn: {
  47. col: {
  48. span: 3,
  49. push: 3,
  50. },
  51. },
  52. global: {
  53. upload: {
  54. props: {
  55. onSuccess(res, file) {
  56. if (res.status === 200) {
  57. file.url = res.data.src;
  58. } else {
  59. this.$Message.error(res.msg);
  60. }
  61. },
  62. },
  63. },
  64. frame: {
  65. props: {
  66. closeBtn: false,
  67. okBtn: false,
  68. },
  69. },
  70. },
  71. },
  72. spinShow: false,
  73. FromData: null,
  74. currentTab: '',
  75. headerList: [],
  76. headerChildrenList: [],
  77. childrenId: '',
  78. title: '',
  79. };
  80. },
  81. created() {
  82. this.getAllData();
  83. },
  84. watch: {
  85. $route(to, from) {
  86. this.headerChildrenList = [];
  87. this.getAllData();
  88. },
  89. childrenId() {
  90. this.getFrom();
  91. },
  92. },
  93. methods: {
  94. childrenList(index) {
  95. let that = this;
  96. that.headerList.forEach(function (item) {
  97. if (item.value.toString() === that.currentTab) {
  98. if (item.children === undefined) {
  99. that.childrenId = item.id;
  100. that.headerChildrenList = [];
  101. } else {
  102. that.headerChildrenList = item.children;
  103. that.childrenId = item.children.length ? item.children[index ? index : 0].id.toString() : '';
  104. }
  105. }
  106. });
  107. },
  108. // 头部tab
  109. getHeader(index) {
  110. this.spinShow = true;
  111. return new Promise((resolve, reject) => {
  112. let tab_id = this.$route.params.tab_id;
  113. let data = {
  114. type: this.$route.params.type ? this.$route.params.type : 0,
  115. pid: tab_id ? tab_id : 0,
  116. };
  117. headerListApi(data)
  118. .then(async (res) => {
  119. let config = res.data.config_tab;
  120. this.headerList = config;
  121. this.currentTab = config[index ? index : 0].value.toString();
  122. this.childrenList(index ? 1 : 0);
  123. resolve(this.currentTab);
  124. this.spinShow = false;
  125. })
  126. .catch((err) => {
  127. this.spinShow = false;
  128. this.$Message.error(err);
  129. });
  130. });
  131. },
  132. // 表单
  133. getFrom() {
  134. this.spinShow = true;
  135. return new Promise((resolve, reject) => {
  136. let ids = '';
  137. if (this.$route.params.type === '3') {
  138. ids = this.$route.params.tab_id;
  139. } else {
  140. if (this.childrenId) {
  141. ids = this.childrenId;
  142. } else {
  143. ids = this.currentTab;
  144. }
  145. }
  146. let data = {
  147. tab_id: Number(ids),
  148. };
  149. let logistics = 'freight/config/edit_basics',
  150. agent = 'agent/config/edit_basics',
  151. integral = 'marketing/integral_config/edit_basics',
  152. sms = 'serve/sms_config/edit_basics',
  153. config = 'setting/config/edit_basics';
  154. let url =
  155. this.$route.name === 'setting_logistics'
  156. ? logistics
  157. : this.$route.name === 'setting_distributionSet'
  158. ? agent
  159. : this.$route.name === 'setting_message'
  160. ? sms
  161. : this.$route.name === 'setting_setSystem'
  162. ? config
  163. : integral;
  164. dataFromApi(data, url)
  165. .then(async (res) => {
  166. this.spinShow = false;
  167. if (res.data.status === false) {
  168. return this.$authLapse(res.data);
  169. }
  170. this.FromData = res.data;
  171. this.rules = res.data.rules;
  172. this.title = res.data.title;
  173. })
  174. .catch((res) => {
  175. this.spinShow = false;
  176. this.$Message.error(res.msg);
  177. });
  178. });
  179. },
  180. async getAllData() {
  181. if (this.$route.query.from === 'download') {
  182. await this.getHeader(2);
  183. } else if (this.$route.params.type !== '3') {
  184. this.childrenId = '';
  185. await this.getHeader();
  186. } else {
  187. this.headerList = [];
  188. this.getFrom();
  189. }
  190. },
  191. // 选择
  192. changeTab() {
  193. this.childrenList();
  194. },
  195. // 二级选择
  196. changeChildrenTab(name) {
  197. this.childrenId = name;
  198. },
  199. // 提交表单 group
  200. onSubmit(formData) {
  201. request({
  202. url: this.FromData.action,
  203. method: this.FromData.method,
  204. data: formData,
  205. })
  206. .then((res) => {
  207. this.getAdminTitle();
  208. this.$Message.success(res.msg);
  209. })
  210. .catch((res) => {
  211. this.$Message.error(res.msg);
  212. });
  213. },
  214. getAdminTitle() {
  215. getLogo().then((res) => {
  216. localStorage.setItem('ADMIN_TITLE', res.data.site_name);
  217. });
  218. },
  219. },
  220. };
  221. </script>
  222. <style scoped lang="stylus">
  223. .ivu-tabs {
  224. margin-bottom: 18px;
  225. }
  226. .fromBox {
  227. min-height: 600px;
  228. margin-top 0px !important ;
  229. }
  230. .article-manager /deep/ .ivu-form-item{
  231. margin-bottom: 20px !important;
  232. }
  233. </style>