Authored by htoooth

fix

@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 <div style="text-align: center"> 9 <div style="text-align: center">
10 <FilterItem :label="'商品分类名称'"> 10 <FilterItem :label="'商品分类名称'">
11 - <Input >fdsa</Input> 11 + <Input v-model="name"/>
12 </FilterItem> 12 </FilterItem>
13 </div> 13 </div>
14 14
@@ -20,15 +20,27 @@ @@ -20,15 +20,27 @@
20 </template> 20 </template>
21 21
22 <script> 22 <script>
  23 +
  24 + import service from 'shop-category-service';
  25 +
23 export default { 26 export default {
24 data() { 27 data() {
25 return { 28 return {
26 model: false, 29 model: false,
27 - modal_loading: false 30 + modal_loading: false,
  31 + name: '',
  32 + id: ''
28 } 33 }
29 }, 34 },
30 methods: { 35 methods: {
31 - show() { 36 + update(c) {
  37 + this.reset();
  38 + this.model = true;
  39 + this.id = c.categoryId;
  40 + this.name = c.categoryName;
  41 + },
  42 + create() {
  43 + this.reset();
32 this.model = true; 44 this.model = true;
33 }, 45 },
34 close() { 46 close() {
@@ -38,17 +50,20 @@ @@ -38,17 +50,20 @@
38 this.modal_loading = true; 50 this.modal_loading = true;
39 51
40 this.save().then(() => { 52 this.save().then(() => {
41 - setTimeout(() => {  
42 - this.close();  
43 - }, 2000) 53 + this.modal_loading = false;
  54 + this.$emit('on-success');
  55 + this.close();
44 }) 56 })
45 }, 57 },
46 cancel(){ 58 cancel(){
47 this.close(); 59 this.close();
48 }, 60 },
49 save() { 61 save() {
  62 + return service.updateCategoryName(this.id, this.name);
50 }, 63 },
51 reset() { 64 reset() {
  65 + this.name = '';
  66 + this.id = '';
52 } 67 }
53 } 68 }
54 } 69 }
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <Page :total="pageData.total" :current="pageData.current" 11 <Page :total="pageData.total" :current="pageData.current"
12 @on-change="pageChange" :page-size="20" show-total></Page> 12 @on-change="pageChange" :page-size="20" show-total></Page>
13 </LayoutList> 13 </LayoutList>
14 - <EditName ref="showNameEdit"></EditName> 14 + <EditName ref="showNameEdit" @on-success="onEditSuccess"></EditName>
15 </LayoutBody> 15 </LayoutBody>
16 </template> 16 </template>
17 17
@@ -19,30 +19,35 @@ @@ -19,30 +19,35 @@
19 import _ from 'lodash'; 19 import _ from 'lodash';
20 import {tableCols, pageData, tableData} from './store'; 20 import {tableCols, pageData, tableData} from './store';
21 import components from './components'; 21 import components from './components';
  22 + import service from 'shop-category-service';
