Newer
Older
Nanping_sponge_GCYPG / src / views / preassess / adaptationConfig / index.vue
@liyingjing liyingjing on 25 Oct 2023 7 KB 工程预评估
  1. <template>
  2. <div class="adaptationConfig">
  3. <div class="top">
  4. <el-form ref="ruleForm" inline :model="form">
  5. <el-form-item label="使用状态:" prop="status">
  6. <el-select v-model="form.status" placeholder="使用状态">
  7. <el-option label="全部" value="" />
  8. <el-option label="启用" value="1" />
  9. <el-option label="停用" value="0" />
  10. </el-select>
  11. </el-form-item>
  12. <el-form-item label="时间:" prop="time">
  13. <el-date-picker
  14. v-model="form.time"
  15. type="daterange"
  16. range-separator="~"
  17. start-placeholder="开始时间"
  18. end-placeholder="结束时间"
  19. format="YYYY-MM-DD"
  20. value-format="YYYY-MM-DD"
  21. />
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="Search" @click="search">
  25. 查询</el-button>
  26. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  27. </el-form-item>
  28. </el-form>
  29. <el-row class="mb8">
  30. <el-button type="primary" plain icon="Plus" @click="openDialog({}, 'add')">新增</el-button>
  31. </el-row>
  32. </div>
  33. <el-table :data="tableData" v-loading="loading" stripe :max-height="600">
  34. <el-table-column type="index" width="55" label="序号" align="center" />
  35. <el-table-column label="记录名称" prop="configName" show-overflow-tooltip width="200">
  36. <template #default="{ row }">
  37. <span style="color: #409eef">{{ row.configName }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="启用时间" align="center" prop="startDatetime" show-overflow-tooltip />
  41. <el-table-column label="停用时间" align="center" prop="endDatetime" show-overflow-tooltip />
  42. <el-table-column label="修改人" align="center" prop="updateNickName" show-overflow-tooltip />
  43. <el-table-column label="修改日期" align="center" prop="updateTime" show-overflow-tooltip />
  44. <el-table-column label="使用状态" align="center" prop="status" show-overflow-tooltip>
  45. <template #default="{ row }">
  46. <el-tag :type="statusMap.get(row.status).type" v-if="row.status">{{ statusMap.get(row.status).text }}</el-tag>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="操作" align="center" show-overflow-tooltip width="254">
  50. <template #default="{ row }">
  51. <el-button type="primary" link @click="copy(row)">复制</el-button>
  52. <el-button type="primary" link @click="enable(row)" :disabled="row.status === '1'">启用</el-button>
  53. <el-button type="primary" link @click="openDialog(row, 'view')">查看</el-button>
  54. <el-button type="primary" link @click="openDialog(row, 'edit')">修改</el-button>
  55. <el-button type="danger" link @click="del(row)">删除</el-button>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <pagination :total="total" v-model:page="pageNum" v-model:limit="pageSize" @pagination="getTableList" />
  60. <el-dialog
  61. v-model="visible"
  62. :title="`${opts.text}适应性配置`"
  63. :close-on-click-modal="false"
  64. width="70%"
  65. :before-close="close"
  66. class="dialog"
  67. >
  68. <tableDalgo v-if="visible" ref="tableDalgoRef" :id="row.id || ''" :opts="opts.type"></tableDalgo>
  69. <template #footer v-if="opts.type !== 'view'">
  70. <div class="dialog-footer">
  71. <el-button type="primary" @click="submit">保存</el-button>
  72. <el-button @click="close">取消</el-button>
  73. </div>
  74. </template>
  75. </el-dialog>
  76. </div>
  77. </template>
  78.  
  79. <script setup>
  80. import tableDalgo from './tableDalgo.vue'
  81. import { reactive, ref, onMounted, computed } from 'vue'
  82. import { optTextMap, statusMap } from '@/utils/map'
  83. import {
  84. getFacilitiesAdaptabilityConfigPage,
  85. getFacilitiesAdaptabilityConfigAddWithItem,
  86. facilitiesAdaptabilityConfigDel,
  87. facilitiesAdaptabilityConfigCopy,
  88. facilitiesAdaptabilityConfigEnable
  89. }
  90. from '@/api/preassess/adaptationConfig.js'
  91. import { usePagination } from '@/hooks'
  92. const { proxy } = getCurrentInstance();
  93.  
  94. const form = reactive({
  95. status: '',
  96. time: []
  97. })
  98. const params = computed(() => {
  99. const args = JSON.parse(JSON.stringify(form))
  100. const { time } = args
  101. delete args.time
  102. return {
  103. ...args,
  104. startDatetime: time[0] || '',
  105. endDatetime: time[1] || ''
  106. }
  107. })
  108. const {
  109. pageNum,
  110. pageSize,
  111. tableData,
  112. total,
  113. loading,
  114. getTableList
  115. } = usePagination(getFacilitiesAdaptabilityConfigPage, params)
  116. const visible = ref(false)
  117. const row = ref({})
  118. const opts = reactive({
  119. type: '',
  120. text: ''
  121. })
  122.  
  123. const search = () => {
  124. pageNum.value = 1
  125. getTableList()
  126. }
  127.  
  128. const resetQuery = () => {
  129. proxy.$refs.ruleForm.resetFields()
  130. search()
  131. }
  132.  
  133. const openDialog = (data, type) => {
  134. visible.value = true
  135. opts.type = type
  136. opts.text = optTextMap.get(type)
  137. row.value = data
  138. }
  139.  
  140. const close = () => {
  141. visible.value = false
  142. opts.type = ''
  143. opts.text = ''
  144. row.value = {}
  145. }
  146.  
  147. const submit = async () => {
  148. opts.type === 'add' ? create(): update()
  149. }
  150.  
  151. const create = async () => {
  152. console.log(proxy.$refs.tableDalgoRef.tableData)
  153. const list = proxy.$refs.tableDalgoRef.tableData
  154. const typeList = proxy.$refs.tableDalgoRef.sponge_engineering_type.map(it => it.value)
  155. const params = list.map(item => {
  156. const result = {
  157. facilitiesPolluteRemoveConfigItemId: item.id,
  158. adaptabilityConfigJson: []
  159. }
  160. for (const key in item) {
  161. if (Object.hasOwnProperty.call(item, key)) {
  162. if(typeList.includes(key)){
  163. result.adaptabilityConfigJson.push({
  164. key,
  165. value: item[key]
  166. })
  167. }
  168. }
  169. }
  170. result.adaptabilityConfigJson = JSON.stringify(result.adaptabilityConfigJson)
  171. return result
  172. })
  173. console.log(params)
  174. const res = await getFacilitiesAdaptabilityConfigAddWithItem(params)
  175. if(res.code !== 200) return
  176. proxy.$modal.msgSuccess('操作成功!')
  177. close()
  178. search()
  179. }
  180.  
  181. const update = () => {
  182. close()
  183. proxy.$modal.msgSuccess('操作成功!')
  184. }
  185.  
  186. const del = (row) => {
  187. proxy.$modal
  188. .confirm("是否确认删除?")
  189. .then(async () => {
  190. const res = await facilitiesAdaptabilityConfigDel(row.id)
  191. if(res?.code !== 200) return
  192. proxy.$modal.msgSuccess('操作成功!')
  193. getTableList()
  194. })
  195. .catch(() => {});
  196. }
  197.  
  198. const copy = (row) => {
  199. proxy.$modal
  200. .confirm("是否确认复制?")
  201. .then(async () => {
  202. const res = await facilitiesAdaptabilityConfigCopy({ id: row.id })
  203. if(res?.code !== 200) return
  204. proxy.$modal.msgSuccess('操作成功!')
  205. getTableList()
  206. })
  207. .catch(() => {});
  208. }
  209.  
  210. const enable = (row) => {
  211. proxy.$modal
  212. .confirm("是否确认启用?")
  213. .then(async () => {
  214. const res = await facilitiesAdaptabilityConfigEnable(row.id)
  215. if(res?.code !== 200) return
  216. proxy.$modal.msgSuccess('操作成功!')
  217. getTableList()
  218. })
  219. .catch(() => {});
  220. }
  221.  
  222. onMounted(() => {
  223. getTableList()
  224. })
  225. </script>
  226.  
  227. <style lang="scss" scoped>
  228. .adaptationConfig {
  229. padding: 20px;
  230. height: 90vh;
  231. overflow-y: hidden;
  232. .top {
  233. margin-bottom: 15px;
  234. }
  235. }
  236.  
  237. ::v-deep(.dialog) {
  238. .el-dialog__body {
  239. padding-bottom: 20px !important;
  240. }
  241. .el-dialog__footer {
  242. padding-top: 0 !important;
  243. }
  244. }
  245. </style>