index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="pic">
  3. <!-- 头部功能组件 -->
  4. <cu-loadding :show="show" />
  5. <!-- header -->
  6. <cu-custom isBack bgColor="bg-gradual-blue"><view slot="content">海报</view></cu-custom>
  7. <!-- section -->
  8. <!-- 富文本 -->
  9. <rich-text :nodes="value.describe"></rich-text>
  10. <view class="bg-white text-gray text-center padding-bottom">
  11. <view v-if="value.name" class="padding-lr-sm padding-tb">{{value.name}},邀请你购买</view>
  12. <view class="padding-lr-sm padding-bottom">{{value.title}}</view>
  13. <view style="width: 400rpx;height: 400rpx;margin: 0 auto;">
  14. <image @click="previewImage(value.wxCode)" style="width: 100%;height: 100%;" mode="aspectFit" :src="value.wxCode" />
  15. </view>
  16. <view class="padding-lr-sm">点击保存</view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. value:"",
  25. show: true
  26. };
  27. },
  28. onLoad(options) {
  29. this.initRequest();
  30. },
  31. methods: {
  32. // 报错
  33. showErr(content) {
  34. content = JSON.stringify(content) === '{}' ? '未知错误' : content;
  35. uni.showModal({
  36. content,
  37. showCancel: false,
  38. success: res => console.log(res)
  39. });
  40. },
  41. async initRequest() {
  42. try {
  43. var res = await this.$global.request({
  44. url: '/customer/activity/poster/',
  45. method: 'get',
  46. header: {
  47. 'Content-Type': 'application/x-www-form-urlencoded',
  48. Authorization: uni.getStorageSync('token')
  49. },
  50. data: {
  51. appid: this.$store.state.userInfo.appid,
  52. activity_id: this.$store.state.userInfo.activity_id
  53. }
  54. });
  55. res.data.describe=this.$global.richTextChange(res.data.describe);
  56. res.data.wxCode=this.$global.options.REQUESTURL+res.data.wxCode;
  57. res.data.name=this.$store.state.userInfo.name;
  58. this.value=res.data;
  59. } catch (err) {
  60. this.showErr(err);
  61. } finally {
  62. this.show = false;
  63. }
  64. },
  65. // 识别二维码
  66. previewImage(img){
  67. uni.previewImage({current:img,urls:[img]});
  68. this.savefunc(img)
  69. },
  70. // 保存图片
  71. savefunc(img){
  72. uni.downloadFile({
  73. url:img,
  74. success:(res)=>{
  75. if(res.statusCode===200){
  76. uni.saveImageToPhotosAlbum({
  77. filePath:res.tempFilePath,
  78. success(res){
  79. uni.showToast({
  80. icon:"none",
  81. title:"保存成功"
  82. })
  83. },
  84. fail(err){
  85. uni.showToast({
  86. icon:"none",
  87. title:"保存失败"
  88. })
  89. }
  90. })
  91. }
  92. }
  93. })
  94. }
  95. }
  96. };
  97. </script>
  98. <style></style>