<template>
    <span>
        <el-button  type="primary" icon="el-icon-search" class="m-inputbtn-btn" @click="onDialogOpen"></el-button>
        <el-dialog title="机构选择" :visible.sync="dialogOpen">
            <!-- <el-form size="mini" :inline="true">
                 <el-form-item>
                    <el-input v-model="model.ptyname" placeholder="请输入机构名称" />
                </el-form-item>
                <el-form-item>
                    <el-button  type="primary" icon="el-icon-search" @click="searchPty">查询</el-button>
                </el-form-item>                
            </el-form> -->
            <el-table :data="model.ptyData" size="mini" height="270"
                @row-dblclick="selectRow"
                v-loading="loading"
            >
                <el-table-column property="extkey" label="客户号" width="130"></el-table-column>
                <el-table-column property="nam" label="中文名称" width="230"></el-table-column>
                <el-table-column property="adr" label="中文地址" width="270"></el-table-column>
                <el-table-column property="nam1" label="英文名称1" width="120"></el-table-column>
                <el-table-column property="nam2" label="英文名称2" width="120"></el-table-column>
                <el-table-column property="tel" label="电话" width="100"></el-table-column>
            </el-table>
            <el-pagination
                layout="prev, pager, next"
                :total="1">
            </el-pagination>
        </el-dialog>
    </span>
</template>
<script>
import Api from "~/service/Api"
import Utils from "~/utils"

export default {
    props:['service','flag','extkey','ctx'],
    data(){
        return {
            dialogOpen:false,
            loading:true,
            model:{
                ptyname:"",
                ptyData:[]
            }
        }
    },
    methods:{
        onDialogOpen(){
            this.dialogOpen = true
            this.searchPty() //默认查询
        },
        async searchPty(){
            let rtnmsg = await Api.post(this.service,{params: {flg:this.flag,extkey:this.extkey},data: {}})
            if(rtnmsg.code == SUCCESS)
            {
                this.model.ptyData = rtnmsg.data
            }
            this.loading = false
        },
        selectRow(row){
            //model[`${prefix}_extkey`] = row.extkey || ""
            
            let adrblk=''
            let nam =row.nam
            let adr=row.adr
			let nam1=row.nam1|| ""
			let nam2=row.nam2|| ""
			let str1=row.str1|| ""
            let str2=row.str2|| ""
            let ptyinr=row.ptyinr|| ""
			if (nam1)
				adrblk=nam1
			if (nam2)
				adrblk=adrblk+"\r\n"+nam2
			if (str1)
				adrblk=adrblk+"\r\n"+str1
			if (str2)
				adrblk=adrblk+"\r\n"+str2
            // model[`${prefix}_adrblk`] = adrblk;
            this.ctx.extkey = row.extkey || ""
            this.ctx.adrblk = adrblk   
            this.ctx.namcn = nam
            this.ctx.adrcn = adr
            this.ctx.ptyinr = ptyinr
            this.dialogOpen = false
            // model[`${prefix}_namcn`] = nam; 
            // model[`${prefix}_adrcn`] = adr; 
            // model[`${prefix}_ptyinr`] = ptyinr; 
        }
    }
}
</script>