国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

基于Element-ui 表單彈窗列表選擇封裝

這篇具有很好參考價(jià)值的文章主要介紹了基于Element-ui 表單彈窗列表選擇封裝。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

不知道怎么描述這個(gè)東西了。。el-select下拉框大家都知道,但是下拉框只能選擇一個(gè),而且如果數(shù)據(jù)太多的話也不太容易選擇,所以這里就是封裝了組件包含對(duì)應(yīng)的彈窗,就是能實(shí)現(xiàn)多選,而且列表也是分頁展示的,選擇完之后將對(duì)應(yīng)的名稱展示在文本框中,傳給后端對(duì)應(yīng)的用逗號(hào)隔開(用什么隔開都可以,跟后端商量)的id

大致的效果圖就是:?

基于Element-ui 表單彈窗列表選擇封裝?

這個(gè)關(guān)聯(lián)合同就是我們封裝的,輸入框添加了disabled,不可編輯的,只能通過點(diǎn)擊右側(cè)彈窗來進(jìn)行選擇。點(diǎn)擊彈窗之后的效果圖:?

基于Element-ui 表單彈窗列表選擇封裝

這里我們要考慮的就是:

  1. 點(diǎn)擊彈窗要展示出列表,進(jìn)行選擇,選擇完之后點(diǎn)擊確定要將對(duì)應(yīng)的名稱展示出來,多個(gè)就用逗號(hào)隔開,然后拿到對(duì)應(yīng)id對(duì)應(yīng)賦值。
  2. 第二就是回顯的問題,當(dāng)我們選擇完之后再次點(diǎn)擊彈窗,這時(shí)候要將我們已選擇數(shù)據(jù)在列表上進(jìn)行回顯勾選,后臺(tái)返回?cái)?shù)據(jù)的時(shí)候,我們要根據(jù)id依次查詢對(duì)應(yīng)的數(shù)據(jù),將對(duì)應(yīng)的名稱展示出來,然后點(diǎn)擊彈窗的時(shí)候同樣的進(jìn)行數(shù)據(jù)回顯勾選?

這里直接附上代碼:?

index.vue?

<template>
<div>
  <el-input placeholder="請(qǐng)選擇" :size="size" :disabled="inpDisabled" style="line-hight:40px" v-model="name" class="input-with-select">
    <el-button slot="append" :disabled="btnDisabled" @click="showUserSelect" icon="el-icon-search"></el-button>
  </el-input>
  <!-- 合同列表 -->
  <ContractSelectDialog
    ref="contractSelect"
    @doSubmit="selectionsToInput"
    :selectData="selectData"
    :single="single"
  />
</div>
</template>
<script>
import ContractSelectDialog from './contractSelectDialog'
import ContractService from '@/api/contract/ContractService'
export default {
  data () {
    return {
      name: '',
      selectData: [],
      contractService: null
    }
  },
  props: {
    size: {
      type: String,
      default: 'small'
    },
    value: {
      type: String,
      default: ''
    },
    btnDisabled: {
      type: Boolean,
      default: false
    },
    inpDisabled: {
      type: Boolean,
      default: true
    },
    single: {  // 是否啟用單選
      type: Boolean,
      default: false
    }
  },
  components: {
    ContractSelectDialog
  },
  created () {
    this.contractService = new ContractService()
  },
  watch: {
    value: {
      handler (newVal) {
        this.selectData = []
        if (newVal) {
          newVal.split(',').forEach((id) => { // 回顯拿數(shù)據(jù)
            this.contractService.queryById(id).then(({data}) => {
              if (data && data.id !== '') {
                this.selectData.push(data)
              }
            })
          })
        }
      },
      immediate: true,
      deep: false
    },
    selectData: {
      handler (newVal) {
        this.name = newVal.map(contract => contract.contractName).join(',')
      },
      immediate: false,
      deep: false
    }
  },
  methods: {
    // 設(shè)置選中
    selectionsToInput (selections) {
      this.selectData = selections
      this.$emit('getInfo', this.selectData)
    },
    // 顯示列表
    showUserSelect () {
      this.$refs.contractSelect.init()
    }
  }
}
</script>
<style>
.el-form-item__content .el-input-group {
  vertical-align: middle;
}
.el-tag + .el-tag {
  margin-left: 5px;
  margin-bottom: 5px;
}
</style>

對(duì)應(yīng)的彈窗組件?

