index.vue 6.9 KB

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