const _Http = getApp().globalData.http;
Component({
    properties: {
        list: {
            type: Array
        },
        ownertable: {
            type: String
        },
        ownerid: {
            type: Number
        },
        teamleaderId: {
            type: String
        },
        ismyteam: {
            type: Boolean,
            value: false
        }
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
            this.setData({
                userid: wx.getStorageSync('userMsg').userid,
            })
        }
    },
    options: {
        addGlobalClass: true
    },
    data: {
        show: false,
        changeItem: {},
        loading: false
    },
    methods: {
        /* 处理删除 */
        handleDelete(e) {
            const {
                item
            } = e.currentTarget.dataset;
            wx.showModal({
                title: getApp().globalData.Language.getMapText('提示'),
                content: `是否确认移除${item.name}?`,
                cancelText: getApp().globalData.Language.getMapText('取消'),
                confirmText: getApp().globalData.Language.getMapText('确定'),
                complete: ({
                    confirm
                }) => {
                    if (confirm) _Http.basic({
                        "accesstoken": "7eb155cb0a9ed5895056afc151af7d7f",
                        "id": 20220930103801,
                        "content": {
                            "ownertable": item.ownertable,
                            "ownerid": item.ownerid,
                            "userids": [item.userid]
                        }
                    }).then(s => {
                        wx.showToast({
                            title: s.code == '1' ? '移除成功!' : s.msg,
                            icon: "none"
                        });
                        if (s.code == '1') getCurrentPages().find(v => v.__route__ == "pages/group/index").getList();
                    })
                }
            })
        },
        /* 更换负责人 */
        changeUser() {
            wx.navigateTo({
                url: `/pages/group/select?data=${JSON.stringify({
                     ownertable:this.data.ownertable,
                     ownerid:this.data.ownerid,
                })}&radio=true&model=List&principal=true`,
            })
        },
        /* 更换负责人 */
        handelSubmit(arr) {
            const that = this;
            wx.showModal({
                title: getApp().globalData.Language.getMapText('提示'),
                content: getApp().globalData.Language.getMapText('是否确认更换负责人'),
                cancelText: getApp().globalData.Language.getMapText('取消'),
                confirmText: getApp().globalData.Language.getMapText('确定'),
                complete: ({
                    confirm
                }) => {
                    if (confirm) wx.showModal({
                        title: getApp().globalData.Language.getMapText('提示'),
                        content: getApp().globalData.Language.getMapText('是否参与该数据的后续工作'),
                        cancelText: getApp().globalData.Language.getMapText('不参与'),
                        confirmText: getApp().globalData.Language.getMapText('参与'),
                        complete: (s) => {
                            _Http.basic({
                                "id": 20220930103701,
                                "content": {
                                    ownertable: that.data.ownertable,
                                    ownerid: that.data.ownerid,
                                    userid: arr[0],
                                    isaddoldleader: s.confirm ? 1 : 0
                                }
                            }).then(res => {
                                console.log("更换负责人", res)
                                if (res.code != '1') return wx.showToast({
                                    title: res.data,
                                    icon: "none"
                                });
                                wx.showToast({
                                    title: getApp().globalData.Language.getMapText('更换成功'),
                                    icon: "none"
                                });
                                setTimeout(() => {
                                    getCurrentPages().forEach(v => {
                                        if (["packageA/project/index", "ackageA/setclient/index", "pages/group/index"].includes(v.__route__)) {
                                            v.getList(true);
                                        } else if (["packageA/setclient/detail", "packageA/project/detail"].includes(v.__route__)) {
                                            // v.getDetail()
                                        }
                                    })
                                    wx.navigateBack({
                                        delta: 2
                                    });
                                }, 300)
                            })

                        }
                    })
                }
            })
        },
        changeRadio(e) {
            this.setData({
                'changeItem.editable': e.currentTarget.dataset.name
            })
        },
        openPopup(e) {
            const {
                item
            } = e.currentTarget.dataset;
            this.setData({
                changeItem: item,
                show: true
            })
        },
        onCancel() {
            this.setData({
                changeItem: {},
                show: false
            })
        },
        onConfirm() {
            let that = this;
            this.setData({
                loading: true
            })
            _Http.basic({
                "id": "20230302183101",
                "content": {
                    "editable": this.data.changeItem.editable,
                    "sys_datateamid": this.data.changeItem.sys_datateamid
                },
            }).then(res => {
                that.setData({
                    loading: false
                })
                wx.showToast({
                    title: res.code == '1' ? '设置成功' : res.msg,
                    icon: "none"
                })
                if (res.code == '1') {
                    getCurrentPages().find(v => v.__route__ == "pages/group/index").getList();
                    that.onCancel()
                }
            })
        }
    }
})