school-form-launch.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="content">
  3. <!-- 上榜方式区域 -->
  4. <view class="box">
  5. <view class="box_title">
  6. <text class="text">*</text>
  7. 上榜方式
  8. </view>
  9. <picker :range="listRange" @change="changeMode">
  10. <view class="box_input">
  11. <view class="picker" :class="{ pick: form.mode }">{{ form.mode ? form.mode : '请选择上榜方式' }}</view>
  12. <uni-icons type="down" size="24" color="#A6A6A6"></uni-icons>
  13. </view>
  14. </picker>
  15. </view>
  16. <!-- 上传照片区域 -->
  17. <view class="upload">
  18. <image v-if="form.image" class="img" :src="form.image" mode="aspectFill" @click="clickImg(form.image)"></image>
  19. <view v-else class="upload_box" @click="handleUpload">
  20. <uni-icons type="plusempty" size="30" color="#A6A6A6"></uni-icons>
  21. 上传照片
  22. </view>
  23. <!-- 删除图标区域 -->
  24. <view class="delete" v-if="form.image" @click="clickClose">
  25. <uni-icons type="close" size="15" color="#fff"></uni-icons>
  26. </view>
  27. </view>
  28. <!-- 人物简介区域 -->
  29. <view class="desc">
  30. <view class="desc_title">人物简介</view>
  31. <textarea v-model="form.descript" class="textarea" maxlength="-1" placeholder="请输入人物简介"></textarea>
  32. </view>
  33. <!-- 提交按钮区域 -->
  34. <view class="btn" @click="handleSubmit">提交</view>
  35. </view>
  36. </template>
  37. <script setup>
  38. import { ref } from 'vue'
  39. import { uploadImage } from '@/api/uploadImage.js'
  40. import { getApplication } from '@/api/index.js'
  41. const $emit = defineEmits(['change'])
  42. // 上榜方式筛选框数组
  43. const listRange = ['自荐', '学院推荐']
  44. // 提交数据
  45. const form = ref({
  46. // 上榜方式(展示)
  47. mode: '',
  48. // 自荐:1 学院推荐:2 (接口参数)
  49. preferredMethod: '',
  50. // 照片
  51. image: '',
  52. // 人物简介
  53. descript: ''
  54. })
  55. // 选择上榜方式时的回调
  56. const changeMode = (e) => {
  57. // console.log(e)
  58. let index = e.detail.value
  59. form.value.mode = listRange[index]
  60. form.value.preferredMethod = index - 0 + 1
  61. // console.log(form.value)
  62. }
  63. // 上传照片回调
  64. const handleUpload = () => {
  65. uni.chooseImage({
  66. count: 1,
  67. success: async (res) => {
  68. // console.log(res)
  69. uni.showLoading({
  70. title: '上传中...',
  71. mask: true
  72. })
  73. let temp = await uploadImage(res.tempFilePaths[0])
  74. let result = JSON.parse(temp.data)
  75. // console.log(result)
  76. if (result.code == 200) {
  77. form.value.image = result.data.fileUrl
  78. }
  79. // console.log(form.value)
  80. uni.hideLoading()
  81. }
  82. })
  83. }
  84. // 点击图片回调
  85. const clickImg = (e) => {
  86. uni.previewImage({
  87. urls: [e]
  88. })
  89. }
  90. // 点击删除图标回调
  91. const clickClose = () => {
  92. uni.showModal({
  93. title: '提示',
  94. content: '确定删除照片吗?',
  95. success: (res) => {
  96. if (res.confirm) {
  97. form.value.image = ''
  98. }
  99. }
  100. })
  101. }
  102. // 提交按钮回调
  103. const handleSubmit = () => {
  104. // console.log(form.value)
  105. uni.showModal({
  106. title: '提示',
  107. content: '确定提交吗?',
  108. success: (res) => {
  109. if (res.confirm) {
  110. // 提交请求
  111. handleSubmitReq()
  112. }
  113. }
  114. })
  115. }
  116. // 提交请求
  117. const handleSubmitReq = async () => {
  118. const res = await getApplication(form.value)
  119. // console.log(res)
  120. if (res.code == 200) {
  121. uni.showToast({
  122. title: '提交成功',
  123. icon: 'success'
  124. })
  125. setTimeout(() => {
  126. $emit('change', 1)
  127. }, 1500)
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .content {
  133. margin-top: 20rpx;
  134. .box {
  135. margin-bottom: 15rpx;
  136. font-size: 28rpx;
  137. .box_title {
  138. display: flex;
  139. margin-bottom: 15rpx;
  140. .text {
  141. color: #d43030;
  142. }
  143. }
  144. .box_input {
  145. display: flex;
  146. justify-content: space-between;
  147. align-items: center;
  148. padding: 0 22rpx;
  149. width: 710rpx;
  150. height: 80rpx;
  151. border-radius: 6rpx;
  152. background-color: #f5f5f5;
  153. .input {
  154. height: 100%;
  155. font-size: 28rpx;
  156. }
  157. .picker {
  158. color: #a6a6a6;
  159. }
  160. .pick {
  161. color: #000;
  162. }
  163. }
  164. }
  165. .upload {
  166. position: relative;
  167. margin-top: 56rpx;
  168. .img {
  169. width: 140rpx;
  170. height: 140rpx;
  171. border-radius: 8rpx;
  172. }
  173. .upload_box {
  174. display: flex;
  175. flex-direction: column;
  176. justify-content: center;
  177. align-items: center;
  178. margin-top: 30rpx;
  179. width: 140rpx;
  180. height: 140rpx;
  181. color: #a6a6a6;
  182. font-size: 24rpx;
  183. border-radius: 8rpx;
  184. background-color: #f0f6fc;
  185. }
  186. .delete {
  187. z-index: 1;
  188. position: absolute;
  189. top: 5rpx;
  190. left: 102rpx;
  191. display: flex;
  192. align-items: center;
  193. justify-content: center;
  194. width: 30rpx;
  195. height: 30rpx;
  196. }
  197. }
  198. .desc {
  199. margin-top: 30rpx;
  200. .desc_title {
  201. font-size: 28rpx;
  202. font-weight: bold;
  203. }
  204. .textarea {
  205. box-sizing: border-box;
  206. padding: 10rpx;
  207. margin-top: 15rpx;
  208. width: 710rpx;
  209. height: 308rpx;
  210. font-size: 28rpx;
  211. border-radius: 6rpx;
  212. background-color: #f5f5f5;
  213. }
  214. }
  215. .btn {
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. margin: 100rpx auto;
  220. width: 661rpx;
  221. height: 90rpx;
  222. font-size: 28rpx;
  223. color: #fff;
  224. border-radius: 8rpx;
  225. background-color: #007aff;
  226. }
  227. }
  228. </style>