batchMag.vue 13 KB

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