Elment ui 动态表格与表单校验 列表数据 组件

news2025/3/9 21:55:06

组件做个记录,方便以后会用到。

效果:

代码 :

<template>
  <el-dialog title="商品详情" :visible.sync="dialogVisible" width="80%">
    <el-tabs v-model="activeTab">
      <el-tab-pane label="营销表现" name="marketing">
        <div class="boxForm">
          <p class="fz-18 mb-40">营销表现</p>
          <el-form ref="formData" :model="formData" >

            
            <el-table :data="formData.tableData" style="width: 100%">
              <el-table-column label="日期" width="230">
                <template slot="header" slot-scope="scope">
                  <span style="color: red">*</span>日期
                </template>
                <template slot-scope="scope">
                  <el-form-item v-if="scope.row.active"  :prop="'tableData.' + scope.$index + '.date'" > {{ formatDateRange(scope.row.date) }}</el-form-item>
                  <el-form-item
                    v-else
                    :prop="'tableData.' + scope.$index + '.date'" 
                    :rules="[ { required: true, message: '请选择', trigger: 'change' } ]">
                    <el-date-picker v-model="scope.row.date" type="daterange" format="yyyy年MM月dd日"
                      value-format="yyyy-MM-dd" style="width: 100%" required size="mini"></el-date-picker>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="成交额" width="200">
                <template slot="header" slot-scope="scope">
                  <span style="color: red">*</span>成交额
                </template>
                <template slot-scope="scope">
                  <el-form-item v-if="scope.row.active" :prop="'tableData.' + scope.$index + '.amount'" > {{ scope.row.amount }} USD</el-form-item>
                  <el-form-item
                    v-else
                    :prop="'tableData.' + scope.$index + '.amount'" 
                    :rules="[ { required: true, message: '请输入', trigger: 'blur' }]"
                  >
                    <el-input-number
                      v-model="scope.row.amount"
                      placeholder="请输入成交额"
                      style="width:110px"
                      :min="0"
                      :precision="2"
                      size="mini"
                      :controls="false"
                    ></el-input-number>
                    USD
                  </el-form-item>
                </template>
              </el-table-column>

              <el-table-column label="订单数">
                <template slot="header" slot-scope="scope">
                  <span style="color: red">*</span>订单数
                </template>
                <template slot-scope="scope">
                  <el-form-item v-if="scope.row.active" :prop="'tableData.' + scope.$index + '.orders'" > {{ scope.row.orders }}</el-form-item>
                  <el-form-item
                    v-else
                    :prop="'tableData.' + scope.$index + '.orders'" 
                    :rules="[ { required: true, message: '请输入', trigger: 'blur' }]"
                  >
                    <el-input-number
                      v-model="scope.row.orders"
                      placeholder="请输入订单数"
                      style="width:120px"
                      :min="0"
                      size="mini"
                      :controls="false"
                    ></el-input-number>
                  </el-form-item>
                </template>
              </el-table-column>

              <el-table-column label="推广次数">
                <template slot="header" slot-scope="scope">
                  <span style="color: red">*</span>推广次数
                </template>
                <template slot-scope="scope">
                  <el-form-item v-if="scope.row.active" :prop="'tableData.' + scope.$index + '.promotions'" > {{ scope.row.promotions }}</el-form-item>
                  <el-form-item
                    v-else
                    :prop="'tableData.' + scope.$index + '.promotions'" 
                    :rules="[ { required: true, message: '请输入', trigger: 'blur' }]"
                  >
                    <el-input-number
                      v-model="scope.row.promotions"
                      placeholder="请输入推广次数"
                      style="width:120px"
                      :min="0"
                      size="mini"
                      :controls="false"
                    ></el-input-number>
                  </el-form-item>
                </template>
              </el-table-column>

              <el-table-column label="操作人">
                <template slot="header" slot-scope="scope">
                  <span style="color: red">*</span>操作人
                </template>
                <template slot-scope="scope">
                  <el-form-item v-if="scope.row.active" :prop="'tableData.' + scope.$index + '.operator'" > {{ showoperation(scope.row.operator) }}</el-form-item>
                  <el-form-item
                    v-else
                    :prop="'tableData.' + scope.$index + '.operator'" 
                    :rules="[ { required: true, message: '请选择', trigger: 'change' }]"
                  >
                    <el-select v-model="scope.row.operator" placeholder="请选择" size="mini" style="width:120px">
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>




              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button type="text" @click="handleAdd(scope.$index)" v-if="scope.$index == 0">添加</el-button>
                  <el-button type="text" @click="handleEdit(scope.$index)" v-if="scope.row.active">编辑</el-button>
                  <el-button type="text" @click="handleDel(scope.$index)" v-if="scope.$index !== 0" style="color:red;">删除</el-button>
                  
                </template>
              </el-table-column>
            </el-table>
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper" :total="formData.tableData.length"></el-pagination>
          </el-form>
        </div>
      </el-tab-pane>
    </el-tabs>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveOrUpdate">保存更新</el-button>
      <el-button @click="dialogVisible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>

