import { formatTime } from "@/utils/common.js"
export const CommentMixin = {
    filters: {
        getSkuStr(list) {
            let strlist = []
            if (list instanceof Array) {
                for (let item of list) {
                    strlist.push(`${item.propKey}:${item.propVal}`)
                }
            }
            return strlist.join(' ')
        },
        getGoodsScore(val) {
            if (typeof val === 'number') {
                let str = val.toString()
                if (str.includes(".")) {
                    return str
                } else {
                    return str + ".0"
                }
            } else {
                return "0.0"
            }
        },
        getTime(val) {
            if (val) {
                return formatTime(new Date(val), "yyyy-MM-dd")
            }
        },
        timeDifference(val, creatDate) {
            let days = 0
            if (val) {
                const firstDate = formatTime(new Date(creatDate), "yyyy/MM/dd")
                const appendDate = formatTime(new Date(val), "yyyy/MM/dd")
                if (firstDate !== appendDate) {
                    let difference = new Date(appendDate).getTime() - new Date(firstDate).getTime()
                    days = difference / (1000 * 60 * 60 * 24)
                }
            }
            return 0
        }
    },
}