Date.prototype.Format =  function (fmt) {  // author: meizz 
  var o = {
     "M+":  this.getMonth() + 1,  // 月份 
     "d+":  this.getDate(),  // 日 
     "h+":  this.getHours(),  // 小时 
     "m+":  this.getMinutes(),  // 分 
     "s+":  this.getSeconds(),  // 秒 
     "q+": Math.floor(( this.getMonth() + 3) / 3),  // 季度 
     "S":  this.getMilliseconds()  // 毫秒 
 };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, ( this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for ( var k  in o)
  if ( new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

export function bindInput(event) {
  var obj = {},
    key = event.target.dataset['key'];
  obj[key] = event.detail.value;
  console.log(obj)
  this.setData(obj);
}

export function randomWord(randomFlag, min, max) {
  let str = "";
  let range = min;
  let arr = [
    "0",
    "1",
    "2",
    "3",
    "4",
    "5",
    "6",
    "7",
    "8",
    "9",
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "j",
    "k",
    "l",
    "m",
    "n",
    "o",
    "p",
    "q",
    "r",
    "s",
    "t",
    "u",
    "v",
    "w",
    "x",
    "y",
    "z",
    "A",
    "B",
    "C",
    "D",
    "E",
    "F",
    "G",
    "H",
    "I",
    "J",
    "K",
    "L",
    "M",
    "N",
    "O",
    "P",
    "Q",
    "R",
    "S",
    "T",
    "U",
    "V",
    "W",
    "X",
    "Y",
    "Z",
  ];
  // 随机产生
  if (randomFlag) {
    range = Math.round(Math.random() * (max - min)) + min;
  }
  for (var i = 0; i < range; i++) {
    let pos = Math.round(Math.random() * (arr.length - 1));
    str += arr[pos];
  }
  return str;
}
export function autoSubcrebe() {
  return new Promise(resolve => {
    wx.getSetting({
      withSubscriptions: true,
      success: (setting) => {
        let hasAuto = false
        if (setting && setting.subscriptionsSetting && setting.subscriptionsSetting.itemSettings && setting.subscriptionsSetting.itemSettings[subId]) {
          subcribe()
          hasAuto = true
        }
        resolve(hasAuto)
      }
    })
  })
  
}
export function isDef(value) {
  return value !== undefined && value !== null;
}
export function isObj(x) {
  const type = typeof x;
  return x !== null && (type === 'object' || type === 'function');
}
export function isNumber(value) {
  return /^\d+(\.\d+)?$/.test(value);
}
export function range(num, min, max) {
  return Math.min(Math.max(num, min), max);
}
export function nextTick(fn) {
  setTimeout(() => {
      fn();
  }, 1000 / 30);
}
let systemInfo = null;
export function getSystemInfoSync() {
  if (systemInfo == null) {
      systemInfo = wx.getSystemInfoSync();
  }
  return systemInfo;
}
export function addUnit(value) {
  if (!isDef(value)) {
      return undefined;
  }
  value = String(value);
  return isNumber(value) ? `${value}px` : value;
}
