resource-service.js 1.35 KB

import Service from './service';
import ResourceApi from '@/api/resource-api';

class ResourceService extends Service {
  constructor() {
    super();
    this.api = new ResourceApi();
  }

  list() {
    return this.api.list();
  }

  info(id) {
    return this.api.info(id).then(result => {
      // let {resGoodsPools, resContentInfos} = result.data;

      let resGoodsPools = result.data.resGoodsPools;
      let resContentInfos = result.data.resContentInfos || [];
      resContentInfos.sort((a, b) => {
        if (a.orderBy < b.orderBy) {
          return -1;
        }

        if (a.orderBy > b.orderBy) {
          return 1;
        }

        return 0;
      });

      if (resGoodsPools) {
        resContentInfos.push({
          type: 'resGoodsPoools',
          data: resGoodsPools
        });
      }

      return resContentInfos;
    });
  }

  editGoodsPool(data) {
    return this.api.editGoodsPool(data);
  }

  editResource(data) {
    return this.api.editResource(data);
  }

  addOrUpdateResource(data) { //  添加或删除资源位
    if (data.id) {
      return this.api.editResourceListItem(data);
    } else {
      return this.api.addResourceListItem(data);
    }
  }

  addOrUpdateResourceDetail(data) { // 添加或修改资源位内容(一张图两张图用)
    return this.api.addOrUpdateResourceDetail(data);
  }

}

export default ResourceService;