动态添加表格中下拉框

news/2024/7/24 9:11:36 标签: vue

父级页面

<div class="threePart">
            <ul>
                <li style="width:114px"><span style="color:red;">*</span>场景</li>
                <li style="width:222px"><span style="color:red;">*</span>账号</li>
                <li style="width:112px"><span style="color:red;">*</span>交易类型</li>
                <li style="width:113px"><span style="color:red;">*</span>收支类型</li>
                <li style="width:112px"><span style="color:red;">*</span>交易币种</li>
                <li style="width:142px"><span style="color:red;">*</span>交易金额</li>
                <li style="width:232px"><span style="color:red;">*</span>交易时间</li>
                <li style="width:223px"><span style="color:red;">*</span>备注</li>
                <li style="width:91px;border-right:1px solid #a7a6a6;">操作</li>
            </ul>
            <table border="1" cellspacing="0">
                <tbody id="tbMain">
                    <tr1 v-for="(it,index) in quotations" :key="it.id" :ref="'quotation' + index" :rowDate="it" :handlingFeeCurrency="ruleFormSecond.handlingFeeCurrency" :transactionCurrency="ruleFormSecond.transactionCurrency" :scenesLists="scenesList" @add="addLedger" @del="del(index)"></tr1>
                </tbody>
            </table>
        </div>

父级页面js

import tr1 from './tr-con.vue'
export default {
data() {
    // 业务分类基准数据格式
	const quotationBase = {
	  a: undefined,
	  b: undefined
	}
	return {
    // 业务分类基准数据格式
	  quotationBase,
	  quotations: [{'id': '-3'}]
	}
  },
  methods: {
	// 添加台账记录
    addLedger() {
      if (this.quotations.length < 10) {
        const quotation = Object.assign({ id: this.randomString(9) }, this.quotationBase)
        this.quotations.push(quotation)
      } else {
        this.$message({
          message: '最多可录入10笔台账',
          type: 'warning'
        })
      }
    },
    randomString(length) {
      const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
      let result = ''
      for (let i = length; i > 0; --i) {
        result += str[Math.floor(Math.random() * str.length)]
      }
      return result
    },
    // 删除台账记录
    del(k) {
      this.quotations.splice(k, 1)
    },
  }
}

父级页面样式

.threePart {
        width: 1361px;
        ul {
            list-style: none;
            word-wrap: nowrap;
            li {
                text-align: center;
                display: inline-block;
                border: 1px solid #a7a6a6;
                padding: 5px;
                border-bottom: 0;
                border-right: 0;
            }
        }
        table {
            width: 1360px;
            border: 1px solid #a7a6a6;
            tbody {
                td {
                    padding: 5px;
                    text-align: center;
                    a {
                        font-size: 24px;
                        margin-left: 3px;
                    }
                    .el-input__icon {
                        color: #7b7b7c !important;
                    }
                    .el-input__inner {
                        border: 1px solid #7b7b7c !important;
                    }
                }
            }
        }
    }

子级页面

<template>
    <div class="tdCon">
            <tr>
                <td style="width:100px">
                    <el-select v-model="Data.transType" placeholder="请选择" style="width:100px">
                        <el-option v-for="item in scenesLists" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </td>
                <td style="width:210px">
                    <el-input style="width:210px;" v-model="Data.accNo"></el-input>
                </td>
                <td style="width:100px">
                    <el-select v-model="Data.busType" placeholder="请选择" style="width:100px">
                        <el-option v-for="item in transactionTypeVal" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </td>
                <td style="width:100px">
                    <el-select v-model="Data.category" placeholder="请选择" style="width:100px">
                        <el-option v-for="item in category" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </td>
                <td style="width:100px">
                    <!-- Data.currency -->
                    <el-select v-show="transactionCurrency === '' && handlingFeeCurrency === ''" v-model="Data.currency" placeholder="请选择" style="width:100px">
                        <el-option v-for="item in transactionCurrencyVal" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                    <el-select v-show="transactionCurrency !== '' || handlingFeeCurrency !== ''" v-model="Data.currency" placeholder="请选择" style="width:100px">
                        <el-option v-for="item in transactionCurrencyVal" v-show="transactionCurrency === item.value || handlingFeeCurrency === item.value || item.value===''" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </td>
                <td style="width:130px">
                    <el-input style="width:130px;" v-model="Data.transAmount"></el-input>
                </td>
                <td style="width:200px">
                    <!-- <el-date-picker
                    v-model="Data.transTime"
                    type="date"
                    :picker-options="pickerOptions"
                    placeholder="选择日期">
                    </el-date-picker> -->
                    <el-date-picker
                      v-model="Data.transTime"
                      type="datetime"
                      :picker-options="pickerOptions"
                      placeholder="选择日期">
                    </el-date-picker>
                </td>
                <td style="width:210px">
                    <el-input style="width:210px;" v-model="Data.remark"></el-input>
                </td>
                <td style="width:92px">
                    <a @click="addLedger">+</a>
                    <a @click="del()">-</a>
                </td>
            </tr>
    </div>
