addChildInformation.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <view>
  3. <u-navbar title="添加子女信息" >
  4. </u-navbar>
  5. <view class="photo" @click="uploadPhoto">
  6. <u-avatar class="avatar"
  7. :src="form.headPhoto != null ? form.headPhoto : '../../assets/img/head.png'" size="160">
  8. </u-avatar>
  9. <view class="edit-photo">
  10. <img src="../../../assets/img/md-camera_alt@1x(1).png" alt="">
  11. </view>
  12. </view>
  13. <view class="change">
  14. 点击更换头像
  15. </view>
  16. <view class="gender">
  17. <view class="man" :class="activeClass ? 'checked' : ''" @click="genderClick">
  18. </view>
  19. <view class="woman" :class="!activeClass ? 'checked' : ''" @click="genderClick">
  20. </view>
  21. </view>
  22. <view class="infos">
  23. <view class="name">
  24. <input type="text" v-model="form.studentName" placeholder="请填写子女姓名">
  25. <view class="icon">
  26. <img src="../../../assets/img/riLine-user-5-line@1x.png" alt="">
  27. </view>
  28. </view>
  29. <view class="birthday" @click="show=true">
  30. <input type="text" v-model="form.birthday" placeholder="请选择子女生日" readonly="readonly" />
  31. <view class="icon">
  32. <img src="../../../assets/img/riLine-calendar-line@1x.png" alt="">
  33. </view>
  34. <view class="icon-right">
  35. <u-icon name="arrow-down" color="#0DBAC7" size="36"></u-icon>
  36. </view>
  37. </view>
  38. <u-picker mode="time" v-model="show" :params="params"
  39. @confirm="confirmTime" @cancel="cancelTime"></u-picker>
  40. </view>
  41. <u-alert-tips :show-icon="true" type="warning" :title="title" :description="description"
  42. :show="alertShow"></u-alert-tips>
  43. <button class="submit" @click="submit"> 提交</button>
  44. <button class="delete" v-if="form.studentId" @click="deleteStudent"> 删除</button>
  45. </view>
  46. </template>
  47. <script>
  48. import * as mineApi from '@/apis/youth/mine.js'
  49. import * as loginApi from '@/apis/login.js'
  50. export default {
  51. data() {
  52. return {
  53. alertShow: false,
  54. title: '',
  55. description: '',
  56. form: {
  57. studentId: '',
  58. studentName: '',
  59. gender: 1,
  60. birthday: '',
  61. headPhoto: ''
  62. },
  63. activeClass: true,
  64. show: false,
  65. params: {
  66. year: true,
  67. month: true,
  68. day: true,
  69. hour: false,
  70. minute: false,
  71. second: false,
  72. timestamp: true,
  73. },
  74. parentsInfo: {}
  75. }
  76. },
  77. onLoad(op) {
  78. if(op) {
  79. this.form.studentId = op.id;
  80. this.getStudentDetail();
  81. this.getParentsInfo();
  82. }
  83. },
  84. methods: {
  85. getParentsInfo() {
  86. uni.showLoading({
  87. title: "加载中",
  88. mask: true,
  89. })
  90. loginApi.findByOpenId({
  91. openId: this.carhelp.getOpenId()
  92. }).then((response) => {
  93. uni.hideLoading();
  94. this.parentsInfo = response.data.regUser;
  95. }).catch(error => {
  96. uni.showToast({
  97. title: error,
  98. icon: "none"
  99. })
  100. })
  101. },
  102. getStudentDetail() {
  103. uni.showLoading({
  104. title: "加载中",
  105. mask: true,
  106. })
  107. mineApi.getStudentDtl({
  108. studentId: this.form.studentId
  109. }).then((response) => {
  110. uni.hideLoading();
  111. this.form.studentName = response.data.studentName;
  112. this.form.gender = response.data.gender;
  113. this.form.birthday = response.data.birthday;
  114. this.form.headPhoto = response.data.headPhoto;
  115. if(this.form.gender == '1') {
  116. this.activeClass = true;
  117. }else {
  118. this.activeClass = false;
  119. }
  120. }).catch(error => {
  121. uni.showToast({
  122. title: error,
  123. icon: "none"
  124. })
  125. })
  126. },
  127. confirmTime(params) {
  128. this.form.birthday = params.year + '-' + params.month + '-' + params.day;
  129. this.show = false;
  130. },
  131. cancelTime() {
  132. this.show = false;
  133. },
  134. submit() {
  135. if(this.form.studentId) {
  136. this.getUpdateStudent();
  137. }else {
  138. this.getAddStudent();
  139. }
  140. },
  141. deleteStudent() {
  142. uni.showLoading({
  143. title: "加载中",
  144. mask: true,
  145. })
  146. mineApi.deleteStudent({
  147. studentId: this.form.studentId
  148. }).then((response) => {
  149. uni.hideLoading();
  150. uni.navigateBack({
  151. })
  152. }).catch(error => {
  153. uni.showToast({
  154. title: error,
  155. icon: "none"
  156. })
  157. })
  158. },
  159. genderClick() {
  160. this.activeClass = !this.activeClass;
  161. if(this.activeClass) {
  162. this.form.gender = 1;
  163. }else {
  164. this.form.gender = 0;
  165. }
  166. },
  167. getAddStudent() {
  168. if(!this.form.studentName) {
  169. uni.showToast({
  170. title: "请填写子女姓名",
  171. icon: "none"
  172. })
  173. return
  174. }
  175. if(!this.form.birthday) {
  176. uni.showToast({
  177. title: "请选择子女生日",
  178. icon: "none"
  179. })
  180. return
  181. }
  182. uni.showLoading({
  183. title: "加载中",
  184. mask: true,
  185. })
  186. mineApi.addStudent({
  187. studentName: this.form.studentName,
  188. gender: this.form.gender,
  189. birthday: this.form.birthday,
  190. headPhoto: this.form.headPhoto
  191. }).then((response) => {
  192. uni.hideLoading();
  193. this.alertShow = false;
  194. uni.navigateBack({
  195. })
  196. }).catch(error => {
  197. uni.hideLoading();
  198. this.alertShow = true;
  199. this.description = error+','+'例如:填写姓名时可用‘姓名+您的电话’的形式';
  200. // uni.showToast({
  201. // title: error,
  202. // icon: "none"
  203. // })
  204. })
  205. },
  206. getUpdateStudent() {
  207. uni.showLoading({
  208. title: "加载中",
  209. mask: true,
  210. })
  211. mineApi.updateStudent({
  212. studentId: this.form.studentId,
  213. studentName: this.form.studentName,
  214. gender: this.form.gender,
  215. birthday: this.form.birthday,
  216. headPhoto: this.form.headPhoto,
  217. firstContactName: this.parentsInfo.nickName,
  218. firstContactPhone: this.parentsInfo.phone
  219. }).then((response) => {
  220. uni.hideLoading();
  221. uni.navigateBack({
  222. })
  223. }).catch(error => {
  224. uni.showToast({
  225. title: error,
  226. icon: "none"
  227. })
  228. })
  229. },
  230. uploadPhoto() {
  231. let _self = this;
  232. var token = _self.carhelp.getToken()
  233. const crop = {
  234. quality: 100,
  235. width: 600,
  236. height: 600,
  237. resize: true
  238. };
  239. // 上传图片
  240. uni.chooseImage({
  241. count: 1,
  242. crop,
  243. success: async (res) => {
  244. //(res);
  245. let tempFile = res.tempFiles[0],
  246. avatar_file = {
  247. // #ifdef H5
  248. extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
  249. // #endif
  250. // #ifndef H5
  251. extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
  252. // #endif
  253. },
  254. filePath = res.tempFilePaths[0]
  255. // #ifndef APP-PLUS
  256. //(`filePath=${filePath}`)
  257. //非app端用前端组件剪裁头像,app端用内置的原生裁剪
  258. let fileData = await new Promise((callback) => {
  259. uni.navigateTo({
  260. url: '/pages/components/cropImage?path=' + filePath +
  261. `&options=${JSON.stringify(crop)}`,
  262. animationType: "fade-in",
  263. events: {
  264. success: url => {
  265. callback(url)
  266. }
  267. }
  268. });
  269. })
  270. // #endif
  271. //返回 base64 图片
  272. //(fileData);
  273. // var token = _self.carhelp.getToken()
  274. uni.showLoading({
  275. title: '上传中'
  276. });
  277. uni.request({
  278. url: process.car.BASE_URL + "/mobile/student/uploadBase64",
  279. method: 'POST',
  280. data: {
  281. photoBase64Data: fileData
  282. },
  283. header: {
  284. 'Authorization': token,
  285. 'content-type': 'application/x-www-form-urlencoded'
  286. },
  287. success: (res) => {
  288. let jsonData = res.data;
  289. _self.form.headPhoto = jsonData.data;
  290. // _self.save();
  291. uni.hideLoading();
  292. }
  293. });
  294. }
  295. });
  296. },
  297. }
  298. }
  299. </script>
  300. <style lang="scss" scoped>
  301. page{
  302. background-color: #fff;
  303. }
  304. .photo{
  305. margin: 20px auto 8px;
  306. width: 160rpx;
  307. height: 160rpx;
  308. position: relative;
  309. img{
  310. width: 100%;
  311. height: 100%;
  312. border-radius: 999px;
  313. }
  314. }
  315. .edit-photo{
  316. width: 56rpx;
  317. height: 56rpx;
  318. background-color: rgba(78, 141, 246, 1);
  319. border: 4rpx solid rgba(255, 255, 255, 1);
  320. text-align: center;
  321. border-radius: 999px;
  322. z-index: 999;
  323. position: absolute;
  324. right: 0;
  325. bottom: 0;
  326. img{
  327. width: 32rpx;
  328. height: 32rpx;
  329. margin-top: 8rpx;
  330. }
  331. }
  332. .change{
  333. color: rgba(13, 186, 199, 1);
  334. text-align: center;
  335. }
  336. .gender{
  337. width: 50%;
  338. margin: 20px auto 40px;
  339. display: flex;
  340. justify-content: space-between;
  341. .man,.woman{
  342. width: 160rpx;
  343. line-height: 64rpx;
  344. border-radius: 100rpx;
  345. background-color: rgba(242, 242, 242, 1);
  346. color: rgba(16, 16, 16, 1);
  347. font-size: 28rpx;
  348. text-align: center;
  349. }
  350. .checked{
  351. background-color: #fff;
  352. color: #43C9D3;
  353. border: 1px solid #43C9D3;
  354. }
  355. }
  356. uni-input{
  357. width: 74.4%;
  358. margin: 0 auto;
  359. border: 1px solid rgba(13, 186, 199, 1);
  360. border-radius: 50px;
  361. height: 88rpx;
  362. line-height: 88rpx;
  363. }
  364. .name,.birthday{
  365. position: relative;
  366. margin-bottom: 20px;
  367. }
  368. ::v-deep.uni-input-placeholder{
  369. text-indent: 72rpx;
  370. color: rgba(204, 204, 204, 1);
  371. font-size:32rpx;
  372. }
  373. ::v-deep.uni-input-input{
  374. text-indent: 72rpx;
  375. }
  376. .icon{
  377. position: absolute;
  378. top: 26rpx;
  379. left: 120rpx;
  380. img{
  381. width: 40rpx;
  382. height: 40rpx;
  383. }
  384. }
  385. .icon-right{
  386. position: absolute;
  387. top: 26rpx;
  388. right: 120rpx;
  389. }
  390. .submit{
  391. margin: 64px 48px 16px 48px;
  392. background-color: rgba(13, 186, 199, 1);
  393. color: rgba(255, 255, 255, 1);
  394. font-size: 16px;
  395. line-height: 44px;
  396. border-radius: 50px;
  397. }
  398. .delete{
  399. margin: 0 48px;
  400. font-size: 16px;
  401. line-height: 44px;
  402. border-radius: 50px;
  403. background-color: rgba(220, 223, 224, 1);
  404. color: rgba(51, 51, 51, 1);
  405. }
  406. </style>