fund.vue 6.2 KB

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