user-record.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import tickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  2. // module/user/pages/user-record/user-record.ts
  3. import { getUserInfoMethod, getUserRecordMethod } from "../../request";
  4. import { getPageOrientation } from "../../../../lib/wx/page";
  5. interface Column {
  6. label: string;
  7. value: string;
  8. width?: number;
  9. height?: number;
  10. }
  11. const defaultColumns: Column[] = [
  12. { label: '', value: 'reportTime' },
  13. { label: '女性特殊期', value: 'womenSpecialPeriod' },
  14. { label: '身高', value: 'height' },
  15. { label: '体重', value: 'weight' },
  16. { label: '饮酒情况', value: 'drinkState' },
  17. { label: '吸烟情况', value: 'smokeState' },
  18. { label: '食物过敏', value: 'foodAllergy' },
  19. { label: '喜好口味', value: 'hobbyFlavor' },
  20. { label: '职业', value: 'job' },
  21. ]
  22. Component({
  23. behaviors: [
  24. tickleBehavior,
  25. ],
  26. lifetimes: {
  27. attached() { this.load(); }
  28. },
  29. properties: {},
  30. data: {
  31. orientation: '' as 'portrait' | 'landscape',
  32. containerStyle: '',
  33. columns: [] as Column[],
  34. maxLines: 3,
  35. },
  36. methods: {
  37. async getColumns() {
  38. const { orientation, width, height, left = 0, right = 0, } = getPageOrientation();
  39. const { sex } = await getUserInfoMethod();
  40. const columns = sex === '1'
  41. ? [...defaultColumns]
  42. : defaultColumns.filter(item => item.value !== 'womenSpecialPeriod');
  43. let maxLines = 3;
  44. if (orientation === 'portrait') {
  45. columns[0].height = 50;
  46. const length = columns.length;
  47. const rowHeight = Math.floor((height - columns[0].height) / (length - 1));
  48. for (let index = 1; index < length; index++) { columns[index].height = rowHeight; }
  49. maxLines = Math.floor(rowHeight / 22);
  50. }
  51. this.setData({
  52. columns, maxLines,
  53. orientation,
  54. containerStyle: `width: ${width}px;height: ${height}px;margin-left: ${left}px;margin-right: ${right}px;`
  55. })
  56. },
  57. async load() {
  58. wx.showLoading({ title: '加载中' });
  59. try {
  60. await this.getColumns();
  61. const { data } = await getUserRecordMethod();
  62. this.setData({ dataset: data });
  63. } catch (error) {
  64. getTickleContext.call(this).showErrorMessage(error.errMsg)
  65. }
  66. wx.hideLoading();
  67. }
  68. }
  69. })