You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

139 lines
3.0 KiB

  1. <template>
  2. <view @click="click" class="tree-item">
  3. <!-- 用户头像 -->
  4. <image
  5. v-if="item.type === 'user'"
  6. class="tree-item-avatar"
  7. :src="avatar"
  8. :style="{ borderRadius: roundAvatar ? '50%' : '3px' }"
  9. mode="aspectFill"
  10. ></image>
  11. <!-- 名称 -->
  12. <text class="tree-item-title">{{ item.name + (item.mobile ? '(' +item.mobile + ')' : "") }}</text>
  13. <!-- 用户标签 -->
  14. <l-tag :line="tagColor" size="sm" class="margin-left-sm">{{ tagName }}</l-tag>
  15. <uni-view v-if="item.type === 'user' && item.mobile" class="margin-left-sm sm line-gray cu-tag" style="z-index: 1;" @tap="copy(item.mobile)">复制</uni-view>
  16. <!-- 如果开启选择按钮显示,并且级别符合,则显示按钮 -->
  17. <view v-if="button" class="tree-item-action">
  18. <l-button v-if="!selectIds.includes(item.id)" @click="itemClick(item)" line="green" size="sm">选择</l-button>
  19. <l-button v-else @click="itemClick(item)" line="blue" size="sm">取消选择</l-button>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import uniCopy from "@/common/js/uni-copy.js"
  25. export default {
  26. name: 'l-organize-single-item',
  27. props: {
  28. item: {},
  29. button: {},
  30. value:{},
  31. },
  32. data(){
  33. return{
  34. selectIds:[],
  35. }
  36. },
  37. created() {
  38. this.init()
  39. },
  40. methods: {
  41. init(){
  42. if(this.value){
  43. this.selectIds = this.value.split(",")
  44. }
  45. },
  46. // 点击事件
  47. click(e) {
  48. this.$emit('click', e)
  49. },
  50. itemClick(root){
  51. if(this.selectIds.indexOf(root.id) !== -1){
  52. this.selectIds.splice(this.selectIds.indexOf(root.id),1)
  53. }else{
  54. this.selectIds.push(root.id)
  55. }
  56. this.$emit('buttonClick', root)
  57. },
  58. copy(mobile){
  59. uniCopy({
  60. content:mobile,
  61. success:(res)=>{
  62. uni.showToast({
  63. title: "复制手机号成功~",
  64. icon: 'none',
  65. duration:3000,
  66. })
  67. },
  68. error:(e)=>{
  69. uni.showToast({
  70. title: e,
  71. icon: 'none',
  72. duration:3000,
  73. })
  74. }
  75. })
  76. }
  77. },
  78. computed: {
  79. // 获取用户头像
  80. avatar() {
  81. if (!Number.isNaN(this.item.img)) {
  82. return Number(this.item.img) === 1 ? '/static/img-avatar/chat-boy.jpg' : '/static/img-avatar/chat-girl.jpg'
  83. }
  84. return this.item.img
  85. },
  86. // 获取树形列表每一项后面 tag 的显示
  87. tagName() {
  88. return { user: '职员', department: '部门', company: '公司' }[this.item.type]
  89. },
  90. // 获取 tag 的颜色
  91. tagColor(item) {
  92. return { company: 'red', department: 'blue', user: 'green' }[this.item.type]
  93. },
  94. // 头像圆形/方形显示参数
  95. roundAvatar() {
  96. return this.CONFIG('pageConfig.roundAvatar')
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="less" scoped>
  102. .tree-item {
  103. background-color: #fff;
  104. display: flex;
  105. min-height: 65rpx;
  106. align-items: center;
  107. .tree-item-avatar {
  108. width: 60rpx;
  109. height: 60rpx;
  110. margin-top: 8rpx;
  111. margin-bottom: 8rpx;
  112. margin-left: 30rpx;
  113. margin-right: 16rpx;
  114. }
  115. .tree-item-action {
  116. position: absolute;
  117. right: 30rpx;
  118. }
  119. }
  120. </style>