intentionForm.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="form" label-width="140">
  4. <u-form-item label="学员姓名" prop="studentName" required>
  5. <u-input v-model="form.studentName" placeholder="请输入学员姓名" />
  6. </u-form-item>
  7. <u-form-item label="家长姓名" prop="parentsName" required>
  8. <u-input v-model="form.parentsName" placeholder="请输入家长姓名" />
  9. </u-form-item>
  10. <u-form-item label="学员性别" prop="sex" required right-icon="arrow-right" @click.native="sexShow = true">
  11. <text>{{form.sex}}</text>
  12. </u-form-item>
  13. <u-form-item label="学员年龄" prop="age" required>
  14. <u-input v-model="form.age" type="number" placeholder="请输入学员年龄" />
  15. </u-form-item>
  16. <u-form-item label="学生生日" prop="birthday" required right-icon="arrow-right" @click.native="birthdayShow = true">
  17. <text>{{form.birthday}}</text>
  18. </u-form-item>
  19. <u-form-item label="手机号码" prop="phone" required>
  20. <u-input v-model="form.phone" type="number" placeholder="请输入手机号码" />
  21. </u-form-item>
  22. <u-form-item label="备注">
  23. <u-input v-model="form.remark" type="textarea" placeholder="请输入备注" auto-height :height="100" />
  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="birthdayParams" @confirm="setBirthday"></u-picker>
  28. <view class="handle-fix-box">
  29. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">提交</u-button>
  30. </view>
  31. <u-top-tips ref="uTips"></u-top-tips>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. mapGetters
  37. } from 'vuex'
  38. const NET = require('@/utils/request')
  39. const API = require('@/config/api')
  40. export default {
  41. computed: {
  42. ...mapGetters([
  43. 'customStyle',
  44. ])
  45. },
  46. data() {
  47. return {
  48. form: {
  49. studentName: '',
  50. parentsName: '',
  51. sex: '',
  52. age: '',
  53. birthday: '',
  54. phone: '',
  55. remark: '',
  56. },
  57. rules: {
  58. studentName: [{
  59. required: true,
  60. message: '请输入学员姓名',
  61. trigger: 'change'
  62. }],
  63. parentsName: [{
  64. required: true,
  65. message: '请输入家长姓名',
  66. trigger: 'change'
  67. }],
  68. sex: [{
  69. required: true,
  70. message: '请选择学员性别',
  71. trigger: 'change'
  72. }],
  73. age: [{
  74. required: true,
  75. message: '请输入学员年龄',
  76. trigger: 'change'
  77. }],
  78. birthday: [{
  79. required: true,
  80. message: '请选择学生生日',
  81. trigger: 'change'
  82. }],
  83. phone: [{
  84. required: true,
  85. message: '请输入手机号码',
  86. trigger: 'change'
  87. },
  88. {
  89. pattern: /^1[0-9]{10}$/g,
  90. transform(value) {
  91. return String(value);
  92. },
  93. message: '请输入正确格式的手机号码'
  94. },
  95. ],
  96. },
  97. sexShow: false,
  98. sexList: [{
  99. text: '男'
  100. },
  101. {
  102. text: '女'
  103. }
  104. ],
  105. birthdayShow: false,
  106. birthdayParams: {
  107. year: true,
  108. month: true,
  109. day: true,
  110. hour: false,
  111. minute: false,
  112. second: false
  113. },
  114. }
  115. },
  116. onLoad() {},
  117. onReady() {
  118. this.$refs.form.setRules(this.rules);
  119. },
  120. methods: {
  121. // 设置性别
  122. setSex(index) {
  123. this.form.sex = this.sexList[index].text
  124. },
  125. // 设置生日
  126. setBirthday(object) {
  127. this.form.birthday = object.year + '-' + object.month + '-' + object.day
  128. },
  129. // 提交表单
  130. submitForm() {
  131. this.$refs.form.validate(valid => {
  132. if (valid) {
  133. NET.request(API.submitIntentionForm, {
  134. ...this.form
  135. }, 'POST').then(res => {
  136. this.$refs.uTips.show({
  137. title: '提交成功',
  138. type: 'success',
  139. })
  140. setTimeout(() => {
  141. uni.navigateBack()
  142. }, 1000)
  143. }).catch(error => {
  144. this.$refs.uTips.show({
  145. title: error.message,
  146. type: 'warning',
  147. })
  148. })
  149. }
  150. });
  151. },
  152. },
  153. }
  154. </script>
  155. <style>
  156. page {
  157. width: 100%;
  158. height: 100%;
  159. position: relative;
  160. }
  161. </style>
  162. <style lang="scss" scoped>
  163. @import "@/static/css/themes.scss";
  164. .content {
  165. width: 100%;
  166. float: left;
  167. padding: 0 15px 60px 15px;
  168. box-sizing: border-box;
  169. }
  170. </style>