match.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="form">
  3. <view class="value other">
  4. <view class="title">类型</view>
  5. <view class="label">
  6. <picker name="type" @change="typeChange" :value="index" :range="typeList" range-key="dictLabel">
  7. <view class="picker">{{type_name||'请选择类型'}}</view>
  8. </picker>
  9. </view>
  10. </view>
  11. <view class="value other margin">
  12. <view class="title">人数</view>
  13. <view class="label">
  14. <picker name="number" @change="numberChange" :value="index" :range="numberList" range-key="dictLabel">
  15. <view class="picker">{{number_name||'请选择人数'}}</view>
  16. </picker>
  17. </view>
  18. </view>
  19. <view class="value other">
  20. <view class="title">对手</view>
  21. <view class="label" @tap="toOpponent">
  22. <text v-if="form.opponent">{{opponent_name}}</text>
  23. <text v-else>请选择</text>
  24. </view>
  25. </view>
  26. <view class="value other">
  27. <view class="title">日期</view>
  28. <view class="label">
  29. <picker name="date" mode="date" @change="dateChange" :value="index">
  30. <view class="picker">{{form.date||'请选择日期'}}</view>
  31. </picker>
  32. </view>
  33. </view>
  34. <view class="value other">
  35. <view class="title">时间</view>
  36. <view class="label">
  37. <picker name="time" mode="time" @change="timeChange" :value="index">
  38. <view class="picker">{{form.time||'请选择时间'}}</view>
  39. </picker>
  40. </view>
  41. </view>
  42. <view class="value other">
  43. <view class="title">时长</view>
  44. <view class="label">
  45. <picker name="duration" @change="durationChange" :value="index" :range="durationList"
  46. range-key="dictLabel">
  47. <view class="picker">{{duration_name||'请选择时长'}}</view>
  48. </picker>
  49. </view>
  50. </view>
  51. <view class="value other margin">
  52. <view class="title">地点</view>
  53. <view class="label" @tap="toLocaltion">
  54. <text v-if="form.address">{{form.address}}</text>
  55. <text v-else>请选择</text>
  56. </view>
  57. </view>
  58. <view class="value other">
  59. <view class="title">费用</view>
  60. <view class="label">
  61. <input name="money" class="input" :value="form.money" placeholder="请输入费用" />
  62. </view>
  63. </view>
  64. <view class="value other">
  65. <view class="title">人数上限</view>
  66. <view class="label">
  67. <input name="name" class="input" :value="form.max_person" placeholder="请输入人数上限" />
  68. </view>
  69. </view>
  70. <view class="value other">
  71. <view class="title">公开报名</view>
  72. <view class="label">
  73. <picker name="is_open" @change="openChange" :value="index" :range="openList" range-key="dictLabel">
  74. <view class="picker">{{open_name||'请选择'}}</view>
  75. </picker>
  76. </view>
  77. </view>
  78. <view class="value other" v-if="form.date&&form.time">
  79. <view class="title">报名截止时间</view>
  80. <view class="label">
  81. <uni-datetime-picker :start="form.date" :border="false" v-model="form.end_time" />
  82. </view>
  83. </view>
  84. <view class="value other">
  85. <view class="title">活动标题</view>
  86. <view class="label">
  87. <input name="title" class="input" :value="form.title" placeholder="请输入活动标题" />
  88. </view>
  89. </view>
  90. <view class="remark margin">
  91. <view class="label">
  92. <textarea name="brief" :value="form.brief" placeholder="请输入简介" />
  93. </view>
  94. </view>
  95. <view class="remark">
  96. <view class="title">上传图片</view>
  97. <view class="label">
  98. <uni-file-picker v-model="form.file" fileMediatype="image" :list-styles="imageStyles" limit="6"
  99. title="最多选择6张图片" @select="toUpload" @delete="toDelete"></uni-file-picker>
  100. </view>
  101. </view>
  102. <view class="btn" style="display: none;">
  103. <button form-type="submit">保存</button>
  104. </view>
  105. </view>
  106. </template>
  107. <script setup lang="ts">
  108. import moment from 'moment';
  109. import { ref, toRefs, getCurrentInstance, defineExpose } from 'vue';
  110. //该依赖已内置不需要单独安装
  111. import { onShow } from "@dcloudio/uni-app";
  112. // 请求接口
  113. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  114. const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
  115. // 信息
  116. const form = ref({ file: [], number: '5', type: '0', duration: '2.0', is_open: 'Y' });
  117. // 对手名称
  118. const opponent_name = ref('');
  119. // 类型
  120. const type_name = ref('足球');
  121. // 人数
  122. const number_name = ref('5人制');
  123. // 是否公开
  124. const open_name = ref('');
  125. // 时长
  126. const duration_name = ref('2.0小时');
  127. const listStyles = ref({
  128. width: 64,
  129. height: 64,
  130. border: {
  131. color: "#ff5a5f",
  132. width: 2,
  133. style: 'dashed',
  134. radius: '2px'
  135. }
  136. });
  137. const props = defineProps({
  138. id: { type: String, default: () => '' },
  139. typeList: { type: Array, default: () => [] },
  140. numberList: { type: Array, default: () => [] },
  141. openList: { type: Array, default: () => [] },
  142. durationList: { type: Array, default: () => [] },
  143. });
  144. const { id, typeList, durationList, numberList, openList } = toRefs(props);
  145. onShow(() => {
  146. uni.$on('opponentInfo', function (item) {
  147. form.value.opponent = item.id
  148. opponent_name.value = item.name
  149. })
  150. })
  151. // 类型选择
  152. const typeChange = (e) => {
  153. const data = typeList.value[e.detail.value]
  154. if (data) {
  155. type_name.value = data.dictLabel
  156. form.value.type = data.dictValue
  157. }
  158. };
  159. // 人数选择
  160. const numberChange = (e) => {
  161. const data = numberList.value[e.detail.value]
  162. if (data) {
  163. number_name.value = data.dictLabel
  164. form.value.number = data.dictValue
  165. }
  166. };
  167. // 日期选择器
  168. const dateChange = (e) => {
  169. form.value.date = e.detail.value
  170. };
  171. // 时间选择器
  172. const timeChange = (e) => {
  173. form.value.time = e.detail.value
  174. };
  175. // 时长选择选择
  176. const durationChange = (e) => {
  177. const data = durationList.value[e.detail.value]
  178. if (data) {
  179. duration_name.value = data.dictLabel
  180. form.value.duration = data.dictValue
  181. }
  182. };
  183. // 是否公开选择器
  184. const openChange = (e) => {
  185. const data = openList.value[e.detail.value]
  186. if (data) {
  187. open_name.value = data.dictLabel
  188. form.value.is_open = data.dictValue
  189. }
  190. };
  191. // 定位
  192. const toLocaltion = (e) => {
  193. uni.chooseLocation({
  194. success: function (res) {
  195. searchAddress(res);
  196. }
  197. })
  198. };
  199. // 解析位置详细信息
  200. const searchAddress = (e) => {
  201. form.value.address = e.address
  202. };
  203. // 上传图片
  204. const toUpload = async (e) => {
  205. const arr = await $apifile(`/common/upload`, 'file', e.tempFilePaths[0],
  206. 'file');
  207. if (arr.code == 200) {
  208. form.value.file.push({
  209. name: arr.originalFilename,
  210. url: arr.url
  211. })
  212. console.log(form.value.file);
  213. } else {
  214. uni.showToast({
  215. title: arr.msg,
  216. icon: 'none'
  217. });
  218. }
  219. };
  220. // 删除图片
  221. const toDelete = async (e) => {
  222. form.value.file = form.value.file.filter(i => i.name != e.tempFile.name)
  223. console.log(form.value.file);
  224. };
  225. // 对手选择
  226. const toOpponent = () => {
  227. uni.navigateTo({
  228. url: `/pagesHome/create/person`,
  229. })
  230. };
  231. // 创建
  232. const formSubmit = async () => {
  233. if (!form.value.opponent) {
  234. uni.showToast({ title: '请选择比赛对手', icon: 'none' });
  235. return
  236. } else if (!form.value.date) {
  237. uni.showToast({ title: '请选择活动日期', icon: 'none' });
  238. return
  239. } else if (!form.value.time) {
  240. uni.showToast({ title: '请选择活动时间', icon: 'none' });
  241. return
  242. } else if (!form.value.address) {
  243. uni.showToast({ title: '请选择活动场地', icon: 'none' });
  244. return
  245. } else {
  246. if (form.value.file && form.value.file.length == 0) delete form.value.file
  247. form.value.teamId = id.value
  248. const arr = await $api(`friendship`, 'POST', form.value);
  249. if (arr.code === 200) {
  250. const data = {
  251. matchId: arr.id,
  252. type: '0',
  253. red: form.value.teamId,
  254. blue: form.value.opponent,
  255. startTime: moment(form.value.date + ' ' + form.value.time).format("YYYY-MM-DD HH:mm"),
  256. endTime: moment(form.value.startTime).add(form.value.duration, 'hours').format("YYYY-MM-DD HH:mm"),
  257. }
  258. const res = await $api(`game`, 'POST', data);
  259. if (res.code === 200) {
  260. uni.navigateTo({
  261. url: `/pagesHome/activity/info?id=${res.id}`,
  262. })
  263. }
  264. } else {
  265. uni.showToast({
  266. title: arr.msg,
  267. icon: 'error'
  268. });
  269. }
  270. }
  271. }
  272. // 第二部:暴露方法
  273. defineExpose({
  274. formSubmit
  275. })
  276. </script>
  277. <style lang="scss" scoped>
  278. .form {
  279. display: flex;
  280. flex-direction: column;
  281. background-color: var(--f9Color);
  282. .other {
  283. padding: 4vw 2vw;
  284. border-bottom: 1px solid var(--footColor);
  285. }
  286. .margin {
  287. margin: 0 0 3vw 0;
  288. }
  289. .remark {
  290. background-color: var(--mainColor);
  291. padding: 3vw 2vw 0 2vw;
  292. .title {
  293. padding: 0 0 3vw 0;
  294. border-bottom: 1px solid var(--footColor);
  295. }
  296. }
  297. .value {
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. background-color: var(--mainColor);
  302. .label {
  303. .input {
  304. text-align: right;
  305. }
  306. }
  307. }
  308. }
  309. </style>