pearl-add-resource.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="container">
  3. <view class="page-header">
  4. <text class="page-title">登记资源</text>
  5. </view>
  6. <!-- 选择资源类型 -->
  7. <view class="form-section">
  8. <text class="section-label">资源类型</text>
  9. <view class="type-grid">
  10. <view class="type-item" v-for="(name, key) in resourceTypes" :key="key"
  11. :class="{selected: selectedType === key}"
  12. @click="selectedType = key">
  13. <text class="type-icon">{{ typeIcons[key] }}</text>
  14. <text class="type-name">{{ name }}</text>
  15. </view>
  16. </view>
  17. </view>
  18. <!-- 资源名称 -->
  19. <view class="form-section">
  20. <text class="section-label">资源名称 <text class="required-mark">*</text></text>
  21. <input class="name-input" v-model="name" :placeholder="namePlaceholder" maxlength="50" />
  22. </view>
  23. <!-- 资源描述 -->
  24. <view class="form-section">
  25. <text class="section-label">描述(选填)</text>
  26. <textarea class="desc-input" v-model="description"
  27. :placeholder="descPlaceholder" maxlength="200"></textarea>
  28. </view>
  29. <!-- 关联联系人(选填) -->
  30. <view class="form-section">
  31. <text class="section-label">关联联系人(选填)</text>
  32. <view class="member-select" v-if="contacts.length > 0">
  33. <view class="member-item" v-for="c in contacts" :key="c.id"
  34. :class="{selected: selectedContactId === c.id}"
  35. @click="selectContact(c)">
  36. <text class="member-name">{{ c.name }}</text>
  37. <text class="member-rel">{{ c.relationshipType }}</text>
  38. </view>
  39. </view>
  40. <text class="empty-hint" v-else>暂无联系人,可暂不关联</text>
  41. </view>
  42. <!-- 提交按钮 -->
  43. <view class="submit-bar">
  44. <button class="btn-submit" @click="onSubmit" :disabled="!canSubmit">保存资源</button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import { getContactList, addPearlResource } from '../../utils/api.js'
  50. export default {
  51. data() {
  52. return {
  53. contacts: [],
  54. selectedContactId: null,
  55. selectedType: '',
  56. name: '',
  57. description: '',
  58. resourceTypes: {
  59. INFO: '信息',
  60. PLACE: '场所',
  61. SKILL: '技能'
  62. },
  63. typeIcons: {
  64. INFO: '📚',
  65. PLACE: '🏠',
  66. SKILL: '🛠️'
  67. }
  68. }
  69. },
  70. computed: {
  71. canSubmit() {
  72. return this.selectedType && this.name.trim()
  73. },
  74. namePlaceholder() {
  75. if (this.selectedType === 'INFO') {
  76. return '如:升学政策渠道、名师课程资源'
  77. }
  78. if (this.selectedType === 'PLACE') {
  79. return '如:社区图书馆、运动场馆'
  80. }
  81. if (this.selectedType === 'SKILL') {
  82. return '如:编程辅导、英语陪练'
  83. }
  84. return '请输入资源名称'
  85. },
  86. descPlaceholder() {
  87. if (this.selectedType === 'INFO') {
  88. return '如:在哪获取、谁提供、怎么用'
  89. }
  90. if (this.selectedType === 'PLACE') {
  91. return '如:地址、开放时间、适合场景'
  92. }
  93. if (this.selectedType === 'SKILL') {
  94. return '如:擅长方向、可帮助的内容'
  95. }
  96. return '简单描述一下这个资源'
  97. }
  98. },
  99. onLoad(options) {
  100. if (options.type) {
  101. this.selectedType = options.type
  102. }
  103. this.loadContacts()
  104. },
  105. methods: {
  106. async loadContacts() {
  107. try {
  108. var res = await getContactList({ page: 1, size: 100 })
  109. if (res.code === 200 && res.data) {
  110. this.contacts = res.data.list || (Array.isArray(res.data) ? res.data : [])
  111. }
  112. } catch (e) {
  113. // 静默:不阻塞登记
  114. }
  115. },
  116. selectContact(contact) {
  117. this.selectedContactId = this.selectedContactId === contact.id ? null : contact.id
  118. },
  119. async onSubmit() {
  120. if (!this.canSubmit) {
  121. uni.showToast({ title: '请选择类型并填写名称', icon: 'none' })
  122. return
  123. }
  124. try {
  125. var data = {
  126. type: this.selectedType,
  127. name: this.name.trim(),
  128. description: this.description.trim()
  129. }
  130. if (this.selectedContactId) {
  131. data.contactId = this.selectedContactId
  132. }
  133. var res = await addPearlResource(data)
  134. if (res.code === 200) {
  135. uni.showToast({ title: '保存成功', icon: 'success' })
  136. setTimeout(function() {
  137. uni.navigateBack()
  138. }, 1500)
  139. } else {
  140. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  141. }
  142. } catch (e) {
  143. uni.showToast({ title: '保存失败', icon: 'none' })
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style scoped>
  150. .container {
  151. min-height: 100vh;
  152. background: #f5f5f5;
  153. padding: 24rpx;
  154. }
  155. .page-header {
  156. padding: 20rpx 0 30rpx;
  157. }
  158. .page-title {
  159. font-size: 36rpx;
  160. font-weight: bold;
  161. color: #333;
  162. }
  163. .form-section {
  164. background: #fff;
  165. border-radius: 16rpx;
  166. padding: 24rpx;
  167. margin-bottom: 20rpx;
  168. }
  169. .section-label {
  170. font-size: 28rpx;
  171. color: #333;
  172. font-weight: 500;
  173. display: block;
  174. margin-bottom: 16rpx;
  175. }
  176. .required-mark {
  177. color: #F97316;
  178. }
  179. .type-grid {
  180. display: flex;
  181. flex-wrap: wrap;
  182. gap: 16rpx;
  183. }
  184. .type-item {
  185. width: calc(33.33% - 11rpx);
  186. padding: 20rpx 0;
  187. text-align: center;
  188. border: 2rpx solid #e0e0e0;
  189. border-radius: 12rpx;
  190. background: #fafafa;
  191. }
  192. .type-item.selected {
  193. border-color: #F97316;
  194. background: #FFF7ED;
  195. }
  196. .type-icon {
  197. font-size: 40rpx;
  198. display: block;
  199. margin-bottom: 8rpx;
  200. }
  201. .type-name {
  202. font-size: 22rpx;
  203. color: #666;
  204. }
  205. .name-input {
  206. width: 100%;
  207. height: 88rpx;
  208. background: #fafafa;
  209. border-radius: 12rpx;
  210. padding: 0 20rpx;
  211. font-size: 28rpx;
  212. box-sizing: border-box;
  213. }
  214. .desc-input {
  215. width: 100%;
  216. height: 160rpx;
  217. background: #fafafa;
  218. border-radius: 12rpx;
  219. padding: 20rpx;
  220. font-size: 28rpx;
  221. box-sizing: border-box;
  222. }
  223. .member-select {
  224. display: flex;
  225. flex-wrap: wrap;
  226. gap: 16rpx;
  227. }
  228. .member-item {
  229. padding: 16rpx 24rpx;
  230. border: 2rpx solid #e0e0e0;
  231. border-radius: 12rpx;
  232. background: #fafafa;
  233. }
  234. .member-item.selected {
  235. border-color: #F97316;
  236. background: #FFF7ED;
  237. }
  238. .member-name {
  239. font-size: 28rpx;
  240. color: #333;
  241. display: block;
  242. }
  243. .member-rel {
  244. font-size: 22rpx;
  245. color: #999;
  246. }
  247. .empty-hint {
  248. font-size: 26rpx;
  249. color: #999;
  250. }
  251. .submit-bar {
  252. margin-top: 40rpx;
  253. }
  254. .btn-submit {
  255. width: 100%;
  256. background: #F97316;
  257. color: #fff;
  258. border: none;
  259. border-radius: 12rpx;
  260. padding: 24rpx 0;
  261. font-size: 32rpx;
  262. }
  263. .btn-submit[disabled] {
  264. background: #ccc;
  265. }
  266. </style>