export const storeStatus = ['正常营业', '停用'];

export const storeType = ['直营', '加盟', '其他'];

export class DrugStore {
  init(data = {}, isNew = true) {
    this.name = typeof data.name == 'string' ? data.name.trim() : '';
    this.store_id = typeof data.store_id == 'string' ? data.store_id.trim() : '';
    this.type = storeType.includes(data.type) ? data.type : '';
    this.introduce = typeof data.introduce == 'string' ? data.introduce.trim() : '';
    this.imgs = Array.isArray(data.imgs) ? data.imgs.filter(i => typeof i === 'string' && i.trim()) : [];
    this.region = Array.isArray(data.region) ? data.region.filter(i => typeof i === 'string' && i.trim()).slice(0, 3) : [];
    this.address = typeof data.address == 'string' ? data.address.trim() : '';
    this.longitude = typeof data.longitude == 'string' && data.longitude.trim() && parseFloat(data.longitude) > 0 ? `${parseFloat(data.longitude)}` : '';
    this.latitude = typeof data.latitude == 'string' && data.latitude.trim() && parseFloat(data.latitude) > 0 ? `${parseFloat(data.latitude)}` : '';
    this.charge_id = typeof data.charge_id == 'string' ? data.charge_id.trim() : '';
    this.status = storeStatus.includes(data.status) ? data.status : '';
    this.openingHours = typeof data.openingHours == 'string' ? data.openingHours.trim() : '';
    this.accountId = typeof data.accountId == 'string' ? data.accountId.trim() : '';
    this.saleWine = typeof data.saleWine == 'boolean' ? data.saleWine : false;
    if (isNew) {
      this.status = '正常营业';
      this.region = ['浙江省', '绍兴市', '']
    }
    return this
  }

}