<template>
  <div>
    <el-dialog
      title="合同選擇"
      width="1000px"
      :close-on-click-modal="false"
      :append-to-body="true"
      v-dialogDrag
      class="userDialog"
      :visible.sync="visible"
    >
      <el-container style="height: 500px">
        <el-container>
          <el-header style="text-align: left; font-size: 12px; height: 30px">
            <el-form
              size="small"
              :inline="true"
              ref="searchForm"
              :model="searchForm"
              @keyup.enter.native="refreshList()"
              @submit.native.prevent
            >
              <el-form-item prop="contractNo">
                <el-input
                  size="small"
                  v-model="searchForm.contractNo"
                  placeholder="合同編號(hào)"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item prop="contracntName">
                <el-input
                  size="small"
                  v-model="searchForm.contracntName"
                  placeholder="合同名稱"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button
                  type="primary"
                  @click="refreshList()"
                  size="small"
                  icon="el-icon-search"
                  >查詢</el-button
                >
                <el-button
                  @click="resetSearch()"
                  size="small"
                  icon="el-icon-refresh-right"
                >重置</el-button>
              </el-form-item>
            </el-form>
          </el-header>
          <el-main>
            <el-table
              :data="dataList"
              v-loading="loading"
              size="small"
              border
              ref="contractTable"
              @select="handleSelectionChange"
              height="calc(100% - 40px)"
              style="width: 100%"
            >
              <el-table-column
                type="selection"
                header-align="center"
                align="center"
                width="50"
              >
              </el-table-column>
              <el-table-column
                prop="contractNo"
                header-align="center"
                align="left"
                sortable="custom"
                min-width="90"
                label="合同編號(hào)"
              >
              </el-table-column>
              <el-table-column
                prop="contractName"
                header-align="center"
                align="left"
                sortable="custom"
                min-width="90"
                label="合同名稱"
              >
              </el-table-column>
              <el-table-column
                prop="contractAmount"
                header-align="center"
                align="left"
                sortable="custom"
                min-width="110"
                label="合同金額"
              >
              </el-table-column>
              <el-table-column
                prop="oppositeCompany"
                header-align="center"
                align="center"
                sortable="custom"
                min-width="110"
                label="對(duì)方單位"
              >
              </el-table-column>
              <el-table-column
                prop="signDate"
                header-align="center"
                align="left"
                sortable="custom"
                min-width="110"
                label="簽訂時(shí)間"
              >
            </el-table-column>
            </el-table>
            <el-pagination
              @size-change="sizeChangeHandle"
              @current-change="currentChangeHandle"
              :current-page="pageNo"
              :page-sizes="[5, 10, 50, 100]"
              :page-size="pageSize"
              :total="total"
              layout="total, sizes, prev, pager, next, jumper"
            >
            </el-pagination>
          </el-main>
        </el-container>
      </el-container>
      <span slot="footer" class="dialog-footer">
        <el-button
          size="small"
          @click="visible = false"
          icon="el-icon-circle-close"
          >關(guān)閉</el-button
        >
        <el-button
          size="small"
          type="primary"
          icon="el-icon-circle-check"
          @click="doSubmit()"
          >確定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchForm: {
        contractNo: '',
        contracntName: ''
      },
      dataListAllSelections: [], // 所有選中的數(shù)據(jù)包含跨頁數(shù)據(jù)
      idKey: "id", // 標(biāo)識(shí)列表數(shù)據(jù)中每一行的唯一鍵的名稱(需要按自己的數(shù)據(jù)改一下)
      dataList: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      orders: [],
      loading: false,
      visible: false,
    };
  },
  props: {
    selectData: {
      type: Array,
      default: () => {
        return [];
      },
    },
    // 是否啟用單選
    single: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.dataListAllSelections = JSON.parse(JSON.stringify(this.selectData));
        this.resetSearch();
      });
    },
    // 獲取數(shù)據(jù)列表
    refreshList() {
      this.loading = true;
      this.$http({
        url: "/contract/list", // 自己的接口路徑
        method: "get",
        params: {
          current: this.pageNo,
          size: this.pageSize,
          orders: this.orders,
          ...this.searchForm,
        },
      }).then(({ data }) => {
        this.dataList = data.records;
        this.total = data.total;
        this.pageNo = data.current;
        this.loading = false;
        this.$nextTick(() => {
          this.setSelectRow();
        });
      });
    },
    // 每頁數(shù)
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageNo = 1;
      this.refreshList();
    },
    // 當(dāng)前頁
    currentChangeHandle(val) {
      this.pageNo = val;
      this.refreshList();
    },
    // 排序
    resetSearch() {
      this.$refs.searchForm.resetFields();
      this.refreshList();
    },
    // 選中數(shù)據(jù)
    handleSelectionChange(selection, row) {
      if (this.single && selection.length > 1) {
        this.$refs.contractTable.clearSelection();
        this.$refs.contractTable.toggleRowSelection(row);
      }
      this.dataListAllSelections = this.single ? [row] : selection
    },
    // 設(shè)置選中的方法
    setSelectRow() {
      this.$refs.contractTable.clearSelection();
      if (!this.dataListAllSelections || this.dataListAllSelections.length <= 0) {
        return;
      }
      for (let i = 0; i < this.dataList.length; i++) {
        if (this.dataListAllSelections.some(item => item[this.idKey] == this.dataList[i][this.idKey])) {
          // 設(shè)置選中,記住table組件需要使用ref="table"
          this.$refs.contractTable.toggleRowSelection(this.dataList[i], true);
        }
      }
    },
    doSubmit() {
      this.visible = false;
      this.$emit("doSubmit", this.dataListAllSelections);
    },
  },
};
</script>
<style lang="scss">
.userDialog {
  .el-dialog__body {
    padding: 10px 0px 0px 10px;
    color: #606266;
    font-size: 14px;
    word-break: break-all;
  }
  .el-main {
    padding: 20px 20px 5px 20px;
    .el-pagination {
      margin-top: 5px;
    }
  }
}
</style>

