teacher_authentication_add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="auth-Container" style="background-color: #f0f0f0;">
  3. <uni-forms ref="baseForm" :modelValue="baseFormData" labelWidth="75px" :rules="rules" validateTrigger="bind">
  4. <uni-forms-item label="真实姓名" name="name" required>
  5. <uni-easyinput v-model="baseFormData.name" placeholder="请输入姓名" maxlength="6" trim="both" />
  6. </uni-forms-item>
  7. <uni-forms-item label="手机号" required>
  8. <button class="getPhone" open-type="getPhoneNumber" type="primary" size="mini"
  9. @getphonenumber="getPhoneNumber">获取手机号</button>
  10. </uni-forms-item>
  11. <uni-forms-item label="微信号" name="weixinId" required>
  12. <uni-easyinput v-model="baseFormData.weixinId" placeholder="微信号(不便接听电话时微信沟通)" maxlength="25"
  13. trim="both" />
  14. </uni-forms-item>
  15. <uni-forms-item label="英文名" name="englishName">
  16. <uni-easyinput v-model="baseFormData.englishName" placeholder="请输入你的英文名" maxlength="25" trim="both" />
  17. </uni-forms-item>
  18. <uni-forms-item label="身份证号" name="idCard" required>
  19. <uni-easyinput v-model="baseFormData.idCard" type="idcard" placeholder="请输入你的身份证号" />
  20. </uni-forms-item>
  21. <uni-forms-item label="性别" name="sex" required>
  22. <uni-data-checkbox v-model="baseFormData.sex" :localdata="sexs" />
  23. </uni-forms-item>
  24. <uni-forms-item label="身份" name="identify" required>
  25. <uni-data-checkbox v-model="baseFormData.identify" :localdata="identifies" />
  26. </uni-forms-item>
  27. <uni-forms-item label="身份证照片" required>
  28. <text style="color: blue;">(说明:需要能看清楚证件号码、日期及头像)</text>
  29. <uni-file-picker fileMediatype="image" :sizeType="sizeType" v-model="idCardFrontByte" :fileExtname="fileExtname" limit="1" title="身份证正面" @select="selectIdCardFront" @delete="deletePhoto" />
  30. <uni-file-picker fileMediatype="image" :sizeType="sizeType" v-model="idCardBackByte" :fileExtname="fileExtname" limit="1" title="身份证背面" @select="selcetIdCardBack" @delete="deletePhoto" />
  31. </uni-forms-item>
  32. <uni-forms-item label="学生/毕业证" required>
  33. <text style="color: blue;">(已毕业的需要上传毕业证)</text>
  34. <uni-file-picker fileMediatype="image" :sizeType="sizeType" v-model="diplomaPhotoByte" :fileExtname="fileExtname" limit="1" @select="selectDiplomaPhoto" @delete="deletePhoto" />
  35. </uni-forms-item>
  36. <uni-forms-item label="头像" required>
  37. <text style="color: blue;">(说明:只能上传证件照,上传其他照片审核不予通过)</text>
  38. <uni-file-picker fileMediatype="image" :sizeType="sizeType" v-model="profilePhotoByte" :fileExtname="fileExtname" limit="1" @select="selectProfilePhoto" @delete="deletePhoto" />
  39. </uni-forms-item>
  40. <uni-forms-item label="毕业/就读学校" name="school" required>
  41. <uni-easyinput v-model="baseFormData.school" placeholder="请输入学校全称" maxlength="30" trim="both" />
  42. </uni-forms-item>
  43. <uni-forms-item label="所学专业" name="major" required>
  44. <uni-easyinput v-model="baseFormData.major" placeholder="请输入专业名称" maxlength="20" trim="both" />
  45. </uni-forms-item>
  46. <uni-forms-item label="学历" name="education" required>
  47. <uni-data-select v-model="baseFormData.education" :localdata="educations" />
  48. </uni-forms-item>
  49. <uni-forms-item label="籍贯" name="nativePlace" required>
  50. <uni-easyinput v-model="baseFormData.nativePlace" placeholder="xx省xx市xx区" maxlength="30" trim="both" />
  51. </uni-forms-item>
  52. </uni-forms>
  53. <view class="authenticationBtnWrapper">
  54. <button class="authenticationBtn" type="primary" @click="submit">{{buttonMessage}}</button>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import { mapState, mapMutations } from 'vuex'
  60. export default {
  61. computed: {
  62. ...mapState('m_user', ['authentication']),
  63. },
  64. data() {
  65. return {
  66. fileExtname: 'png,jpg',
  67. sizeType: ['compressed'],
  68. idCardFrontByte: [{
  69. url: '',
  70. extname: '',
  71. name: ''
  72. }],
  73. idCardBackByte: [{
  74. url: '',
  75. extname: '',
  76. name: ''
  77. }],
  78. profilePhotoByte: [{
  79. url: '',
  80. extname: '',
  81. name: ''
  82. }],
  83. diplomaPhotoByte: [{
  84. url: '',
  85. extname: '',
  86. name: ''
  87. }],
  88. buttonMessage: '申请认证',
  89. isLoading: false, // 节流阀
  90. baseFormData: {
  91. name: '',
  92. weixinId: '',
  93. idCard: '',
  94. sex: '男',
  95. identify: '专职老师',
  96. school: '',
  97. major: '',
  98. education: '',
  99. nativePlace: '',
  100. education: '本科在读'
  101. },
  102. sexs: [{
  103. text: '男',
  104. value: '男'
  105. }, {
  106. text: '女',
  107. value: '女'
  108. }],
  109. // 单选老师身份
  110. identifies: [{
  111. text: '专职老师',
  112. value: '专职老师'
  113. }, {
  114. text: '在校大学生',
  115. value: '在校大学生'
  116. }],
  117. educations: [{
  118. value: '专科在读',
  119. text: '专科在读'
  120. }, {
  121. value: '专科毕业',
  122. text: '专科毕业'
  123. }, {
  124. value: '本科在读',
  125. text: '本科在读'
  126. }, {
  127. value: '本科毕业',
  128. text: '本科毕业'
  129. }, {
  130. value: '硕士在读',
  131. text: '硕士在读'
  132. }, {
  133. value: '硕士毕业',
  134. text: '硕士毕业'
  135. }, {
  136. value: '博士在读',
  137. text: '博士在读'
  138. }, {
  139. value: '博士毕业',
  140. text: '博士毕业'
  141. }],
  142. rules: {
  143. name: {
  144. rules: [{
  145. required: true,
  146. errorMessage: '请输入姓名',
  147. }]
  148. },
  149. weixinId: {
  150. rules: [{
  151. required: true,
  152. errorMessage: '请输入微信号',
  153. }, {
  154. errorMessage: '请输入正确的微信号',
  155. pattern: '^[a-zA-Z][a-zA-Z\\d_-]{5,19}$',
  156. }]
  157. },
  158. idCard: {
  159. rules: [{
  160. required: true,
  161. errorMessage: '请输入身份证号',
  162. }, {
  163. errorMessage: '请输入正确的身份证号',
  164. pattern: '^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$',
  165. }]
  166. },
  167. school: {
  168. rules: [{
  169. required: true,
  170. errorMessage: '请输入学校全称',
  171. }]
  172. },
  173. major: {
  174. rules: [{
  175. required: true,
  176. errorMessage: '请输入专业名称',
  177. }]
  178. },
  179. nativePlace: {
  180. rules: [{
  181. required: true,
  182. errorMessage: '请输入籍贯',
  183. },
  184. {
  185. pattern: '[\\u4e00-\\u9fa5]+[\\u7701]{1}[\\u4e00-\\u9fa5]+[\\u5E02]{1}[\\u4e00-\\u9fa5]+[\\u53BF|\\u533A]{1}',
  186. errorMessage: '请输入正确的格式:xx省xx市xx区/县',
  187. }
  188. ]
  189. }
  190. }
  191. };
  192. },
  193. onLoad(option) {
  194. if (option.item) {
  195. this.baseFormData = JSON.parse(decodeURIComponent(option.item))
  196. this.buttonMessage = '修改认证'
  197. this.getPhotoes()
  198. } else {
  199. this.idCardFrontByte = [],
  200. this.idCardBackByte = [],
  201. this.profilePhotoByte = [],
  202. this.diplomaPhotoByte = [],
  203. this.buttonMessage = '申请认证'
  204. }
  205. },
  206. methods: {
  207. ...mapMutations('m_user', ['updateAuthentication']),
  208. // 获取图片
  209. async getPhotoes() {
  210. this.diplomaPhotoByte[0].url = this.baseFormData.diplomaPhoto
  211. this.diplomaPhotoByte[0].name = 'diplomaPhoto'
  212. this.idCardBackByte[0].url = this.baseFormData.idCardBack
  213. this.idCardBackByte[0].name = 'idCardBack'
  214. this.profilePhotoByte[0].url = this.baseFormData.profilePhoto
  215. this.profilePhotoByte[0].name = 'profilePhoto'
  216. this.idCardFrontByte[0].url = this.baseFormData.idCardFront
  217. this.idCardFrontByte[0].name = 'idCardFront'
  218. },
  219. // 手机号
  220. async getPhoneNumber(e) {
  221. if (e.detail.code === undefined) return uni.$showMsg('获取手机号失败!')
  222. const query = {
  223. code: e.detail.code
  224. }
  225. const {
  226. data: result
  227. } = await uni.$http.get('/ucenter/mini-program-openid-uid/wxGetPhone', query)
  228. if (result.code === 20000) {
  229. this.baseFormData.phone = result.data.phone
  230. return uni.$showMsg('获取手机成功!')
  231. }
  232. },
  233. deletePhoto(e) {
  234. const photoName = e.tempFile.name
  235. this.baseFormData[photoName] = ''
  236. },
  237. // 上传身份证正面
  238. selectIdCardFront(e) {
  239. this.getUploadPaths(e, 'this.baseFormData.idCardFront')
  240. },
  241. // 上传身份证背面
  242. selcetIdCardBack(e) {
  243. this.getUploadPaths(e, 'this.baseFormData.idCardBack')
  244. },
  245. // 上传毕业/学生证
  246. selectDiplomaPhoto(e) {
  247. this.getUploadPaths(e, 'this.baseFormData.diplomaPhoto')
  248. },
  249. // 上传头像
  250. selectProfilePhoto(e) {
  251. this.getUploadPaths(e, 'this.baseFormData.profilePhoto')
  252. },
  253. getUploadPaths(e, item) {
  254. if (e.tempFiles[0].size > 2000000) {
  255. return uni.$showMsg('图片大小最多2M,超出限制')
  256. }
  257. var that = this
  258. wx.uploadFile({
  259. url: uni.$http.baseUrl + '/file/uploading',
  260. filePath: e.tempFilePaths[0],
  261. name: 'file',
  262. header: {
  263. token: uni.getStorageSync('token')
  264. },
  265. success(res) {
  266. const result = JSON.parse(res.data)
  267. const item1 = item.substring(item.lastIndexOf('.') + 1)
  268. that.baseFormData[item1] = result.data.url
  269. },
  270. fail(res) {
  271. if (res.errno === 1001) {
  272. uni.$showMsg('只能选择.jpg或者.png的图片')
  273. }
  274. }
  275. })
  276. },
  277. submit() {
  278. if (this.isLoading) {
  279. return uni.$showMsg('操作过快,请耐心等待…')
  280. }
  281. this.isLoading = true
  282. this.$refs.baseForm.validate().then(res => {
  283. if (this.baseFormData.phone === undefined) return uni.$showMsg('手机号未获取!')
  284. if (this.baseFormData.idCardFront === undefined || this.baseFormData.idCardFront === '') return uni.$showMsg('身份证正面未上传!')
  285. if (this.baseFormData.idCardBack === undefined || this.baseFormData.idCardBack === '') return uni.$showMsg('身份证背面未上传!')
  286. if (this.baseFormData.diplomaPhoto === undefined || this.baseFormData.diplomaPhoto === '') return uni.$showMsg('学生/毕业证未上传!')
  287. if (this.baseFormData.profilePhoto === undefined || this.baseFormData.profilePhoto === '') return uni.$showMsg('头像未上传!')
  288. if (this.buttonMessage === '修改认证') {
  289. const certificationUrl = '/education/teacher-certifications/updateCertificationInfo'
  290. this.sendRequest(certificationUrl, 2)
  291. } else {
  292. const certificationUrl = '/education/teacher-certifications/saveCertificationInfo'
  293. this.sendRequest(certificationUrl, 1)
  294. }
  295. }).catch(err => {
  296. this.isLoading = false
  297. })
  298. this.isLoading = false
  299. },
  300. sendRequest(certificationUrl, count) {
  301. uni.request({
  302. url: uni.$http.baseUrl + certificationUrl,
  303. data: this.baseFormData,
  304. header: {
  305. token: uni.getStorageSync('token')
  306. },
  307. method: 'POST',
  308. success: res => {
  309. this.isLoading = false
  310. uni.$showMsg(res.data.message)
  311. this.updateAuthentication('审核中')
  312. setTimeout(() => {
  313. uni.navigateBack({
  314. delta: count
  315. })
  316. }, 1000)
  317. }
  318. })
  319. }
  320. }
  321. }
  322. </script>
  323. <!-- 设置页面背景 -->
  324. <style lang="scss">
  325. page{
  326. height: 100%;
  327. //background-color: #FFF2CC;
  328. }
  329. </style>
  330. <style lang="scss" scoped>
  331. .auth-Container{
  332. width: 96%;
  333. height: 100%;
  334. padding-left: 20rpx;
  335. }
  336. .warning {
  337. color: red
  338. }
  339. // 获取手机号按钮背景样式
  340. .getPhone{
  341. background-color: #35b882;
  342. }
  343. // 申请认证按钮样式
  344. .authenticationBtnWrapper{
  345. height: 140rpx;
  346. }
  347. .authenticationBtn{
  348. width: 260rpx;
  349. border-radius: 50rpx;
  350. margin-bottom: 40rpx;
  351. background-color: #35b882;
  352. }
  353. </style>