</template>

子级页面js

export default {
  name: 'TdCon',
  // scenesLists是场景的下拉内容
  props: ['scenesLists', 'transactionCurrency', 'rowDate', 'handlingFeeCurrency'],
  data() {
    // 表格数据基准格式
	const DataBase = {
      transType: '',
      accNo: '',
      busType: '',
      category: '',
      currency: '',
      transAmount: '',
      transTime: '',
      remark: ''
	}
    return {
      // 表格数据基准格式
	  DataBase,
	  // 表格数据
	  Data: Object.assign({}, DataBase),
      transactionTypeVal: [
        { value: '', label: '--请选择--' }
      ],
      transactionCurrencyVal: [
        { value: '', label: '--请选择--' }
      ],
      category: [
        { value: '', label: '--请选择--' },
        { value: 'IN', label: '收入' },
        { value: 'OUT', label: '支出' }
      ],
      pickerOptions: {
        // 选择当前月份或大于当前月份时间
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      }
    }
  },
  watch: {
    rowDate: {
        handler(){
          if (this.rowDate.transType !== undefined || this.rowDate.accNo !==undefined || this.rowDate.busType !== undefined || this.rowDate.category !== undefined || this.rowDate.currency !==undefined || this.rowDate.transAmount !==undefined || this.rowDate.remark !==undefined || this.rowDate.transTime !==undefined) {
            this.Data.transType = this.rowDate.transType
            this.Data.accNo = this.rowDate.accNo
            this.Data.busType = this.rowDate.busType
            this.Data.category = this.rowDate.category
            this.Data.currency = this.rowDate.currency 
            this.Data.transAmount = this.rowDate.transAmount
            this.Data.remark = this.rowDate.remark
            this.Data.transTime = this.rowDate.transTime
          }
        },
        immediate: true
      }
  },
  mounted() {
    this.acctTypeChannelListBusType()
    this.AccCurrencyListDictQuery()
  },
  methods: {
      addLedger() {
          this.$emit('add')
      },
      del() {
          this.$emit('del')
      },
      getData() {
  		return Object.assign({}, this.Data)
	  }
  }
}

子级页面样式

<style lang="scss">
.tdCon {
    width: 100%;
}
</style>

示例

在这里插入图片描述


http://www.niftyadmin.cn/n/1367722.html

相关文章

vue下载静态的模板

在组件文件中代码 export function downloadByA({ url, name temp }) {// 生成一个a元素const a document.createElement(a)// 创建一个单击事件const event new MouseEvent(click)// 设置图片名称a.download name// 如果跳转页面&#xff0c;则在其他页面跳转a.target _…

element UI中table组件不换行

.el-table .cell {white-space: nowrap;}

身份证保留前6位和后两位其它用*号代替

idNum.replace(/(\w{6})\w*(\w{2})/, $1**********$2)示例

elemet ui 时间区间不可超过1年

<el-form-item prop"dateArea" label"交易时间&#xff1a;"><el-date-pickertype"date"placeholder"选择开始日期"v-model"ruleForm.dateArea1"></el-date-picker><span style"margin: 0 5px;&q…

Vue全家桶构建项目

步骤一、安装vue-cli 首先&#xff0c;我们可以通过npm安装vue-clic,前提是我们需要有node环境&#xff0c;如果电脑还没安装node&#xff0c;先安装&#xff0c;可通过 node -v 查询node的版本号&#xff0c;有版本号则已经安装成功&#xff1b; vue全家桶项目构建教程 接下…

Vue下载文件不成功及下载文件名称问题

看代码 import axiosDown from "axios";downloadFile(path) {return axiosDown({url: path,method: "get",responseType: "blob" // 这一步也很关键&#xff0c;一定要加上 responseType 值为 blob});},downloadWay(item) {// console.log(item…

js代码优化

1.避免多条件并列 let status process; let arr [process, wait, fail] if (arr.includes(status)) {console.log(避免多条件并列--2);}

C++ day44

1、全局变量&#xff0c;int monster 10000;定义英雄类hero&#xff0c;受保护的属性string name&#xff0c;int hp,int attcKk;公有的无参构造&#xff0c;有参构造&#xff0c;虚成员函数void AtK()[blood-0,}&#xff0c;法师类继承自英雄类&#xff0c;私有属性int ap_at…