addChildInformation.vue 8.0 KB

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