const _Http = getApp().globalData.http;
Page({
    data: {
        domainList: [],
        active: "",
        createYear: new Date().getFullYear()
    },
    onLoad(options) {
        let domainList = options.domainList.split(",").filter(v => v != '全部')
        this.setData({
            domainList,
            active: domainList[0] || ""
        })
    },
    /* 选择领域 */
    selector(e) {
        this.setData({
            active: e.currentTarget.dataset.item
        })
    },
    selectorYear(e) {
        this.setData({
            createYear: e.detail.value,
        })
    },
    /* 创建年度 */
    addObjective() {
        let that = this;
        let page = getCurrentPages().find(v => v.__route__ == 'packageA/contract/detail').selectComponent("#Objective");
        wx.showModal({
            title: '提示',
            content: `是否确定创建${that.data.createYear}年度${that.data.active}领域业绩目标`,
            complete: (res) => {
                if (res.confirm) _Http.basic({
                    "id": 20221229104202,
                    "content": {
                        "year": that.data.createYear,
                        "sa_salestargetbillid": 0, //新建年度是为0，添加人员时为具体的数据id
                        "sys_enterpriseid": page.data.content.sys_enterpriseid,
                        "sa_contractid": page.data.content.sa_contractid,
                        tradefield: that.data.active
                    }
                }).then(res => {
                    console.log("新建年度", res)
                    if (res.msg != '成功') return wx.showToast({
                        title: res.msg,
                        icon: "none"
                    });
                    let i = page.data.yearArr.findIndex(v => v == that.data.createYear);
                    if (i == -1) page.data.yearArr.push(that.data.createYear);
                    page.setData({
                        yearArr: page.data.yearArr,
                        pickerIndex: i == -1 ? page.data.yearArr.length - 1 : i,
                        "content.where.year": that.data.createYear,
                        "content.where.tradefield": "",
                        domainIndex: 0
                    });
                    wx.navigateBack()
                    // page.editObjective();
                    page.getList1(true, true)
                })
            }
        })
    },
})