Jelajahi Sumber

修改删除添加更新

guhongwei 5 tahun lalu
induk
melakukan
a18001b91e

+ 2 - 2
src/layout/otheruser/otheruserList.vue

@@ -13,8 +13,8 @@
           </el-table-column>
           <el-table-column fixed="right" label="操作" align="center">
             <template slot-scope="scope">
-              <el-button @click="$router.push({ path: '/otheruser/detail', query: { id: scope.$index } })" type="text"><i class="el-icon-edit"></i></el-button>
-              <el-button @click.native.prevent="deleteRow(scope.$index, debtTable)" type="text"><i class="el-icon-delete"></i></el-button>
+              <el-button @click="$router.push({ path: '/otheruser/detail', query: { id: scope.row.id } })" type="text"><i class="el-icon-edit"></i></el-button>
+              <el-button @click.prevent="deleteRow(scope.row.id)" type="text"><i class="el-icon-delete"></i></el-button>
             </template>
           </el-table-column>
         </el-table>

+ 35 - 5
src/views/otheruser/detail.vue

@@ -22,6 +22,8 @@
 import topInfo from '@/layout/common/topInfo.vue';
 import detailTop from '@/layout/common/detailTop.vue';
 import otheruserForm from '@/layout/otheruser/otheruserForm.vue';
+import { createNamespacedHelpers, mapGetters } from 'vuex';
+const { mapActions: otheruser } = createNamespacedHelpers('otheruser');
 export default {
   name: 'detail',
   props: {},
@@ -35,13 +37,41 @@ export default {
     topTitle: '用户信息管理',
     ruleForm: {},
   }),
-  created() {},
-  computed: {},
+  created() {
+    this.searchInfo();
+  },
+  computed: {
+    id() {
+      return this.$route.query.id;
+    },
+  },
   methods: {
+    ...otheruser(['query', 'fetch', 'update', 'create']),
+    async searchInfo() {
+      if (this.id) {
+        const res = await this.fetch(this.id);
+        this.$set(this, `ruleForm`, res.data);
+      }
+    },
     // 提交
-    submitForm(form) {
-      console.log(form);
-      this.resetForm();
+    async submitForm(form) {
+      let data = form;
+      let res;
+      let msg;
+      if (this.id) {
+        res = await this.updates(data);
+        this.$message({
+          message: '信息修改成功',
+          type: 'success',
+        });
+      } else {
+        res = await this.create(data);
+        this.$message({
+          message: '信息添加成功',
+          type: 'success',
+        });
+      }
+      if (this.$checkRes(res, msg)) this.$router.push({ path: '/otheruser/index' });
     },
     // 取消
     resetForm() {

+ 6 - 21
src/views/otheruser/index.vue

@@ -31,33 +31,16 @@ export default {
   data: () => ({
     topTitle: '其他用户',
     display: 'block',
-    debtTable: [
-      {
-        name: '其他用户',
-        phone: '123456789',
-        type: '0',
-      },
-      {
-        name: '其他用户',
-        phone: '123456789',
-        type: '1',
-      },
-      {
-        name: '其他用户',
-        phone: '123456789',
-        type: '2',
-      },
-    ],
+    debtTable: [],
   }),
   created() {
     this.searchInfo();
   },
   computed: {},
   methods: {
-    ...otheruser(['query']),
+    ...otheruser(['query', 'delete']),
     async searchInfo({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
-      console.log(res);
       this.$set(this, `debtTable`, res.data);
     },
     // 添加
@@ -65,8 +48,10 @@ export default {
       this.$router.push({ path: '/otheruser/detail' });
     },
     // 删除
-    deleteRow(id) {
-      console.log(id);
+    async deleteRow(id) {
+      const res = await this.delete(id);
+      this.$checkRes(res, '删除成功', '删除失败');
+      this.searchInfo();
     },
   },
 };