emis-frontend/src/views/emis/EmisBaseTools/CustomerAddressSimplePicker.vue

233 lines
5.8 KiB
Vue
Raw Normal View History

2024-05-07 04:53:57 +00:00
<template>
<div :id="createdId">
<el-popover
trigger="click"
ref="popoverRef"
effect="light"
:show-arrow="false"
>
2024-05-25 09:36:22 +00:00
<div >
2024-05-07 04:53:57 +00:00
<el-table
2024-05-25 09:36:22 +00:00
v-loading="loading"
2024-05-07 04:53:57 +00:00
ref="comboGridTable"
2024-05-25 09:36:22 +00:00
style="width: 100%;"
:data="optionItems"
@row-click="onRowClick"
:row-key="row => row.empCode"
stripe
:row-style="isRed"
element-loading-text="Loading"
2024-05-07 04:53:57 +00:00
>
<el-table-column :label="$t('名称')" align="left" prop="name" width="100" />
<el-table-column :label="$t('电话')" align="left" prop="phone" width="100" />
<el-table-column :label="$t('地址')" align="left" prop="country" width="100" :show-overflow-tooltip="true" >
<template slot-scope="scope">
<div>{{scope.row.countryName}}{{scope.row.provinceName}}{{scope.row.cityName}}{{scope.row.countyName}} {{scope.row.address}}</div>
</template>
</el-table-column>
<el-table-column :label="$t('公司')" align="left" prop="company" width="100" :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>
2024-05-25 09:36:22 +00:00
<el-input
slot="reference"
ref="inputValue"
:value="svalue"
:placeholder="placeholder"
@input="handleInput"
@focus="onFocus"
@blur="onBlur"
@clear="onClear"
clearable
>
<template slot="suffix">
<!-- <i class="el-icon-arrow-down select-down" :class="visible&&'rotate180'"></i> -->
<i slot="suffix" class="el-icon-search"></i>
</template>
</el-input>
2024-05-07 04:53:57 +00:00
</el-popover>
</div>
</template>
<script>
import emitter from 'element-ui/src/mixins/emitter';
2024-05-16 05:58:42 +00:00
import { listSimpleEmisCustomerAddress } from "@/api/emis/emisCustomerAddress";
2024-05-07 04:53:57 +00:00
export default {
name: "CustomerAddressSimplePicker",
mixins: [emitter],
props: {
value: {
type: [String, Number],
required: false
},
2024-06-08 13:10:56 +00:00
useSiteCode:{
type:[String,Number]
},
2024-05-07 04:53:57 +00:00
addressType:{
type:[String,Number]
},
2024-05-16 05:58:42 +00:00
countryCode:{
type:[String]
},
2024-05-07 04:53:57 +00:00
isInitiated:{
type: [Boolean,String],
required: false,
default:false
},
placeholder:{
type: String,
required: false
},
disabled:{
type: [Boolean,String],
required: false
},
pagination: {
type: Boolean, default: true
},
},
data() {
return {
createdId: '0',
loading:false,
2024-05-25 09:36:22 +00:00
2024-05-07 04:53:57 +00:00
total:0,
2024-05-25 09:36:22 +00:00
optionItems: [],
// 缺省值
defaultTotal:0,
defaultItems:null,
sId: null,
2024-05-07 04:53:57 +00:00
svalue: this.value,
2024-05-25 09:36:22 +00:00
isInputing: false,
2024-05-07 04:53:57 +00:00
queryParams:{
pageNum:1,
pageSize:5,
2024-05-25 09:36:22 +00:00
searchValue:null,
2024-06-08 13:10:56 +00:00
useSiteCode:this.useSiteCode,
2024-05-07 04:53:57 +00:00
addressType: this.addressType,
2024-05-16 05:58:42 +00:00
country:this.countryCode,
2024-05-07 04:53:57 +00:00
}
};
},
watch: {
2024-05-25 09:36:22 +00:00
value(newVal,oldVal) {
if(this.value!=null){
this.svalue=this.value;
}
2024-05-07 04:53:57 +00:00
},
2024-05-25 09:36:22 +00:00
countryCode(newVal){
this.queryParams.country=newVal;
this.defaultItems=null;
},
addressType(newVal){
this.queryParams.addressType=newVal;
this.defaultItems=null;
2024-05-25 23:07:16 +00:00
},
useSiteCode(newVal){
this.queryParams.useSiteCode=newVal;
this.defaultItems=null;
2024-05-16 05:58:42 +00:00
}
2024-05-07 04:53:57 +00:00
},
mounted() {
this.createdId = String(new Date().getTime()) // 给个随机id 判断是否clickoutside
},
created() {
2024-05-25 09:36:22 +00:00
if(this.svalue!=null){
this.svalue = this.value;
}
2024-05-07 04:53:57 +00:00
},
methods: {
2024-05-25 09:36:22 +00:00
onFocus(){
// 第一次点击时需要初始化
if(!this.defaultItems){
this.queryParams.pageNum=1;
this.queryData(null,null);
}else{
this.total = this.defaultTotal;
this.optionItems = [...this.defaultItems];
}
// this.$refs.popoverRef.doShow();
2024-05-07 04:53:57 +00:00
},
2024-05-25 09:36:22 +00:00
handleInput(val) {
if(val == null ) return;
this.isInputing = true;
this.svalue = val;
2024-05-07 04:53:57 +00:00
this.queryParams.pageNum = 1
2024-05-25 09:36:22 +00:00
this.queryData(val,null)
2024-05-07 04:53:57 +00:00
},
onRowClick(row, column, event) {
2024-05-25 09:36:22 +00:00
this.svalue=row.name;
2024-05-07 04:53:57 +00:00
2024-05-25 09:36:22 +00:00
this.isInputing = false;
this.sId=row.id;
2024-05-07 04:53:57 +00:00
2024-05-25 09:36:22 +00:00
this.$emit("input", this.svalue);
2024-05-07 04:53:57 +00:00
this.$emit("onChange",row);
this.$refs.popoverRef.doClose();
},
2024-05-25 09:36:22 +00:00
isRed({ row }) {
if (row.id == this.sId) {
return {
"color": "red",
"font-weight": "bold",
};
}
},
2024-05-07 04:53:57 +00:00
changePage(cur) {
this.queryParams.pageNum = cur
2024-07-21 03:43:45 +00:00
this.queryData(this.queryParams.searchValue)
2024-05-07 04:53:57 +00:00
},
2024-05-25 09:36:22 +00:00
onClear(el){
this.svalue = null;
2024-05-07 04:53:57 +00:00
this.$emit("input", this.svalue);
2024-05-15 05:41:09 +00:00
this.dispatch('ElFormItem', 'el.form.blur', [this.svalue]);
2024-05-07 04:53:57 +00:00
},
2024-05-25 09:36:22 +00:00
onBlur(el) {
this.$emit("input", this.svalue);
this.dispatch('ElFormItem', 'el.form.blur', [this.svalue]);
2024-05-07 04:53:57 +00:00
},
2024-05-25 09:36:22 +00:00
queryData(val,key) {
2024-05-07 04:53:57 +00:00
this.loading = true;
2024-05-25 09:36:22 +00:00
this.loading = true;
this.queryParams.searchValue = val;
2024-05-07 04:53:57 +00:00
2024-05-16 05:58:42 +00:00
listSimpleEmisCustomerAddress(this.queryParams).then(response => {
2024-05-07 04:53:57 +00:00
this.loading = false;
this.total = response.total;
2024-05-25 09:36:22 +00:00
this.optionItems = response.rows;
// 初始值存储
if(key==null && val==null){
this.defaultTotal = this.total+0;
this.defaultItems=[...this.optionItems]
}
2024-05-07 04:53:57 +00:00
});
},
getIndex($index) {
return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + $index + 1
},
}
};
</script>