subscribelForm.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="content">
  3. <u-form :model="subscribelForm" ref="subscribelForm" label-width="140">
  4. <u-form-item label="学生姓名" prop="studentName" required>
  5. <u-input v-model="subscribelForm.studentName" placeholder="请输入学生姓名" />
  6. </u-form-item>
  7. <!-- <u-form-item label="家长姓名" prop="fatherName" required>
  8. <u-input v-model="subscribelForm.fatherName" placeholder="请输入家长姓名" />
  9. </u-form-item> -->
  10. <u-form-item label="学生性别" prop="sex" required>
  11. <u-input v-model="subscribelForm.sex" placeholder="请选择学生性别" :select-open="sexShow" type="select" @click="sexShow = true" />
  12. </u-form-item>
  13. <u-form-item label="学生年龄" prop="age" required>
  14. <u-input v-model="subscribelForm.age" placeholder="请输入学生年龄" type="number" />
  15. </u-form-item>
  16. <!-- <u-form-item label="学生生日" prop="birthday" required>
  17. <u-input v-model="subscribelForm.birthday" placeholder="请选择学生生日" :select-open="birthdayShow" type="select" @click="birthdayShow = true" />
  18. </u-form-item> -->
  19. <u-form-item label="手机号码" prop="phone" required>
  20. <u-input v-model="subscribelForm.phone" type="number" placeholder="请输入手机号码" />
  21. </u-form-item>
  22. <!-- <u-form-item label="体验日期" placeholder="请选择体验日期" prop="experience">
  23. <u-input v-model="subscribelForm.experience" :select-open="experienceShow" type="select" @click="experienceShow = true" />
  24. </u-form-item> -->
  25. </u-form>
  26. <u-action-sheet :list="sexList" v-model="sexShow" @click="setSex"></u-action-sheet>
  27. <u-picker v-model="birthdayShow" mode="time" :params="params" @confirm="setBirthday"></u-picker>
  28. <u-calendar v-model="experienceShow" mode="date" :active-bg-color="mainColor" btn-type="error" availableText="有课"
  29. :available="availableList" @change="setExperience" max-date="2300-12-31"></u-calendar>
  30. <view class="handle-fix-box">
  31. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">保存</u-button>
  32. </view>
  33. <u-top-tips ref="uTips"></u-top-tips>
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. mapGetters
  39. } from 'vuex'
  40. const NET = require('@/utils/request')
  41. const API = require('@/config/api')
  42. export default {
  43. computed: {
  44. ...mapGetters([
  45. 'mainColor',
  46. 'customStyle',
  47. ])
  48. },
  49. data() {
  50. return {
  51. subscribelForm: {
  52. studentName: '',
  53. // fatherName: '',
  54. sex: '',
  55. age: '',
  56. // birthday: '',
  57. phone: '',
  58. // placeSchool: '',
  59. // experience: '',
  60. },
  61. rules: {
  62. studentName: [{
  63. required: true,
  64. message: '请输入学生姓名',
  65. trigger: 'change'
  66. }],
  67. fatherName: [{
  68. required: true,
  69. message: '请输入家长姓名',
  70. trigger: 'change'
  71. }],
  72. sex: [{
  73. required: true,
  74. message: '请选择学生性别',
  75. trigger: 'change'
  76. }],
  77. age: [{
  78. required: true,
  79. message: '请输入学生年龄',
  80. trigger: 'change'
  81. }],
  82. birthday: [{
  83. required: true,
  84. message: '请选择学生生日',
  85. trigger: 'change'
  86. }],
  87. phone: [{
  88. required: true,
  89. message: '请输入手机号码',
  90. trigger: 'change'
  91. },
  92. {
  93. pattern: /^1[0-9]{10}$/g,
  94. transform(value) {
  95. return String(value);
  96. },
  97. message: '请输入正确格式的手机号码'
  98. },
  99. ],
  100. },
  101. sexShow: false,
  102. sexList: [{
  103. text: '男'
  104. },
  105. {
  106. text: '女'
  107. }
  108. ],
  109. birthdayShow: false,
  110. params: {
  111. year: true,
  112. month: true,
  113. day: true,
  114. hour: false,
  115. minute: false,
  116. second: false
  117. },
  118. experienceShow: false,
  119. availableList: []
  120. }
  121. },
  122. onLoad(options) {
  123. this.subscribelForm.phone = uni.getStorageSync('userData').phone
  124. },
  125. onReady() {
  126. this.$refs.subscribelForm.setRules(this.rules);
  127. },
  128. methods: {
  129. // 设置性别
  130. setSex(index) {
  131. this.subscribelForm.sex = this.sexList[index].text
  132. },
  133. // 设置生日
  134. setBirthday(object) {
  135. this.subscribelForm.birthday = object.year + '-' + object.month + '-' + object.day
  136. },
  137. // 设置体验日期
  138. setExperience(object) {
  139. let date = object.year + '-' + object.month + '-' + object.day
  140. if (this.availableList.filter(site => site == date).length) {
  141. this.subscribelForm.experience = date
  142. } else {
  143. this.subscribelForm.experience = ''
  144. this.$refs.uTips.show({
  145. title: '请选择可用日期',
  146. type: 'error',
  147. })
  148. }
  149. },
  150. // 提交表单
  151. submitForm() {
  152. this.$refs.subscribelForm.validate(valid => {
  153. if (valid) {
  154. NET.request(API.submitStudentForm, this.subscribelForm, 'POST').then(res => {
  155. this.$refs.uTips.show({
  156. title: '新增成功',
  157. type: 'success',
  158. })
  159. setTimeout(() => {
  160. uni.redirectTo({
  161. url: '/pagesMember/subscribelSuccess'
  162. });
  163. }, 1000)
  164. }).catch(error => {
  165. this.$refs.uTips.show({
  166. title: error.message,
  167. type: 'warning',
  168. })
  169. })
  170. }
  171. });
  172. },
  173. },
  174. }
  175. </script>
  176. <style>
  177. page {
  178. width: 100%;
  179. height: 100%;
  180. position: relative;
  181. }
  182. </style>
  183. <style lang="scss" scoped>
  184. @import "@/static/css/themes.scss";
  185. .content {
  186. width: 100%;
  187. float: left;
  188. padding: 0 15px 60px 15px;
  189. box-sizing: border-box;
  190. }
  191. </style>