add.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view>
  3. <u-navbar title="2025迎新春活动" :is-back="false"></u-navbar>
  4. <view class="infos">
  5. <u-form :model="form" ref="uForm" label-width="200">
  6. <u-form-item label="姓名" prop="name">
  7. <u-input v-model="form.name" placeholder="请输入姓名" />
  8. </u-form-item>
  9. <u-form-item label="年龄" prop="age">
  10. <u-input v-model="form.age" placeholder="请输入年龄" />
  11. </u-form-item>
  12. <u-form-item label="是否为青少年宫学员" label-width="400">
  13. <u-radio-group v-model="radioValue" slot="right">
  14. <u-radio name="1">是</u-radio>
  15. <u-radio name="0">否</u-radio>
  16. </u-radio-group>
  17. </u-form-item>
  18. <u-form-item label="所在项目" prop="categoryN">
  19. <view style="width: 100%;" @click="show=true">
  20. <u-input style="pointer-events: none" type="select" v-model="form.categoryN"
  21. placeholder="请选择所在项目" />
  22. </view>
  23. <!-- <u-input v-model="form.categoryN" type="select" placeholder="请选择所在项目" @click="show=true" /> -->
  24. </u-form-item>
  25. <u-form-item label="家长联系方式" prop="contact">
  26. <u-input v-model="form.contact" placeholder="请输入家长联系方式" />
  27. </u-form-item>
  28. </u-form>
  29. </view>
  30. <u-select v-model="show" mode="single-column" :list="activityList" label-name="name"
  31. @confirm="confirm"></u-select>
  32. <view>
  33. <u-toast ref="uToast" />
  34. </view>
  35. <view class="btn">
  36. <button @click="submit">提 交</button>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import * as activityApi from '@/apis/parents/activity.js'
  42. export default {
  43. data() {
  44. return {
  45. activityId: '',
  46. radioValue: '1',
  47. show: false,
  48. activityList: [],
  49. form: {
  50. id: '',
  51. name: '',
  52. age: '',
  53. isStudent: '',
  54. category: '',
  55. categoryN: '',
  56. contact: ''
  57. },
  58. rules: {
  59. name: [{
  60. required: true,
  61. message: '请输入姓名',
  62. trigger: ['change', 'blur'],
  63. }],
  64. age: [{
  65. required: true,
  66. message: '请输入年龄',
  67. trigger: ['change', 'blur'],
  68. }],
  69. categoryN: [{
  70. required: true,
  71. message: '请选择所在项目',
  72. trigger: ['change', 'blur'],
  73. }],
  74. contact: [{
  75. required: true,
  76. message: '请输入家长联系方式',
  77. trigger: ['change', 'blur'],
  78. }]
  79. }
  80. }
  81. },
  82. onLoad(op) {
  83. if(op.id) {
  84. this.activityId = op.id;
  85. this.getEdit();
  86. }
  87. },
  88. onReady() {
  89. this.$refs.uForm.setRules(this.rules);
  90. this.getActivityList();
  91. },
  92. methods: {
  93. getEdit() {
  94. activityApi.edit(this.activityId).then((response) => {
  95. this.form = response.data;
  96. if(this.form.isStudent) {
  97. this.radioValue = '1';
  98. } else {
  99. this.radioValue = '0';
  100. }
  101. }).catch(error => {
  102. uni.showToast({
  103. title: error,
  104. icon: "none"
  105. })
  106. })
  107. },
  108. getActivityList() {
  109. activityApi.itemList().then((response) => {
  110. this.activityList = response.data;
  111. }).catch(error => {
  112. uni.showToast({
  113. title: error,
  114. icon: "none"
  115. })
  116. })
  117. },
  118. submit() {
  119. this.$refs.uForm.validate(valid => {
  120. if (valid) {
  121. if(this.radioValue == '1') {
  122. this.form.isStudent = true;
  123. } else {
  124. this.form.isStudent = false;
  125. }
  126. activityApi.add(this.form).then((response) => {
  127. this.$refs.uToast.show({
  128. title: '报名成功',
  129. type: 'success'
  130. })
  131. }).catch(error => {
  132. uni.showToast({
  133. title: error,
  134. icon: "none"
  135. })
  136. })
  137. }
  138. });
  139. },
  140. confirm(e) {
  141. this.form.category = e[0].value;
  142. this.form.categoryN = e[0].label;
  143. },
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .infos {
  149. padding: 0px 30rpx;
  150. background-color: #fff;
  151. margin-bottom: 24rpx;
  152. .item {
  153. display: flex;
  154. justify-content: space-between;
  155. border-bottom: 1px solid rgba(244, 244, 244, 1);
  156. padding: 24rpx 0;
  157. .title {
  158. color: #333333;
  159. font-weight: bold;
  160. .asterisk {
  161. color: rgba(244, 68, 68, 1);
  162. }
  163. }
  164. .value {
  165. color: rgba(51, 51, 51, 1);
  166. font-weight: bold;
  167. .icon {
  168. margin-left: 8rpx;
  169. }
  170. .add {
  171. color: #FF3D00;
  172. }
  173. .placeholder {
  174. color: #CCCCCC;
  175. }
  176. }
  177. }
  178. }
  179. .btn {
  180. padding: 20rpx 0;
  181. background-color: #fff;
  182. position: fixed;
  183. bottom: 0;
  184. left: 0;
  185. right: 0;
  186. button {
  187. width: 91.4%;
  188. border-radius: 50px;
  189. background-color: rgba(13, 186, 199, 1);
  190. color: rgba(255, 255, 255, 1);
  191. font-size: 16px;
  192. line-height: 80rpx;
  193. }
  194. }
  195. /deep/uni-input {
  196. width: 300rpx;
  197. text-align: right !important;
  198. }
  199. /deep/.uni-input-placeholder {
  200. color: #cccccc !important;
  201. }
  202. </style>