瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
6.1 KiB

  1. <template>
  2. <view class="page">
  3. <navbar title="创建群组" bgColor="#5baaff" color="#fff" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="form-container">
  5. <!-- 群组头像 -->
  6. <view class="avatar-section">
  7. <view class="avatar-title">群组头像</view>
  8. <view class="avatar-upload" @click="chooseAvatar">
  9. <image v-if="groupForm.avatar" :src="groupForm.avatar" class="avatar-preview" mode="aspectFill"></image>
  10. <view v-else class="avatar-placeholder">
  11. <uv-icon name="camera" size="60rpx" color="#ccc"></uv-icon>
  12. <text>点击上传头像</text>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 群组信息表单 -->
  17. <view class="form-section">
  18. <view class="form-item">
  19. <view class="form-label">群组名称</view>
  20. <uv-input
  21. v-model="groupForm.name"
  22. placeholder="请输入群组名称"
  23. :border="false"
  24. :clearable="true"
  25. ></uv-input>
  26. </view>
  27. <view class="form-item">
  28. <view class="form-label">群组描述</view>
  29. <uv-textarea
  30. v-model="groupForm.description"
  31. placeholder="请输入群组描述"
  32. :border="false"
  33. :maxlength="200"
  34. height="120"
  35. ></uv-textarea>
  36. </view>
  37. <view class="form-item">
  38. <view class="form-label">群组类型</view>
  39. <uv-picker
  40. :list="groupTypes"
  41. v-model="groupForm.type"
  42. @confirm="onTypeConfirm"
  43. >
  44. <view class="picker-trigger">
  45. <text>{{ getTypeName(groupForm.type) }}</text>
  46. <uv-icon name="arrow-right" size="30rpx" color="#ccc"></uv-icon>
  47. </view>
  48. </uv-picker>
  49. </view>
  50. <view class="form-item">
  51. <view class="form-label">群组公告</view>
  52. <uv-textarea
  53. v-model="groupForm.announcement"
  54. placeholder="请输入群组公告(可选)"
  55. :border="false"
  56. :maxlength="500"
  57. height="120"
  58. ></uv-textarea>
  59. </view>
  60. <view class="form-item">
  61. <view class="form-label">加入方式</view>
  62. <uv-radio-group v-model="groupForm.joinType">
  63. <view class="radio-item">
  64. <uv-radio name="free" label="自由加入"></uv-radio>
  65. </view>
  66. <view class="radio-item">
  67. <uv-radio name="approve" label="需要审核"></uv-radio>
  68. </view>
  69. </uv-radio-group>
  70. </view>
  71. </view>
  72. <!-- 创建按钮 -->
  73. <view class="submit-section">
  74. <uv-button
  75. type="primary"
  76. text="创建群组"
  77. :loading="submitting"
  78. @click="createGroup"
  79. ></uv-button>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. export default {
  86. data() {
  87. return {
  88. submitting: false,
  89. groupForm: {
  90. name: '',
  91. description: '',
  92. avatar: '',
  93. type: 'local',
  94. announcement: '',
  95. joinType: 'free'
  96. },
  97. groupTypes: [
  98. {
  99. label: '同城群',
  100. value: 'local'
  101. },
  102. {
  103. label: '兴趣群',
  104. value: 'interest'
  105. },
  106. {
  107. label: '工作群',
  108. value: 'work'
  109. },
  110. {
  111. label: '学习群',
  112. value: 'study'
  113. }
  114. ]
  115. }
  116. },
  117. methods: {
  118. // 选择头像
  119. chooseAvatar() {
  120. uni.chooseImage({
  121. count: 1,
  122. sizeType: ['compressed'],
  123. sourceType: ['album', 'camera'],
  124. success: (res) => {
  125. this.groupForm.avatar = res.tempFilePaths[0]
  126. // 这里可以上传图片到服务器
  127. this.uploadAvatar(res.tempFilePaths[0])
  128. }
  129. })
  130. },
  131. // 上传头像
  132. uploadAvatar(filePath) {
  133. // 这里实现图片上传逻辑
  134. console.log('上传头像:', filePath)
  135. },
  136. // 类型选择确认
  137. onTypeConfirm(e) {
  138. this.groupForm.type = e.value
  139. },
  140. // 获取类型名称
  141. getTypeName(type) {
  142. const typeItem = this.groupTypes.find(item => item.value === type)
  143. return typeItem ? typeItem.label : '请选择群组类型'
  144. },
  145. // 创建群组
  146. createGroup() {
  147. if (!this.groupForm.name.trim()) {
  148. uni.showToast({
  149. title: '请输入群组名称',
  150. icon: 'none'
  151. })
  152. return
  153. }
  154. if (!this.groupForm.description.trim()) {
  155. uni.showToast({
  156. title: '请输入群组描述',
  157. icon: 'none'
  158. })
  159. return
  160. }
  161. this.submitting = true
  162. // 模拟创建群组
  163. setTimeout(() => {
  164. this.submitting = false
  165. uni.showToast({
  166. title: '创建成功',
  167. icon: 'success'
  168. })
  169. // 跳转到群组详情页
  170. setTimeout(() => {
  171. this.$utils.navigateTo('/pages_order/group/groupDetail?id=999')
  172. }, 1500)
  173. }, 1000)
  174. }
  175. }
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .page {
  180. background-color: #f5f5f5;
  181. min-height: 100vh;
  182. .form-container {
  183. padding: 20rpx;
  184. .avatar-section {
  185. background-color: #fff;
  186. padding: 30rpx;
  187. border-radius: 20rpx;
  188. margin-bottom: 20rpx;
  189. .avatar-title {
  190. font-size: 30rpx;
  191. font-weight: bold;
  192. color: #333;
  193. margin-bottom: 20rpx;
  194. }
  195. .avatar-upload {
  196. display: flex;
  197. justify-content: center;
  198. .avatar-preview {
  199. width: 120rpx;
  200. height: 120rpx;
  201. border-radius: 20rpx;
  202. }
  203. .avatar-placeholder {
  204. width: 120rpx;
  205. height: 120rpx;
  206. border: 2rpx dashed #ddd;
  207. border-radius: 20rpx;
  208. display: flex;
  209. flex-direction: column;
  210. align-items: center;
  211. justify-content: center;
  212. text {
  213. font-size: 20rpx;
  214. color: #999;
  215. margin-top: 10rpx;
  216. }
  217. }
  218. }
  219. }
  220. .form-section {
  221. background-color: #fff;
  222. padding: 30rpx;
  223. border-radius: 20rpx;
  224. margin-bottom: 20rpx;
  225. .form-item {
  226. margin-bottom: 30rpx;
  227. &:last-child {
  228. margin-bottom: 0;
  229. }
  230. .form-label {
  231. font-size: 28rpx;
  232. color: #333;
  233. margin-bottom: 15rpx;
  234. font-weight: bold;
  235. }
  236. .picker-trigger {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. padding: 20rpx 0;
  241. border-bottom: 1rpx solid #f0f0f0;
  242. text {
  243. font-size: 28rpx;
  244. color: #333;
  245. }
  246. }
  247. .radio-item {
  248. margin-bottom: 15rpx;
  249. &:last-child {
  250. margin-bottom: 0;
  251. }
  252. }
  253. }
  254. }
  255. .submit-section {
  256. padding: 40rpx 0;
  257. .uv-button {
  258. width: 100%;
  259. height: 80rpx;
  260. border-radius: 40rpx;
  261. font-size: 32rpx;
  262. }
  263. }
  264. }
  265. }
  266. </style>