subscribelForm.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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="birthday" required v-show="showinput">
  14. <u-input v-model="subscribelForm.birthday" placeholder="请选择学生生日" :select-open="birthdayShow" type="select" @click="birthdayShow = true" />
  15. </u-form-item>
  16. <!-- <u-form-item label="学生年龄" prop="age" required>
  17. <u-input v-model="subscribelForm.age" placeholder="请输入学生年龄" type="number" />
  18. </u-form-item> -->
  19. <u-form-item label="身份类型" prop="studentCardName" v-show="showinput">
  20. <u-input v-model="subscribelForm.studentCardName" placeholder="请选择身份类型" type="select" @click="handletypeShowclick(1)" />
  21. </u-form-item>
  22. <u-form-item :label="subscribelForm.studentCardName || '身份证号'" prop="studentCardNumber" v-show="showinput">
  23. <u-input v-model="subscribelForm.studentCardNumber" placeholder="请输入证件号" @click="handleWriteCardClick(1)" />
  24. </u-form-item>
  25. <u-form-item label="家长姓名" prop="fatherName" required v-show="showinput">
  26. <u-input v-model="subscribelForm.fatherName" placeholder="请输入家长姓名" />
  27. </u-form-item>
  28. <u-form-item label="关系" prop="relation" required v-show="showinput">
  29. <u-input v-model="subscribelForm.relation" placeholder="请输入关系" />
  30. </u-form-item>
  31. <u-form-item label="身份类型" prop="parentCardName" required v-show="showinput">
  32. <u-input v-model="subscribelForm.parentCardName" placeholder="请选择身份类型" type="select" @click="handletypeShowclick(2)" />
  33. </u-form-item>
  34. <u-form-item :label="subscribelForm.parentCardName || '身份证号'" prop="parentCardNumber" required v-show="showinput">
  35. <u-input v-model="subscribelForm.parentCardNumber" placeholder="请输入证件号" @click="handleWriteCardClick(2)" />
  36. </u-form-item>
  37. <u-form-item label="手机号码" prop="phone" required v-show="showinput">
  38. <u-input v-model="subscribelForm.phone" type="number" placeholder="请输入手机号码" />
  39. </u-form-item>
  40. <!-- <u-form-item label="体验日期" placeholder="请选择体验日期" prop="experience">
  41. <u-input v-model="subscribelForm.experience" :select-open="experienceShow" type="select" @click="experienceShow = true" />
  42. </u-form-item> -->
  43. </u-form>
  44. <!-- 学生性别 -->
  45. <u-action-sheet :list="sexList" v-model="sexShow" @click="setSex"></u-action-sheet>
  46. <!-- 生日 -->
  47. <u-picker v-model="birthdayShow" mode="time" :params="params" @confirm="setBirthday"></u-picker>
  48. <!-- 身份类型 -->
  49. <u-action-sheet :list="typeList" v-model="typeShow" @click="setType"></u-action-sheet>
  50. <!-- <u-calendar v-model="experienceShow" mode="date" :active-bg-color="mainColor" btn-type="error" availableText="有课"
  51. :available="availableList" @change="setExperience" max-date="2300-12-31"></u-calendar> -->
  52. <view class="handle-fix-box">
  53. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm">
  54. {{ subscribelForm.studentId ? '修改' : '新增' }}
  55. </u-button>
  56. </view>
  57. <u-top-tips ref="uTips"></u-top-tips>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. mapGetters
  63. } from 'vuex'
  64. const NET = require('@/utils/request')
  65. const API = require('@/config/api')
  66. export default {
  67. computed: {
  68. ...mapGetters([
  69. 'mainColor',
  70. 'customStyle',
  71. ])
  72. },
  73. data() {
  74. return {
  75. showinput:true,
  76. subscribelForm: {
  77. studentName: '',
  78. sex: '',
  79. age: '',
  80. birthday: '',
  81. studentCard: '',
  82. studentCardName: '',
  83. studentCardNumber: '',
  84. fatherName: '',
  85. relation: '',
  86. parentCard: '',
  87. parentCardName: '',
  88. parentCardNumber: '',
  89. phone: ''
  90. },
  91. rules: {
  92. studentName: [{
  93. required: true,
  94. message: '请输入学生姓名',
  95. trigger: 'change'
  96. }],
  97. sex: [{
  98. required: true,
  99. message: '请选择学生性别',
  100. trigger: 'change'
  101. }],
  102. birthday: [{
  103. required: true,
  104. message: '请选择学生生日',
  105. trigger: 'change'
  106. }],
  107. age: [{
  108. required: true,
  109. message: '请输入学生年龄',
  110. trigger: 'change'
  111. }],
  112. fatherName: [{
  113. required: true,
  114. message: '请输入家长姓名',
  115. trigger: 'change'
  116. }],
  117. relation: [{
  118. required: true,
  119. message: '请输入关系',
  120. trigger: 'change'
  121. }],
  122. parentCardName: [{
  123. required: true,
  124. message: '请选择身份类型',
  125. trigger: 'change'
  126. }],
  127. parentCardNumber: [{
  128. required: true,
  129. message: '输入证件号',
  130. trigger: 'change'
  131. }],
  132. phone: [{
  133. required: true,
  134. message: '请输入手机号码',
  135. trigger: 'change'
  136. },
  137. {
  138. pattern: /^1[0-9]{10}$/g,
  139. transform(value) {
  140. return String(value);
  141. },
  142. message: '请输入正确格式的手机号码'
  143. },
  144. ],
  145. },
  146. sexShow: false,
  147. sexList: [{
  148. text: '男'
  149. },
  150. {
  151. text: '女'
  152. }
  153. ],
  154. // 1 学生身份类型 2 家长身份类型
  155. typeNumber: 1,
  156. typeShow: false,
  157. typeList: [
  158. {
  159. text: '身份证号'
  160. },
  161. {
  162. text: '护照号'
  163. }
  164. ],
  165. birthdayShow: false,
  166. params: {
  167. year: true,
  168. month: true,
  169. day: true,
  170. hour: false,
  171. minute: false,
  172. second: false
  173. },
  174. experienceShow: false,
  175. availableList: []
  176. }
  177. },
  178. onLoad(options) {
  179. //审核不让收集省份证等信息
  180. if(Date.parse(new Date())<1661835600000){
  181. this.showinput=false
  182. }
  183. // this.subscribelForm.phone = uni.getStorageSync('userData').phone
  184. const info = JSON.parse(decodeURIComponent(options.info))
  185. if(info) {
  186. let data = {}
  187. uni.setNavigationBarTitle({
  188. title: '修改信息'
  189. });
  190. if(info.idCard) {
  191. data['studentCardName'] = info.idCard.split(',')[0]
  192. data['studentCardNumber'] = info.idCard.split(',')[1]
  193. }
  194. console.log(info.parentIdCard)
  195. if(info.parentIdCard) {
  196. data['parentCardName'] = info.parentIdCard.split(',')[0]
  197. data['parentCardNumber'] = info.parentIdCard.split(',')[1]
  198. }
  199. if(info.parentIdCard==null){
  200. info.parentIdCard=''
  201. }
  202. if(info.idCard==null){
  203. info.idCard=''
  204. }
  205. this.subscribelForm = { ...info, ...data}
  206. } else {
  207. uni.setNavigationBarTitle({
  208. title: '添加信息'
  209. });
  210. }
  211. },
  212. onReady() {
  213. this.$refs.subscribelForm.setRules(this.rules);
  214. },
  215. methods: {
  216. // 设置性别
  217. setSex(index) {
  218. this.subscribelForm.sex = this.sexList[index].text
  219. },
  220. // 设置生日
  221. setBirthday(object) {
  222. this.subscribelForm.birthday = object.year + '-' + object.month + '-' + object.day
  223. },
  224. //
  225. handletypeShowclick(index) {
  226. this.typeNumber = index
  227. this.typeShow = true
  228. },
  229. setType(object) {
  230. console.log(this.typeNumber);
  231. if(this.typeNumber == 1) {
  232. this.subscribelForm.studentCard = object
  233. this.subscribelForm.studentCardName = this.typeList[object].text
  234. console.log(this.subscribelForm);
  235. } else {
  236. this.subscribelForm.parentCard = object
  237. this.subscribelForm.parentCardName = this.typeList[object].text
  238. console.log(this.subscribelForm);
  239. }
  240. },
  241. handleWriteCardClick(index) {
  242. console.log(index);
  243. console.log(this.subscribelForm);
  244. if((index == 1 && !this.subscribelForm.studentCardName) || (index == 2 && !this.subscribelForm.parentCardName)) {
  245. this.$refs.uTips.show({
  246. title: '请先选择身份类型',
  247. type: 'warning',
  248. })
  249. }
  250. },
  251. // 提交表单
  252. submitForm() {
  253. this.$refs.subscribelForm.validate(valid => {
  254. if (valid) {
  255. let info = {
  256. idCard: this.subscribelForm.studentCardName ? this.subscribelForm.studentCardName + ',' +this.subscribelForm.studentCardNumber : '',
  257. parentIdCard: this.subscribelForm.parentCardName + ',' +this.subscribelForm.parentCardNumber
  258. }
  259. NET.request(this.subscribelForm.studentId ? API.updateStudentForm : API.submitStudentForm , { ...this.subscribelForm, ...info }, 'POST').then(res => {
  260. if(this.subscribelForm.studentId) {
  261. this.$refs.uTips.show({
  262. title: '修改成功',
  263. type: 'success',
  264. })
  265. setTimeout(() => {
  266. uni.navigateBack({})
  267. }, 1000)
  268. } else {
  269. this.$refs.uTips.show({
  270. title: '新增成功',
  271. type: 'success',
  272. })
  273. setTimeout(() => {
  274. uni.redirectTo({
  275. url: '/pagesMember/subscribelSuccess'
  276. });
  277. }, 1000)
  278. }
  279. }).catch(error => {
  280. this.$refs.uTips.show({
  281. title: error.message,
  282. type: 'warning',
  283. })
  284. })
  285. }
  286. })
  287. },
  288. // 设置体验日期
  289. setExperience(object) {
  290. let date = object.year + '-' + object.month + '-' + object.day
  291. if (this.availableList.filter(site => site == date).length) {
  292. this.subscribelForm.experience = date
  293. } else {
  294. this.subscribelForm.experience = ''
  295. this.$refs.uTips.show({
  296. title: '请选择可用日期',
  297. type: 'error',
  298. })
  299. }
  300. }
  301. }
  302. }
  303. </script>
  304. <style>
  305. page {
  306. width: 100%;
  307. height: 100%;
  308. position: relative;
  309. }
  310. </style>
  311. <style lang="scss" scoped>
  312. @import "@/static/css/themes.scss";
  313. .content {
  314. width: 100%;
  315. float: left;
  316. padding: 0 15px 60px 15px;
  317. box-sizing: border-box;
  318. }
  319. </style>