const _Http = getApp().globalData.http;
Page({
    data: {
        filtrate: false,
        content: {
            "isExport": 0,
            "nocache": true,
            "version": 1,
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": "",
            },
            "sort": []
        }
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '公海线索');
        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();
        let filtratelist = [];
        _Http.basic({
            "id": 20221223141802,
            "content": {
                "pageNumber": 1,
                "pageSize": 9999,
                "where": {
                    "condition": ""
                }
            }
        }, false).then(res => {
            console.log("获取领域", res)
            if (res.code == '1') {
                filtratelist.push({
                    label: "领域",
                    index: null,
                    showName: "tradefield", //显示字段
                    valueKey: "tradefield", //返回Key
                    selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
                    value: "", //选中值
                    list: res.data
                })
                this.setData({
                    filtratelist
                })
            }
        })
        _Http.basic({
            "id": 20221013104401,
            "content": {
                "nochace": true,
                "isExport": 1,
                "pageNumber": 1,
                sys_systemtagid: 14,
                "pageSize": 1000,
                "where": {
                    "condition": ""
                }
            }
        }, false).then(res => {
            console.log("获取标签", res)
            if (res.code == '1') {
                filtratelist.push({
                    label: "标签",
                    index: null,
                    type: "checkbox",
                    showName: "tag", //显示字段
                    valueKey: "tag", //返回Key
                    selectKey: "tag", //传参 代表选着字段 不传参返回整个选择对象
                    value: "", //选中值
                    list: res.data
                })
                this.setData({
                    filtratelist
                })
            }
        })
        _Http.basic({
            "classname": "sysmanage.develop.optiontype.optiontype",
            "method": "optiontypeselect",
            "content": {
                "typename": "cluesourcesift"
            }
        }).then(res => {
            console.log("获取来源", res)
            if (res.code == '1') {
                filtratelist.push({
                    label: "来源",
                    index: null,
                    showName: "value", //显示字段
                    valueKey: "cluesource", //返回Key
                    selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
                    value: "", //选中值
                    list: res.data
                })
                this.setData({
                    filtratelist
                })
            }
        })
    },
    onClick() {
        this.setData({
            filtrate: true
        })
    },
    /* 处理筛选 */
    handleFilter({
        detail
    }) {
        detail.condition = this.data.content.where.condition;
        this.data.content.where = detail;
        this.getList(true)
    },
    /* 获取列表 */
    getList(init = false) {
        _Http.init(this.data.content, init).then(content => {
            _Http.basic({
                "id": 20221101094402,
                content
            }).then(res => {
                console.log("公海线索", res)
                this.selectComponent('#ListBox').RefreshToComplete();
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                this.setData({
                    content: _Http.paging(content, res),
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    loading: false,
                })
                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();
    }
})