/**
 * Created by yee.wang on 2019-02-28
 **/ import { USER_URL } from "../constants/Urls" ; import { wait } from "../utils" ; import { goods_data } from "../mock" ; import FilterModel from "./FilterModel" ; import { Field , mapValue } from "@vmojs/base" ; import { AxiosVmo } from "@vmojs/axios" ; interface IGoodsQuery { id : number ; search ? : string ; filter ? : any ; } interface IGoodsCollection { goods : GoodsModel [ ] ; goodsRows : number ; filters : FilterModel [ ] ; } export default class GoodsModel extends AxiosVmo { protected static requestUrl : string = USER_URL ; @ Field public id : number ; @ Field public catId : number ; @ Field public aliasName : string ; @ Field public uid : number ; @ Field public userId : number ; @ Field public size : { x : number ; y : number ; } ; param query public static async list ( query ) { const { items } = await this . fetch ( query ) ; return mapValue ( items , GoodsModel ) ; } param query public static async listWithDetail ( query ) { const { items , allRows , aggr } = await this . fetch ( query ) ; const goods = mapValue ( items , GoodsModel ) ; const filters = mapValue ( aggr , FilterModel ) ; return { goods , goodsRows : allRows , filters } ; } public static async fetch ( query ) { await wait ( 1000 * Math . random ( ) ) ; return goods_data ; } protected load ( data ) { data . catId = data . cat_id ; data . aliasName = data . aliasname ; data . userId = data . user_id ; return super . load ( data ) ; } }