emis-frontend/src/views/emis/EmisBaseTools/GoodsInput.vue
2024-07-29 08:21:58 +08:00

166 lines
4.1 KiB
Vue

<template>
<div :id="createdId">
<el-popover
placement="bottom"
trigger="click"
ref="popoverRef"
:popper-options="{ boundariesElement: '.el-form', removeOnDestroy: true }"
>
<div >
<el-table
ref="comboGridTable"
v-loading="loading"
style="width: 100%;"
:data="optionItems"
@row-click="onRowClick"
:row-key="row => row.goodsCode"
stripe
:row-style="isRed"
element-loading-text="Loading"
>
<el-table-column label="序号" align="center" width="60">
<template slot-scope="scope">
<span v-text="getIndex(scope.$index)"> </span>
</template>
</el-table-column>
<el-table-column label="货物名称" align="left" prop="goodsName" width="100" />
<el-table-column label="英文名称" align="center" prop="goodsNameEn" width="150" :show-overflow-tooltip="true" />
</el-table>
<el-pagination v-show="pagination" small
:total="total"
:page-size="5"
layout="prev, pager, next, total"
@current-change="changePage"
/>
</div>
<el-input
slot="reference"
ref="inputValue"
:value="svalue"
:placeholder="placeholder"
@input="onInput"
@blur="onBlur"
@clear="onClear"
clearable
>
<!-- <template slot="suffix">
<i slot="suffix" class="el-icon-edit"></i>
</template> -->
</el-input>
</el-popover>
</div>
</template>
<script>
import emitter from 'element-ui/src/mixins/emitter';
import { listSimpleEmisGoods} from "@/api/emis/emisGoods";
import { debounce } from 'throttle-debounce'
export default {
name: "GoodsInput",
mixins: [emitter],
props: {
value: {
type: String,
required: false
},
placeholder:{
type: String,
required: false
},
disabled:{
type: [Boolean,String],
required: false
},
pagination: {
type: Boolean, default: true
},
},
data() {
return {
createdId: '0',
loading:false,
total:0,
optionItems: [],
svalue: this.value,
queryParams:{
pageNum:1,
pageSize:5,
goodsName:null,
searchValue:null,
}
};
},
watch: {
value(newVal,oldVal) {
this.svalue=this.value;
},
},
mounted() {
// 给个随机id 判断是否clickoutside
this.createdId = String(new Date().getTime())
},
created() {
this.svalue=this.value;
},
methods: {
onInput(val) {
this.svalue = val;
this.queryParams.pageNum = 1
this.queryParams.goodsName=val;
debounce(250, this.queryData() );
},
onRowClick(row, column, event) {
this.svalue=row.goodsName;
this.$emit("input", this.svalue);
this.$emit("onChange",row);
this.$refs.popoverRef.doClose();
},
isRed({ row }) {
if (row.goodsName == this.svalue) {
return {
"color": "red",
"font-weight": "bold",
};
}
},
onClear(el){
this.svalue = null;
this.$emit("input", this.svalue);
this.dispatch('ElFormItem', 'el.form.blur', [this.svalue]);
},
onBlur(el) {
this.$emit("input", this.svalue);
this.dispatch('ElFormItem', 'el.form.blur', [this.svalue]);
},
changePage(cur) {
this.queryParams.pageNum = cur
this.queryData()
},
queryData() {
this.loading = true;
listSimpleEmisGoods(this.queryParams).then(response => {
this.loading = false;
this.total = response.total;
this.optionItems = response.rows;
});
},
getIndex($index) {
return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + $index + 1
},
}
};
</script>