123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- <!--
- * @Author: your name
- * @Date: 2024-05-27 09:23:37
- * @LastEditTime: 2024-07-05 16:03:11
- * @LastEditors: bogon
- * @Description: In User Settings Edit
- * @FilePath: /performance-test/src/views/performance/batchMag.vue
- -->
- <template>
- <div class="global-variable" v-loading="loading">
- <div class="condition">
- <el-form
- :inline="true"
- ref="ruleForm"
- :model="formInline"
- class="demo-form-inline"
- :rules="rules"
- >
- <el-form-item label="风场名称:" prop="fieldName">
- <el-input
- size="small"
- v-model="formInline.fieldName"
- placeholder="请输入风场名称"
- ></el-input>
- </el-form-item>
- <el-form-item label="状态:" prop="batchState" size="small">
- <el-select v-model="formInline.batchState" placeholder="请选择状态">
- <el-option label="启用" value="1"></el-option>
- <el-option label="停用" value="0"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="分析时间">
- <el-date-picker
- size="small"
- v-model="formInline.picker"
- type="daterange"
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- @change="onDateChange"
- >
- </el-date-picker>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="onSubmit" size="small"
- >查询</el-button
- >
- <el-button @click="reset('ruleForm')" size="small">重置</el-button>
- </el-form-item>
- </el-form>
- </div>
- <div class="list-page">
- <div class="newly">
- <el-button
- v-hasPermi="['performance:batchMag:add']"
- type="primary"
- @click="newnuedialog"
- size="small"
- >新增</el-button
- >
- </div>
- <el-table
- v-loading="loading"
- class="center-align-table"
- :data="tableData"
- border
- :cell-style="rowStyle"
- >
- <el-table-column align="center" label="批次名称" prop="batchName">
- </el-table-column>
- <!-- <el-table-column align="center" label="批次编号" prop="batchCode">
- </el-table-column> -->
- <el-table-column prop="fieldName" align="center" label="关联风场">
- </el-table-column>
- <el-table-column
- prop="batchState"
- align="center"
- label="状态"
- width="100"
- >
- <template slot-scope="scope">
- <span>
- {{
- scope.row.batchState == 0
- ? "禁用"
- : scope.row.batchState == 1
- ? "启用"
- : "/"
- }}</span
- >
- </template>
- </el-table-column>
- <el-table-column prop="createTime" align="center" label="创建时间">
- </el-table-column>
- <el-table-column
- prop="transition"
- align="center"
- fixed="right"
- label="操作"
- width="200"
- >
- <template slot-scope="scope">
- <el-button
- v-hasPermi="['performance:batchMag:edit']"
- @click="compile(scope.row)"
- type="text"
- size="small"
- >编辑</el-button
- >
- <el-button
- v-hasPermi="['performance:batchMag:editState']"
- v-if="scope.row.batchState == 0"
- @click="setState(1, scope.row)"
- type="text"
- size="small"
- >启用</el-button
- >
- <el-button
- v-else
- v-hasPermi="['performance:batchMag:editState']"
- style="color: #666"
- @click="setState(0, scope.row)"
- type="text"
- size="small"
- >禁用</el-button
- >
- <el-button
- style="color: #f00"
- @click="deleted(scope.row)"
- v-hasPermi="['performance:batchMag:delete']"
- type="text"
- size="small"
- :disabled="scope.row.batchState == 1"
- >删除</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- <div class="pagination-container">
- <el-pagination
- @current-change="handleCurrentChange"
- :current-page.sync="formInline.pageNum"
- layout="total, prev, pager, next"
- :page-size="formInline.pageSize"
- :total="formInline.totalSize"
- >
- </el-pagination>
- </div>
- </div>
- <!-- 弹出层 -->
- <!-- 新增 /编辑-->
- <el-dialog
- :title="title"
- :visible.sync="nuedialog"
- width="500px"
- :before-close="handleCloses"
- >
- <div v-loading="loadingView" class="views">
- <el-form
- :model="ruleForm"
- :rules="addUserRules"
- ref="addUserForm"
- label-width="100px"
- class="demo-ruleForm"
- >
- <el-form-item label="关联风场:" prop="fieldCode">
- <el-select
- :disabled="title === '编辑'"
- v-model="ruleForm.fieldCode"
- placeholder="请选择关联风场"
- style="width: 100%"
- >
- <el-option
- :label="item.fieldName"
- v-for="item in fieldCodeList"
- :value="item.codeNumber"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item
- label="批次名称"
- prop="batchName"
- v-if="title === '编辑'"
- >
- <el-input
- v-model="ruleForm.batchName"
- placeholder="请输入批次名称"
- ></el-input>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="cancel('addUserForm')" size="small"
- >取 消</el-button
- >
- <el-button
- type="primary"
- @click="submitForm('addUserForm')"
- size="small"
- >确 定</el-button
- >
- </span>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import {
- getBatchMagList,
- addFieldBatch,
- updateFieldBatch,
- queryCodeNum,
- onOrOffFieldBatch,
- deleteFieldBatch,
- createBatchName,
- } from "@/api/performance.js";
- export default {
- data() {
- return {
- loadingView: false,
- loading: false, //数据加载中
- rules: {
- fieldCode: { trigger: "change" },
- batchState: { trigger: "blur" },
- },
- startDate: "",
- endDate: "",
- fieldCodeList: [],
- formInline: {
- fieldName: undefined,
- batchState: undefined,
- picker: [],
- pageNum: 1,
- pageSize: 10,
- totalSize: 0,
- },
- tableData: [],
- // 新增编辑表单
- ruleForm: {
- fieldCode: null,
- batchName: null,
- batchCode: null,
- },
- addUserRules: {
- batchCode: {
- required: true,
- message: "请选择关联风场",
- trigger: "change",
- },
- batchName: [
- { required: true, message: "请输入批次名称", trigger: "blur" },
- ],
- },
- //修改密码
- editUserPassword: {
- oldPWD: "",
- newPWD: "",
- userId: "",
- },
- nuedialog: false,
- title: "",
- };
- },
- created() {
- this.getTableList();
- this.getQueryCodeNumList();
- },
- methods: {
- handleCloses(done) {
- this.$confirm("确认关闭?")
- .then((_) => {
- done();
- })
- .catch((_) => {});
- },
- onDateChange(date) {
- if (Array.isArray(date)) {
- this.startDate = this.$formatDate(date[0]);
- this.endDate = this.$formatDate(date[1]);
- if (this.endDate < this.startDate) {
- this.endDate = this.startDate;
- }
- } else {
- this.startDate = null;
- this.endDate = null;
- }
- },
- //获取风场列表
- async getQueryCodeNumList() {
- this.loading = true;
- try {
- const result = await queryCodeNum();
- this.fieldCodeList = result.data.fieldCodeList;
- this.loading = false;
- } catch (error) {
- console.error(error);
- this.loading = false;
- }
- },
- //分页数据切换
- handleCurrentChange(val) {
- this.formInline.pageNum = val;
- this.getTableList();
- },
- //修改状态
- setState(state, row) {
- //启用接口
- this.loading = true;
- onOrOffFieldBatch({ batchCode: row.batchCode, batchState: state })
- .then((res) => {
- this.$message({
- message: res.msg,
- type: "success",
- });
- this.loading = false;
- this.getTableList();
- })
- .catch((error) => {
- this.loading = false;
- });
- },
- async getTableList() {
- try {
- this.loading = true;
- const result = await getBatchMagList({
- ...this.formInline,
- picker: undefined,
- startTime: this.startDate || undefined,
- endTime: this.endDate || undefined,
- totalSize: undefined,
- });
- this.tableData = result.data.list;
- this.formInline.totalSize = result.data.totalSize;
- this.loading = false;
- } catch (error) {
- this.$message({
- type: "error",
- message: "请检查是否连接网络",
- });
- }
- },
- rowStyle() {
- return "text-align:center";
- },
- // 查询
- onSubmit() {
- this.getTableList();
- },
- // 重置
- reset(formName) {
- this.formInline.picker = [];
- this.startDate = undefined;
- this.endDate = undefined;
- this.$refs[formName].resetFields();
- this.getTableList();
- },
- // 新增,编辑确定
- submitForm(formName) {
- // this.loading = true;
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.loadingView = true;
- switch (this.title) {
- case "新增":
- const obj = this.fieldCodeList.find(
- (item) => item.codeNumber === this.ruleForm.fieldCode
- );
- const form = new FormData();
- form.append("fieldName", obj.fieldName);
- createBatchName(form).then((results) => {
- addFieldBatch({
- ...this.ruleForm,
- batchName: results.data,
- batchCode: undefined,
- })
- .then((res) => {
- this.$message({
- type: "success",
- message: res.msg,
- });
- // this.loading = false;
- this.getTableList();
- this.nuedialog = false;
- this.loadingView = false;
- })
- .catch(() => {
- this.loadingView = false;
- // this.loading = false;
- });
- });
- break;
- case "编辑":
- updateFieldBatch({ ...this.ruleForm, fieldCode: undefined })
- .then((res) => {
- this.$message({
- type: "success",
- message: res.msg,
- });
- this.getTableList();
- this.nuedialog = false;
- this.loadingView = false;
- })
- .catch(() => {
- this.loadingView = false;
- });
- break;
- }
- // this.nuedialog = false;
- } else {
- return false;
- }
- });
- },
- //点击取消
- cancel(formName) {
- this.$refs[formName] && this.$refs[formName].resetFields();
- this.ruleForm = {
- fieldCode: null,
- batchCode: null,
- batchName: null,
- };
- this.nuedialog = false;
- this.loadingView = false;
- },
- // 编辑 回显数据
- async compile(row) {
- try {
- // 直接替换整个对象,以确保 Vue 的响应式系统能够检测到变化
- this.ruleForm = {
- fieldCode: row.fieldCode,
- batchCode: row.batchCode,
- batchName: row.batchName,
- };
- this.nuedialog = true;
- this.title = "编辑";
- } catch (error) {
- this.$message.error("获取用户信息失败");
- }
- },
- // 删除
- deleted(row) {
- this.$confirm("此操作将永久删除该用户, 是否继续?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- this.loading = true;
- deleteFieldBatch({ batchCode: row.batchCode })
- .then((res) => {
- this.$message({
- type: "success",
- message: "删除成功!",
- });
- this.loading = false;
- this.getTableList();
- })
- .catch(() => {
- this.loading = false;
- });
- })
- .catch(() => {
- this.$message({
- type: "info",
- message: "已取消删除",
- });
- });
- },
- // 新增
- newnuedialog() {
- this.cancel("addUserForm");
- this.ruleForm = {
- batchCode: "",
- batchName: "",
- fieldCode: "",
- };
- this.nuedialog = true;
- this.title = "新增";
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .general {
- display: flex;
- flex-wrap: wrap;
- .condition {
- width: 50%;
- display: flex;
- p {
- width: 100px;
- text-align: right;
- line-height: 40px;
- }
- span {
- line-height: 40px;
- padding-left: 20px;
- }
- .el-select {
- width: 100%;
- margin-bottom: 20px;
- }
- .el-input {
- margin-bottom: 20px;
- }
- }
- }
- .attachment {
- display: flex;
- padding-top: 10px;
- p {
- margin-right: 20px;
- color: #409eff;
- }
- }
- .addition {
- display: flex;
- justify-content: flex-end;
- margin-bottom: 10px;
- }
- .demo-ruleForm {
- .el-form-item {
- margin-bottom: 25px;
- }
- }
- </style>
|