fund.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view class="switch-roles">
  3. <nav-bar title="福利待遇" color="#000"></nav-bar>
  4. <view class="roles-content">
  5. <view class="content-card">
  6. <view class="card-title">福利待遇</view>
  7. <!-- 已选标签展示区(核心新增) -->
  8. <view class="selected-tags" v-if="selectedTags.length > 0">
  9. <view class="selected-tag-item" v-for="(tag, index) in selectedTags" :key="index">
  10. <text>{{ tag }}</text>
  11. <u-icon
  12. name="close"
  13. size="24rpx"
  14. color="#999"
  15. @click.stop="removeTag(index)"
  16. ></u-icon>
  17. </view>
  18. </view>
  19. <!-- 自定义输入 + 添加按钮区域 -->
  20. <view class="input-area">
  21. <textarea
  22. v-model="customWelfare"
  23. placeholder="请输入自定义福利"
  24. maxlength="500"
  25. class="custom-textarea"
  26. ></textarea>
  27. <button class="add-btn" @click="addCustomTag">添加</button>
  28. <view class="word-count">
  29. <text>{{ customWelfare.length }}</text> /500
  30. </view>
  31. </view>
  32. <!-- 常用标签区域 -->
  33. <view class="tag-section">
  34. <view class="section-title">常用福利标签</view>
  35. <view class="tag-list">
  36. <view
  37. class="tag-item"
  38. :class="{ 'tag-selected': selectedTags.includes(item) }"
  39. v-for="item in fundList"
  40. :key="item"
  41. @click="toggleTag(item)"
  42. >
  43. {{ item }}
  44. </view>
  45. </view>
  46. <view class="selected-count">已选 {{ selectedTags.length }} 个福利</view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="submit-btn" @click="submitWelfare">确定</view>
  51. </view>
  52. </template>
  53. <script>
  54. import navBar from "@/components/nav-bar/index.vue";
  55. export default {
  56. data() {
  57. return {
  58. fundList: [
  59. "五险一金", "定期体检", "年终奖", "带薪年假",
  60. "员工旅游", "节日福利", "绩效奖金", "零食下午茶",
  61. "住房补贴", "交通补贴", "餐饮补贴", "通讯补贴"
  62. ],
  63. customWelfare: "",
  64. selectedTags: [], // 存储所有选中的标签(系统+自定义)
  65. };
  66. },
  67. components: { navBar },
  68. methods: {
  69. // 切换系统标签选中状态
  70. toggleTag(tag) {
  71. if (this.selectedTags.includes(tag)) {
  72. this.selectedTags = this.selectedTags.filter(item => item !== tag);
  73. } else {
  74. if (this.selectedTags.length < 10) {
  75. this.selectedTags.push(tag);
  76. } else {
  77. uni.showToast({ title: '最多选择10个福利', icon: 'none' });
  78. }
  79. }
  80. },
  81. // 移除已选标签(系统或自定义)
  82. removeTag(index) {
  83. this.selectedTags.splice(index, 1);
  84. },
  85. // 添加自定义标签
  86. addCustomTag() {
  87. const tag = this.customWelfare.trim();
  88. if (!tag) {
  89. uni.showToast({ title: '请输入福利内容', icon: 'none' });
  90. return;
  91. }
  92. if (this.selectedTags.includes(tag)) {
  93. uni.showToast({ title: '该福利已添加', icon: 'none' });
  94. return;
  95. }
  96. if (this.selectedTags.length >= 10) {
  97. uni.showToast({ title: '最多选择10个福利', icon: 'none' });
  98. return;
  99. }
  100. this.selectedTags.push(tag); // 添加到选中列表
  101. this.customWelfare = ""; // 清空输入框
  102. },
  103. // 提交回传
  104. submitWelfare() {
  105. const welfareData = this.selectedTags.join(';');
  106. uni.$emit("fundData", welfareData);
  107. uni.navigateBack();
  108. },
  109. },
  110. };
  111. </script>
  112. <style lang="scss" scoped>
  113. .switch-roles {
  114. background-color: #f5f7fa;
  115. position: absolute;
  116. left: 0;
  117. right: 0;
  118. top: 0;
  119. bottom: 0;
  120. display: flex;
  121. flex-direction: column;
  122. .roles-content {
  123. width: 100%;
  124. flex: 1;
  125. overflow-y: auto;
  126. padding: 20rpx;
  127. }
  128. .content-card {
  129. background-color: #fff;
  130. border-radius: 16rpx;
  131. padding: 30rpx;
  132. margin-bottom: 20rpx;
  133. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  134. }
  135. .card-title {
  136. font-size: 32rpx;
  137. font-weight: 600;
  138. color: #333;
  139. margin-bottom: 20rpx;
  140. }
  141. /* 已选标签展示区样式 */
  142. .selected-tags {
  143. display: flex;
  144. flex-wrap: wrap;
  145. gap: 16rpx;
  146. padding: 10rpx 0;
  147. margin-bottom: 20rpx;
  148. min-height: 60rpx;
  149. border-bottom: 1rpx solid #f0f0f0;
  150. padding-bottom: 15rpx;
  151. .selected-tag-item {
  152. display: inline-flex;
  153. align-items: center;
  154. background-color: #f0f7ff;
  155. border-radius: 60rpx;
  156. padding: 8rpx 20rpx;
  157. padding-right: 12rpx;
  158. font-size: 24rpx;
  159. color: #007aff;
  160. gap: 8rpx;
  161. u-icon {
  162. margin-left: 5rpx;
  163. padding: 2rpx;
  164. &:active {
  165. background-color: rgba(0, 0, 0, 0.05);
  166. border-radius: 50%;
  167. }
  168. }
  169. }
  170. }
  171. .input-area {
  172. display: flex;
  173. flex-direction: column;
  174. margin-bottom: 30rpx;
  175. .custom-textarea {
  176. width: 100%;
  177. min-height: 120rpx;
  178. border: 1rpx solid #e5e7eb;
  179. border-radius: 8rpx;
  180. padding: 20rpx;
  181. font-size: 26rpx;
  182. margin-bottom: 16rpx;
  183. }
  184. .add-btn {
  185. align-self: flex-end;
  186. background-color: #007aff;
  187. color: #fff;
  188. border-radius: 8rpx;
  189. font-size: 24rpx;
  190. padding: 10rpx 24rpx;
  191. margin-bottom: 10rpx;
  192. }
  193. .word-count {
  194. font-size: 22rpx;
  195. color: #999;
  196. text-align: right;
  197. text {
  198. color: #007aff;
  199. }
  200. }
  201. }
  202. .tag-section {
  203. .section-title {
  204. font-size: 28rpx;
  205. color: #666;
  206. margin-bottom: 20rpx;
  207. }
  208. .tag-list {
  209. display: flex;
  210. flex-wrap: wrap;
  211. gap: 16rpx;
  212. margin-bottom: 20rpx;
  213. .tag-item {
  214. padding: 12rpx 24rpx;
  215. border: 1rpx solid #d1d5db;
  216. border-radius: 60rpx;
  217. color: #4b5563;
  218. font-size: 26rpx;
  219. background-color: #fff;
  220. }
  221. .tag-selected {
  222. border-color: #007aff;
  223. color: #007aff;
  224. background-color: #e0f2ff;
  225. }
  226. }
  227. .selected-count {
  228. font-size: 24rpx;
  229. color: #666;
  230. }
  231. }
  232. .submit-btn {
  233. margin: 30rpx;
  234. padding: 24rpx 0;
  235. border-radius: 100rpx;
  236. background: linear-gradient(90deg, #005eff, #00bfff);
  237. color: #fff;
  238. font-size: 32rpx;
  239. font-weight: 500;
  240. text-align: center;
  241. }
  242. }
  243. </style>