let _Http = getApp().globalData.http;
Page({
    data: {
        detail: null,
        list: [],
        showPage: "转化客户信息",
        showItemList: [{
            label: "客户地址",
            key: 'address'
        }, {
            label: "企业税号",
            key: 'taxno'
        }, {
            label: "医院类型",
            key: 'type'
        }, {
            label: "负责人",
            key: 'leaderName'
        }, {
            label: "负责手机号",
            key: 'phonenumber'
        }, {
            label: "成交状态",
            key: 'tradingstatus'
        }, {
            label: "最近跟进时间",
            key: 'followdate'
        }, {
            label: "归属应用",
            key: 'systemapp'
        }]
    },
    onLoad(options) {
        let detail = JSON.parse(options.data),
            customersnote = detail.customersnote;
        let industry = []
        try {
            industry = JSON.parse(customersnote.industry)
        } catch (error) {}
        /*  {
                label: "客户等级",
                value: customersnote.customergrade
            }, */
        this.setData({
            detail,
            showMsgList: [{
                label: "客户名称",
                value: customersnote.enterprisename
            }, {
                label: "企业简称",
                value: customersnote.abbreviation
            }, {
                label: "医院类型",
                value: customersnote.type
            }, {
                label: "客户分类",
                value: customersnote.customergrade
            }, {
                label: "联系人",
                value: customersnote.contactsinfo.name
            }, {
                label: "联系方式",
                value: customersnote.contactsinfo.phonenumber || customersnote.contactsinfo.telephone
            }, {
                label: "客户行业",
                value: industry.length ? industry.join(",") : ''
            }, {
                label: "税号",
                value: customersnote.taxno
            }, {
                label: "法人",
                value: customersnote.contact
            }, {
                label: "联系电话",
                value: customersnote.phonenumber
            }, {
                label: "省市县",
                value: [customersnote.province, customersnote.city, customersnote.county]
            }, {
                label: "详细地址",
                value: customersnote.address
            }, {
                label: "上级企业",
                value: customersnote.parent_enterprisename
            }, {
                label: "客户来源",
                value: customersnote.source
            }, {
                label: "归属经销商",
                value: customersnote.agents_enterprisename
            }]
        })
        this.queryRepetition()
    },
    /* 查询是否重复 */
    queryRepetition(e) {
        _Http.basic({
            "id": 20221208172002,
            content: {
                pageSize: 9999,
                ...this.data.detail.customersnote
            }
        }).then(res => {
            console.log("客户查重", res)
            if (res.code == 0) return wx.showToast({
                title: res.msg,
                icon: "none"
            });
            if (res.data.length) {
                this.setData({
                    list: res.data.map(v => {
                        try {
                            v.leaderName = v.leader[0].name
                        } catch (error) {
                            v.leaderName = ""
                        }
                        return v
                    }),
                    showPage: "重复客户",
                })
                wx.showModal({
                    content: `查询到${res.data.length}条疑似重复客户信息\n
                    当前线索不可转化客户`,
                    confirmText: "我知道了",
                    showCancel: false
                })
            }
        })
    },
    tabChange({
        detail
    }) {
        this.setData({
            showPage: detail.title
        })
    },
    handleAudit(e) {
        let status = e.currentTarget.dataset.type;
        wx.showLoading({
            title: '操作中...',
        })
        _Http.basic({
            "id": 20240907134204,
            "content": {
                "sat_orderclueid": this.data.detail.sat_orderclueid,
                status
            }
        }).then(res => {
            console.log(status + "审核", res)
            wx.hideLoading()
            wx.showToast({
                title: res.code == 0 ? res.msg : '操作成功',
                icon: "none",
                mask: res.code == 1
            });
            if (res.code == 1) {
                getCurrentPages().forEach(v => {
                    if (v.__route__ == 'packageA/saleClue/detail') v.getDetail()
                })
                setTimeout(() => {
                    wx.navigateBack()
                }, 800)
            }
        })
    }
})