batchMag.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <!--
  2. * @Author: your name
  3. * @Date: 2024-05-27 09:23:37
  4. * @LastEditTime: 2024-06-18 16:08:24
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/performance/batchMag.vue
  8. -->
  9. <template>
  10. <div class="global-variable" v-loading="loading">
  11. <div class="condition">
  12. <el-form
  13. :inline="true"
  14. ref="ruleForm"
  15. :model="formInline"
  16. class="demo-form-inline"
  17. :rules="rules"
  18. >
  19. <el-form-item label="风场名称:" prop="fieldName">
  20. <el-input
  21. size="small"
  22. v-model="formInline.fieldName"
  23. placeholder="请输入风场名称"
  24. ></el-input>
  25. </el-form-item>
  26. <el-form-item label="状态:" prop="batchState" size="small">
  27. <el-select v-model="formInline.batchState" placeholder="请选择状态">
  28. <el-option label="启用" value="1"></el-option>
  29. <el-option label="停用" value="0"></el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="分析时间">
  33. <el-date-picker
  34. size="small"
  35. v-model="formInline.picker"
  36. type="daterange"
  37. range-separator="至"
  38. start-placeholder="开始日期"
  39. end-placeholder="结束日期"
  40. @change="onDateChange"
  41. >
  42. </el-date-picker>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button type="primary" @click="onSubmit" size="small"
  46. >查询</el-button
  47. >
  48. <el-button @click="reset('ruleForm')" size="small">重置</el-button>
  49. </el-form-item>
  50. </el-form>
  51. </div>
  52. <div class="list-page">
  53. <div class="newly">
  54. <el-button type="primary" @click="newnuedialog" size="small"
  55. >新增</el-button
  56. >
  57. </div>
  58. <el-table
  59. v-loading="loading"
  60. class="center-align-table"
  61. :data="tableData"
  62. border
  63. :cell-style="rowStyle"
  64. >
  65. <el-table-column align="center" label="批次名称" prop="batchName">
  66. </el-table-column>
  67. <el-table-column align="center" label="批次编号" prop="batchCode">
  68. </el-table-column>
  69. <el-table-column prop="fieldName" align="center" label="关联风场">
  70. </el-table-column>
  71. <el-table-column
  72. prop="batchState"
  73. align="center"
  74. label="状态"
  75. width="100"
  76. >
  77. <template slot-scope="scope">
  78. <span>
  79. {{
  80. scope.row.batchState == 0
  81. ? "禁用"
  82. : scope.row.batchState == 1
  83. ? "启用"
  84. : "/"
  85. }}</span
  86. >
  87. </template>
  88. </el-table-column>
  89. <el-table-column prop="createTime" align="center" label="创建时间">
  90. </el-table-column>
  91. <el-table-column
  92. prop="transition"
  93. align="center"
  94. fixed="right"
  95. label="操作"
  96. width="200"
  97. >
  98. <template slot-scope="scope">
  99. <el-button @click="compile(scope.row)" type="text" size="small"
  100. >编辑</el-button
  101. >
  102. <el-button
  103. v-if="scope.row.batchState == 0"
  104. @click="setState(1, scope.row)"
  105. type="text"
  106. size="small"
  107. >启用</el-button
  108. >
  109. <el-button
  110. v-else
  111. style="color: #666"
  112. @click="setState(0, scope.row)"
  113. type="text"
  114. size="small"
  115. >禁用</el-button
  116. >
  117. <el-button
  118. style="color: #f00"
  119. @click="deleted(scope.row)"
  120. type="text"
  121. size="small"
  122. :disabled="scope.row.batchState == 1"
  123. >删除</el-button
  124. >
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <div class="pagination-container">
  129. <el-pagination
  130. @current-change="handleCurrentChange"
  131. :current-page.sync="formInline.pageNum"
  132. layout="total, prev, pager, next"
  133. :page-size="formInline.pageSize"
  134. :total="formInline.totalSize"
  135. >
  136. </el-pagination>
  137. </div>
  138. </div>
  139. <!-- 弹出层 -->
  140. <!-- 新增 /编辑-->
  141. <el-dialog :title="title" :visible.sync="nuedialog" width="500px">
  142. <div v-loading="loadingView" class="views">
  143. <el-form
  144. :model="ruleForm"
  145. :rules="addUserRules"
  146. ref="addUserForm"
  147. label-width="100px"
  148. class="demo-ruleForm"
  149. >
  150. <el-form-item label="关联风场:" prop="fieldCode">
  151. <el-select
  152. :disabled="title === '编辑'"
  153. v-model="ruleForm.fieldCode"
  154. placeholder="请选择关联风场"
  155. style="width: 100%"
  156. >
  157. <el-option
  158. :label="item.fieldName"
  159. v-for="item in fieldCodeList"
  160. :value="item.codeNumber"
  161. ></el-option>
  162. </el-select>
  163. </el-form-item>
  164. <el-form-item label="批次名称" prop="batchName">
  165. <el-input
  166. v-model="ruleForm.batchName"
  167. placeholder="请输入批次名称"
  168. ></el-input>
  169. </el-form-item>
  170. </el-form>
  171. <span slot="footer" class="dialog-footer">
  172. <el-button @click="cancel('addUserForm')" size="small"
  173. >取 消</el-button
  174. >
  175. <el-button
  176. type="primary"
  177. @click="submitForm('addUserForm')"
  178. size="small"
  179. >确 定</el-button
  180. >
  181. </span>
  182. </div>
  183. </el-dialog>
  184. </div>
  185. </template>
  186. <script>
  187. import {
  188. getBatchMagList,
  189. addFieldBatch,
  190. updateFieldBatch,
  191. queryCodeNum,
  192. onOrOffFieldBatch,
  193. deleteFieldBatch,
  194. } from "@/api/performance.js";
  195. export default {
  196. data() {
  197. return {
  198. loadingView: false,
  199. loading: false, //数据加载中
  200. rules: {
  201. fieldCode: { trigger: "change" },
  202. batchState: { trigger: "blur" },
  203. },
  204. startDate: "",
  205. endDate: "",
  206. fieldCodeList: [],
  207. formInline: {
  208. fieldName: undefined,
  209. batchState: undefined,
  210. picker: [],
  211. pageNum: 1,
  212. pageSize: 10,
  213. totalSize: 0,
  214. },
  215. tableData: [],
  216. // 新增编辑表单
  217. ruleForm: {
  218. fieldCode: null,
  219. batchName: null,
  220. batchCode: null,
  221. },
  222. addUserRules: {
  223. batchCode: {
  224. required: true,
  225. message: "请选择关联风场",
  226. trigger: "change",
  227. },
  228. batchName: [
  229. { required: true, message: "请输入批次名称", trigger: "blur" },
  230. ],
  231. },
  232. //修改密码
  233. editUserPassword: {
  234. oldPWD: "",
  235. newPWD: "",
  236. userId: "",
  237. },
  238. nuedialog: false,
  239. title: "",
  240. };
  241. },
  242. created() {
  243. this.getTableList();
  244. this.getQueryCodeNumList();
  245. },
  246. methods: {
  247. onDateChange(date) {
  248. if (Array.isArray(date)) {
  249. this.startDate = this.$formatDate(date[0]);
  250. this.endDate = this.$formatDate(date[1]);
  251. if (this.endDate < this.startDate) {
  252. this.endDate = this.startDate;
  253. }
  254. } else {
  255. this.startDate = null;
  256. this.endDate = null;
  257. }
  258. },
  259. //获取风场列表
  260. async getQueryCodeNumList() {
  261. this.loading = true;
  262. try {
  263. const result = await queryCodeNum();
  264. console.log(result, "result");
  265. this.fieldCodeList = result.data.fieldCodeList;
  266. this.loading = false;
  267. } catch (error) {
  268. console.error(error);
  269. this.loading = false;
  270. }
  271. },
  272. //分页数据切换
  273. handleCurrentChange(val) {
  274. this.formInline.pageNum = val;
  275. this.getTableList();
  276. },
  277. //修改状态
  278. setState(state, row) {
  279. //启用接口
  280. this.loading = true;
  281. onOrOffFieldBatch({ batchCode: row.batchCode, batchState: state })
  282. .then((res) => {
  283. console.log(res, "res");
  284. this.$message({
  285. message: res.msg,
  286. type: "success",
  287. });
  288. this.loading = false;
  289. this.getTableList();
  290. })
  291. .catch((error) => {
  292. this.loading = false;
  293. });
  294. },
  295. async getTableList() {
  296. try {
  297. this.loading = true;
  298. console.log(this.startDate, this.endDate, "formInline");
  299. const result = await getBatchMagList({
  300. ...this.formInline,
  301. picker: undefined,
  302. startTime: this.startDate || undefined,
  303. endTime: this.endDate || undefined,
  304. totalSize: undefined,
  305. });
  306. console.log(result.data, "res.data");
  307. this.tableData = result.data.list;
  308. this.formInline.totalSize = result.data.totalSize;
  309. this.loading = false;
  310. } catch (error) {
  311. this.$message({
  312. type: "error",
  313. message: "请检查是否连接网络",
  314. });
  315. }
  316. },
  317. rowStyle() {
  318. return "text-align:center";
  319. },
  320. // 查询
  321. onSubmit() {
  322. this.getTableList();
  323. },
  324. // 重置
  325. reset(formName) {
  326. this.formInline.picker = [];
  327. this.startDate = undefined;
  328. this.endDate = undefined;
  329. this.$refs[formName].resetFields();
  330. this.getTableList();
  331. },
  332. // 新增,编辑确定
  333. submitForm(formName) {
  334. // this.loading = true;
  335. this.$refs[formName].validate((valid) => {
  336. if (valid) {
  337. this.loadingView = true;
  338. console.log(this.ruleForm, "this.ruleForm");
  339. switch (this.title) {
  340. case "新增":
  341. addFieldBatch({ ...this.ruleForm, batchCode: undefined })
  342. .then((res) => {
  343. this.$message({
  344. type: "success",
  345. message: res.msg,
  346. });
  347. // this.loading = false;
  348. this.getTableList();
  349. this.nuedialog = false;
  350. this.loadingView = false;
  351. })
  352. .catch(() => {
  353. this.loadingView = false;
  354. // this.loading = false;
  355. });
  356. break;
  357. case "编辑":
  358. updateFieldBatch({ ...this.ruleForm, fieldCode: undefined })
  359. .then((res) => {
  360. this.$message({
  361. type: "success",
  362. message: res.msg,
  363. });
  364. this.getTableList();
  365. this.nuedialog = false;
  366. this.loadingView = false;
  367. })
  368. .catch(() => {
  369. this.loadingView = false;
  370. });
  371. break;
  372. }
  373. // this.nuedialog = false;
  374. } else {
  375. return false;
  376. }
  377. });
  378. },
  379. //点击取消
  380. cancel(formName) {
  381. this.$refs[formName] && this.$refs[formName].resetFields();
  382. this.ruleForm = {
  383. fieldCode: null,
  384. batchCode: null,
  385. batchName: null,
  386. };
  387. this.nuedialog = false;
  388. this.loadingView = false;
  389. },
  390. // 编辑 回显数据
  391. async compile(row) {
  392. try {
  393. // 直接替换整个对象,以确保 Vue 的响应式系统能够检测到变化
  394. this.ruleForm = {
  395. fieldCode: row.fieldCode,
  396. batchCode: row.batchCode,
  397. batchName: row.batchName,
  398. };
  399. this.nuedialog = true;
  400. this.title = "编辑";
  401. } catch (error) {
  402. this.$message.error("获取用户信息失败");
  403. }
  404. },
  405. // 删除
  406. deleted(row) {
  407. this.$confirm("此操作将永久删除该用户, 是否继续?", "提示", {
  408. confirmButtonText: "确定",
  409. cancelButtonText: "取消",
  410. type: "warning",
  411. })
  412. .then(() => {
  413. this.loading = true;
  414. deleteFieldBatch({ batchCode: row.batchCode })
  415. .then((res) => {
  416. this.$message({
  417. type: "success",
  418. message: "删除成功!",
  419. });
  420. this.loading = false;
  421. this.getTableList();
  422. })
  423. .catch(() => {
  424. this.loading = false;
  425. });
  426. })
  427. .catch(() => {
  428. this.$message({
  429. type: "info",
  430. message: "已取消删除",
  431. });
  432. });
  433. },
  434. // 新增
  435. newnuedialog() {
  436. this.cancel("addUserForm");
  437. this.ruleForm = {
  438. batchCode: "",
  439. batchName: "",
  440. fieldCode: "",
  441. };
  442. this.nuedialog = true;
  443. this.title = "新增";
  444. },
  445. },
  446. };
  447. </script>
  448. <style lang="scss" scoped>
  449. .general {
  450. display: flex;
  451. flex-wrap: wrap;
  452. .condition {
  453. width: 50%;
  454. display: flex;
  455. p {
  456. width: 100px;
  457. text-align: right;
  458. line-height: 40px;
  459. }
  460. span {
  461. line-height: 40px;
  462. padding-left: 20px;
  463. }
  464. .el-select {
  465. width: 100%;
  466. margin-bottom: 20px;
  467. }
  468. .el-input {
  469. margin-bottom: 20px;
  470. }
  471. }
  472. }
  473. .attachment {
  474. display: flex;
  475. padding-top: 10px;
  476. p {
  477. margin-right: 20px;
  478. color: #409eff;
  479. }
  480. }
  481. .addition {
  482. display: flex;
  483. justify-content: flex-end;
  484. margin-bottom: 10px;
  485. }
  486. .demo-ruleForm {
  487. .el-form-item {
  488. margin-bottom: 25px;
  489. }
  490. }
  491. </style>