Bladeren bron

服务分类编辑逻辑更新

梁沛聪 6 jaren geleden
bovenliggende
commit
93761f1c6d
3 gewijzigde bestanden met toevoegingen van 74 en 32 verwijderingen
  1. 2
    1
      hksystem/src/main.js
  2. 36
    21
      hksystem/src/views/service/edit.vue
  3. 36
    10
      hksystem/src/views/service/index.vue

+ 2
- 1
hksystem/src/main.js Bestand weergeven

@@ -1,6 +1,6 @@
1 1
 import Vue from 'vue';
2 2
 import iView from 'iview';
3
-import {Message} from 'iview';
3
+import {Message,Modal} from 'iview';
4 4
 import {router} from './router/index';
5 5
 import {appRouter} from './router/router';
6 6
 import store from './store';
@@ -18,6 +18,7 @@ Vue.use(Login);
18 18
 Vue.use(Edit);
19 19
 Vue.prototype.$message = Message
20 20
 Vue.prototype.$Message = Message
21
+Vue.prototype.$Modal = Modal
21 22
 Vue.prototype.axios = util.ajax;
22 23
 Vue.prototype.$domain = util.ajaxUrl;
23 24
 

+ 36
- 21
hksystem/src/views/service/edit.vue Bestand weergeven

@@ -9,7 +9,7 @@
9 9
                 <Card>
10 10
                     <Form :label-width="110">
11 11
                         <FormItem label="父分类">
12
-                            <Select v-model="form.pid">
12
+                            <Select v-model="form.pname">
13 13
                                 <Option v-for="item in pList" :value="item.name" :key="item.id">{{ item.name }}</Option>
14 14
                             </Select>
15 15
                         </FormItem>
@@ -25,12 +25,15 @@
25 25
                         <FormItem label="服务介绍">
26 26
                             <Input v-model="form.summary" />
27 27
                         </FormItem>
28
+                        <FormItem label="提交项">
29
+                            <Input v-model="form.fields_json" type="textarea" :rows="10" placeholder="请输入表单提交项" />
30
+                        </FormItem>
28 31
                         <FormItem label="服务详情">
29 32
                             <editor :editor-content="form.content"></editor>
30 33
                         </FormItem>
31 34
                          <FormItem label="服务图片">
32 35
                              <img :src="form.photo" style="width:100%;max-width:750px;" v-if="form.photo" class="upload-img">
33
-                             <Upload :headers="uploadHeader" :on-success="handleSuccess" :action='$domain + "/upload"'>
36
+                             <Upload :on-success="handleSuccess" :action='$domain + "/upload"'>
34 37
                                 <Button icon="ios-cloud-upload-outline">上传更新图片</Button>
35 38
                             </Upload>
36 39
                         </FormItem>
@@ -43,6 +46,7 @@
43 46
                     </Form>
44 47
                     <div class="submit">
45 48
                         <Button @click="handlePublish" :loading="publishLoading" icon="ios-checkmark" size="large" type="primary">发布</Button>
49
+                        <Button @click="cancelEdit" style="margin-left:10px;" size="large" type="default">取消</Button>
46 50
                     </div>
47 51
                 </Card>
48 52
             </Col>
@@ -59,7 +63,8 @@ export default {
59 63
         editor
60 64
     },
61 65
     props: {
62
-        formContent: Object
66
+        formContent: Object,
67
+        parentList: Array
63 68
     },
64 69
     watch: {
65 70
         formContent() {
@@ -67,47 +72,57 @@ export default {
67 72
                 this.formContent.location = '';
68 73
             }
69 74
             this.form = this.formContent;
75
+        },
76
+        parentList() {
77
+            this.pList = this.parentList;
70 78
         }
71 79
     },
72 80
     data () {
73 81
         return {
74 82
             form: this.formContent,
75 83
             publishLoading: false,
76
-            pList: []
84
+            pList: this.parentList
77 85
         };
78 86
     },
