index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="container">
  3. <uni-card v-if="formData && formData.status == 1">
  4. <uni-section title="驳回原因" type="line">
  5. <text class="msg">{{ formData.rejectReason }}</text>
  6. </uni-section>
  7. </uni-card>
  8. <uni-forms ref="baseForm" :modelValue="formData" :label-width="110" :rules="rules">
  9. <uni-forms-item v-for="item in fileds" :label="item.title" :name="item.name" :key="item.name" required>
  10. <uni-easyinput v-if="!item.formatter && !item.type" type="text" v-model="formData[item.name]" :placeholder="`请输入${item.title}`" />
  11. <uni-data-checkbox v-model="formData[item.name]" v-if="item.formatter && item.type == 'checkbox'" :multiple="item.multiple || false" :localdata="item.dict" />
  12. <text class="msg" v-if="item.name == 'baobaoloudong'">例:XX小区 + X栋</text>
  13. <uni-data-select v-model="formData[item.name]" v-if="item.type == 'picker'" :localdata="item.dict" placeholder="请选择社区"></uni-data-select>
  14. </uni-forms-item>
  15. </uni-forms>
  16. <button :disabled="formData.status == 0 || formData.status == 2" class="btn" type="primary" @click="submitForm">{{ btnText }}</button>
  17. </view>
  18. </template>
  19. <script>
  20. import request from '../../api/report.js';
  21. export default {
  22. data() {
  23. return {
  24. pickerList: [],
  25. btnText: '提交',
  26. formData: {},
  27. fileds: [
  28. { name: 'name', title: '姓名' },
  29. { name: 'sex', title: '性别', formatter: 'dict:user_sex_type', type: 'checkbox' },
  30. { name: 'workUnit', title: '工作单位' },
  31. { name: 'deptId', title: '报到社区', type: 'picker' },
  32. { name: 'baobaoloudong', title: '包保楼栋' },
  33. { name: 'phone', title: '联系电话' },
  34. { name: 'jianrensanzhang', title: '是否兼任三长', formatter: 'dict:jianrensanzhang_type', type: 'checkbox' },
  35. ],
  36. rules: {
  37. name: {
  38. rules:[{ required: true, errorMessage: '请填写姓名' }]
  39. },
  40. sex: {
  41. rules:[{ required: true, errorMessage: '请选择性别' }]
  42. },
  43. phone: {
  44. rules:[{ required: true, errorMessage: '请填写联系电话' }]
  45. },
  46. workUnit: {
  47. rules:[{ required: true, errorMessage: '请填写工作单位' }]
  48. },
  49. baobaoloudong: {
  50. rules:[{ required: true, errorMessage: '请填写包保楼栋' }]
  51. },
  52. jianrensanzhang: {
  53. rules:[{ required: true, errorMessage: '请选择是否兼任三长' }]
  54. },
  55. deptId: {
  56. rules:[{ required: true, errorMessage: '请选择报到社区' }]
  57. },
  58. }
  59. }
  60. },
  61. async mounted() {
  62. const getCommunity = await request.getCommunity();
  63. this.pickerList = getCommunity.rows;
  64. const res = await request.getGbStatus();
  65. if (res.data) {
  66. this.formData = { ...res.data, sex: String(res.data.sex), jianrensanzhang: String(res.data.jianrensanzhang) };
  67. if (res.data.status == 0) this.btnText = '审核中';
  68. // if (res.data.status == 1) this.btnText = '已驳回';
  69. if (res.data.status == 2) this.btnText = '已报到';
  70. }
  71. await this.setDict();
  72. },
  73. onShow() {},
  74. methods: {
  75. async setDict() {
  76. this.fileds = await Promise.all(this.fileds.map(async e => {
  77. if (e.name == 'deptId') e.dict = this.pickerList.map(e => ({ ...e, text: e.deptName, value: e.deptId }));;
  78. if (e.formatter && e.formatter.includes('dict')) {
  79. const dictType = e.formatter.split(':')[1];
  80. const res = await request.getDict(dictType);
  81. if (res.code == 200) e.dict = res.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  82. }
  83. return e;
  84. }));
  85. },
  86. async submitForm() {
  87. this.$refs.baseForm.validate().then(async valid=>{
  88. let res;
  89. if (this.formData.xiachenganbuId) {
  90. res = await request.updategb(this.formData);
  91. } else {
  92. res = await request.submitgb(this.formData);
  93. }
  94. if (res.code == 200) {
  95. uni.showToast({
  96. title: '提交成功',
  97. icon: 'success',
  98. duration: 2000,
  99. });
  100. setTimeout(() => {
  101. uni.navigateBack();
  102. }, 1000)
  103. }
  104. }).catch(err =>{
  105. console.log('表单错误信息:', err);
  106. })
  107. }
  108. },
  109. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  110. onReachBottom() {}
  111. }
  112. </script>
  113. <style>
  114. .uni-forms {
  115. width: 90%;
  116. margin: 10px auto;
  117. }
  118. .btn {
  119. width: 90%;
  120. margin: 0 auto;
  121. }
  122. .msg {
  123. color: red;
  124. font-size: 12px;
  125. }
  126. </style>