online-service.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <block v-if="online_service_status == 1">
  3. <!-- 是否商品页样式 -->
  4. <view v-if="propIsGoods == true" class="goods-chat-container item fl cp">
  5. <block v-if="is_chat == 1">
  6. <view @tap="chat_event">
  7. <image class="icon" :src="common_static_url+'chat-icon.png'" mode="scaleToFill"></image>
  8. <text class="text dis-block text-size-xs cr-gray">客服</text>
  9. </view>
  10. </block>
  11. <block v-else>
  12. <!-- #ifdef MP-WEIXIN || MP-TOUTIAO || MP-BAIDU || MP-KUAISHOU -->
  13. <button open-type="contact" :show-message-card="propCard" :send-message-title="propTitle" :send-message-path="propPath" :send-message-img="propImg">
  14. <image class="icon" :src="common_static_url+'chat-icon.png'" mode="scaleToFill"></image>
  15. <!-- #endif -->
  16. <!-- #ifdef MP-ALIPAY -->
  17. <button open-type="contact" class="alipay-contact">
  18. <contact-button :tnt-inst-id="mini_alipay_tnt_inst_id" :scene="mini_alipay_scene" :alipay-card-no="mini_alipay_openid || ''" :icon="common_static_url+'chat-icon.png'" size="40rpx*40rpx" />
  19. <!-- #endif -->
  20. <!-- #ifdef H5 || APP -->
  21. <button type="default" @tap="call_event">
  22. <image class="icon" :src="common_static_url+'chat-icon.png'" mode="scaleToFill"></image>
  23. <!-- #endif -->
  24. <text class="text dis-block text-size-xs cr-gray">客服</text>
  25. </button>
  26. </block>
  27. </view>
  28. <!-- 默认浮动展示-可拖拽位置 -->
  29. <view v-else>
  30. <block v-if="is_online_service_fixed == 1">
  31. <movable-area class="online-service-movable-container" :style="'height: calc(100% - '+height_dec+'rpx);top:'+top+'rpx;'">
  32. <movable-view direction="all" :x="x" :y="y" :animation="false" class="online-service-event-submit">
  33. <block v-if="is_chat == 1">
  34. <button type="default" :class="common_ent" @tap="chat_event">
  35. <image class="icon dis-block" :src="common_static_url+'online-service-icon.png'"></image>
  36. </button>
  37. </block>
  38. <block v-else>
  39. <!-- #ifdef MP-WEIXIN || MP-TOUTIAO || MP-BAIDU -->
  40. <button open-type="contact" :class="common_ent" :show-message-card="propCard" :send-message-title="propTitle" :send-message-path="propPath" :send-message-img="propImg">
  41. <image class="icon dis-block" :src="common_static_url+'online-service-icon.png'"></image>
  42. </button>
  43. <!-- #endif -->
  44. <!-- #ifdef MP-ALIPAY -->
  45. <button open-type="contact" :class="'alipay-contact '+common_ent">
  46. <contact-button :tnt-inst-id="mini_alipay_tnt_inst_id" :scene="mini_alipay_scene" :alipay-card-no="mini_alipay_openid || ''" :icon="common_static_url+'online-service-icon.png'" size="40rpx*40rpx" />
  47. </button>
  48. <!-- #endif -->
  49. <!-- #ifdef H5 || APP -->
  50. <button type="default" :class="common_ent" @tap="call_event">
  51. <image class="icon dis-block" :src="common_static_url+'online-service-icon.png'"></image>
  52. </button>
  53. <!-- #endif -->
  54. </block>
  55. </movable-view>
  56. </movable-area>
  57. </block>
  58. </view>
  59. </block>
  60. </template>
  61. <script>
  62. const app = getApp();
  63. var common_static_url = app.globalData.get_static_url('common');
  64. export default {
  65. data() {
  66. return {
  67. common_static_url: common_static_url,
  68. is_chat: 0,
  69. chat_url: null,
  70. common_app_customer_service_tel: null,
  71. online_service_status: 0,
  72. is_online_service_fixed: app.globalData.data.is_online_service_fixed,
  73. mini_alipay_tnt_inst_id: null,
  74. mini_alipay_scene: null,
  75. mini_alipay_openid: null,
  76. system: null,
  77. x: 0,
  78. y: 0,
  79. top: 0,
  80. height_dec: 0,
  81. is_first: 1,
  82. common_ent: ''
  83. };
  84. },
  85. components: {},
  86. props: {
  87. propIsGoods: {
  88. type: Boolean,
  89. default: false
  90. },
  91. propIsBar: {
  92. type: Boolean,
  93. default: false
  94. },
  95. propIsNav: {
  96. type: Boolean,
  97. default: false
  98. },
  99. propCard: {
  100. type: Boolean,
  101. default: false
  102. },
  103. propTitle: {
  104. type: String,
  105. default: ''
  106. },
  107. propImg: {
  108. type: String,
  109. default: ''
  110. },
  111. propPath: {
  112. type: String,
  113. default: ''
  114. },
  115. propIsGrayscale: {
  116. type:Number,
  117. default: 0
  118. },
  119. propIsChat: {
  120. type:Number,
  121. default: 0
  122. },
  123. propChatUrl: {
  124. type: String,
  125. default: ''
  126. },
  127. },
  128. // 属性值改变监听
  129. watch: {
  130. // 是否灰度
  131. propIsGrayscale(value, old_value) {
  132. this.common_ent = (value == 1) ? 'grayscale' : '';
  133. }
  134. },
  135. // 页面被展示
  136. created: function(e) {
  137. this.init_config();
  138. // 非首次进入则重新初始化配置接口
  139. if (this.is_first == 0) {
  140. app.globalData.init_config();
  141. }
  142. // 数据设置
  143. var system = app.globalData.get_system_info(null, null, true);
  144. var width = app.globalData.window_width_handle(system.windowWidth);
  145. var height = app.globalData.window_height_handle(system);
  146. // 页面是否定义导航
  147. var top_h = this.propIsNav ? 170 : 0;
  148. this.setData({
  149. is_first: 0,
  150. system: system,
  151. // 位置坐标
  152. x: width - 43,
  153. y: height - 380,
  154. // 展示位置处理
  155. top: top_h,
  156. height_dec: top_h,
  157. // #ifdef H5 || APP
  158. top: 90,
  159. height_dec: this.propIsBar ? 190 : 90,
  160. // #endif
  161. // 是否使用客服系统
  162. is_chat: this.propIsChat || this.is_chat,
  163. chat_url: this.propChatUrl || this.chat_url,
  164. });
  165. },
  166. methods: {
  167. // 初始化配置
  168. init_config(status) {
  169. if ((status || false) == true) {
  170. // 是否使用客服系统
  171. var is_chat = app.globalData.get_config('plugins_base.chat.data.is_mobile_chat', 0);
  172. var chat_url = app.globalData.get_config('plugins_base.chat.data.chat_url');
  173. if(is_chat == 1 && chat_url != null) {
  174. this.setData({
  175. is_chat: is_chat,
  176. chat_url: chat_url,
  177. common_app_customer_service_tel: app.globalData.get_config('config.common_app_customer_service_tel'),
  178. online_service_status: app.globalData.get_config('config.common_app_is_online_service', 0)
  179. });
  180. } else {
  181. // #ifdef MP-WEIXIN || MP-TOUTIAO || MP-BAIDU || MP-ALIPAY || MP-KUAISHOU || H5 || APP
  182. this.setData({
  183. common_app_customer_service_tel: app.globalData.get_config('config.common_app_customer_service_tel'),
  184. online_service_status: app.globalData.get_config('config.common_app_is_online_service', 0)
  185. });
  186. // #endif
  187. // #ifdef H5 || APP
  188. if((this.common_app_customer_service_tel || null) == null) {
  189. this.setData({
  190. online_service_status: 0
  191. });
  192. }
  193. // #endif
  194. // #ifdef MP-ALIPAY
  195. // 在线客服开启,获取用户openid
  196. if(this.online_service_status == 1)
  197. {
  198. this.setData({
  199. mini_alipay_tnt_inst_id: app.globalData.get_config('config.common_app_mini_alipay_tnt_inst_id'),
  200. mini_alipay_scene: app.globalData.get_config('config.common_app_mini_alipay_scene'),
  201. mini_alipay_openid: app.globalData.get_user_cache_info('alipay_openid')
  202. });
  203. }
  204. // #endif
  205. }
  206. } else {
  207. app.globalData.is_config(this, 'init_config');
  208. }
  209. },
  210. // 客服电话
  211. call_event() {
  212. if (this.common_app_customer_service_tel == null) {
  213. app.globalData.showToast("客服电话有误");
  214. } else {
  215. app.globalData.call_tel(this.common_app_customer_service_tel);
  216. }
  217. },
  218. // 进入客服系统
  219. chat_event() {
  220. var url = this.propChatUrl || this.chat_url || null;
  221. app.globalData.chat_entry_handle(url);
  222. }
  223. }
  224. };
  225. </script>
  226. <style>
  227. .online-service-movable-container {
  228. position: fixed;
  229. width: 100%;
  230. height: 100%;
  231. top: 0;
  232. left: 0;
  233. background: transparent;
  234. pointer-events: none;
  235. z-index: 2;
  236. }
  237. .online-service-event-submit {
  238. pointer-events: auto;
  239. }
  240. .online-service-event-submit,
  241. .online-service-event-submit button {
  242. width: 31px;
  243. height: 31px;
  244. border-radius: 50%;
  245. }
  246. .online-service-event-submit button {
  247. border: 0;
  248. padding: 5px;
  249. box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  250. background: rgba(0, 0, 0, 0.6);
  251. }
  252. .online-service-event-submit .icon {
  253. width: 21px !important;
  254. height: 21px !important;
  255. }
  256. .goods-chat-container button {
  257. padding: 0;
  258. border: 0;
  259. line-height: initial;
  260. font-size: 24rpx;
  261. background: transparent;
  262. }
  263. .goods-chat-container .icon {
  264. width: 40rpx;
  265. height: 40rpx;
  266. margin: 10rpx 0 5rpx 0;
  267. }
  268. .goods-chat-container .text {
  269. margin-top: -10rpx;
  270. }
  271. /* #ifdef MP-ALIPAY */
  272. .goods-chat-container .alipay-contact {
  273. margin-top: 10rpx;
  274. }
  275. .goods-chat-container .alipay-contact .text {
  276. margin-top: -5rpx;
  277. }
  278. .online-service-event-submit contact-button {
  279. line-height: initial;
  280. display: block;
  281. }
  282. /* #endif */
  283. </style>