export const ZmMixin = {
  methods: {
    warn(msg) {
      this.$message({
        message: msg,
        type: 'warning'
      })
    },
    success(msg) {
      this.$message({
        message: msg,
        type: 'success'
      })
    },
    error(msg) {
      this.$message({
        message: msg,
        type: 'error'
      })
    },
    simpleConfirm(msg, bt = "确定") {
      return this.$alert(msg, {
        title: "提示",
        confirmButtonText: bt
      })
    },
    needConfirm(msg, sure = '确定', cancel = '取消') {
      return this.$confirm(msg, '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: sure,
        cancelButtonText: cancel
      })
    },
    zmRes(r) {
      if (r.data && r.data.code == 0) {
        return r.data.data || true
      } else {
        this.error(r.msg || '出错了！')
      }
    },
    checkEmpty(value, name) {
      //console.log("value = " + value + " name = " + name)
      if (value == undefined) {
        this.warn(name + "不能为空!")
        return false
      }
      return true
    },
    parseRange(param, key = "createTime") {
      if (param && param[key]) {
        return [param.createTime[0], param.createTime[1]]
      }
      return ['', '']
    },
    remain(v, digits = 2) {
      return Math.round(v * 10 * digits) / (10 * digits)
    }
  },
  computed: {
    isPermit() {
      return r => {
        return this.vaildData(this.permissions[r], false)
      }
    }
  },
  filters: {
    checkEmpty(r) {
      return (r == undefined || r == '') ? '--' : r
    }
  }
}
