batchMag.vue 14 KB

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