使用:?

組件默認(rèn)是多選,可以傳入single為true來啟用單選文章來源地址http://www.zghlxwxcb.cn/news/detail-509827.html

?
<template>
  <div>
    <el-form
      size="small"
      :model="inputForm"
      ref="inputForm"
      v-loading="loading"
      :disabled="formReadOnly"
      label-width="120px"
    >
      <el-row :gutter="15">
        <el-col :span="12">
          <el-form-item label="關(guān)聯(lián)合同" prop="associatedContracts" :rules="[]">
            <ContractSelect
              :value="inputForm.associatedContracts"
              @getInfo="getContranct"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import ContractSelect from '@/components/contractSelect/index.vue'
export default {
  data() {
    return {
      title: '',
      method: '',
      visible: false,
      loading: false,
      inputForm: {
        id: '',
        associatedContracts: '', // 關(guān)聯(lián)合同
      },
    }
  },
  components: { ContractSelect },
  methods: {
    // 關(guān)聯(lián)合同
    getContranct(selections) {
      this.inputForm.associatedContracts = selections.map(item => item.id).join(',')
    }
  }
}
</script>

到了這里,關(guān)于基于Element-ui 表單彈窗列表選擇封裝的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 基于element-ui的年份范圍選擇器

    基于element-ui的年份范圍選擇器

    下載對(duì)應(yīng)的代碼到本地 文件地址,以下是我的目錄結(jié)構(gòu),我將下載的文件放到了src/components下。 全局引入或者局部引入使用 全局引入 局部引入 調(diào)用方法,下面的參數(shù)和element-ui原有el-date-picker的api保持不變 日期限制處理(禁用),下面我以我這邊的需求為例, 選擇的年份需等

    2024年02月07日
    瀏覽(21)
  • 基于element-ui封裝上傳圖片到騰訊云Cos組件

    基于element-ui封裝上傳圖片到騰訊云Cos組件

    組件需求 上傳圖片到騰訊云Cos服務(wù)器 可以顯示傳入的圖片地址 可以刪除傳入的圖片地址 可以上傳圖片到云服務(wù)器 上傳到騰訊云之后,可以返回圖片地址,顯示 上傳成功之后,可以回調(diào)成功函數(shù) 需要使用借助一個(gè)插件,幫助我們上傳圖片資源到騰訊云Cos 使用element的el-upl

    2023年04月17日
    瀏覽(69)
  • uniapp 微信小程序 自定義彈框+picker下拉選擇列表+輸入表單:拒絕-選擇理由彈窗

    uniapp 微信小程序 自定義彈框+picker下拉選擇列表+輸入表單:拒絕-選擇理由彈窗

    效果: 1、template 2、data: 3、methods: 4、style

    2024年01月20日
    瀏覽(96)
  • 基于Vue和Element-UI自定義分組以及分組全選Select 選擇器

    基于Vue和Element-UI自定義分組以及分組全選Select 選擇器

    上一篇博文我們已經(jīng)實(shí)現(xiàn)了基于Vue和Element-UI中Select 選擇器的分組全選以及樣式修改問題, 但是在分組方面我們是用了element-ui 自帶的 使用el-option-group對(duì)備選項(xiàng)進(jìn)行分組,它的label屬性為分組名 的功能,但是出來的效果樣式很難自定義,就算是魔改element的樣式也有一些改不了

    2023年04月08日
    瀏覽(28)
  • 基于Vue+Element-Ui開發(fā)的月日組件,可以選擇月份和天數(shù)小插件(新版本)

    基于Vue+Element-Ui開發(fā)的月日組件,可以選擇月份和天數(shù)小插件(新版本)

    最近有粉絲在使用的過程中發(fā)現(xiàn)不能滿足自己項(xiàng)目上的需求,評(píng)論說不支持 placeholder 以及更改輸入框大小 size ,所以又趕緊更新了一個(gè)版本,之前是1.0.7,現(xiàn)在新版本為1.1.0,點(diǎn)擊查看之前的老版本 本組件是基于Vue和Element-ui,因Element官方組件庫沒有可以選擇月份和天數(shù)的組

    2023年04月19日
    瀏覽(25)
  • 關(guān)閉element UI的彈窗,再次打開顯示表單驗(yàn)證提示

    關(guān)閉element UI的彈窗,再次打開顯示表單驗(yàn)證提示

    打開彈窗,沒有填寫任何信息,點(diǎn)擊保存按鈕,觸發(fā)了表單的驗(yàn)證提示,沒有進(jìn)行任何操作,點(diǎn)擊【關(guān)閉按鈕】或者【取消按鈕】關(guān)閉彈窗,再次打開彈窗,仍然顯示表單的驗(yàn)證提示信息, ? 解決方法: 給el-dialog添加@close事件,給取消按鈕添加點(diǎn)擊事件,在事件中對(duì)表單進(jìn)

    2024年02月15日
    瀏覽(23)
  • element-ui 動(dòng)態(tài)表單

    背景:朋友入職新公司,做項(xiàng)目重構(gòu),根據(jù)后端返回表單內(nèi)容,動(dòng)態(tài)生成表單,于是自己實(shí)現(xiàn)了下,哪里寫的不好,歡迎各位提建議: 因?yàn)殚_關(guān)和多選框默認(rèn)值是非空字符串,所以在created生命周期單獨(dú)處理了下

    2024年02月11日
    瀏覽(23)
  • element-ui 表單校驗(yàn)?大全

    element-ui 官網(wǎng) element-ui 表單校驗(yàn)的規(guī)則如下:

    2024年02月08日
    瀏覽(29)
  • 基于vue element-ui 封裝上傳圖片組件 功能:上傳,刪除,預(yù)覽,上傳圖片水印,拖拽排序,上傳進(jìn)度條等

    基于vue element-ui 封裝上傳圖片組件 功能:上傳,刪除,預(yù)覽,上傳圖片水印,拖拽排序,上傳進(jìn)度條等

    我們?cè)陂_發(fā)后臺(tái)時(shí)肯定避免不了上傳圖片的功能 例如: 上傳圖片回顯 上傳完成 : 預(yù)覽查看 , 刪除等 如果是圖片列表,還可能讓你拖動(dòng)圖片排序 有的后臺(tái)項(xiàng)目可能要給圖片添加水印,添加標(biāo)記 有的后臺(tái)可能要炫酷一點(diǎn) 添加進(jìn)度條功能 現(xiàn)在我們要完成上面的一系列功能,這里我

    2024年02月16日
    瀏覽(28)
  • element-ui表單自定義校驗(yàn)

    element-ui表單自定義校驗(yàn)

    1.問題描述 項(xiàng)目開發(fā)過程中,遇到表單校驗(yàn),這次的校驗(yàn)規(guī)則比較嚴(yán),element-ui表單自帶的校驗(yàn)完全解決不了問題。 2.解決方法 使用elementui表單校驗(yàn)中的自定義校驗(yàn),validUsername是自定義的校驗(yàn)方法名稱 2.1 定義表單校驗(yàn): 2.2 自定義校驗(yàn)方法: 注意:方法中一定義要返回call

    2024年02月11日
    瀏覽(32)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包