79
-    mounted() {
80
-        this.axios.get('classify/parent', {}).then((res) => {
81
-            if (res.data.status == 0) {
82
-                this.pList = res.data.data;
83
-            }
84
-        });
85
-    },
86 87
     methods: {
88
+        cancelEdit() {
89
+            this.$emit("pub-cancel");
90
+        },
87 91
         handlePublish() {
88
-            if (true) {
92
+            // return console.warn(this.form, this.pList);
93
+            const form = this.form;
94
+            if (form.name && form.pname) {
89 95
                 this.publishLoading = true;
90 96
                 let content = tinymce.activeEditor.getContent();
97
+                for (let p of this.pList) {
98
+                    if (p.name === form.pname) {
99
+                        form.pid = p.id;
100
+                    }
101
+                }
91 102
                 let data = {
92
-                    pid: this.form.pid,
93
-                    name: this.form.name,
94
-                    info: this.form.info,
95
-                    summary: this.form.summary,
96
-                    server: this.form.server,
97
-                    content: content,
98
-                    photo: this.form.photo,
99
-                    location: this.form.location
103
+                    pid: form.pid,
104
+                    name: form.name,
105
+                    info: form.info,
106
+                    summary: form.summary,
107
+                    // server: form.server,
108
+                    server: 'server',
109
+                    content,
110
+                    photo: form.photo,
111
+                    location: form.location || 'bottom',
112
+                    fields_json: form.fields_json
100 113
                 };
101 114
                 if (this.form.id) {
102 115
                     data.id = this.form.id;
103 116
                 }
104 117
                 this.axios.post("/classify/store", data).then((res) => {
118
+                    this.publishLoading = false;
105 119
                     if (res.data.status == 0) {
106 120
                         this.$Message.success('操作成功!');
107
-                        this.publishLoading = false;
108 121
                         setTimeout(() => {
109 122
                             this.$emit("pub-success");
110 123
                         }, 1000);
124
+                    } else {
125
+                        this.$Message.warning(res.data.message);
111 126
                     }
112 127
                 });
113 128
             } else {

+ 36
- 10
hksystem/src/views/service/index.vue Bestand weergeven

@@ -30,7 +30,7 @@
30 30
                 </Card>
31 31
             </Col>
32 32
         </Row>
33
-        <edit v-show="editShow" @pub-success="pubSuccess" :form-content="formContent"></edit>
33
+        <edit v-show="editShow" @pub-cancel="pubCancel" @pub-success="pubSuccess" :parent-list="pList" :form-content="formContent"></edit>
34 34
     </div>
35 35
 </template>
36 36
 
@@ -47,7 +47,7 @@ export default {
47 47
         },
48 48
         prosHandle() {
49 49
             let products = [].concat(JSON.parse(JSON.stringify(this.products)));
50
-            console.log(products);
50
+            // console.log(products);
51 51
             for(let p of products) {
52 52
                 if (p.location === 'top') {
53 53
                     p._location = '是'
@@ -63,6 +63,7 @@ export default {
63 63
             total: 0,
64 64
             pageSize: 20,
65 65
             proShow: true,
66
+            pList: [],
66 67
             formContent: {},
67 68
             columns: [
68 69
                 {title: "分类名称", key: 'name', align: 'center'},
@@ -98,9 +99,17 @@ export default {
98 99
                                         this.proShow = false;
99 100
                                         this.products.forEach((product) => {
100 101
                                             if (product.id == id) {
102
+                                                if (product.location !== 'top') {
103
+                                                    product.location = '';
104
+                                                }
101 105
                                                 this.formContent = product;
102 106
                                             }
103 107
                                         })
108
+                                        for(let p of this.pList) {
109
+                                            if (p.id === this.formContent.pid) {
110
+                                                this.formContent.pname = p.name;
111
+                                            }
112
+                                        }
104 113
                                     }
105 114
                                 }
106 115
                             }, '修改'),
@@ -115,14 +124,23 @@ export default {
115 124
                                 on: {
116 125
                                     click: () => {
117 126
                                         let id = params.row.id;
118
-                                        this.axios.delete(`/classify/${id}`)
119
-                                            .then((res) => {
120
-                                                this.products = this.products.filter((product) => {
121
-                                                    if (product.id != id) {
122
-                                                        return true;
123
-                                                    }
124
-                                                });
125
-                                            });
127
+                                        this.$Modal.confirm({
128
+                                            title: '警告',
129
+                                            content: '确定要删除当前分类?',
130
+                                            onOk: () => {
131
+                                                this.axios.delete(`/classify/${id}`)
132
+                                                    .then((res) => {
133
+                                                        this.products = this.products.filter((product) => {
134
+                                                            if (product.id != id) {
135
+                                                                return true;
136
+                                                            }
137
+                                                        });
138
+                                                    });
139
+                                            },
140
+                                            onCancel: () => {
141
+                                                
142
+                                            }
143
+                                        });
126 144
                                     }
127 145
                                 }
128 146
                             }, '删除')
@@ -142,6 +160,9 @@ export default {
142 160
             this.proShow = true;
143 161
             this.getData();
144 162
         },
163
+        pubCancel() {
164
+            this.proShow = true;
165
+        },
145 166
         getData (num) {
146 167
             this.axios.get("/classifies", {
147 168
                 params: {
@@ -152,6 +173,11 @@ export default {
152 173
                 this.pageSize = res.data.per_page;
153 174
                 this.total = res.data.total;
154 175
             });
176
+            this.axios.get('classify/parent', {}).then((res) => {
177
+                if (res.data.status == 0) {
178
+                    this.pList = res.data.data;
179
+                }
180
+            });
155 181
         }
156 182
     },
157 183
     created () {

Loading…
Annuleren
Opslaan