var _this = this;

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import dayjs from "dayjs";
export var guid = function guid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    var r = Math.random() * 16 | 0;
    var v = c == 'x' ? r : r & 0x3 | 0x8;
    return v.toString(16);
  });
}; // 如果你想禁用第一次首先执行的话，传递{leading: false}，还有如果你想禁用最后一次执行的话，传递{trailing: false}。
// 默认是 第一次首先执行并且最后一次会执行，相当于 {leading: true, trailing: true}

export var throttle = function throttle(func, wait, options) {
  var previous = 0;
  var timeout = null;
  var context;
  var args;
  if (!options) options = {};

  var later = function later() {
    previous = options.leading === false ? 0 : new Date().getTime();
    timeout = null;
    func.apply(context, args);

    if (!timeout) {
      context = null;
      args = [];
    }
  };

  var throttled = function throttled() {
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    var now = new Date().getTime();
    if (!previous && options.leading === false) previous = now;
    var remaining = wait - (now - previous);
    context = this;

    if (remaining <= 0 || remaining > wait) {
      if (timeout) {
        clearTimeout(timeout);
        timeout = null;
      }

      previous = now;
      func.apply(context, args);

      if (!timeout) {
        context = null;
        args = [];
      }
    } else if (!timeout && options.trailing !== false) {
      timeout = setTimeout(later, remaining);
    }
  };

  return throttled;
};
/**
 * 防抖
 * @param {*} fn 将执行的函数
 * @param {*} time 防抖规定的时间
 */

export var debounce = function debounce(fn) {
  var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 800;
  var timer = null;
  return function () {
    for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }

    if (timer) clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(_this, args);
    }, delay);
  };
};
export var extendClone = Object.assign;
export var deepClone = function deepClone(data) {
  var cloneData = null;

  if (Array.isArray(data)) {
    cloneData = [];

    for (var i = 0; i < data.length; i += 1) {
      var item = data[i];
      cloneData[i] = deepClone(item);
    }
  } else if (_typeof(data) === 'object' && data !== null) {
    cloneData = {};
    Object.keys(data).forEach(function (key) {
      var item = data[key];
      cloneData[key] = deepClone(item);
    });
  } else {
    cloneData = data;
  }

  return cloneData;
};
export var to = function to(promise) {
  // eslint-disable-next-line no-prototype-builtins
  if (!promise || !Promise.prototype.isPrototypeOf(promise)) {
    return new Promise(function (resolve, reject) {
      reject(new Error('requires promises as the param'));
    }).catch(function (err) {
      return [err, null];
    });
  }

  return promise.then(function () {
    for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
      args[_key3] = arguments[_key3];
    }

    return [null].concat(args);
  }).catch(function (err) {
    return [err];
  });
};
export var sync = function sync(fn) {
  for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
    args[_key4 - 1] = arguments[_key4];
  }

  return new Promise(function (resolve, reject) {
    var obj = _objectSpread({}, args[0]);

    var success = obj.success;

    obj.success = function () {
      for (var _len5 = arguments.length, params = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
        params[_key5] = arguments[_key5];
      }

      success && success.apply.apply(success, [this].concat(params));
      var r = params.length > 1 ? params : params[0];
      resolve(r);
    };

    var fail = obj.fail;

    obj.fail = function () {
      for (var _len6 = arguments.length, params = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
        params[_key6] = arguments[_key6];
      }

      fail && fail.apply.apply(fail, [this].concat(params));
      var r = params.length > 1 ? params : params[0];
      reject(r);
    };

    fn(obj);
  });
}; //时间初始化

export var init_date = function init_date(date) {
  var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD HH:mm:ss';
  return date ? dayjs(date).format(format) : dayjs().format(format);
}; //时间戳初始化

export var init_time = function init_time(time) {
  return time ? dayjs.unix(time) : dayjs().unix();
}; //时间差

export var less_time = function less_time(time1, time2) {
  var array_time1 = time1.split(":");
  var array_time2 = time2.split(":");
  var new_time1 = dayjs().hour(Number(array_time1[0])).minute(Number(array_time1[1])).second(Number(array_time1[2] || '0')).millisecond(Number(array_time1[3] || '0')).unix();
  var new_time2 = dayjs().hour(Number(array_time2[0])).minute(Number(array_time2[1])).second(Number(array_time2[2] || '0')).millisecond(Number(array_time2[3] || '0')).unix();
  return new_time1 - new_time2;
}; //获取凌晨时间戳

export var am_time = function am_time(date) {
  var new_date = date ? dayjs(date) : dayjs();
  return new_date.hour(23).minute(59).second(59).millisecond(999).unix();
}; //获取午夜时间戳

export var pm_time = function pm_time(date) {
  var new_date = date ? dayjs(date) : dayjs();
  return new_date.hour(0).minute(0).second(0).millisecond(0).unix();
}; //去空格

export var trim = function trim(value) {
  return value.replace(/\s+/g, "");
}; //内容替换

export var replaceAll = function replaceAll(text, repstr, newstr) {
  return text.replace(new RegExp(repstr, "gm"), newstr);
}; // 价格过滤

export var filePrice = function filePrice(obj) {
  return Math.floor(obj) / 100;
}; //金额格式化

export var rmoney = function rmoney(money) {
  return parseFloat(money).toFixed(2).toString().split('').reverse().join('').replace(/(\d{3})/g, '$1,').replace(/\,$/, '').split('').reverse().join('');
}; //判断是否为空

export function isDef(val) {
  if (val !== null && val !== void 0 ? val : '' !== '') {
    return true;
  } else {
    return false;
  }
}