yuwandanmian 2 năm trước cách đây
mục cha
commit
c07b3a005a

+ 3 - 4
src/views/rule/case/components/CreateDialog.vue

@@ -107,11 +107,10 @@ export default {
       this.$refs[formName].validate(async(valid) => {
         if (valid) {
           createCaseRuleList(this.ruleForm).then(res => {
-            console.log(res)
+            this.data.bSwitch = false
+            this.$emit('refresh')
+            this.$message.success(res.m || '操作成功')
           })
-          // .catch(error => {
-          // }).finally(() => {
-          // })
         } else {
           return false
         }

+ 32 - 3
src/views/rule/case/components/TableBox.vue

@@ -42,8 +42,13 @@
         width="100"
       >
         <template slot-scope="scope">
-          <el-tag v-if="scope.row.status === 1" type="success">正常</el-tag>
-          <el-tag v-if="scope.row.status === 0" type="danger">停用</el-tag>
+          <el-switch
+            v-model="scope.row.status"
+            active-color="#13ce66"
+            :active-value="1"
+            :inactive-value="0"
+            @change="handleStatusChange(scope.row)"
+          />
         </template>
       </el-table-column>
       <el-table-column
@@ -57,12 +62,14 @@
       </el-table-column>
     </el-table>
     <!-- 新增、编辑 -->
-    <CreateDialog v-if="createData.bSwitch" :data="createData" :types="types" :categorys="categorys" />
+    <CreateDialog v-if="createData.bSwitch" :data="createData" :types="types" :categorys="categorys" @refresh="handleRefresh" />
   </div>
 </template>
 
 <script>
 import CreateDialog from './CreateDialog.vue'
+import { createCaseRuleList } from '@/api/admin'
+
 export default {
   components: {
     CreateDialog
@@ -109,6 +116,28 @@ export default {
     onEdit(row) {
       this.createData.row = row
       this.createData.bSwitch = true
+    },
+    handleStatusChange(row) {
+      const index = row.status ? 1 : 0
+      this.$confirm('确认要更改为 <strong>' + ['停用', '正常'][index] + '</strong> 状态吗?', '提示', {
+        dangerouslyUseHTMLString: true,
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        createCaseRuleList(row).then(res => {
+          this.data.bSwitch = false
+          this.$emit('refresh')
+          this.$message.success(res.m || '操作成功')
+        }).catch(function() {
+          row.status = row.status === 0 ? 1 : 0
+        })
+      }).catch(function() {
+        row.status = row.status === 0 ? 1 : 0
+      })
+    },
+    handleRefresh() {
+      this.$emit('refresh')
     }
   }
 }

+ 4 - 1
src/views/rule/case/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="app-container">
     <SearchBoxVue :data="searchData" :types="types" :categorys="categorys" @search="handleSearch" />
-    <TableBoxVue :loading="loading" :types="types" :categorys="categorys" :data="tableData" style="margin-top: -40px;" />
+    <TableBoxVue :loading="loading" :types="types" :categorys="categorys" :data="tableData" style="margin-top: -40px;" @refresh="handleRefresh" />
     <pagination
       :auto-scroll="false"
       :total="paginationData.total"
@@ -49,6 +49,9 @@ export default {
     this.getList()
   },
   methods: {
+    handleRefresh() {
+      this.getList()
+    },
     getType() {
       getType().then(res => {
         const { p } = res