activity.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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=='1'" 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, defineExpose } 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. id: { type: String, default: () => '' },
  114. type: { type: String, default: () => '0' },
  115. typeList: { type: Array, default: () => [] },
  116. activityList: { type: Array, default: () => [] },
  117. openList: { type: Array, default: () => [] },
  118. durationList: { type: Array, default: () => [] },
  119. });
  120. const { id, type, typeList, activityList, durationList, openList } = toRefs(props);
  121. // 类型选择
  122. const typeChange = (e) => {
  123. let data
  124. if (type.value == '1') {
  125. data = typeList.value[e.detail.value]
  126. if (data) form.value.type = data.dictLabel
  127. } else {
  128. data = activityList.value[e.detail.value]
  129. if (data) form.value.type = data.dictLabel
  130. }
  131. };
  132. // 时长选择选择
  133. const durationChange = (e) => {
  134. const data = durationList.value[e.detail.value]
  135. if (data) form.value.duration = data.dictLabel
  136. };
  137. // 日期选择器
  138. const dateChange = (e) => {
  139. form.value.date = e.detail.value
  140. };
  141. // 时间选择器
  142. const timeChange = (e) => {
  143. form.value.time = e.detail.value
  144. };
  145. // 是否公开选择器
  146. const openChange = (e) => {
  147. form.value.is_open = e.detail.value
  148. };
  149. // 上传图片
  150. const toUpload = async (e) => {
  151. const arr = await $apifile(`/common/upload`, 'file', e.tempFilePaths[0],
  152. 'file');
  153. if (arr.code == 200) {
  154. form.value.file.push({
  155. newFileName: arr.newFileName,
  156. originalFilename: arr.originalFilename,
  157. url: arr.url
  158. })
  159. console.log(form.value.file);
  160. } else {
  161. uni.showToast({
  162. title: arr.msg,
  163. icon: 'none'
  164. });
  165. }
  166. };
  167. // 删除图片
  168. const toDelete = async (e) => {
  169. form.value.file = form.value.file.filter(i => i.originalFilename != e.tempFile.name)
  170. console.log(form.value.file);
  171. };
  172. // 创建
  173. const formSubmit = () => {
  174. console.log(form.value)
  175. }
  176. // 第二部:暴露方法
  177. defineExpose({
  178. formSubmit
  179. })
  180. </script>
  181. <style lang="scss" scoped>
  182. .form {
  183. display: flex;
  184. flex-direction: column;
  185. background-color: var(--f9Color);
  186. .other {
  187. padding: 4vw 2vw;
  188. border-bottom: 1px solid var(--footColor);
  189. }
  190. .margin {
  191. margin: 0 0 3vw 0;
  192. }
  193. .remark {
  194. background-color: var(--mainColor);
  195. padding: 3vw 2vw 0 2vw;
  196. .title {
  197. padding: 0 0 3vw 0;
  198. border-bottom: 1px solid var(--footColor);
  199. }
  200. }
  201. .value {
  202. display: flex;
  203. justify-content: space-between;
  204. align-items: center;
  205. background-color: var(--mainColor);
  206. .label {
  207. .input {
  208. text-align: right;
  209. }
  210. }
  211. }
  212. }
  213. </style>