const _Http = getApp().globalData.http;
Component({
    properties: {
        ptype: {
            type: String,
            value: "浏览"
        },
        dataId: {
            type: String,
            value: ''
        },
        dataAuth: {
            type: String,
            value: '' //all 内部 经销商
        }
    },
    data: {
        actions: [{
            name: '',
            color: '#3874F6'
        }],
        actionShow: false,
        active: "经销商"
    },
    lifetimes: {
        ready() {
            let params = {
                "classname": "saletool.notice.data", //默认通告
                "method": "getSaleareaInfo", //默认经销商
                "content": {
                    sat_noticeid: this.data.dataId,
                    "sat_coursewareid": this.data.dataId
                }
            };
            if (this.data.ptype == '学习') params.classname = "saletool.courseware.data";
            if (this.data.dataAuth != 'all') {
                params.method = this.data.dataAuth == '内部' ? 'getInternalInfo' : 'getSaleareaInfo'
                this.setData({
                    active: this.data.dataAuth
                })
            };
            this.setData({
                params
            })
            this.getData();
        },
    },
    options: {
        addGlobalClass: true
    },
    methods: {
        onChange(e) {
            let {
                name
            } = e.detail;
            this.setData({
                active: name,
                "params.method": name == '内部' ? 'getInternalInfo' : 'getSaleareaInfo'
            });
            this.getData();
        },
        getData() {
            _Http.basic(this.data.params).then(res => {
                console.log(this.data.active, "学习数据", res)
                this.setData({
                    list: res.data,
                    tips: res.tips
                });
            })
        },
        callOut(e) {
            const {
                item
            } = e.currentTarget.dataset;
            this.setData({
                'actions[0].name': '呼叫 ' + item.phonenumber,
                actionShow: true
            })

        },
        handleCallOut(e) {
            let phone = e.detail.name.split(' ')[1];
            wx.makePhoneCall({
                phoneNumber: phone,
                success() {},
                fail() {}
            })
        },
        onClose() {
            this.setData({
                'actions[0].name': '',
                actionShow: false
            })
        },
    }
})