/**
 * 通用方法工具类
 */
const CommonUtils = {
  /**
   * 数组转字符串
   * @param {Array} arr -数组
   *
   * @return {String}
   */
  array2String(arr) {
    let str = "";

    arr.forEach((item) => {
      str += item.toString() + ",";
    });
    if (str.length > 1) {
      str = str.substring(0, str.length - 1);
    }

    return str;
  },

  /**
   * ID数组转字符串
   * @param {Array} arr -数组
   *
   * @summery <arr参数：[{id: id, name: name}]>
   *
   * @return {String}
   */
  ids2String(arr) {
    let str = "";

    arr.forEach((item) => {
      str += item.id.toString() + ",";
    });
    if (str.length > 1) {
      str = str.substring(0, str.length - 1);
    }

    return str;
  },

  /**
   * 字符串转SQL字符串
   * @param {String} str -字符串
   *
   * @return {String}
   */
  str2Sqlstr(str) {
    let sqlStr = "";

    str.split(',').forEach((item) => {
      sqlStr += "'" + item + "',";
    });
    if (sqlStr.length > 1) {
      sqlStr = sqlStr.substring(0, sqlStr.length - 1);
    }

    return sqlStr;
  }
}

export default CommonUtils;
