Product.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Collection, Model } from 'js-abstract-model'
  2. class Product extends Model {
  3. constructor (data) {
  4. super(data, [
  5. { key: 'id' },
  6. { key: 'thumbnail' },
  7. { key: 'title' },
  8. { key: 'inventory' },
  9. { key: 'store_category' },
  10. { key: 'content_category' },
  11. {
  12. key: 'unit_price',
  13. default: 0
  14. },
  15. {
  16. key: 'discount_percent',
  17. default: 0
  18. },
  19. { key: 'description' },
  20. { key: 'maximum_order_count' },
  21. { key: 'is_physical' },
  22. { key: 'weight' },
  23. { key: 'physical_type' },
  24. { key: 'specification' }
  25. ], {
  26. is_physical: {
  27. infoKey: 'is_physical_info',
  28. enumListKey: 'is_physicalEnums',
  29. enums: [
  30. {
  31. label: 'فیزیکی',
  32. value: true
  33. },
  34. {
  35. label: 'مجازی',
  36. value: false
  37. }
  38. ]
  39. },
  40. physical_type: {
  41. infoKey: 'physical_type_info',
  42. enumListKey: 'physical_typeEnums',
  43. enums: [
  44. {
  45. label: 'لوح فشرده',
  46. value: 'CD'
  47. },
  48. {
  49. label: 'کتاب',
  50. value: 'BOOK'
  51. },
  52. {
  53. label: 'جزوه',
  54. value: 'MANUSCRIPT'
  55. }
  56. ]
  57. }
  58. })
  59. if (!this.thumbnail) {
  60. this.thumbnail = '/img/sample-post-thumbnail.jpg'
  61. }
  62. }
  63. getFinalPrice () {
  64. return parseInt(this.unit_price * (100 - this.discount_percent)).toLocaleString('fa')
  65. }
  66. }
  67. class ProductList extends Collection {
  68. model () {
  69. return Product
  70. }
  71. }
  72. export { Product, ProductList }