const _Http = getApp().globalData.http;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        content: {
            "isExport": 0,
            "nocache": true,
            "version": 1,
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": "",
            },
            "sort": []
        }
    },
    onLoad(options) {
        this.setData({
            "content.type": wx.getStorageSync('templetList')[0].templetid,
            insert: wx.getStorageSync('auth').worderclue_public.options.some(v => v == 'insert'), //查询新增权限
            allot: wx.getStorageSync('auth').worderclue_public.options.some(v => v == 'allot')
        });
        this.getList();
    },
    /* 获取列表 */
    getList(init = false, data) {
        if (init.detail != undefined) init = init.detail;
        let content = this.data.content;
        if (init) content.pageNumber = 1;
        if (content.pageNumber > content.pageTotal) return;
        if (data) {
            content.where.type = data.typeActive
            content.where.status = data.statusActive;
            content.where.startdate = data.startdate;
            content.where.enddate = data.enddate;
        }
        _Http.basic({
            "id": 20221101094402,
            content
        }).then(res => {
            console.log("线索", res)
            this.selectComponent('#ListBox').RefreshToComplete();
            if (res.msg != '成功') return wx.showToast({
                title: res.data,
                icon: "none"
            })
            res.data = res.data.map(v => {
                v.progress = v.stage / v.totalstage * 100;
                return v
            })
            this.setData({
                'content.pageNumber': res.pageNumber + 1,
                'content.pageTotal': res.pageTotal,
                'content.total': res.total,
                'content.sort': res.sort,
                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
            });
            this.setListHeight();
            this.getTags();
        })
    },
    /* 处理搜索 */
    onSearch({
        detail
    }) {
        this.setData({
            "content.where.condition": detail
        });
        this.getList(true);
    },
    /* 获取列表标签 */
    getTags() {
        let list = this.data.list,
            ownerids = list.map(v => v.sat_orderclueid);
        _Http.basic({
            "id": 20221018102001,
            "content": {
                nocache: true,
                "ownertable": "sat_orderclue",
                ownerids
            }
        }).then(res => {
            console.log("标签", res)
            for (let key in res.data) {
                let index = list.findIndex(v => v.sat_orderclueid == key);
                list[index].tags = res.data[key]
            };
            this.setData({
                list
            })
        })
    },
    /* 去添加 */
    openType() {
        wx.navigateTo({
            url: '/packageA/publicClue/addClue',
        })
    },
    /* 选择添加报价形式 */
    typeSelect({
        detail
    }) {
        wx.navigateTo({
            url: detail.name == '项目报价' ? '/packageA/offers/addProjectOffer' : '/packageA/offers/addSetclientOffer',
        });
        this.typeCancel();
    },
    onReady() {
        this.setListHeight();
    },
    setListHeight() {
        this.selectComponent("#ListBox").setHeight(".total", this);
    },
    onShareAppMessage() {

    }
})