index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <!-- 在线客服 -->
  3. <view v-if="isShow" class="diy-service" :style="{ '--right': `${itemStyle.right * 2}rpx`, '--bottom': `${itemStyle.bottom * 2}rpx` }">
  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>