22 23
23 export default { 24 export default {
24 data() { 25 data() {
25 return { 26 return {
26 self: this, 27 self: this,
27 tableCols, 28 tableCols,
28 - tableData, 29 + tableData: [],
29 pageData, 30 pageData,
30 } 31 }
31 }, 32 },
  33 + mounted() {
  34 + this.getData();
  35 + },
32 methods: { 36 methods: {
33 clickEditName(row) { 37 clickEditName(row) {
34 - this.$refs.showNameEdit.show(row) 38 + this.$refs.showNameEdit.update(row)
35 }, 39 },
36 clickDelete(row) { 40 clickDelete(row) {
  41 + let _this = this;
  42 +
37 this.$Modal.confirm({ 43 this.$Modal.confirm({
38 title: '删除店铺商品分类', 44 title: '删除店铺商品分类',
39 - content: '你确定 删除 商品分类 test 么?',  
40 - onOk: function() {  
41 - 45 + content: `你确定 删除 商品分类 ${row.categoryName} 么?`,
  46 + onOk() {
  47 + _this.deleteCategory(row.categoryId).then(() => {
  48 + _this.tableData.splice(_this.tableData.indexOf(row), 1)
  49 + });
42 }, 50 },
43 - onCancel: function() {  
44 -  
45 - }  
46 }) 51 })
47 }, 52 },
48 clickEditRelation(row) { 53 clickEditRelation(row) {
@@ -50,12 +55,33 @@ @@ -50,12 +55,33 @@
50 this.$router.push({name: 'shop.category.edit', query: { categoryId }}) 55 this.$router.push({name: 'shop.category.edit', query: { categoryId }})
51 }, 56 },
52 clickCreate() { 57 clickCreate() {
53 - 58 + this.$refs.showNameEdit.create()
54 }, 59 },
55 pageChange() { 60 pageChange() {
56 61
57 }, 62 },
58 - 63 + getData() {
  64 + return service.getCategoryList(pageData.current).then((result) => {
  65 + if (result.code === 200) {
  66 + this.pageData.total = result.data.total;
  67 + this.pageData.current = result.data.currentPage;
  68 + this.tableData = result.data.rows;
  69 + }
  70 + });
  71 + },
  72 + deleteCategory(id) {
  73 + return service.deleteCategory(id).then((result) => {
  74 + if (result.code === 200) {
  75 + return Promise.resolve();
  76 + } else {
  77 + return Promise.reject();
  78 + }
  79 + });
  80 + },
  81 + onEditSuccess() {
  82 + console.log('ok');
  83 + this.getData();
  84 + }
59 }, 85 },
60 components: { 86 components: {
61 ...components 87 ...components
  1 +/**
  2 + * Created by TaoHuang on 2017/5/9.
  3 + */
  4 +
  5 +import _ from 'lodash';
  6 +import request from 'axios';
  7 +
  8 +const apiUrl = {
  9 + categoryList: '/platform/getShopsCategoryList',
  10 + updateCategory: '/platform/addOrUpdateShopsCategory',
  11 + deleteCategory: '/platform/deleteShopsCategory'
  12 +};
  13 +
  14 +function getCategoryList(page = 1) {
  15 + return request.get(apiUrl.categoryList, {
  16 + params: {
  17 + page
  18 + }
  19 + }).then(res => res.data);
  20 +}
  21 +
  22 +/**
  23 + * 更新或者新建分类
  24 + * @param id 有id 时是更新,没有id 是新建
  25 + * @param name
  26 + * @returns {Promise.<TResult>|Promise<R2|R1>|Promise<R>}
  27 + */
  28 +function updateCategoryName(id, name) {
  29 + let data = {
  30 + categoryName: name,
  31 + };
  32 +
  33 + if (id) {
  34 + data.categoryId = id
  35 + }
  36 +
  37 + return request.post(apiUrl.updateCategory, data).then(res => res.data);
  38 +}
  39 +
  40 +function deleteCategory(id) {
  41 + return request.post(apiUrl.deleteCategory, {
  42 + categoryId: id
  43 + }).then(res => res.data);
  44 +}
  45 +
  46 +export default {
  47 + getCategoryList,
  48 + updateCategoryName,
  49 + deleteCategory
  50 +}
@@ -30,7 +30,10 @@ let domainApis = { @@ -30,7 +30,10 @@ let domainApis = {
30 getShopDetailById: '/SellerShopController/getShopDetailById', 30 getShopDetailById: '/SellerShopController/getShopDetailById',
31 updateShopBaseInfoById: '/SellerShopController/updateShopBaseInfoById', 31 updateShopBaseInfoById: '/SellerShopController/updateShopBaseInfoById',
32 uploads: '/fileupload/uploads', 32 uploads: '/fileupload/uploads',
33 - findBusinessShopsDecorator: '/ShopsDecoratorRest/findBusinessShopsDecorator' 33 + findBusinessShopsDecorator: '/ShopsDecoratorRest/findBusinessShopsDecorator',
  34 + getShopsCategoryList: '/SellerShopController/getShopsCategoryList',
  35 + addOrUpdateShopsCategory: '/SellerShopController/addOrUpdateShopsCategory',
  36 + deleteShopsCategory: '/SellerShopController/deleteShopsCategory'
34 }, 37 },
35 shop: { 38 shop: {
36 login: '/loginInter' 39 login: '/loginInter'