工作需求ElementUi组件的使用

加油,新时代打工人!

组件源码

html 复制代码
<template>
  <div @mouseenter="mousein = true" @mouseleave="mousein = false">
     <el-input type="text" clearable autocomplete="off" v-model="searchDoc.originName"  placeholder="请选择" size="small" :style="style"
      @focus="handleShowDatatable(true)" @blur="handleShowDatatable(false)" @input="getList" />
    <div ref="tableContainer" :style="tableStyle" v-show="showDatatable" >
       <el-table
      :data="tableData"
        border
      style="width: 100%"
      @row-click="handleRowClick">
      <el-table-column
        prop="originCode"
        label="产地编码"
        width="180">
      </el-table-column>
      <el-table-column
        prop="originName"
        label="产地名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="zjm"
        label="助记码"
        width="70">
      </el-table-column>
       </el-table>
    <div class="paginationclass">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="pagination.pageIndex"
        :limit.sync="pagination.pageSize"
        @pagination="getList"
      />
    </div>
    </div>
  </div>
  
</template>

<script>
import{  
    getMnufacturerList
} from "@/api/manufacturer/manufacturer.js"

export default {
  name: 'MyFacturerName',
  props: {
    value: {
      type: Object
    },
    width: {
      type: [Number, String]
    },
      index:{
          type: [Number, String]

      },
  },
  data(){
    return {
      loading: false,
      searchDoc: {
        originName: '',
        id: 0
      },
      mousein: false,
      showDatatable: false,
      tableStyle: {
        'position':'absolute',
        'background-color':'#FFFFFF',
        'z-index':10,
        'max-height':'200px',
        'overflow-y':'auto',
      },
       pagination: {
        pageIndex: 1,
        pageSize: 10,
      },
      queryParams: {
        originName: "",
      },

      total: 0,
      tableData: [],
      selectRow: null,
    }
  },
  methods: {
   getList() {
      getMnufacturerList({
        ...this.pagination,
        ...this.queryParams,
        originName:this.searchDoc.originName
      }).then((res) => {
        this.tableData = res.data.list;
        this.total = res.data.total;
      }).catch((err) => {
          this.$Message.error('请求产地信息时异常: ', err)
      }).finally(() => {
          this.loading = false
      });
    },

      handleRowClick(item){
          this.searchDoc = {
              originCode: item.originCode,
              originName:item.originName,
              zjm:item.zjm,
              providerName:item.providerName
          }
          let data={
              index:this.index,
              searchDoc:this.searchDoc
          }
          this.$emit('sendname',data.searchDoc.providerName)
          this.closeDatatable()
      },
    handleShowDatatable(isShow){
      if(!this.mousein && !isShow){
        this.showDatatable = false
      }else{
        this.showDatatable = true
        if(this.tableData.length == 0){
          this.getList()
        }
      }
    },
    closeDatatable(){
      this.showDatatable = false
    }
  },
  computed: {
    style(){
      let style = {width: '180px'}
      if(this.width){
        style.width = `${this.width}px`
      }
      return style
    }
  },
  watch: {
    searchDoc: function(val){
      if(!val.originName){
        this.searchDoc.id = 0
      }
      this.$emit('input', this.searchDoc)
    }
  },
  mounted(){

  }
  
}
</script>
<style scoped>
.paginationclass {
  margin-left: 40%;
  margin-top: 20px;
  margin-bottom: 20px;
}
</style>

导入

html 复制代码
import MyFacturerName from "@/components/MyFacturerMedid/My-Facturer-medid.vue";

使用

html 复制代码
<MyFacturerName @sendzjm="setfaceturerName" :index1="scope.$index">
</MyFacturerName>
相关推荐
EndingCoder几秒前
React从基础入门到高级实战:React 高级主题 - React Concurrent 特性:深入探索与实践指南
前端·javascript·react.js·前端框架
EndingCoder1 分钟前
React从基础入门到高级实战:React 生态与工具 - React Query:异步状态管理
前端·javascript·react.js·前端框架
TE-茶叶蛋3 分钟前
ReactJS 中的 JSX工作原理
前端·react.js·前端框架
水煮白菜王3 分钟前
React 编译器
前端·react.js·前端框架
霸王蟹4 分钟前
React 项目中封装 Excel 导入导出组件:技术分享与实践
前端·笔记·学习·react.js·typescript·excel·vite
wl_4 分钟前
react-color-palette源码解析
前端·react.js·调色板
集成显卡9 分钟前
图片压缩工具 | Electron+Vue3+Rsbuild开发桌面应用
前端·javascript·electron·vue
赵庆明老师13 分钟前
webpack打包基本配置
前端·webpack·node.js
偷光29 分钟前
现代 CSS 高阶技巧:实现平滑内凹圆角的工程化实践
前端·css·小程序
Blossom.1181 小时前
人工智能在智能供应链中的创新应用与未来趋势
前端·人工智能·深度学习·安全·机器学习