import {
    ApiModel
} from "../../../utils/api";
const _Http = new ApiModel();
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        //数据
        itemData: {
            type: Object
        },
        //创建者id
        role: {
            type: Boolean
        },
        //是否显示底部
        isShowBottom: {
            type: Boolean,
            value: true
        }
    },

    /**
     * 组件的初始数据
     */
    data: {},

    /**
     * 组件的方法列表
     */
    methods: {
        change() {
            this.setData({
                role: !this.data.role
            })
        },
        //浏览图片
        preViewImage(e) {
            const {
                type,
                url
            } = e.target.dataset;
            if (type == "emoji") return;
            let urls = [];
            urls.push(url)
            wx.previewImage({
                urls: urls,
            })
        },
        //去查看统计
        toStats(e) {
            const {
                type
            } = e.target.dataset;
            if (type != undefined) wx.navigateTo({
                url: '/pages/chatRoom/stats?type=' + type + '&timsubjectid=' + this.data.itemData.timsubjectid + '&timdialogid=' + this.data.itemData.timdialogid,
            })
        },
        //回复话题
        writBack() {
            // return console.log(this.data.itemData)
            _Http.basic({
                "accesstoken": wx.getStorageSync('userData').token,
                "classname": "system.im.imdialog.imdialog",
                "method": "subjectAnswer",
                "content": {
                    "timsubjectid": this.data.itemData.timsubjectid
                }
            }).then(res => {
                console.log("回复话题", res)
                if (res.msg != '成功') return wx.showToast({
                    title: res.data,
                    icon: "none"
                });
                _Http.basic({
                    "accesstoken": wx.getStorageSync('userData').token,
                    "classname": "system.im.imdialog.imdialog",
                    "method": "quickcontact",
                    "content": {
                        "tenterprise_userid": this.data.itemData.sendfrom.userid,
                        "message": this.data.itemData
                    }
                }).then(res => {
                    console.log("回复创建一对一聊天", res)
                    if (res.msg != '成功') return wx.showToast({
                        title: res.data,
                        icon: "none"
                    });
                    wx.navigateTo({
                        url: '/pages/chatRoom/dialogbox?id=' + res.data[0].timdialogid,
                    })
                })
            })
        }
    }
})