const _Http = getApp().globalData.http;
Component({
    properties: {
        sa_projectid: {
            type: String
        },
        disabled: {
            type: Boolean
        },
        isInsert: {
            type: Boolean
        }
    },
    lifetimes: {
        attached: function () {
            if (wx.getStorageSync('siteP').siteid == 'HY') {
                this.setData({
                    typeList: this.data.typeList.filter(v => v.name != '居间协议')
                })
            }
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    data: {
        typeShow: false,
        typeList: [{
            name: getApp().globalData.Language.getMapText('经销项目协议'),
            route: 'type2'
        }, {
            name: getApp().globalData.Language.getMapText('直销项目协议'),
            route: 'type3'
        }, {
            name: getApp().globalData.Language.getMapText('居间协议'),
            route: 'type4'
        }],
        "sa_projectid": 1,
        "content": {
            "nocache": true,
            "sa_projectid": 1,
            pageNumbe: 1,
            pageTotal: 1,
            total: null,
            "where": {
                "conditino": ""
            }
        }
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    methods: {
        getList(id, init) {
            let content = this.data.content;
            content.sa_projectid = id;
            if (init) content.pageNumber = 1
            _Http.basic({
                "id": "20221223102102",
                content
            }).then(res => {
                console.log("关联合同列表", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                this.setData({
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    "content.pageNumber": res.pageNumber + 1,
                    "content.pageSize": res.pageSize,
                    "content.pageTotal": res.pageTotal,
                    "content.sa_projectid": id,
                    "content.total": res.total,
                    sa_projectid: id,
                })
            })
        },
        /* 修改总数 */
        changeTotal() {
            this.setData({
                "content.total": this.data.content.total - 1
            })
        },
        /* 去添加 */
        openType() {
            if (this.data.isInsert) {
                this.setData({
                    typeShow: true
                })
            } else {
                wx.showModal({
                    title: getApp().globalData.Language.getMapText('提示'),
                    content: getApp().globalData.Language.getMapText('当前项目未审核或报备审核未通过，不可创建合同'),
                    showCancel: false,
                    confirmText: getApp().globalData.Language.getMapText('确定'),
                })
            }
        },
        typeCancel() {
            this.setData({
                typeShow: false
            })
        },
        /* 选择添加报价形式 */
        typeSelect({
            detail
        }) {
            let page = getCurrentPages()[getCurrentPages().length - 1];
            wx.navigateTo({
                url: `/packageA/contract/add/${detail.route}/index?project=${JSON.stringify(page.data.detail)}`,
            })
            this.typeCancel();
        },
    }
})