batchMag.vue 14 KB

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