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