const getTime = require("../../../../../utils/getTime"),
    deleteMark = require("../../../../../utils/deleteMark"),
    _Http = getApp().globalData.http;
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        endChange: Function,
        sat_orderclueid: Number
    },

    /**
     * 组件的初始数据
     */
    data: {
        actionShow: false,
        time: "",
        actions: [{
            name: '电话沟通',
        }, {
            name: '当面沟通',
        }, {
            name: '微信沟通',
        }],
        "content": {
            "content": "",
            "followupmode": "",
            "logtype": "跟进",
            "competitor": ""
        },
        disabled: true,
        loading: false
    },
    /**
     * 组件的方法列表
     */
    methods: {
        submit() {
            if (this.data.disabled || this.data.loading) return;
            let content = this.data.content;
            content.sat_orderclueid = this.data.sat_orderclueid;
            this.setData({
                loading: true
            })
            _Http.basic({
                "classname": "saletool.orderclue.web.orderclue",
                "method": "addFollowUpLog",
                content
            }).then(res => {
                console.log(res)
                this.setData({
                    loading: false
                })
                if (res.msg != '成功') return wx.showToast({
                    title: res.msg,
                    icon: "none"
                });
                wx.showToast({
                    title: '保存成功!',
                })
                setTimeout(() => {
                    this.triggerEvent("endChange");
                }, 300);
            })
        },
        /* 打开选择跟进方式 */
        selectWay() {
            this.setData({
                actionShow: !this.data.actionShow
            })
        },
        /* 选择方式 */
        onSelect(e) {
            this.setData({
                "content.followupmode": e.detail.name
            })
            this.isDisabled();
        },
        /* 选择结果 */
        changeType(e) {
            if (e.target.dataset.name) this.setData({
                'content.logtype': e.target.dataset.name
            })
            this.isDisabled();
        },
        /* 输入框输入内容 */
        inputChange(e) {
            let text = e.type == 'input' ? e.detail.value : e.detail;
            text = deleteMark.queryStr(text);

            const {
                label
            } = e.currentTarget.dataset;

            this.setData({
                ["content." + label]: text
            })
            this.isDisabled();
        },
        isDisabled() {
            let data = this.data.content,
                disabled = (data.followupmode != '' && data.content != '') ? false : true;
            this.setData({
                disabled
            })
        },
        updateTime() {
            this.setData({
                time: getTime.formatTime(new Date(), "-")
            })
        }
    }
})