const msg = (message = '提示', time = 1500) => {
  const div = document.createElement('div');
  div.className = 's-layer';
  div.innerHTML = `<div class="s-layer-tips">${message}</>`;
  document.body.appendChild(div);
  if (time !== 'always') {
    setTimeout(() => {
      document.body.removeChild(div);
    }, time);
  }
};
const close = () => {
  const layer = document.querySelectorAll('.s-layer');
  layer.forEach(item => {
    document.body.removeChild(item);
  });
};
const sConfirm = conf => {
  const title = conf.title ? conf.title : '提示';
  const message = conf.msg ? conf.msg : '提示';
  const div = document.createElement('div');
  div.className = 's-layer';
  div.innerHTML = `<div class="s-layer-confirm">
		<div class="s-layer-box">
			<div class="s-layer-title">${title}</div>
			<div class="s-layer-msg"><span>${message}</span></div>
				<div class="s-layer-btn">
					<div class="s-layer-close">取消</div>
					<div class="s-layer-sub">确定</div>
				</div>
		</div>
	</div>`;
  document.body.appendChild(div);
  document.querySelector('.s-layer-confirm .s-layer-close').onclick = () => {
    if (conf.close) {
      conf.close();
    } else {
      close();
    }
  };
  document.querySelector('.s-layer-confirm .s-layer-sub').onclick = () => {
    if (conf.ok) {
      conf.ok();
    } else {
      close();
    }
  };
};
export default {
  msg,
  sConfirm,
  close
};
