赵殿龙 1 an în urmă
părinte
comite
df9f11b19e

+ 18 - 0
src/api/rule/config.js

@@ -44,3 +44,21 @@ export function del_rule(data) {
     data: data
   })
 }
+
+// 规则模板-修改状态
+export function edit_rule_status(data) {
+  return request({
+    url: '/quality_rule/edit_rule_status',
+    method: 'post',
+    data: data
+  })
+}
+
+// 规则详情
+export function get_rule_detail(data) {
+  return request({
+    url: '/quality_rule/get_rule_detail',
+    method: 'get',
+    params: data
+  })
+}

+ 8 - 1
src/views/rule/config/components/CreateDialog.vue

@@ -282,6 +282,7 @@
 <script>
 import { add_rule } from '@/api/rule/config'
 import { get_all_word_map } from '@/api/dict'
+import { get_rule_detail } from '@/api/rule/config'
 
 export default {
   props: {
@@ -399,10 +400,16 @@ export default {
   created() {
     this.getQcData()
     if (this.data.row.id) {
-      // todo
+      this.getDetail(this.data.row.id)
     }
   },
   methods: {
+    // 获取详情
+    getDetail(id) {
+      get_rule_detail({ id }).then(res => {
+        console.log(res)
+      })
+    },
     // 搜索质控字典
     getQcData() {
       get_all_word_map({ status: 1 }).then(res => {

+ 33 - 3
src/views/rule/config/components/TableBox.vue

@@ -84,9 +84,18 @@
         width="120"
       >
         <template slot-scope="scope">
+          <el-switch
+            v-model="scope.row.status"
+            active-color="#13ce66"
+            :active-value="1"
+            :inactive-value="2"
+            @change="handleStatusChange(scope.row)"
+          />
+        </template>
+        <!-- <template slot-scope="scope">
           <el-tag v-if="scope.row.status === 1" type="success">开启中</el-tag>
           <el-tag v-if="scope.row.status === 2" type="danger">禁用中</el-tag>
-        </template>
+        </template> -->
       </el-table-column>
       <el-table-column
         v-if="codes.includes('type')"
@@ -154,7 +163,7 @@
 
 <script>
 import CreateDialog from './CreateDialog.vue'
-import { del_rule } from '@/api/rule/config'
+import { del_rule, edit_rule_status } from '@/api/rule/config'
 
 export default {
   components: {
@@ -205,7 +214,11 @@ export default {
       createData: {
         bSwitch: false,
         row: {}
-      }
+      },
+      statusArr: [
+        { 'id': 1, 'name': '启用' },
+        { 'id': 2, 'name': '停用' }
+      ]
     }
   },
   created() {
@@ -248,6 +261,23 @@ export default {
     handleChange(val) {
       const checkedCount = val.length
       this.checkAll = checkedCount === this.defaultCodes.length
+    },
+    handleStatusChange(row) {
+      const statusIndex = this.statusArr.findIndex((value) => parseInt(value.id) === parseInt(row.status))
+      this.$confirm('确认要更改为 <strong>' + this.statusArr[statusIndex].name + '</strong> 状态吗?', '提示', {
+        dangerouslyUseHTMLString: true,
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        edit_rule_status({ id: row.id, status: row.status }).then((res) => {
+          this.$message.success(res.m || '操作成功')
+        }).catch(function() {
+          row.status = row.status === 1 ? 2 : 1
+        })
+      }).catch(function() {
+        row.status = row.status === 1 ? 2 : 1
+      })
     }
   }
 }