index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <!-- 在线客服 -->
  3. <view v-if="isShow" class="diy-service" :style="{'--right': `${right}px`, '--bottom': `${bottom}px`}">
  4. <!-- 拨打电话 -->
  5. <block v-if="params.type === 'phone'">
  6. <view class="service-icon" @click="onMakePhoneCall">
  7. <image class="image" :src="params.image"></image>
  8. </view>
  9. </block>
  10. <!-- 在线聊天 -->
  11. <block v-else-if="params.type === 'chat'">
  12. <customer-btn>
  13. <view class="service-icon">
  14. <image class="image" :src="params.image"></image>
  15. </view>
  16. </customer-btn>
  17. </block>
  18. </view>
  19. </template>
  20. <script>
  21. import CustomerBtn from '@/components/customer-btn'
  22. import {rpx2px} from '@/utils/util'
  23. import SettingModel from '@/common/model/Setting'
  24. export default {
  25. components: {
  26. CustomerBtn
  27. },
  28. props: {
  29. itemStyle: Object,
  30. params: Object
  31. },
  32. data() {
  33. return {
  34. isShow: false
  35. }
  36. },
  37. computed: {
  38. right() {
  39. return rpx2px(2 * this.itemStyle.right)
  40. },
  41. bottom() {
  42. return rpx2px(2 * this.itemStyle.bottom)
  43. }
  44. },
  45. async created() {
  46. if (this.params.type === 'phone') {
  47. this.isShow = true
  48. }
  49. if (this.params.type === 'chat') {
  50. // this.isShow = await SettingModel.isShowCustomerBtn()
  51. }
  52. },
  53. methods: {
  54. /**
  55. * 点击拨打电话
  56. */
  57. onMakePhoneCall(e) {
  58. uni.makePhoneCall({
  59. phoneNumber: this.params.tel
  60. })
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .diy-service {
  67. position: fixed;
  68. z-index: 999;
  69. right: calc(var(--window-right) + var(--right));
  70. // 设置ios刘海屏底部横线安全区域
  71. bottom: calc(constant(safe-area-inset-bottom) + var(--window-bottom) + var(--bottom));
  72. bottom: calc(env(safe-area-inset-bottom) + var(--window-bottom) + var(--bottom));
  73. .service-icon {
  74. padding: 10rpx;
  75. .image {
  76. display: block;
  77. width: 90rpx;
  78. height: 90rpx;
  79. border-radius: 50%;
  80. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  81. }
  82. }
  83. }
  84. </style>