activity.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="form">
  3. <form @submit="formSubmit">
  4. <view class="value other">
  5. <view class="title">类型</view>
  6. <view class="label">
  7. <picker v-if="type=='0'" name="type" @change="typeChange" :value="index" :range="typeList"
  8. range-key="dictLabel">
  9. <view class="picker">{{form.type||'普通训练'}}</view>
  10. </picker>
  11. <picker v-else name="type" @change="typeChange" :value="index" :range="activityList"
  12. range-key="dictLabel">
  13. <view class="picker">{{form.type||'请选择'}}</view>
  14. </picker>
  15. </view>
  16. </view>
  17. <view class="value other">
  18. <view class="title">日期</view>
  19. <view class="label">
  20. <picker name="date" mode="date" @change="dateChange" :value="index">
  21. <view class="picker">{{form.date||'请选择'}}</view>
  22. </picker>
  23. </view>
  24. </view>
  25. <view class="value other">
  26. <view class="title">时间</view>
  27. <view class="label">
  28. <picker name="time" mode="time" @change="timeChange" :value="index">
  29. <view class="picker">{{form.time||'请选择'}}</view>
  30. </picker>
  31. </view>
  32. </view>
  33. <view class="value other">
  34. <view class="title">时长</view>
  35. <view class="label">
  36. <picker name="duration" @change="durationChange" :value="index" :range="durationList"
  37. range-key="dictLabel">
  38. <view class="picker">{{form.duration||'请选择时长'}}</view>
  39. </picker>
  40. </view>
  41. </view>
  42. <view class="value other margin">
  43. <view class="title">地点</view>
  44. <view class="label">
  45. <input name="name" class="input" :value="form.address" placeholder="请选择" />
  46. </view>
  47. </view>
  48. <view class="value other">
  49. <view class="title">费用</view>
  50. <view class="label">
  51. <input name="money" class="input" :value="form.money" placeholder="请输入费用" />
  52. </view>
  53. </view>
  54. <view class="value other">
  55. <view class="title">人数上限</view>
  56. <view class="label">
  57. <input name="name" class="input" :value="form.max_person" placeholder="请输入人数上限" />
  58. </view>
  59. </view>
  60. <view class="value other">
  61. <view class="title">公开报名</view>
  62. <view class="label">
  63. <picker name="is_open" @change="openChange" :value="index" :range="openList" range-key="dictLabel">
  64. <view class="picker">{{form.is_open||'请选择'}}</view>
  65. </picker>
  66. </view>
  67. </view>
  68. <view class="value other" v-if="form.date&&form.time">
  69. <view class="title">报名截止时间</view>
  70. <view class="label">
  71. <uni-datetime-picker :start="form.date" :border="false" v-model="form.end_time" />
  72. </view>
  73. </view>
  74. <view class="value other">
  75. <view class="title">活动标题</view>
  76. <view class="label">
  77. <input name="title" class="input" :value="form.title" placeholder="请输入活动标题" />
  78. </view>
  79. </view>
  80. <view class="remark margin">
  81. <view class="label">
  82. <textarea name="brief" :value="form.brief" placeholder="请输入简介" />
  83. </view>
  84. </view>
  85. <view class="remark">
  86. <view class="title">上传图片</view>
  87. <view class="label">
  88. <uni-file-picker v-model="form.file" fileMediatype="image" :list-styles="imageStyles" limit="6"
  89. title="最多选择6张图片" @select="toUpload" @delete="toDelete"></uni-file-picker>
  90. </view>
  91. </view>
  92. </form>
  93. </view>
  94. </template>
  95. <script setup lang="ts">
  96. import { ref, toRefs, getCurrentInstance } from 'vue';
  97. // 请求接口
  98. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  99. const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
  100. // 信息
  101. const form = ref({ file: [] });
  102. const listStyles = ref({
  103. width: 64,
  104. height: 64,
  105. border: {
  106. color: "#ff5a5f",
  107. width: 2,
  108. style: 'dashed',
  109. radius: '2px'
  110. }
  111. });
  112. const props = defineProps({
  113. type: { type: String, default: () => '0' },
  114. typeList: { type: Array, default: () => [] },
  115. activityList: { type: Array, default: () => [] },
  116. openList: { type: Array, default: () => [] },
  117. durationList: { type: Array, default: () => [] },
  118. });
  119. const { type, typeList, activityList, durationList, openList } = toRefs(props);
  120. // 类型选择
  121. const typeChange = (e) => {
  122. let data
  123. if (type.value == 0) {
  124. data = typeList.value[e.detail.value]
  125. if (data) form.value.type = data.dictLabel
  126. } else {
  127. data = activityList.value[e.detail.value]
  128. if (data) form.value.type = data.dictLabel
  129. }
  130. };
  131. // 时长选择选择
  132. const durationChange = (e) => {
  133. const data = durationList.value[e.detail.value]
  134. if (data) form.value.duration = data.dictLabel
  135. };
  136. // 日期选择器
  137. const dateChange = (e) => {
  138. form.value.date = e.detail.value
  139. };
  140. // 时间选择器
  141. const timeChange = (e) => {
  142. form.value.time = e.detail.value
  143. };
  144. // 是否公开选择器
  145. const openChange = (e) => {
  146. form.value.is_open = e.detail.value
  147. };
  148. // 上传图片
  149. const toUpload = async (e) => {
  150. const arr = await $apifile(`/common/upload`, 'file', e.tempFilePaths[0],
  151. 'file');
  152. if (arr.code == 200) {
  153. form.value.file.push({
  154. newFileName: arr.newFileName,
  155. originalFilename: arr.originalFilename,
  156. url: arr.url
  157. })
  158. console.log(form.value.file);
  159. } else {
  160. uni.showToast({
  161. title: arr.msg,
  162. icon: 'none'
  163. });
  164. }
  165. };
  166. // 删除图片
  167. const toDelete = async (e) => {
  168. form.value.file = form.value.file.filter(i => i.originalFilename != e.tempFile.name)
  169. console.log(form.value.file);
  170. };
  171. </script>
  172. <style lang="scss" scoped>
  173. .form {
  174. display: flex;
  175. flex-direction: column;
  176. background-color: var(--f9Color);
  177. .other {
  178. padding: 4vw 2vw;
  179. border-bottom: 1px solid var(--footColor);
  180. }
  181. .margin {
  182. margin: 0 0 3vw 0;
  183. }
  184. .remark {
  185. background-color: var(--mainColor);
  186. padding: 3vw 2vw 0 2vw;
  187. .title {
  188. padding: 0 0 3vw 0;
  189. border-bottom: 1px solid var(--footColor);
  190. }
  191. }
  192. .value {
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. background-color: var(--mainColor);
  197. .label {
  198. .input {
  199. text-align: right;
  200. }
  201. }
  202. }
  203. }
  204. </style>