金诚优选前端代码
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.

320 lines
8.7 KiB

  1. <template>
  2. <view id="spread">
  3. <view class="spreadpage" v-if="init">
  4. <view class="content">
  5. <view class="content-top" :class="erweima.show_agent_tips ? '' : 'hidden'">
  6. 邀请好友当TA成功下单时
  7. </view>
  8. <view class="content-bottom" :class="erweima.show_agent_tips ? '' : 'hidden'">
  9. 您将获得一笔佣金
  10. </view>
  11. <view class="erweima">
  12. <image mode="widthFix" :src="erweima.agent_mini"></image>
  13. <view class="btn-box">
  14. <!-- #ifdef H5 -->
  15. <view class="save btn" :style="'color: ' + config.mainColor + '; border-color: ' + config.mainColor" v-if="erweima.agent_mini">
  16. 长按保存图片
  17. </view>
  18. <!-- #endif -->
  19. <!-- #ifdef APP-PLUS || MP-WEIXIN-->
  20. <view class="save btn" :style="'color: ' + config.mainColor + '; border-color: ' + config.mainColor" @tap="down" v-if="erweima.agent_mini">
  21. 保存图片
  22. </view>
  23. <!-- #endif -->
  24. <!-- #ifdef MP-WEIXIN -->
  25. <button class="btn share" :style="'background: ' + config.mainColor" type="warn" open-type="share">立即邀请</button>
  26. <!-- #endif -->
  27. <!-- #ifdef APP-PLUS -->
  28. <button class="btn share" :style="'background: ' + config.mainColor" type="warn" @click="shareapp">立即邀请</button>
  29. <!-- #endif -->
  30. <!-- #ifdef H5 -->
  31. <button class="btn share" :style="'background: ' + config.mainColor" type="warn" @tap="togglePopup('middle-img')">立即邀请</button>
  32. <!-- #endif -->
  33. <!-- @click="shareapp" -->
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!--用户拒绝下载图片授权弹出-->
  39. <alert :is_refused="is_refused" bind:close="closeAlert"></alert>
  40. <!-- #ifdef H5 -->
  41. <view >
  42. <uni-popup :show="type === 'middle-img'" position="top" mode="fixed" @hidePopup="togglePopup('')">
  43. <view class="uni-center center-box">
  44. <image style="position: absolute; top: 0;right:0" @tap="togglePopup('')" class="image" src="/static/ico-share-wechat.png" />
  45. </view>
  46. </uni-popup>
  47. </view>
  48. <!-- #endif -->
  49. </view>
  50. </template>
  51. <script>
  52. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  53. import alert from "@/components/alert/alert";
  54. import permision from "@/common/js/permission.js"
  55. export default {
  56. data() {
  57. return {
  58. erweima: {},
  59. config: '',
  60. init: false,
  61. is_refused: false,
  62. type:0
  63. };
  64. },
  65. onShareAppMessage(res) {
  66. return {
  67. title: this.erweima.share_title,
  68. path: '/pages/user/personal/personal?agent_code=' + this.erweima.agent_code,
  69. imageUrl: this.erweima.share_img
  70. };
  71. },
  72. onLoad() {
  73. // 第三方平台配置颜色
  74. var bgConfig = this.$cookieStorage.get('globalConfig') || '';
  75. this.setData({
  76. config: bgConfig
  77. });
  78. },
  79. onShow() {
  80. this.getspread();
  81. },
  82. components: {
  83. alert
  84. },
  85. methods: {
  86. togglePopup(type) {
  87. this.type = type;
  88. },
  89. shareapp(){
  90. var title = this.erweima.share_title;
  91. var agent_code = this.erweima.agent_code;
  92. var imageUrl = this.erweima.share_img;
  93. uni.getProvider({
  94. service:'share',
  95. success:function(res){
  96. uni.share({
  97. provider: "weixin",
  98. scene: "WXSceneSession",
  99. type: 5,
  100. title:title,
  101. imageUrl:imageUrl,
  102. miniProgram:{
  103. id:'gh_72e65196278a',
  104. path:'pages/user/user/user?agent_code=' + agent_code,
  105. type:1,
  106. webUrl:'https://guojiang.club'
  107. },
  108. success: function (res) {
  109. console.log("success:" + JSON.stringify(res));
  110. },
  111. fail: function (err) {
  112. console.log("fail:" + JSON.stringify(err));
  113. }
  114. });
  115. }
  116. })
  117. },
  118. closeAlert() {
  119. this.setData({
  120. is_refused: false
  121. });
  122. },
  123. getspread() {
  124. // #ifdef APP-PLUS || MP-WEIXIN
  125. let api = 'api/distribution/getMiniShareHomeInfo';
  126. let share_url = ''
  127. // #endif
  128. // #ifdef H5
  129. let api = 'api/distribution/getH5ShareHomeInfo';
  130. let origin = window.location.origin;
  131. let share_url = origin + '/pages/index/index/index';
  132. // #endif
  133. this.$http.get({
  134. api: api,
  135. data:{
  136. share_url:share_url
  137. },
  138. header: {
  139. Authorization: this.$cookieStorage.get('user_token')
  140. }
  141. }).then(res => {
  142. if (res.statusCode == 200) {
  143. res = res.data;
  144. if (res.status) {
  145. this.setData({
  146. erweima: res.data,
  147. init: true
  148. });
  149. // #ifdef H5
  150. if (this.$wechat && this.$wechat.isWechat()) {
  151. var title = this.erweima.share_title;
  152. var img= this.erweima.share_img;
  153. var agent_code = this.erweima.agent_code;
  154. var origin = window.location.origin;
  155. var path = origin+'/pages/user/personal/personal?agent_code=' + agent_code
  156. this.$wechat.share({
  157. title: title,
  158. img:img,
  159. desc:'果酱小店'
  160. },path);
  161. }
  162. // #endif
  163. } else {
  164. wx.showModal({
  165. content: '请求失败,请稍后重试',
  166. showCancel: false
  167. });
  168. }
  169. } else {
  170. wx.showModal({
  171. content: '请求失败,请稍后重试',
  172. showCancel: false
  173. });
  174. }
  175. });
  176. },
  177. // 下载图片
  178. down() {
  179. if (this.erweima.agent_mini) {
  180. wx.showLoading({
  181. title: '正在下载',
  182. mask: true
  183. });
  184. this.$http.dowloadFile({
  185. api: this.erweima.agent_mini
  186. }).then(res => {
  187. if (res.statusCode == 200) {
  188. // #ifdef MP-WEIXIN
  189. wx.getSetting({
  190. success: ret => {
  191. // 如果之前没有授权
  192. if (!ret.authSetting['scope.writePhotosAlbum']) {
  193. wx.authorize({
  194. scope: 'scope.writePhotosAlbum',
  195. success: rej => {
  196. this.saveImg(res.tempFilePath);
  197. },
  198. // 用户拒绝授权
  199. fail: ret => {
  200. this.setData({
  201. is_refused: true
  202. });
  203. wx.hideLoading();
  204. }
  205. });
  206. } else {
  207. this.saveImg(res.tempFilePath);
  208. }
  209. }
  210. });
  211. //#endif
  212. // #ifdef APP-PLUS
  213. var that = this;
  214. uni.getSystemInfo({
  215. success(result) {
  216. if(result.platform == 'android'){
  217. that.requestAndroidPermission(res.tempFilePath);
  218. } else if(result.platform == 'ios'){
  219. that.requestIosPermission(res.tempFilePath)
  220. }
  221. }
  222. })
  223. this.requestAndroidPermission(res.tempFilePath);
  224. // #endif
  225. } else {
  226. wx.hideLoading();
  227. wx.showToast({
  228. title: '下载图片失败',
  229. icon: 'none'
  230. });
  231. }
  232. }, err => {});
  233. }
  234. },
  235. //ios app授权
  236. requestIosPermission(url){
  237. var result = judgeIosPermission('photoLibrary');
  238. if(result){
  239. this.saveImg(url);
  240. } else{
  241. permision.gotoAppPermissionSetting()
  242. }
  243. },
  244. // 安卓app授权
  245. async requestAndroidPermission(url) {
  246. var result = await permision.requestAndroidPermission("android.permission.WRITE_EXTERNAL_STORAGE")
  247. var strStatus
  248. if (result == 1) {
  249. strStatus = "已获得授权";
  250. this.saveImg(url);
  251. } else if (result == 0) {
  252. strStatus = "未获得授权";
  253. permision.gotoAppPermissionSetting()
  254. } else {
  255. strStatus = "被永久拒绝权限"
  256. permision.gotoAppPermissionSetting()
  257. }
  258. },
  259. // 保存图片
  260. saveImg(path) {
  261. wx.saveImageToPhotosAlbum({
  262. filePath: path,
  263. success: res => {
  264. wx.hideLoading();
  265. },
  266. fail: rej => {
  267. wx.hideLoading();
  268. wx.showToast({
  269. title: '保存图片失败',
  270. icon: 'none'
  271. });
  272. }
  273. });
  274. },
  275. setData: function (obj) {
  276. let that = this;
  277. let keys = [];
  278. let val, data;
  279. Object.keys(obj).forEach(function (key) {
  280. keys = key.split('.');
  281. val = obj[key];
  282. data = that.$data;
  283. keys.forEach(function (key2, index) {
  284. if (index + 1 == keys.length) {
  285. that.$set(data, key2, val);
  286. } else {
  287. if (!data[key2]) {
  288. that.$set(data, key2, {});
  289. }
  290. }
  291. data = data[key2];
  292. });
  293. });
  294. }
  295. },
  296. computed: {},
  297. watch: {}
  298. };
  299. </script>
  300. <style rel="stylesheet/less" lang="less">
  301. @import "spread";
  302. </style>