多租户商城-商户小程序端
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.

91 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. const NET = require("./request");
  2. const API = require("../config/api");
  3. /**
  4. * @FileDescription:客服相关函数
  5. * @Author: kahu
  6. * @Date: 2022/11/4
  7. * @LastEditors: kahu
  8. * @LastEditTime: 2022/11/4
  9. */
  10. export function Services(shopId) {
  11. let corpId = null, serviceURL = null
  12. const getServiceUrl = async () => {
  13. uni.showLoading({
  14. title:'加载中...'
  15. })
  16. const shopIds = uni.getStorageSync('service_shopids') || []
  17. const corpIds = uni.getStorageSync('service_corpIds') || []
  18. const urls = uni.getStorageSync('service_urls') || []
  19. try {
  20. const res = await NET.request(API.CustomerService, {}, 'get')
  21. if (res.code === '' && res.data.corpId && res.data.url) {
  22. shopIds.push(shopId)
  23. corpIds.push(res.data.corpId)
  24. urls.push(res.data.url)
  25. uni.setStorageSync('service_shopids', shopIds);
  26. uni.setStorageSync('service_corpIds', corpIds);
  27. uni.setStorageSync('service_urls', urls);
  28. corpId = res.data.corpId
  29. serviceURL = res.data.url
  30. }
  31. } finally {
  32. uni.hideLoading()
  33. }
  34. }
  35. const flyToService = ()=>{
  36. if (!serviceURL || !corpId) {
  37. return uni.showToast({
  38. icon:'none',
  39. title:'暂无客服~'
  40. })
  41. }
  42. // #ifdef MP-WEIXIN
  43. wx.openCustomerServiceChat({
  44. extInfo: {
  45. url: serviceURL
  46. },
  47. corpId: corpId
  48. })
  49. // #endif
  50. // #ifdef APP-PLUS
  51. try {
  52. let wechatServices = null
  53. plus.share.getServices(res => {
  54. wechatServices = res.find(wechatItem => wechatItem.id === 'weixin')
  55. if (wechatServices) {
  56. wechatServices.openCustomerServiceChat({
  57. corpid: corpId,
  58. url: serviceURL,
  59. }, success => {
  60. }, err => {
  61. })
  62. } else {
  63. plus.nativeUI.alert('当前环境不支持微信操作!')
  64. }
  65. }, err=>{
  66. console.error(err)
  67. uni.showToast({title: "获取服务失败,不支持该操作。" + JSON.stringify(err), icon: 'none'})
  68. })
  69. } catch (err) {
  70. console.error(err)
  71. uni.showToast({title: "调用失败,不支持该操作。" + JSON.stringify(err), icon: 'none'})
  72. }
  73. // #endif
  74. // #ifdef H5
  75. // window.open(serviceURL) safari浏览器不支持window.open
  76. window.location.href = serviceURL
  77. // #endif
  78. }
  79. return getServiceUrl().then(res=>{
  80. return {
  81. flyToService
  82. }
  83. })
  84. }