index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. </view>
  5. <view class="two">
  6. <text>设置队徽</text>
  7. </view>
  8. <view class="thr">
  9. <form @submit="formSubmit">
  10. <view class="logo">
  11. <image class="image" mode="aspectFill" :src="form.logo||'/static/qiudui.png'" @tap="Preview">
  12. </image>
  13. </view>
  14. <view class="value other">
  15. <view class="title">名称</view>
  16. <view class="label">
  17. <input name="name" class="input" :value="form.name" placeholder="请输入名称" />
  18. </view>
  19. </view>
  20. <view class="value other">
  21. <view class="title">类型</view>
  22. <view class="label">
  23. <picker name="type" @change="typeChange" :value="index" :range="typeList" range-key="dictLabel">
  24. <view class="picker">{{form.type||'请选择类型'}}</view>
  25. </picker>
  26. </view>
  27. </view>
  28. <view class="value other">
  29. <view class="title">城市</view>
  30. <view class="label" @tap="toCity">
  31. <text v-if="form.city">{{form.city}}</text>
  32. <text v-else>请选择城市</text>
  33. </view>
  34. </view>
  35. <view class="value other">
  36. <view class="title">成立时间</view>
  37. <view class="label">
  38. <picker name="date" mode="date" @change="dateChange" :value="index" fields="month">
  39. <view class="picker">{{form.date||'请选择成立时间'}}</view>
  40. </picker>
  41. </view>
  42. </view>
  43. <view class="value other">
  44. <view class="title">队服颜色</view>
  45. <view class="label">
  46. <input name="color" class="input" :value="form.color" placeholder="请输入队服颜色" />
  47. </view>
  48. </view>
  49. <view class="remark">
  50. <view class="title">简介</view>
  51. <view class="label">
  52. <textarea name="brief" :value="form.brief" placeholder="请简单描述球队" />
  53. </view>
  54. </view>
  55. <view class="button">
  56. <button type="warn" size="mini" form-type="submit">创建</button>
  57. </view>
  58. </form>
  59. </view>
  60. </view>
  61. </template>
  62. <script setup lang="ts">
  63. import { getCurrentInstance, computed, ref } from 'vue';
  64. //该依赖已内置不需要单独安装
  65. import { onShow, onLoad } from "@dcloudio/uni-app";
  66. // 请求接口
  67. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  68. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  69. const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
  70. // openid
  71. const openid = computed(() => {
  72. return uni.getStorageSync('openid');
  73. })
  74. // 用户信息
  75. const user = ref({});
  76. // 球队表单
  77. const form = ref({});
  78. // 字典表
  79. const typeList = ref([]);
  80. onShow(() => {
  81. searchUser();
  82. searchOther();
  83. uni.$on('setCity', function (city) {
  84. form.value.city = city
  85. })
  86. })
  87. // 用户信息
  88. const searchUser = async () => {
  89. user.value = uni.getStorageSync('user');
  90. };
  91. // 查询其他信息
  92. const searchOther = async () => {
  93. let res;
  94. // 类型
  95. res = await $api(`dict/data/list`, 'GET', { dictType: 'sys_user_type' });
  96. if (res.code === 200 && res.total > 0) typeList.value = res.rows
  97. };
  98. // 类型选择
  99. const typeChange = (e) => {
  100. const data = typeList.value[e.detail.value]
  101. if (data) form.value.type = data.dictLabel
  102. };
  103. // 时间选择器
  104. const dateChange = (e) => {
  105. form.value.date = e.detail.value
  106. };
  107. // 城市选择
  108. const toCity = () => {
  109. if (form.value.city) {
  110. uni.navigateTo({
  111. url: `/pagesHome/city/index?city=${form.value.city}`,
  112. })
  113. } else {
  114. uni.navigateTo({
  115. url: `/pagesHome/city/index`,
  116. })
  117. }
  118. };
  119. // 上传图片
  120. const Preview = () => {
  121. uni.chooseImage({
  122. count: 1,
  123. sizeType: ['original', 'compressed'],
  124. sourceType: ['album', 'camera'],
  125. success: async function (res) {
  126. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  127. const arr = await $apifile(`/common/upload`, 'file', tempFile[0],
  128. 'file');
  129. if (arr.code == 200) {
  130. form.value.logo = arr.url
  131. } else {
  132. uni.showToast({
  133. title: arr.msg,
  134. icon: 'none'
  135. });
  136. }
  137. }
  138. });
  139. };
  140. // 创建
  141. const formSubmit = async (e) => {
  142. if (user.value.id) {
  143. let data = e.detail.value;
  144. data.logo = form.value.logo;
  145. data.city = form.value.city;
  146. data = delEmptyQueryNodes(data);
  147. data.userId = user.value.id;
  148. const arr = await $api(`team`, 'POST', data);
  149. if (arr.code === 200) {
  150. uni.navigateBack({
  151. delta: 1
  152. })
  153. } else {
  154. uni.showToast({
  155. title: arr.msg,
  156. icon: 'error'
  157. });
  158. }
  159. } else {
  160. uni.showToast({
  161. title: `无用户信息 无法创建球队`,
  162. icon: 'none'
  163. });
  164. }
  165. };
  166. // 去除obj里为null的数据
  167. const delEmptyQueryNodes = (obj = {}) => {
  168. Object.keys(obj).forEach((key) => {
  169. let value = obj[key];
  170. value && typeof value === 'object' && delEmptyQueryNodes(value);
  171. (value === '' || value === null || value === undefined || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  172. });
  173. return obj;
  174. };
  175. </script>
  176. <style lang="scss" scoped>
  177. .content {
  178. display: flex;
  179. flex-direction: column;
  180. width: 100vw;
  181. height: 100vh;
  182. .one {
  183. height: 25vw;
  184. background-color: var(--f00Color);
  185. }
  186. .two {
  187. margin: 10vw 0 0 0;
  188. text-align: center;
  189. font-size: var(--font16Size);
  190. font-weight: bold;
  191. }
  192. .thr {
  193. .logo {
  194. position: fixed;
  195. top: 12vw;
  196. right: 40vw;
  197. .image {
  198. width: 20vw;
  199. height: 20vw;
  200. border-radius: 20vw;
  201. background-color: var(--mainColor);
  202. }
  203. }
  204. .other {
  205. padding: 3vw 2vw;
  206. border-bottom: 1px solid var(--footColor);
  207. }
  208. .remark {
  209. padding: 3vw 2vw 0 2vw;
  210. .title {
  211. padding: 0 0 3vw 0;
  212. }
  213. }
  214. .value {
  215. display: flex;
  216. justify-content: space-between;
  217. align-items: center;
  218. background-color: var(--mainColor);
  219. .label {
  220. .input {
  221. text-align: right;
  222. }
  223. }
  224. }
  225. .button {
  226. text-align: center;
  227. button {
  228. width: 80vw;
  229. font-size: var(--font16Size);
  230. }
  231. }
  232. }
  233. }
  234. </style>