let _Http = getApp().globalData.http;
Component({
    properties: {
        callback: {
            type: Function
        },
        queryClient: {
            type: Function
        }
    },
    data: {
        queryShow: false,
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    methods: {
        /* 引入 */
        introduce(e) {
            let {
                item
            } = e.currentTarget.dataset,
                that = this;
            wx.showModal({
                title: getApp().globalData.Language.getMapText('提示'),
                content: getApp().globalData.Language.getMapText('是否确定引入') + `“${item.companyName}”` + getApp().globalData.Language.getMapText('信息'),
                cancelText: getApp().globalData.Language.getMapText('取消'),
                confirmText: getApp().globalData.Language.getMapText('确定'),
                complete: (res) => {
                    if (res.confirm) {
                        _Http.basic({
                            id: 2024060715002601,
                            content: {
                                companyName: item.companyName,
                            }
                        }).then(res => {
                            console.log("工商详情查询", res)
                            res.data.regProvince = item.regProvince;
                            that.setData({
                                queryShow: false,
                                queryList: null
                            })
                            that.triggerEvent("callback", res.data)
                        })
                    }
                }
            })
        },
        /* 工商查询 */
        queryClient(enterprisename) {
            _Http.basic({
                id: 20221208103601,
                content: {
                    pageNumber: 1,
                    pageTotal: 1,
                    pageSize: 5,
                    keyword: enterprisename,
                }
            }).then(res => {
                console.log("工商查询", res)
                if (!res.data[0]) return wx.showToast({
                    title: getApp().globalData.Language.getMapText('未查询到相关企业') + '！',
                    icon: "none"
                });
                this.setData({
                    queryList: res.data.map(v => {
                        for (const key in v) {
                            if (v[key] == "-") v[key] = ''
                        }
                        return v
                    }),
                    queryShow: true
                })
            })
        },
        openQuery() {
            this.triggerEvent("queryClient")
        },
        onClose() {
            this.setData({
                queryShow: false
            })
        },
    }
})