export default {
  data() {
    return {
      dialogVisible: true,
      activeTab: 'marketing',
      options: [],
      formData: {
        tableData: [
          { date: '', amount: '', orders: '', promotions: '', operator: '', active: false, key: Date.now() },
        ],
      },
      operators: [
        { label: 'Operator 1', value: '1' },
        { label: 'Operator 2', value: '2' },
        { label: 'Operator 3', value: '3' }
      ],
      currentPage: 1,
      pageSize: 10,
      rules: {
        date: [{ required: true, message: '请输入日期', trigger: 'blur' }],
        amount: [{ required: true, message: '请输入成交额', trigger: 'blur' }],
        orders: [{ required: true, message: '请输入订单数', trigger: 'blur' }],
        promotions: [{ required: true, message: '请输入推广次数', trigger: 'blur' }],
        operator: [{ required: true, message: '请选择操作人', trigger: 'change' }]
      }
    };
  },
  created () {
    this.getOperationUser()
  },
  methods: {


    // 认领人
    async getOperationUser () {
      let res = await this.$api.operationUser()
      if (res.code === 10000) {
        this.options = res.data.length
        ? res.data.map((i) => {
            return { ...i, label: i.username, value: i.id }
          })
        : []
      } else {
        this.$message({ type: 'error', message: res.message })
      }
    },


    handleAdd(index) {
      this.formData.tableData.splice(index + 1, 0, { date: '', amount: '', orders: '', promotions: '', operator: '', active: false, key: Date.now() })
    },

    handleDel(index) {
      this.formData.tableData.splice(index, 1)
    },



    // 编辑
    handleEdit(index) {
      this.formData.tableData[index].active = false
    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.currentPage = 1; 
    },
    handleCurrentChange(page) {
      this.currentPage = page;
    },
    saveOrUpdate() {
      this.$refs['formData'].validate((valid) => {
          if (valid) {
            console.log('校验通过')
            this.formData.tableData.map(item => {
              item.active = true
              return item
            })
          }
      })
    },

    showoperation(id) {
      let result = this.options.find(item => item.value === id);
      return result ? result.label : null;
    },
    // 日期转换
    formatDateRange (dateRange) {
      const startDate = new Date(dateRange[0]);
      const endDate = new Date(dateRange[1]);
      const newStartDate = new Date(startDate.getTime() + 39 * 24 * 60 * 60 * 1000); // 加上39天
      const newEndDate = new Date(endDate.getTime() + 39 * 24 * 60 * 60 * 1000); // 加上39天
      const formattedStartDate = `${newStartDate.getFullYear()}.${(newStartDate.getMonth() + 1).toString().padStart(2, '0')}.${newStartDate.getDate().toString().padStart(2, '0')}`;
      const formattedEndDate = `${newEndDate.getFullYear()}.${(newEndDate.getMonth() + 1).toString().padStart(2, '0')}.${newEndDate.getDate().toString().padStart(2, '0')}`;
      return `${formattedStartDate}-${formattedEndDate}`;
    },

  }
};
</script>
<style lang='scss' scoped>
.boxForm {
  box-shadow: rgb(59 59 59 / 10%) 0px 2px 6px 0px;
  border-radius: 8px;
  margin: 4px;
  padding: 20px;
  margin-top: 10px;
}
::v-deep .el-table .cell{
  height: 54px;
} 
::v-deep .el-table th .cell {
  height: 22px !important;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1555243.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据可视化Grafana Windows 安装使用教程(中文版)

1.跳转连接 天梦星服务平台 (tmxkj.top)https://tmxkj.top/#/site?url 2.下载应用程序 官网地址&#xff1a;Grafana get started | Cloud, Self-managed, Enterprisehttps://grafana.com/get/ 3.修改配置文件 grafana\conf\defaults 4.启动\bin\目录下serve应用程序 浏…

C#属性显示

功能&#xff1a; 显示对象的属性&#xff0c;包括可显示属性、可编辑属性、及不可编辑属性。 1、MainWindow.xaml <Window x:Class"FlowChart.MainWindow"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://sche…

使用filezilla连接Ubuntu22.04虚拟机

获取电脑IP和虚拟机IP ① 在windows下ctrlR再输入cmd&#xff0c;打开指令窗口&#xff0c;输入 ipconfig 虚拟机连接电脑用的是NAT模式&#xff0c;故看VMnet8的IP地址 ② 查看虚拟机IP地址 终端输入 ifconfig 如果没安装&#xff0c;按提示安装net-tools sudo apt install …

vue3封装Element导航菜单

1. 导航外层布局 AsideView.vue <template><el-menu:default-active"defaultActive"class"my-menu":collapse"isCollapse":collapse-transition"false"open"handleOpen"close"handleClose"><menu…

云渲染实用工具:3ds max怎么改低版本?

3ds Max是建模领域广泛采用的专业软件&#xff0c;它通过定期更新来不断增强功能和提升性能。但这些频繁的更新有时会导致一些插件暂时无法与新版本完全兼容。为了解决这个问题&#xff0c;设计师们可以采用一个简单有效的方法&#xff0c;那就是将较新版本的3ds Max文件进行版…

拆分巨石:将MVPS和MVAS应用于遗留应用程序——可持续架构(六)

前言 MVP 和 MVA 的概念不仅适用于新应用程序&#xff1b;它们提供了一种新颖的方式来审视对遗留系统的范围变更&#xff0c;以防止过快地承担过多的变化 - 参见图1。MVA 可以帮助组织评估和更新其技术标准&#xff0c;通过展示新技术如何真正对支持 MVP 至关重要。创建 MVA 可…

uniapp对接极光推送(国内版以及海外版)

勾选push&#xff0c;但不要勾选unipush 国内版 网址&#xff1a;极光推送-快速集成消息推送功能,提升APP运营效率 (jiguang.cn) 进入后台&#xff0c;并选择对应应用开始配置 配置安卓包名 以及ios推送证书&#xff0c;是否将生产证书用于开发环境选择是 ios推送证书…

HarmonyOS ArkTS 骨架屏加载显示(二十五)

目录 前言1、骨架屏代码显示2、代码中引用3、效果图展示 前言 所谓骨架屏&#xff0c;就是在页面进行耗时加载时&#xff0c;先展示的等待 UI, 以告知用户程序目前正在运行&#xff0c;稍等即可。 等待的UI大部分是 loading 转圈的弹窗&#xff0c;有的是自己风格的小动画。其实…

【ERP原理与应用】作业·思考题三、四

思考题三 P77第四章3&#xff0c; 6&#xff0c;8 3.生产规划的基本内容是什么&#xff1f; 生产规划是根据企业未来一段时间内预计资源可用量和市场需求量之间的平衡所制定的概括性设想是根据企业所拥有的生产能力和需求预测&#xff0c;对企业未来较长一段时间内的产品、产…

elasticsearch _cat/indices docs.count is different than <index>/_count

今天遇到一个问题&#xff0c;kibana中看到文档数与下面语句查询到的不同 GET /_cat/count/jiankunking_xxxxx_product_expand_test?v GET /jiankunking_xxxxx_product_expand_test/_search?track_total_hitstrue语句查询结果 epoch timestamp count 1711433785 06:16…

用navicat进行mysql表结构同步

用navicat进行mysql表结构同步 前言新增一个列然后进行表结构同步删除一个列然后进行表结构同步把Int列转成TinyInt列&#xff0c;看数字溢出的情况下能不能表结构同步总结 前言 从同事那边了解到还能用navicat进行表结构同步&#xff0c;他会在发布更新的时候&#xff0c;直接…

MPDataDoc类介绍

MPDataDoc类介绍 使用mp数据库新接口mp_api.client.MPRester获取数据&#xff0c;例子如下&#xff1a; from mp_api.client import MPResterwith MPRester(API_KEY) as mpr:docs mpr.summary.search(material_ids["mp-1176451", "mp-561113"])以上代码返…

vue3+threejs新手从零开发卡牌游戏(二十一):添加战斗与生命值关联逻辑

首先将双方玩家的HP存入store中&#xff0c;stores/common.ts代码如下&#xff1a; import { ref, computed } from vue import { defineStore } from piniaexport const useCommonStore defineStore(common, () > {const _font ref() // 字体const p1HP ref(4000) // 己…

常见的Nginx+Redis+MQ+DB架构设计

三高&#xff0c;复杂的架构 SQRS CAP 缓存&#xff0c;限流 【Redis&#xff0c;缓存】 cache-aside 缓存cache&#xff1a;数据源的副本 store 1. Read/Write Through Pattern 读写穿透模式 redis&#xff1a;放当前在线用户&#xff0c;热点数据

iOS UIFont-真香警告之字体管理类

UIFont 系列传送门 第一弹加载本地字体:iOS UIFont-新增第三方字体 第二弹加载线上字体:iOS UIFont-实现三方字体的下载和使用 第三弹搭建字体管理类:iOS UIFont-真香警告之字体管理类 前言 不知道友们是否有过这种经历,项目已经迭代了很多版本,项目中的文件已经上千个了…

ARP协议定义及工作原理

ARP的定义 地址解析协议(Address Resolution Protocol&#xff0c;ARP)&#xff1a;ARP协议可以将IPv4地址(一种逻辑地址)转换为各种网络所需的硬件地址(一种物理地址)。换句话说&#xff0c;所谓的地址解析的目标就是发现逻辑地址与物理地址的映射关系。 ARP仅用于IPv4协议&a…

QT资源添加调用

添加资源文件&#xff0c;新建资源文件夹&#xff0c;命名resource&#xff0c;然后点下一步&#xff0c;点完成 资源&#xff0c;右键add Prefix 添加现有文件 展示的label图片切换 QLabel *led_show; #include "mainwindow.h" #include<QLabel> #include&l…

海豚【货运系统源码】货运小程序【用户端+司机端app】源码物流系统搬家系统源码师傅接单

技术栈&#xff1a;前端uniapp后端vuethinkphp 主要功能&#xff1a; 不通车型配置不通价格参数 多城市定位服务 支持发货地 途径地 目的地智能费用计算 支持日期时间 预约下单 支持添加跟单人数选择 支持下单优惠券抵扣 支持司机收藏订单评价 支持订单状态消息通知 支…

ps 常用命令

ps 常用命令 什么是ps&#xff1f; ps是process status的缩写&#xff0c;用于查看当前系统中运行的进程信息。它提供了关于进程的各种详细信息&#xff0c;如进程 PID、进程状态、CPU 使用情况、内存占用、运行时间等。 常用选项参数 -A &#xff1a;所有的进程均显示出来…

JZ-7-201XMT跳位合位监视专用继电器 220VDC 板后接线,面板安装 JOSEF约瑟

系列型号&#xff1a; JZ-7Y-201XMT跳位合位监视继电器&#xff1b; JZ-7J-201XMT跳位合位监视继电器&#xff1b; JZ-7Y-203XMT跳位合位监视继电器&#xff1b; JZ-7J-203XMT跳位合位监视继电器&#xff1b; JZ-7Y-204XMT跳位合位监视继电器&#xff1b; JZ-7J-204XMT跳…