zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
  <div>
    <div style="margin-bottom:5px;">
      <el-button
        type="primary"
        @click="addOrUpdateHandle"
        :disabled="!indexInfo"
      >
        新增
      </el-button>
    </div>
    <el-table
      stripe
      ref="labelconfigdetaillist"
      :data="list"
      height="600"
      border
      :row-style="{ height: '26px' }"
      :cell-style="{ padding: '0' }"
      v-loading="loading"
    >
      <el-table-column label="序号" type="index" />
      <el-table-column label="是否启用" min-width="6%">
        <template slot-scope="{ row }">
          <el-switch v-model="row.isActive" @change="goEdit(row)" />
        </template>
      </el-table-column>
      <el-table-column label="是否配置数据源" min-width="8%">
        <template slot-scope="{ row }">
          <el-switch v-model="row.isConfigDataSource" @change="goEdit(row)" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="标签元素描述" prop="itemCode" min-width="10%" /> -->
      <el-table-column label="标题" prop="caption" min-width="10%" />
      <el-table-column label="默认值" prop="defaultValue" min-width="10%" />
      <el-table-column label="查询sql" prop="qrySql" min-width="30%" />
      <el-table-column label="创建人" prop="createUser" min-width="8%" />
      <el-table-column label="创建时间" prop="createTime" min-width="10%" />
      <el-table-column label="更新人" prop="updateUser" min-width="8%" />
      <el-table-column label="更新时间" prop="updateTime" min-width="10%" />
      <el-table-column label="操作" min-width="8%">
        <template slot-scope="{ row }">
          <el-button
            class="commonButton"
            type="text"
            @click="deleteHandle(row)"
          >
            删除
          </el-button>
          <el-button
            class="commonButton"
            type="text"
            @click="addOrUpdateHandle(row)"
          >
            修改
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <DetailForm
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      :indexInfo="indexInfo"
      @refreshDataList="getData"
    />
  </div>
</template>
 
<script>
import { fetchList, delObj, putObj } from '@/api/print/configDtl'
 
import DetailForm from './DetailForm'
import { mapGetters } from 'vuex'
 
export default {
  props: {
    indexInfo: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      addOrUpdateVisible: false,
      loading: false,
      list: []
    }
  },
  components: {
    DetailForm
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  created() {},
  watch: {
    indexInfo: {
      deep: true,
      handler(newVal) {
        if (newVal) {
          this.init()
        }
      }
    }
  },
  methods: {
    init() {
      this.getData()
    },
    doLayout() {
      this.$nextTick(() => {
        this.$refs.labelconfigdetaillist.doLayout()
      })
    },
    getData() {
      this.loading = true
      fetchList({
        mid: this.indexInfo.id
      }).then((res) => {
        this.list = res.data.data
        this.loading = false
        this.doLayout()
      })
    },
    // 新增 / 修改
    addOrUpdateHandle(row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row == null ? null : row.id)
      })
    },
    // 删除
    deleteHandle(row) {
      this.$confirm('是否确认删除标签元素:' + row.itemCode, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      })
        .then(function() {
          return delObj(row.id)
        })
        .then((data) => {
          this.$message.success('删除成功')
          this.getData()
        })
    },
    goEdit(row) {
      putObj({
        ...row,
        mid: this.indexInfo.id
      }).then((data) => {
        if (data.data.code !== 0) {
          row.isActive = !row.isActive
        }
      })
    }
  }
}
</script>