pearl-add-resource.vue 6.5 KB

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