Browse Source

车系车型接口

suxinf 4 years ago
parent
commit
64165a7dcb

+ 1 - 1
src/App.vue

@@ -36,7 +36,7 @@ export default {
     return {
       navTitle1: ' > 数据管理',
       navTitle2: '',
-      isManufacturer: 'distributor', // distributor 经销商 manufacturer 厂商
+      isManufacturer: 'manufacturer', // distributor 经销商 manufacturer 厂商
     }
   },
   methods: {

+ 4 - 8
src/views/parameter/CarSeries.vue

@@ -31,9 +31,7 @@
       </div>
     </div>
     <div v-else>
-      <CarType 
-        :parentId='parentId'
-      />
+      <CarType />
     </div>
   </div>
 </template>
@@ -60,7 +58,6 @@ export default {
       // 表格配置
       tableData: [],
       modalFlag: false, // 控制模态框展示
-      parentId: ''
     };
   },
   computed: {
@@ -132,8 +129,7 @@ export default {
     // 点击系列车型
     carType: function (index) {
       // 页面变化
-      this.$router.push({ query: { tag: "vehicle_type" } });
-      this.parentId = this.tableData[index]['id']
+      this.$router.push({ query: { tag: "vehicle_type", id: this.tableData[index]['id'] } });
     },
     // 新增车系  接口
     addCarSeries: function (typeName) {
@@ -177,7 +173,7 @@ export default {
           console.log(err);
         });
     },
-    // 编辑车  接口
+    // 编辑车  接口
     updataCarTypeInfo: function (data) {
       return new Promise((resolve, reject) => {
         this.$http({
@@ -199,7 +195,7 @@ export default {
           });
       });
     },
-    // 删除车   接口
+    // 删除车   接口
     deleteCarTypeInfo: function (id) {
       return new Promise((resolve, reject) => {
         this.$http({

+ 71 - 21
src/views/parameter/components/Carseries/CarType.vue

@@ -39,12 +39,6 @@ import Table from "./CarTypeTable";
 import Modal from "./CarTypeModal";
 
 export default {
-  props: {
-    parentId: {
-      type: String,
-      default: "",
-    },
-  },
   components: {
     Count,
     Table,
@@ -58,6 +52,7 @@ export default {
       currentPage: 1,
       tableData: [],
       modalFlag: false, // 控制模态框展示
+      parentId: (this.$route.query && this.$route.query.id) || "",
     };
   },
   computed: {
@@ -65,11 +60,6 @@ export default {
     totalPage() {
       return Math.ceil(this.sum / this.pageSize);
     },
-    // 获取路由参数
-    queryTag() {
-      console.log(111, this.$route.query);
-      return this.$route.query && this.$route.query.tag ? 0 : 1;
-    },
   },
   methods: {
     // 获取某一页面的数据,展示在表格
@@ -101,24 +91,37 @@ export default {
     },
     // 点击编辑
     edit(index, newName) {
-      console.log(index, newName);
+      let id = this.tableData[index]["id"];
+      let req = {
+        id,
+        typeName: newName,
+        parentId: this.parentId
+      };
+      this.updataCarTypeInfo(req).then(() => {
+        this.getData();
+      });
     },
     // 点击删除
     deleteData(index) {
-      console.log("删除", index);
+      let id = this.tableData[index]['id'];
+      this.deleteCarTypeInfo(id).then(() => {
+        this.getData()
+      })
     },
     // 新增车型模态框 保存
     submit: function (car) {
-      this.addCarSeries(car);
-      this.modalFlag = false;
+      this.addCarSeries(car).then(() => {
+        this.getData();
+        this.modalFlag = false;
+      });
     },
-        // 获取数据  接口
+    // 获取数据  接口
     getData: function () {
       this.$http({
         method: "post",
         url: "/base/carTypeManager/selectCarTypePage",
         data: {
-          parentId: this.parentId
+          parentId: this.parentId,
         },
       })
         .then((res) => {
@@ -134,16 +137,16 @@ export default {
           console.log(err);
         });
     },
-        // 新增车系  接口
+    // 新增车型  接口
     addCarSeries: function (typeName) {
       return new Promise((resolve, reject) => {
         this.$http({
           url: "/base/carTypeManager/addCarTypeInfo",
           method: "post",
-          data: { 
+          data: {
             typeName: typeName,
-            parentId: this.parentId
-           },
+            parentId: this.parentId,
+          },
         })
           .then((res) => {
             if (res.data && res.data.code === 200) {
@@ -159,6 +162,53 @@ export default {
           });
       });
     },
+    // 编辑车型   接口
+    updataCarTypeInfo: function (data) {
+      return new Promise((resolve, reject) => {
+        this.$http({
+          url: "/base/carTypeManager/updateCarTypeInfo",
+          method: "post",
+          data,
+        })
+          .then((res) => {
+            if (res.data && res.data.code === 200) {
+              resolve();
+            } else {
+              alert("编辑失败,请重试");
+              console.log(res);
+            }
+          })
+          .catch((err) => {
+            alert("编辑失败,请重试");
+            reject(err);
+          });
+      });
+    },
+    // 删除车型   接口
+    deleteCarTypeInfo: function (id) {
+      return new Promise((resolve, reject) => {
+        this.$http({
+          url: "/base/carTypeManager/deleteCarTypeInfo",
+          method: "post",
+          data: {
+            parentId: this.parentId,
+            id,
+          },
+        })
+          .then((res) => {
+            if (res.data && res.data.code === 200) {
+              resolve();
+            } else {
+              alert("删除失败,请重试");
+              console.log(res);
+            }
+          })
+          .catch((err) => {
+            alert("删除失败,请重试");
+            reject(err);
+          });
+      });
+    },
   },
   mounted() {
     this.getData();

+ 4 - 6
src/views/parameter/components/Carseries/CarTypeTable.vue

@@ -14,12 +14,11 @@
           :class="{ table_gray: index % 2 === 0 }"
         >
           <td style="width: 50%">
-            <p v-if="!editFlag[index]">{{ obj.carType }}</p>
+            <p v-if="!editFlag[index]">{{ obj.typeName }}</p>
             <input
               type="text"
               v-model="newName"
               v-else
-              :placeholder="obj.carType"
             />
           </td>
           <td style="width: 50%" class="operation">
@@ -69,15 +68,14 @@ export default {
   methods: {
     edit: function (i) {
       this.getEditArr(); // 确保只有一个在编辑
-      this.newName = this.tableData[i] && this.tableData[i].carSeries;
-      console.log(this.newName);
+      this.newName = this.tableData[i] && this.tableData[i].typeName;
       this.editFlag.splice(i, 1, true);
     },
     // 确认编辑
     submitEdit: function (i) {
       if (!this.newName) {
-        alert("姓名不能为空");
-      } else if (this.newName === this.tableData[i].carSeries) {
+        alert("车型不能为空");
+      } else if (this.newName === this.tableData[i].typeName) {
         this.newName = ""; // 没有改
       } else {
         this.$emit("edit", i, this.newName);