index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <form @submit="formSubmit">
  5. <view class="value icon">
  6. <view class="title">头像</view>
  7. <view class="label">
  8. <image class="image" mode="aspectFill" :src="form.icon||config.logoUrl" @tap="Preview"></image>
  9. </view>
  10. </view>
  11. <view class="remark">
  12. 实名信息(仅用于赛事报名、参赛证功能)
  13. </view>
  14. <view class="value other">
  15. <view class="title">姓名</view>
  16. <view class="label">
  17. <input class="input" :value="form.name" placeholder="点击登录" />
  18. </view>
  19. </view>
  20. <view class="value other margin">
  21. <view class="title">昵称</view>
  22. <view class="label">
  23. <input class="input" :value="form.nickname" placeholder="请输入昵称" />
  24. </view>
  25. </view>
  26. <view class="value other">
  27. <view class="title">性别</view>
  28. <view class="label">
  29. <picker @change="sexChange" :value="index" :range="sexList" range-key="dictLabel">
  30. <view class="picker">{{form.sex||'请选择性别'}}</view>
  31. </picker>
  32. </view>
  33. </view>
  34. <view class="value other">
  35. <view class="title">手机号</view>
  36. <view class="label">
  37. <input class="input" :value="form.phone" placeholder="请输入手机号" />
  38. </view>
  39. </view>
  40. <view class="value other">
  41. <view class="title">城市</view>
  42. <view class="label" @tap="toCity">
  43. <text v-if="form.city">{{form.city}}</text>
  44. <text v-else>请选择城市</text>
  45. </view>
  46. </view>
  47. <view class="value other">
  48. <view class="title">身高</view>
  49. <view class="label">
  50. <input class="input" :value="form.height" placeholder="请输入身高" />
  51. </view>
  52. </view>
  53. <view class="value other">
  54. <view class="title">体重</view>
  55. <view class="label">
  56. <input class="input" :value="form.weight" placeholder="请输入体重" />
  57. </view>
  58. </view>
  59. <view class="value other margin">
  60. <view class="title">主要项目</view>
  61. <view class="label">
  62. <picker @change="typeChange" :value="index" :range="typeList" range-key="dictLabel">
  63. <view class="picker">{{form.type||'请选择主要项目'}}</view>
  64. </picker>
  65. </view>
  66. </view>
  67. <view class="value other">
  68. <view class="title">球龄</view>
  69. <view class="label">
  70. <input class="input" :value="form.ballYears" placeholder="请输入球龄" />
  71. </view>
  72. </view>
  73. <view class="value other">
  74. <view class="title">队内位置</view>
  75. <view class="label">
  76. <picker @change="placeChange" :value="index" :range="placeList" range-key="dictLabel">
  77. <view class="picker">{{form.place||'请选择队内位置'}}</view>
  78. </picker>
  79. </view>
  80. </view>
  81. <view class="button">
  82. <button type="primary" size="mini" form-type="submit">保存</button>
  83. </view>
  84. </form>
  85. </view>
  86. </view>
  87. </template>
  88. <script setup lang="ts">
  89. import { getCurrentInstance, computed, ref } from 'vue';
  90. //该依赖已内置不需要单独安装
  91. import { onLoad } from "@dcloudio/uni-app";
  92. // 请求接口
  93. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  94. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  95. const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
  96. // openid
  97. const openid = computed(() => {
  98. return uni.getStorageSync('openid');
  99. })
  100. // 基本信息
  101. const config = ref({ logoUrl: '' });
  102. // 用户信息
  103. const form = ref({ icon: '' });
  104. // 字典表
  105. const sexList = ref([]);
  106. const typeList = ref([]);
  107. const placeList = ref([]);
  108. onLoad(async () => {
  109. await searchOther();
  110. await searchConfig();
  111. await search();
  112. uni.$on('setCity', function (city) {
  113. form.value.city = city
  114. })
  115. })
  116. // 查询其他信息
  117. const searchOther = async () => {
  118. let res;
  119. // 性别
  120. res = await $api(`dict/data/list`, 'GET', { dictType: 'sys_user_sex' });
  121. if (res.code === 200 && res.total > 0) sexList.value = res.rows
  122. // 主要项目
  123. res = await $api(`dict/data/list`, 'GET', { dictType: 'sys_user_type' });
  124. if (res.code === 200 && res.total > 0) typeList.value = res.rows
  125. // 队内位置
  126. res = await $api(`dict/data/list`, 'GET', { dictType: 'sys_user_place' });
  127. if (res.code === 200 && res.total > 0) placeList.value = res.rows
  128. };
  129. // config信息
  130. const searchConfig = async () => {
  131. config.value = uni.getStorageSync('config');
  132. };
  133. // 查询
  134. const search = async () => {
  135. const res = await $api(`matchUser/find`, 'GET', {
  136. openid: openid.value
  137. });
  138. if (res.code === 200) {
  139. if (res.data) console.log(res.data);
  140. else {
  141. uni.navigateTo({
  142. url: `/pages/login/index`,
  143. })
  144. }
  145. } else {
  146. uni.showToast({
  147. title: res.msg || '',
  148. icon: 'error',
  149. });
  150. }
  151. };
  152. // 城市选择
  153. const toCity = () => {
  154. if (form.value.city) {
  155. uni.navigateTo({
  156. url: `/pagesHome/city/index?city=${form.value.city}`,
  157. })
  158. } else {
  159. uni.navigateTo({
  160. url: `/pagesHome/city/index`,
  161. })
  162. }
  163. };
  164. // 性别选择
  165. const sexChange = (e) => {
  166. const data = sexList.value[e.detail.value]
  167. if (data) form.value.sex = data.dictLabel
  168. };
  169. // 主要项目选择
  170. const typeChange = (e) => {
  171. const data = typeList.value[e.detail.value]
  172. if (data) form.value.type = data.dictLabel
  173. };
  174. // 队内位置别选择
  175. const placeChange = (e) => {
  176. const data = placeList.value[e.detail.value]
  177. if (data) form.value.place = data.dictLabel
  178. };
  179. // 上传图片
  180. const Preview = () => {
  181. uni.chooseImage({
  182. count: 1,
  183. sizeType: ['original', 'compressed'],
  184. sourceType: ['album', 'camera'],
  185. success: async function (res) {
  186. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  187. const arr = await $apifile(`/common/upload`, 'file', tempFile[0],
  188. 'file');
  189. if (arr.code == 200) {
  190. form.value.icon = arr.url
  191. } else {
  192. uni.showToast({
  193. title: arr.msg,
  194. icon: 'none'
  195. });
  196. }
  197. }
  198. });
  199. };
  200. </script>
  201. <style lang="scss" scoped>
  202. .content {
  203. display: flex;
  204. flex-direction: column;
  205. width: 100vw;
  206. height: 100vh;
  207. background-color: var(--footColor);
  208. .one {
  209. .icon {
  210. padding: 2vw;
  211. }
  212. .margin {
  213. margin: 3vw 0 0 0;
  214. }
  215. .other {
  216. padding: 3vw 2vw;
  217. border-bottom: 1px solid var(--footColor);
  218. }
  219. .value {
  220. display: flex;
  221. justify-content: space-between;
  222. align-items: center;
  223. background-color: var(--mainColor);
  224. .label {
  225. .input {
  226. text-align: right;
  227. }
  228. .image {
  229. width: 15vw;
  230. height: 15vw;
  231. border-radius: 20vw;
  232. }
  233. }
  234. }
  235. .remark {
  236. padding: 4vw 2vw;
  237. text-align: center;
  238. color: var(--f99Color);
  239. font-size: var(--font18Size);
  240. }
  241. .button {
  242. margin: 2vw 0 0 0;
  243. text-align: center;
  244. button {
  245. font-size: var(--font14Size);
  246. border-radius: 2vw;
  247. background: linear-gradient(to right, #00BFFF, #3F94F1, #7B68EE);
  248. }
  249. }
  250. }
  251. }
  252. </style>