let _Http = getApp().globalData.http;
Component({
    properties: {
        list: {
            type: Array
        },
        detele: {
            type: Boolean
        },
        edit: {
            type: Boolean
        }
    },
    options: {
        addGlobalClass: true
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    methods: {
        handleItem(e) {
            let {
                item
            } = e.currentTarget.dataset;
            wx.showModal({
                title: getApp().globalData.Language.getMapText('提示'),
                content: item.important ? getApp().globalData.Language.joint([{
                    t: 1,
                    v: '是否设置',
                    r: " "
                }, {
                    v: item.enterprisename,
                    r: " "
                }, {
                    t: 1,
                    v: '为主要威胁',
                    r: "？"
                }]) : getApp().globalData.Language.joint([{
                    t: 1,
                    v: '是否取消设置',
                    r: " "
                }, {
                    v: item.enterprisename,
                    r: " "
                }, {
                    t: 1,
                    v: '为主要威胁',
                    r: "？"
                }]),
                cancelText: getApp().globalData.Language.getMapText('取消'),
                confirmText: getApp().globalData.Language.getMapText('确定'),
                complete: (res) => {
                    if (res.confirm) {
                        item.important = item.important == 0 ? 1 : 0;
                        _Http.basic({
                            id: "20221019165802",
                            content: item
                        }).then(res => {
                            wx.showToast({
                                title: res.code == '1' ? getApp().globalData.Language.getMapText('设置成功') : res.msg,
                                icon: "none"
                            });
                            let page = getCurrentPages()[getCurrentPages().length - 1].selectComponent("#Opponent");
                            if (page) {
                                let i = page.data.list.findIndex(v => v.sa_competitorid == item.sa_competitorid);
                                if (i != -1) page.setData({
                                    [`list[${i}]`]: item
                                });
                            }
                        })
                    }
                }
            })
        }
    }
})