index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <form @submit="formSubmit">
  5. <view class="value other" style="display: none;">
  6. <view class="title">id</view>
  7. <view class="label">
  8. <input name="id" class="input" :value="form.id" placeholder="请输入id" />
  9. </view>
  10. </view>
  11. <view class="value icon">
  12. <view class="title">头像</view>
  13. <view class="label">
  14. <image v-if="form.icon" class="image" mode="aspectFill" :src="form.icon" @tap="Preview"></image>
  15. <u-avatar v-else text="车" fontSize="20" randomBgColor :colorIndex="0"></u-avatar>
  16. </view>
  17. </view>
  18. <view class="remark">
  19. 实名信息(仅用于咨询、免费估值功能)
  20. </view>
  21. <view class="value other">
  22. <view class="title">姓名</view>
  23. <view class="label">
  24. <input name="name" class="input" :value="form.name" placeholder="请输入真实姓名" />
  25. </view>
  26. </view>
  27. <view class="value other margin">
  28. <view class="title">昵称</view>
  29. <view class="label">
  30. <input name="nickname" class="input" :value="form.nickname" placeholder="请输入昵称" />
  31. </view>
  32. </view>
  33. <view class="value other">
  34. <view class="title">性别</view>
  35. <view class="label">
  36. <picker name="sex" @change="sexChange" :value="index" :range="sexList" range-key="dictLabel">
  37. <view class="picker">{{form.sex||'请选择性别'}}</view>
  38. </picker>
  39. </view>
  40. </view>
  41. <view class="value other">
  42. <view class="title">手机号</view>
  43. <view class="label">
  44. <input name="phone" class="input" :value="form.phone" placeholder="请输入手机号" />
  45. </view>
  46. </view>
  47. <view class="button">
  48. <button type="warn" size="mini" form-type="submit">保存</button>
  49. </view>
  50. </form>
  51. </view>
  52. </view>
  53. </template>
  54. <script setup lang="ts">
  55. import { getCurrentInstance, computed, ref } from 'vue';
  56. //该依赖已内置不需要单独安装
  57. import { onLoad } from "@dcloudio/uni-app";
  58. // 请求接口
  59. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  60. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  61. const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
  62. // openid
  63. const openid = computed(() => {
  64. return uni.getStorageSync('openid');
  65. })
  66. // 基本信息
  67. const config = ref({ logoUrl: '' });
  68. // 用户信息
  69. const form = ref({ icon: '', city: '', sex: '', nickname: '', phone: '' });
  70. // 字典表
  71. const sexList = ref([]);
  72. onLoad(async () => {
  73. await searchOther();
  74. await searchConfig();
  75. await search();
  76. uni.$on('setCity', function (city) {
  77. form.value.city = city
  78. })
  79. })
  80. // 查询其他信息
  81. const searchOther = async () => {
  82. let res;
  83. };
  84. // config信息
  85. const searchConfig = async () => {
  86. config.value = uni.getStorageSync('config');
  87. };
  88. // 查询
  89. const search = async () => {
  90. };
  91. // 处理字典表数据
  92. const toData = (value, list) => {
  93. if (value) return value = list[value].dictLabel
  94. };
  95. // 性别选择
  96. const sexChange = (e) => {
  97. const data = sexList.value[e.detail.value]
  98. if (data) form.value.sex = data.dictLabel
  99. };
  100. // 上传图片
  101. const Preview = () => {
  102. uni.chooseImage({
  103. count: 1,
  104. sizeType: ['original', 'compressed'],
  105. sourceType: ['album', 'camera'],
  106. success: async function (res) {
  107. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  108. console.log(tempFile);
  109. }
  110. });
  111. };
  112. // 保存
  113. const formSubmit = async (e) => {
  114. let data = e.detail.value;
  115. data.icon = form.value.icon;
  116. data = delEmptyQueryNodes(data);
  117. console.log(data);
  118. };
  119. // 去除obj里为null的数据
  120. const delEmptyQueryNodes = (obj = {}) => {
  121. Object.keys(obj).forEach((key) => {
  122. let value = obj[key];
  123. value && typeof value === 'object' && delEmptyQueryNodes(value);
  124. (value === '' || value === null || value === undefined || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  125. });
  126. return obj;
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .content {
  131. display: flex;
  132. flex-direction: column;
  133. width: 100vw;
  134. height: 100vh;
  135. background-color: var(--footColor);
  136. .one {
  137. .icon {
  138. padding: 2vw;
  139. }
  140. .margin {
  141. margin: 3vw 0 0 0;
  142. }
  143. .other {
  144. padding: 3vw 2vw;
  145. border-bottom: 1px solid var(--footColor);
  146. }
  147. .value {
  148. display: flex;
  149. justify-content: space-between;
  150. align-items: center;
  151. background-color: var(--mainColor);
  152. .label {
  153. .input {
  154. text-align: right;
  155. }
  156. .image {
  157. width: 15vw;
  158. height: 15vw;
  159. border-radius: 20vw;
  160. }
  161. }
  162. }
  163. .remark {
  164. padding: 4vw 2vw;
  165. text-align: center;
  166. color: var(--f99Color);
  167. font-size: var(--font18Size);
  168. }
  169. .button {
  170. margin: 2vw 0 0 0;
  171. text-align: center;
  172. button {
  173. background-color: var(--fFFColor);
  174. font-size: var(--font14Size);
  175. border-radius: 2vw;
  176. }
  177. }
  178. }
  179. }
  180. </style>