user-record.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. },
  35. methods: {
  36. async getColumns() {
  37. const { orientation, width, height, left = 0, right = 0, } = getPageOrientation();
  38. const { sex } = await getUserInfoMethod();
  39. const columns = sex === '1'
  40. ? [...defaultColumns]
  41. : defaultColumns.filter(item => item.value !== 'womenSpecialPeriod');
  42. if (orientation === 'portrait') {
  43. columns[0].height = 50;
  44. const length = columns.length;
  45. const rowHeight = Math.floor((height - columns[0].height) / (length - 1));
  46. for (let index = 1; index < length; index++) { columns[index].height = rowHeight; }
  47. }
  48. this.setData({
  49. columns,
  50. orientation,
  51. containerStyle: `width: ${width}px;height: ${height}px;margin-left: ${left}px;margin-right: ${right}px;`
  52. })
  53. },
  54. async load() {
  55. wx.showLoading({ title: '加载中' });
  56. try {
  57. await this.getColumns();
  58. const { data } = await getUserRecordMethod();
  59. this.setData({ dataset: data });
  60. } catch (error) {
  61. getTickleContext.call(this).showErrorMessage(error.errMsg)
  62. }
  63. wx.hideLoading();
  64. }
  65. }
  66. })