VillageApi.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import { CONVERTER_ADD_DEFAULT, DataModel, transformArrayDataModel } from '@imengyu/js-request-transform';
  2. import { AppServerRequestModule } from '../RequestModules';
  3. import { transformSomeToArray } from '@/common/request/utils/Utils';
  4. export class VillageListItem extends DataModel<VillageListItem> {
  5. constructor() {
  6. super(VillageListItem, "活动列表");
  7. this.setNameMapperCase('Camel', 'Snake');
  8. this._convertTable = {
  9. id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
  10. }
  11. this._nameMapperServer = {
  12. name: 'villageName',
  13. };
  14. this._convertKeyType = (key, direction) => {
  15. if (key.endsWith('At'))
  16. return {
  17. clientSide: 'date',
  18. serverSide: 'string',
  19. };
  20. return undefined;
  21. };
  22. this._afterSolveServer = () => {
  23. this.address =
  24. (this.province || '未知省') +
  25. (this.city || '未知市') +
  26. (this.district || '未知区') +
  27. (this.township || '未知村');
  28. if (this.images && this.images && this.images.length > 0 ) {
  29. this.image = this.images[0]
  30. }
  31. }
  32. }
  33. id !: number;
  34. province = '' as string|null;
  35. city = '' as string|null;
  36. district = '' as string|null;
  37. township = '' as string|null;
  38. address = '';
  39. villageVolunteerId = null as number|null;
  40. villageId = null as number|null;
  41. claimReason = '';
  42. status = '';
  43. statusText = '';
  44. createdAt = null as Date|null;
  45. updatedAt = null as Date|null;
  46. deleteAt = null as Date|null;
  47. image = '';
  48. images = [] as string[];
  49. villageName = '';
  50. volunteerName = '';
  51. }
  52. export class VolunteerRanklistItem extends DataModel<VolunteerRanklistItem> {
  53. constructor() {
  54. super(VolunteerRanklistItem, "活动列表");
  55. this.setNameMapperCase('Camel', 'Snake');
  56. this._convertTable = {
  57. id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
  58. points: [{ clientSide: 'number', serverSide: 'number' }, { clientSide: CONVERTER_ADD_DEFAULT, clientSideParam: { defaultValue: 0 } }],
  59. level: [{ clientSide: 'number', serverSide: 'number' }, { clientSide: CONVERTER_ADD_DEFAULT, clientSideParam: { defaultValue: 0 } }],
  60. }
  61. }
  62. id !: number;
  63. name = '';
  64. mobile = '';
  65. points = 0;
  66. level = 0;
  67. typeText = '';
  68. sexText = '';
  69. statusText = '';
  70. image = '';
  71. }
  72. export class VolunteerInfo extends DataModel<VolunteerInfo> {
  73. constructor() {
  74. super(VolunteerInfo, "活动列表");
  75. this.setNameMapperCase('Camel', 'Snake');
  76. this._convertTable = {
  77. id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
  78. points: [{ clientSide: 'number', serverSide: 'number' }, { clientSide: CONVERTER_ADD_DEFAULT, clientSideParam: { defaultValue: 0 } }],
  79. level: [{ clientSide: 'number', serverSide: 'number' }, { clientSide: CONVERTER_ADD_DEFAULT, clientSideParam: { defaultValue: 0 } }],
  80. }
  81. }
  82. id !: number;
  83. mainBodyId !: number;
  84. type = '';
  85. name = '';
  86. sex = 0;
  87. mobile = '';
  88. regionId = null as number|null;
  89. address = '';
  90. image = '';
  91. birthday = new Date();
  92. intro = '';
  93. points = 0;
  94. level = 0;
  95. status = '';
  96. createdAt = '';
  97. updatedAt = '';
  98. typeText = '';
  99. sexText = '';
  100. statusText = '';
  101. }
  102. export class VillageMenuListItem extends DataModel<VillageMenuListItem> {
  103. constructor() {
  104. super(VillageMenuListItem, "村落菜单列表");
  105. this.setNameMapperCase('Camel', 'Snake');
  106. this._convertTable = {
  107. id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
  108. }
  109. this._nameMapperServer = {
  110. };
  111. this._convertKeyType = (key, direction) => {
  112. if (key.endsWith('At'))
  113. return {
  114. clientSide: 'date',
  115. serverSide: 'string',
  116. };
  117. return undefined;
  118. };
  119. }
  120. name = '';
  121. logo = '';
  122. }
  123. export class VillageApi extends AppServerRequestModule<DataModel> {
  124. constructor() {
  125. super();
  126. }
  127. async getClaimedVallageList(volunteerId?: string) {
  128. return (this.get('/village/village/getVillageList', '获取已认领村落', {
  129. village_volunteer_id: volunteerId,
  130. }))
  131. .then(res => transformArrayDataModel<VillageListItem>(VillageListItem, res.data2, `村落`, true))
  132. .catch(e => { throw e });
  133. }
  134. async getCanClaimVallageList() {
  135. return (this.get('/village/village/getClaimList', '可认领村落列表', {
  136. main_body_id: 2,
  137. }))
  138. .then(res => transformArrayDataModel<VillageListItem>(VillageListItem, transformSomeToArray(res.data2), `村落`, true))
  139. .catch(e => { throw e });
  140. }
  141. async claimVallage(data: any) {
  142. return (this.post('/village/village/addVillageClaim', {
  143. ...data
  144. }, '认领村落')) ;
  145. }
  146. async getVallageList() {
  147. return (this.get('/village/village/getList', '村落列表', {
  148. main_body_id: 2,
  149. }))
  150. .then(res => transformArrayDataModel<VillageListItem>(VillageListItem, transformSomeToArray(res.data2), `村落`, true))
  151. .catch(e => { throw e });
  152. }
  153. async getVolunteerInfo() {
  154. return (await this.post('/village/volunteer/getInfo', {
  155. }, '获取志愿者信息', undefined, VolunteerInfo)).data as VolunteerInfo
  156. }
  157. async getVolunteerRanklist(category?: number) {
  158. return (this.post('/village/volunteer/getRanklist', {
  159. category,
  160. }, '志愿者排行榜'))
  161. .then(res => transformArrayDataModel<VolunteerRanklistItem>(VolunteerRanklistItem, res.data2, ``, true))
  162. .catch(e => { throw e });
  163. }
  164. async getVillageMenuList(id: number) {
  165. return (this.get('/village/menu/getList', '村落菜单列表', {
  166. village_id: id,
  167. }))
  168. .then(res => transformArrayDataModel<VillageMenuListItem>(VillageMenuListItem, res.data2, `村落菜单`, true))
  169. .catch(e => { throw e });
  170. }
  171. }
  172. export default new VillageApi();