const _Http = getApp().globalData.http;
Component({
    properties: {
        sat_orderclueid: {
            type: String
        }
    },
    lifetimes: {
        attached: function () {
            this.querySite();
            getApp().globalData.Language.getLanguagePackage(this)
        },
    },
    data: {
        show: false
    },
    methods: {
        querySite() {
            return new Promise((resolve, reject) => {
                _Http.basic({
                    "id": 20230814102104,
                    "content": {}
                }).then(res => {
                    console.log("查询可转站点", res)
                    if (res.code != '1') return reject()
                    this.setData({
                        siteList: res.data.filter(v => v.siteid != wx.getStorageSync('siteP').siteid).map(v => {
                            v.name = v.sitename;
                            return v
                        })
                    });
                    resolve(res.data.length)
                })

            })
        },
        showSite() {
            if (this.data.siteList.length) {
                this.setData({
                    show: true
                })
            } else {
                that.querySite().then(count => {
                    if (count == 0) return wx.showToast({
                        title: getApp().globalData.Language.getMapText('未查询到可转移站点'),
                        icon: "none",
                    })
                    this.setData({
                        show: true
                    })
                })
            }
        },
        onClose() {
            this.setData({
                show: false
            })
        },
        onSelect({
            detail
        }) {
            let that = this;
            wx.showModal({
                title: getApp().globalData.Language.getMapText('取消'),
                content: getApp().globalData.Language.getMapText('是否确定转移到') + `“${detail.sitename}”` + getApp().globalData.Language.getMapText('站点'),
                cancelText: getApp().globalData.Language.getMapText('取消'),
                confirmText: getApp().globalData.Language.getMapText('确定'),
                complete: ({
                    confirm
                }) => {
                    if (confirm) _Http.basic({
                        "accesstoken": "5371fad42310bda53730d7e685f48c0c",
                        "id": 20230809144804,
                        "content": {
                            "toSiteid": detail.siteid,
                            "sat_orderclueid": [that.data.sat_orderclueid]
                        }
                    }).then(res => {
                        wx.showToast({
                            title: res.code == '1' ? getApp().globalData.Language.getMapText('成功转移到') + `“${detail.sitename}”` + getApp().globalData.Language.getMapText('站点') : res.msg,
                            icon: "none"
                        })
                    })
                }
            })
        }
    }
})