const _Http = getApp().globalData.http;
Component({
    properties: {
        list: Array,
        disabled: Boolean
    },
    data: {
        viewIndex: null
    },
    options: {
        addGlobalClass: true
    },
    methods: {
        selectClient(e) {
            if (!this.data.disabled) return;
            const {
                item
            } = e.currentTarget.dataset,
                pages = getCurrentPages(),
                page = pages[pages.length - 1];
            this.setData({
                taskname: item.taskname,
                content: {
                    sa_projectid: page.data.detail.sa_projectid,
                    sa_projtaskmagid: item.sa_projtaskmagid,
                    sa_projstagemagid: item.sa_projstagemagid,
                }
            })
            if (item.partiestype.length != 0) {
                wx.navigateTo({
                    url: '/packageA/select/setclient/select?params=' + JSON.stringify({
                        "id": 20221129152204,
                        content: {
                            nocache: true,
                            sa_projectid: page.data.detail.sa_projectid,
                            sa_projtaskmagid: item.sa_projtaskmagid,
                            where: {
                                condition: "",
                            }
                        },
                    }) + '&idname=sa_project_partiesid'
                });
                getApp().globalData.handleSelect = this.handleAdd.bind(this);
            } else {
                this.handleAdd({
                    result: []
                });
            }
        },

        handleAdd(e) {
            let content = this.data.content;
            content.sa_project_partiesids = e.result;
            if (e.result.length) {
                wx.redirectTo({
                    url: '/packageA/project/modules/task/add?content=' + JSON.stringify(content) + '&taskname=' + this.data.taskname,
                })
            } else {
                wx.navigateTo({
                    url: '/packageA/project/modules/task/add?content=' + JSON.stringify(content) + '&taskname=' + this.data.taskname,
                })
            }
        },

        viewHistory(e) {
            const {
                sa_projectid,
                sa_projtaskmagid,
                sa_projstagemagid
            } = e.currentTarget.dataset.item,
                content = {
                    nocheca: true,
                    sa_projectid,
                    sa_projtaskmagid,
                    sa_projstagemagid,
                    pageNumber: 1,
                    pageTotal: 1,
                    pageSize: 20
                };
            if (!content.sa_projectid) {
                let page = getCurrentPages().find(v => v.__route__ == 'packageA/project/detail');
                content.sa_projectid = page.data.detail.sa_projectid;
            }
            wx.navigateTo({
                url: '/packageA/project/modules/task/history?content=' + JSON.stringify(content),
            })
        }
    }
})