index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 moment from 'moment';
  64. import { getCurrentInstance, computed, ref } from 'vue';
  65. //该依赖已内置不需要单独安装
  66. import { onShow, onLoad } from "@dcloudio/uni-app";
  67. // 请求接口
  68. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  69. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  70. const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
  71. // openid
  72. const openid = computed(() => {
  73. return uni.getStorageSync('openid');
  74. })
  75. // 用户信息
  76. const user = ref({});
  77. // 球队表单
  78. const form = ref({});
  79. // 字典表
  80. const typeList = ref([]);
  81. onShow(() => {
  82. searchUser();
  83. searchOther();
  84. uni.$on('setCity', function (city) {
  85. form.value.city = city
  86. })
  87. })
  88. // 用户信息
  89. const searchUser = async () => {
  90. user.value = uni.getStorageSync('user');
  91. };
  92. // 查询其他信息
  93. const searchOther = async () => {
  94. let res;
  95. // 类型
  96. res = await $api(`dict/data/list`, 'GET', { dictType: 'sys_user_type', status: '0' });
  97. if (res.code === 200 && res.total > 0) typeList.value = res.rows
  98. };
  99. // 类型选择
  100. const typeChange = (e) => {
  101. const data = typeList.value[e.detail.value]
  102. if (data) form.value.type = data.dictLabel
  103. };
  104. // 时间选择器
  105. const dateChange = (e) => {
  106. form.value.date = e.detail.value
  107. };
  108. // 城市选择
  109. const toCity = () => {
  110. if (form.value.city) {
  111. uni.navigateTo({
  112. url: `/pagesHome/city/index?city=${form.value.city}`,
  113. })
  114. } else {
  115. uni.navigateTo({
  116. url: `/pagesHome/city/index`,
  117. })
  118. }
  119. };
  120. // 上传图片
  121. const Preview = () => {
  122. uni.chooseImage({
  123. count: 1,
  124. sizeType: ['original', 'compressed'],
  125. sourceType: ['album', 'camera'],
  126. success: async function (res) {
  127. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  128. const arr = await $apifile(`/common/upload`, 'file', tempFile[0],
  129. 'file');
  130. if (arr.code == 200) {
  131. form.value.logo = arr.url
  132. } else {
  133. uni.showToast({
  134. title: arr.msg,
  135. icon: 'none'
  136. });
  137. }
  138. }
  139. });
  140. };
  141. // 创建
  142. const formSubmit = async (e) => {
  143. if (user.value.id) {
  144. let data = e.detail.value;
  145. data.logo = form.value.logo;
  146. data.city = form.value.city;
  147. data.create_time = moment().format('YYYY-MM-DD HH:mm:ss');
  148. data = delEmptyQueryNodes(data);
  149. data.userId = user.value.id;
  150. const arr = await $api(`team`, 'POST', data);
  151. if (arr.code === 200) {
  152. uni.navigateBack({
  153. delta: 1
  154. })
  155. } else {
  156. uni.showToast({
  157. title: arr.msg,
  158. icon: 'error'
  159. });
  160. }
  161. } else {
  162. uni.showToast({
  163. title: `无用户信息 无法创建球队`,
  164. icon: 'none'
  165. });
  166. }
  167. };
  168. // 去除obj里为null的数据
  169. const delEmptyQueryNodes = (obj = {}) => {
  170. Object.keys(obj).forEach((key) => {
  171. let value = obj[key];
  172. value && typeof value === 'object' && delEmptyQueryNodes(value);
  173. (value === '' || value === null || value === undefined || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  174. });
  175. return obj;
  176. };
  177. </script>
  178. <style lang="scss" scoped>
  179. .content {
  180. display: flex;
  181. flex-direction: column;
  182. width: 100vw;
  183. height: 100vh;
  184. .one {
  185. height: 25vw;
  186. background-color: var(--f00Color);
  187. }
  188. .two {
  189. margin: 10vw 0 0 0;
  190. text-align: center;
  191. font-size: var(--font16Size);
  192. font-weight: bold;
  193. }
  194. .thr {
  195. .logo {
  196. position: fixed;
  197. top: 12vw;
  198. right: 40vw;
  199. .image {
  200. width: 20vw;
  201. height: 20vw;
  202. border-radius: 20vw;
  203. background-color: var(--mainColor);
  204. }
  205. }
  206. .other {
  207. padding: 3vw 2vw;
  208. border-bottom: 1px solid var(--footColor);
  209. }
  210. .remark {
  211. padding: 3vw 2vw 0 2vw;
  212. .title {
  213. padding: 0 0 3vw 0;
  214. }
  215. }
  216. .value {
  217. display: flex;
  218. justify-content: space-between;
  219. align-items: center;
  220. background-color: var(--mainColor);
  221. .label {
  222. .input {
  223. text-align: right;
  224. }
  225. }
  226. }
  227. .button {
  228. text-align: center;
  229. button {
  230. width: 80vw;
  231. font-size: var(--font16Size);
  232. }
  233. }
  234. }
  235. }
  236. </style>