MemberPickerPopup.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <!--
  3. 统一成员选择弹出控件(底部弹出面板)
  4. 位置:pages/health/components/ —— 位于 pages/health 分包内,
  5. 仅供该分包页面引用;主包/其他分包页面不可引用(分包组件不支持跨分包/主包引用)。
  6. 当前使用方:pages/health/report-list.vue(「调整报告归属」面板)。
  7. 蓝本:components/wuxing-sandbox.vue 的 member-picker-mask / member-picker-panel
  8. (首页能量沙盘「切换视角」成员选择弹出页)。
  9. 用途:替换「需要弹出选择成员」的自定义底部弹出场景。
  10. 约定:
  11. · options 由调用方构建,每项形如 { key, label, memberId, active, member, ...ext }
  12. —— active 为布尔,由调用方或本组件 activeKey 预计算,避免模板 :class 方法调用。
  13. · 选中项显示右侧 check 图标;「取消归属」等特殊操作经 showCancel 呈现为顶部红色行。
  14. · emit('select', option) 携带整项,由调用方决定后续动作(如 reassignReport)。
  15. · emit('close'):遮罩点击 / 右上角 ×。
  16. · emit('cancel-bind'):点击「取消归属」行。
  17. -->
  18. <view v-if="visible" class="member-picker-mask" @click="emitClose">
  19. <view class="member-picker-panel" @click.stop>
  20. <view class="member-picker-title">{{ title }}</view>
  21. <!-- 特殊操作:取消归属(可选) -->
  22. <view class="member-picker-cancel" v-if="showCancel" @click="emitCancelBind">
  23. <text class="member-picker-cancel-text">{{ cancelText }}</text>
  24. <text class="member-picker-cancel-arrow">×</text>
  25. </view>
  26. <!-- 成员选项列表 -->
  27. <view
  28. v-for="option in renderedOptions"
  29. :key="option.key"
  30. class="member-picker-item"
  31. :class="{ 'member-picker-item--active': option.active }"
  32. @click="emitSelect(option)"
  33. >
  34. <text class="member-picker-label">{{ option.label }}</text>
  35. <image class="member-picker-check" v-if="option.active" :src="checkIcon" mode="aspectFit"></image>
  36. </view>
  37. <!-- 空态 -->
  38. <view class="member-picker-empty" v-if="renderedOptions.length === 0">
  39. <text class="member-picker-empty-text">{{ emptyText }}</text>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. /** 选中 check 图标(内联 SVG data URI,品牌深橙 #C2410C,与蓝本 member-picker-check 一致) */
  46. function svgUri(paths, color) {
  47. var inner = ''
  48. for (var i = 0; i < paths.length; i++) {
  49. inner += '<path d="' + paths[i] + '"/>'
  50. }
  51. var svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="' +
  52. color + '" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">' + inner + '</svg>'
  53. return 'data:image/svg+xml,' + encodeURIComponent(svg)
  54. }
  55. var CHECK_ICON = svgUri(['M5 12.8 9.6 17.4 19 7.6'], '#C2410C')
  56. export default {
  57. name: 'MemberPickerPopup',
  58. props: {
  59. /** 是否显示 */
  60. visible: { type: Boolean, default: false },
  61. /** 面板标题 */
  62. title: { type: String, default: '选择成员' },
  63. /** 选项数组:{ key, label, memberId, active, member, ...ext } */
  64. options: { type: Array, default: function() { return [] } },
  65. /** 当前选中 key(可选)。传入后组件自动为匹配项计算 active,调用方可不预计算 */
  66. activeKey: { type: [String, Number], default: null },
  67. /** 是否显示「取消归属」等特殊操作行 */
  68. showCancel: { type: Boolean, default: false },
  69. /** 特殊操作行文案 */
  70. cancelText: { type: String, default: '取消归属' },
  71. /** 空态文案 */
  72. emptyText: { type: String, default: '暂无成员' }
  73. },
  74. data() {
  75. return {
  76. checkIcon: CHECK_ICON
  77. }
  78. },
  79. computed: {
  80. renderedOptions: function() {
  81. var list = this.options instanceof Array ? this.options : []
  82. if (this.activeKey === null || this.activeKey === undefined || this.activeKey === '') {
  83. return list
  84. }
  85. var target = String(this.activeKey)
  86. return list.map(function(option) {
  87. // 保留调用方附加字段(viewMode/member/...),仅覆盖 active —— 供 select 回调按需读取
  88. var copy = {}
  89. for (var k in option) {
  90. if (Object.prototype.hasOwnProperty.call(option, k)) copy[k] = option[k]
  91. }
  92. copy.active = option.active === true || String(option.key) === target
  93. return copy
  94. })
  95. }
  96. },
  97. methods: {
  98. emitClose: function() {
  99. this.$emit('close')
  100. },
  101. emitCancelBind: function() {
  102. this.$emit('cancel-bind')
  103. },
  104. emitSelect: function(option) {
  105. this.$emit('select', option)
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. /* ---- 统一成员选择弹出面板(蓝本:wuxing-sandbox member-picker) ---- */
  112. .member-picker-mask {
  113. position: fixed;
  114. top: 0;
  115. right: 0;
  116. bottom: 0;
  117. left: 0;
  118. z-index: 999;
  119. display: flex;
  120. align-items: flex-end;
  121. background: rgba(0, 0, 0, 0.42);
  122. }
  123. .member-picker-panel {
  124. width: 100%;
  125. max-height: 70vh;
  126. overflow-y: auto;
  127. box-sizing: border-box;
  128. padding: 28rpx 28rpx calc(24rpx + env(safe-area-inset-bottom));
  129. background: $app-surface;
  130. border-radius: 24rpx 24rpx 0 0;
  131. box-shadow: 0 -8rpx 32rpx rgba(0, 0, 0, 0.12);
  132. }
  133. .member-picker-title {
  134. padding-bottom: 16rpx;
  135. font-size: calc(26rpx * var(--font-scale, 1));
  136. font-weight: 700;
  137. color: $app-text;
  138. text-align: center;
  139. }
  140. /* 「取消归属」特殊操作行(红色强调,呼应 report-list 原 cancel-bind-option) */
  141. .member-picker-cancel {
  142. display: flex;
  143. align-items: center;
  144. justify-content: space-between;
  145. padding: 24rpx 0;
  146. border-bottom: 1rpx solid $facade-fill;
  147. margin-bottom: 8rpx;
  148. }
  149. .member-picker-cancel-text {
  150. font-size: calc(28rpx * var(--font-scale, 1));
  151. color: $el-danger;
  152. }
  153. .member-picker-cancel-arrow {
  154. font-size: calc(32rpx * var(--font-scale, 1));
  155. color: $facade-text-ghost;
  156. }
  157. .member-picker-item {
  158. display: flex;
  159. align-items: center;
  160. justify-content: space-between;
  161. min-height: 88rpx;
  162. padding: 0 24rpx;
  163. margin-top: 8rpx;
  164. border-radius: 16rpx;
  165. background: $app-bg;
  166. }
  167. .member-picker-item--active {
  168. background: $brand-primary-soft;
  169. }
  170. .member-picker-label {
  171. font-size: calc(28rpx * var(--font-scale, 1));
  172. color: $app-text;
  173. }
  174. .member-picker-item--active .member-picker-label {
  175. color: $brand-primary-deep;
  176. font-weight: 700;
  177. }
  178. .member-picker-check {
  179. width: 34rpx;
  180. height: 34rpx;
  181. flex-shrink: 0;
  182. }
  183. .member-picker-empty {
  184. padding: 40rpx 0;
  185. text-align: center;
  186. }
  187. .member-picker-empty-text {
  188. font-size: calc(26rpx * var(--font-scale, 1));
  189. color: $facade-text-ghost;
  190. }
  191. </style>