import {
  request
} from '../_utils/request';

/** 获取商品详情 */
export function fetchGood(ID) {
  return new Promise((resolve, reject) => {
    request({
      url: `GoodsApi/getGoodsDetails`,
      data: {SpuId: ID},
      method: 'GET',
      success: function (res) {
        let data = res.data;
        // 图片
        if (data.images) {
          data.primaryImage = data.images.split(',')[0];
          data.images = data.images.split(',');
        }
        if(data.desc){ 
          data.desc = data.desc.replace(/<img([^>]*)style=""([^>]*)>/gi, '<img$1style="max-width:100%;height:auto;"$2>');
        }
        resolve(data);
      },
      fail: function (error) {
        reject(error);
      }
    });
  });
}