index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <view class="container">
  3. <uni-forms ref="baseForm" :modelValue="formData" :label-width="100">
  4. <uni-forms-item v-for="item in fileds" :label="item.title" :name="item.name" :key="item.name">
  5. <uni-easyinput v-if="!item.formatter && !item.type" type="text" v-model="formData[item.name]" :placeholder="`请输入${item.title}`" />
  6. <uni-data-checkbox v-model="formData[item.name]" v-if="item.formatter && item.type == 'checkbox'" :multiple="item.multiple || false" :localdata="item.dict" />
  7. </uni-forms-item>
  8. </uni-forms>
  9. <button class="btn" type="primary" @click="submitForm">提交</button>
  10. </view>
  11. </template>
  12. <script>
  13. import request from '../../api/report.js';
  14. export default {
  15. data() {
  16. return {
  17. formData: {},
  18. fileds: [
  19. { name: 'name', title: '姓名' },
  20. { name: 'sex', title: '性别', formatter: 'dict:user_sex_type', type: 'checkbox' },
  21. { name: 'workUnit', title: '工作单位' },
  22. { name: 'baobaoloudong', title: '包保楼栋' },
  23. { name: 'phone', title: '联系电话' },
  24. { name: 'jianrensanzhang', title: '是否兼任三长', formatter: 'dict:jianrensanzhang_type', type: 'checkbox' },
  25. ]
  26. }
  27. },
  28. async mounted() {
  29. const res = await request.getGbStatus();
  30. if (res.data) {
  31. uni.showToast({
  32. title: '不能重复报道',
  33. icon: 'error',
  34. duration: 2000,
  35. });
  36. setTimeout(() => {
  37. uni.navigateBack();
  38. }, 1000)
  39. return;
  40. }
  41. await this.setDict();
  42. },
  43. onShow() {},
  44. methods: {
  45. async setDict() {
  46. this.fileds = await Promise.all(this.fileds.map(async e => {
  47. if (e.formatter && e.formatter.includes('dict')) {
  48. const dictType = e.formatter.split(':')[1];
  49. const res = await request.getDict(dictType);
  50. if (res.code == 200) e.dict = res.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  51. }
  52. return e;
  53. }));
  54. },
  55. async submitForm() {
  56. const res = await request.submitgb(this.formData);
  57. if (res.code == 200) {
  58. uni.showToast({
  59. title: '提交成功',
  60. icon: 'success',
  61. duration: 2000,
  62. });
  63. setTimeout(() => {
  64. uni.navigateBack();
  65. }, 1000)
  66. }
  67. }
  68. },
  69. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  70. onReachBottom() {}
  71. }
  72. </script>
  73. <style>
  74. .uni-forms {
  75. width: 90%;
  76. margin: 10px auto;
  77. }
  78. .btn {
  79. width: 90%;
  80. margin: 0 auto;
  81. }
  82. </style>