index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <ele-pro-table
  5. ref="table"
  6. :columns="columns"
  7. :datasource="datasource"
  8. :selection.sync="selection"
  9. >
  10. <!-- 表头工具栏 -->
  11. <template v-slot:toolbar>
  12. <el-button
  13. type="primary"
  14. icon="el-icon-plus"
  15. class="ele-btn-icon"
  16. @click="openForm('create')"
  17. >
  18. 新建
  19. </el-button>
  20. <el-button
  21. type="danger"
  22. icon="el-icon-delete"
  23. class="ele-btn-icon"
  24. v-if="selection.length"
  25. @click="handleBatchDelete"
  26. >
  27. 批量删除
  28. </el-button>
  29. </template>
  30. <!-- 操作列 -->
  31. <template v-slot:action="{ row }">
  32. <el-link
  33. type="primary"
  34. :underline="false"
  35. icon="el-icon-edit"
  36. @click="openForm('update', row.pointId)"
  37. >
  38. 编辑
  39. </el-link>
  40. <el-link
  41. type="primary"
  42. :underline="false"
  43. icon="el-icon-delete"
  44. :style="{ color: delColor }"
  45. @click="handleDelete(row.pointId)"
  46. >
  47. 删除
  48. </el-link>
  49. </template>
  50. </ele-pro-table>
  51. </el-card>
  52. <!-- 新增编辑弹窗 -->
  53. <formModel ref="formRef" :dId="deviceId" @success="reload" />
  54. </div>
  55. </template>
  56. <script>
  57. import * as DevicePointApi from '@/api/ledgerAssets/device/presetInfo'
  58. import formModel from './formModel.vue'
  59. export default {
  60. name: 'SubDevicePresetInfo',
  61. components: {
  62. formModel
  63. },
  64. props: {
  65. deviceId: ''
  66. },
  67. data() {
  68. return {
  69. delColor: '#F56C6C',
  70. selection: [],
  71. // 表格列配置
  72. columns: [
  73. {
  74. width: 45,
  75. type: 'selection',
  76. columnKey: 'selection',
  77. align: 'center',
  78. fixed: 'left'
  79. },
  80. {
  81. columnKey: 'index',
  82. label: '序号',
  83. type: 'index',
  84. width: 60,
  85. align: 'center'
  86. },
  87. {
  88. prop: 'pointName',
  89. label: '预置位名称',
  90. align: 'left',
  91. minWidth: 200,
  92. showOverflowTooltip: true
  93. },
  94. {
  95. prop: 'pointJson',
  96. label: '预置位信息(单位:m)',
  97. align: 'center',
  98. width: 200,
  99. showOverflowTooltip: true
  100. },
  101. {
  102. prop: 'indexNo',
  103. label: '排序号',
  104. align: 'center',
  105. width: 100
  106. },
  107. {
  108. columnKey: 'action',
  109. fixed: 'right',
  110. label: '操作',
  111. width: 150,
  112. align: 'center',
  113. slot: 'action'
  114. }
  115. ]
  116. }
  117. },
  118. methods: {
  119. /* 表格数据源 */
  120. datasource({ page, limit }) {
  121. return DevicePointApi.getDevicePointPage({
  122. pageNo: page,
  123. pageSize: limit,
  124. deviceId: this.deviceId
  125. }).then((res) => {
  126. return {
  127. list: res.list.map((item) => ({
  128. ...item,
  129. pointJson: JSON.parse(item.pointJson || '{}')
  130. })),
  131. total: res.total
  132. }
  133. })
  134. },
  135. /* 刷新表格 */
  136. reload() {
  137. this.$refs.table.reload()
  138. },
  139. /** 预置位初始化 */
  140. preSetSuccess() {
  141. this.reload()
  142. },
  143. /** 打开表单 */
  144. openForm(type, id) {
  145. this.$refs.formRef.open(type, id)
  146. },
  147. /** 删除按钮操作 */
  148. handleDelete(id) {
  149. this.$confirm('是否确认删除该预置位?', '警告', {
  150. confirmButtonText: '确定',
  151. cancelButtonText: '取消',
  152. type: 'warning'
  153. })
  154. .then(async () => {
  155. await DevicePointApi.deleteDevicePoint(id)
  156. this.$message.success('删除成功')
  157. this.reload()
  158. })
  159. .catch(() => {})
  160. },
  161. /** 批量删除按钮操作 */
  162. handleBatchDelete() {
  163. if (this.selection.length === 0) {
  164. this.$message.warning('请选择要删除的数据项')
  165. return
  166. }
  167. const ids = this.selection.map((item) => item.pointId)
  168. this.$confirm('是否确认删除选中的预置位?', '警告', {
  169. confirmButtonText: '确定',
  170. cancelButtonText: '取消',
  171. type: 'warning'
  172. })
  173. .then(async () => {
  174. await DevicePointApi.batchDeleteDevicePoint(ids)
  175. this.$message.success('删除成功')
  176. this.reload()
  177. })
  178. .catch(() => {})
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped></style>