猎豆优选小程序

serviceProvider.vue 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <u-mask :show="show" @click="$emit('close')">
  3. <view class="warp">
  4. <view class="rect" @tap.stop>
  5. <view class="kf-block">
  6. <text class="font-bold">{{hint}}</text>
  7. </view>
  8. <image class="kf-evm" :src="serviceInfo.server_info.qrcode" mode="widthFix" :show-menu-by-longpress="true"></image>
  9. <view class="h5-hint">长按识别上方二维码,添加服务商!</view>
  10. <!-- #ifdef MP-WEIXIN -->
  11. <view class="button" @click="downloadImg('fws')">保存二维码到手机</view>
  12. <!-- #endif -->
  13. <block v-if="serviceInfo.server_info.wechat">
  14. <view class="button" @click="copyEvent('fws')">复制微信号</view>
  15. <!-- <view class="wx-text">微信号:{{serviceInfo.server_info.wechat}}</view> -->
  16. </block>
  17. </view>
  18. </view>
  19. </u-mask>
  20. </template>
  21. <script>
  22. export default {
  23. name:"serviceProvider",
  24. props:{
  25. show:{
  26. type: Boolean,
  27. default: false
  28. },
  29. hint:{
  30. type: String,
  31. default: '我是服务商'
  32. }
  33. },
  34. data() {
  35. return {
  36. serviceInfo: {}
  37. };
  38. },
  39. mounted() {
  40. this.getService()
  41. },
  42. methods:{
  43. // 点击下载图片事件,h5不适用
  44. downloadImg(type) {
  45. wx.showLoading({
  46. title: '加载中...'
  47. });
  48. let url = this.serviceInfo.qrcode;
  49. if(type == 'fws'){ // 服务商
  50. url = this.serviceInfo.server_info.qrcode;
  51. }
  52. wx.downloadFile({
  53. url: url, //图片地址
  54. success: function (res) {
  55. //wx.saveImageToPhotosAlbum方法:保存图片到系统相册
  56. wx.saveImageToPhotosAlbum({
  57. filePath: res.tempFilePath, //图片文件路径
  58. success: function (data) {
  59. wx.hideLoading(); //隐藏 loading 提示框
  60. wx.showModal({
  61. title: '提示',
  62. content: '保存成功',
  63. modalType: false,
  64. })
  65. },
  66. // 接口调用失败的回调函数
  67. fail: function (err) {
  68. if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
  69. wx.showModal({
  70. title: '提示',
  71. content: '需要您授权保存相册',
  72. modalType: false,
  73. success: modalSuccess => {
  74. wx.openSetting({
  75. success(settingdata) {
  76. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  77. wx.showModal({
  78. title: '提示',
  79. content: '获取权限成功,再次点击图片即可保存',
  80. modalType: false,
  81. })
  82. } else {
  83. wx.showModal({
  84. title: '提示',
  85. content: '获取权限失败,将无法保存到相册哦~',
  86. modalType: false,
  87. })
  88. }
  89. },
  90. fail(failData) {
  91. console.log("failData", failData)
  92. },
  93. complete(finishData) {
  94. console.log("finishData", finishData)
  95. }
  96. })
  97. }
  98. })
  99. }
  100. },
  101. complete(res) {
  102. wx.hideLoading(); //隐藏 loading 提示框
  103. }
  104. })
  105. }
  106. })
  107. },
  108. // 获取客服信息
  109. async getService () {
  110. try {
  111. const url = this.$api.adzoneCreate_belongToYou;
  112. const params = {}
  113. uni.showLoading({ title: '加载中...', mask: true })
  114. const { data: res } = await this.$postJSON(url, params)
  115. if (res && res.errno == 0) {
  116. this.serviceInfo = res.rst;
  117. } else {
  118. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  119. }
  120. } catch (error) {
  121. uni.showToast({ title: '服务器错误', icon: 'none' })
  122. } finally {
  123. uni.hideLoading()
  124. }
  125. },
  126. //复制微信号
  127. copyEvent(type){
  128. let text = this.serviceInfo.wechat;
  129. if(type == 'fws'){ // 服务商
  130. text = this.serviceInfo.server_info.wechat;
  131. }
  132. this.$copyEvent({text})
  133. },
  134. }
  135. }
  136. </script>
  137. <style scoped lang="scss">
  138. .font-bold{
  139. font-weight: bold;
  140. }
  141. .kf-block{
  142. display: flex;
  143. justify-content: center;
  144. align-items: center;
  145. margin-top: 40rpx;
  146. line-height: 50rpx;
  147. font-size: 32rpx;
  148. color: #333333;
  149. .avatar{
  150. width: 70rpx;
  151. height: 70rpx;
  152. border-radius: 50%;
  153. margin-right: 20rpx;
  154. }
  155. }
  156. .text-block{
  157. display: flex;
  158. justify-content: center;
  159. align-items: center;
  160. font-size: 32rpx;
  161. line-height: 40rpx;
  162. margin-top: 20rpx;
  163. .img{
  164. width: 40rpx;
  165. height: 40rpx;
  166. margin-right: 10rpx;
  167. }
  168. }
  169. .kf-evm{
  170. display: block;
  171. width: 280rpx;
  172. height: 280rpx;
  173. margin: 80rpx auto;
  174. }
  175. .button{
  176. width: 440rpx;
  177. line-height: 70rpx;
  178. background-color: #F52B18;
  179. font-size: 32rpx;
  180. color: #FFFFFF;
  181. text-align: center;
  182. margin: auto;
  183. margin-top: 30rpx;
  184. border-radius: 6rpx;
  185. }
  186. .wx-text{
  187. font-size: 26rpx;
  188. text-align: center;
  189. line-height: 40rpx;
  190. margin-top: 10rpx;
  191. }
  192. .add-question{
  193. text-align: center;
  194. font-size: 26rpx;
  195. line-height: 40rpx;
  196. margin-top: 100rpx;
  197. .fws_button{
  198. color: #F52B18;
  199. margin-left: 6rpx;
  200. font-size: 32rpx;
  201. font-weight: bold;
  202. }
  203. }
  204. .h5-hint{
  205. text-align: center;
  206. font-size: 26rpx;
  207. line-height: 40rpx;
  208. color:#666;
  209. }
  210. .warp {
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. height: 100%;
  215. }
  216. .rect {
  217. width: 600rpx;
  218. height: 860rpx;
  219. background-color: #fff;
  220. border-radius: 20rpx;
  221. padding: 20rpx 40rpx;
  222. }
  223. </style>