index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view v-if="detaile">
  3. <view class="cover">
  4. <image :src="detaile.pic" mode="aspectFill"></image>
  5. </view>
  6. <view class="info">
  7. <view class="tit">{{detaile.title}}</view>
  8. <view class="brief">{{detaile.brief}}</view>
  9. </view>
  10. <view class="form">
  11. <view class="li dflex">
  12. <view class="label">姓名</view>
  13. <input placeholder="请输入姓名" placeholder-class="placeholder" class="ipt flex" />
  14. </view>
  15. <view class="li dflex">
  16. <view class="label">手机</view>
  17. <input placeholder="请输入手机号码" placeholder-class="placeholder" class="ipt flex" />
  18. </view>
  19. <view class="save">免费报名</view>
  20. </view>
  21. <view class="det" v-if="detaile.params.imageList && detaile.params.imageList.length > 0">
  22. <image :src="item.url" mode="widthFix" v-for="(item,index) in detaile.params.imageList" :key="index" @click="previewImg(detaile.params.imageList,index)"></image>
  23. </view>
  24. <view class="btn">立即分享</view>
  25. </view>
  26. </template>
  27. <script>
  28. const app = getApp();
  29. const req = require('../../utils/request.js');
  30. const api = require('../../utils/api.js');
  31. const util = require('../../utils/util.js');
  32. import mpHtml from "../../components/mp-html/components/mp-html/mp-html";
  33. export default {
  34. components: {
  35. mpHtml,
  36. },
  37. data() {
  38. return {
  39. code: '',
  40. rootCode: '',
  41. detaile: '',
  42. };
  43. },
  44. onLoad: async function(options) {
  45. if(options.detail){
  46. let params = JSON.parse(decodeURIComponent(options.detail));
  47. console.log('params==',params)
  48. this.code = params.code;
  49. this.shareCode = params.shareCode
  50. this.rootCode = params.rootCode
  51. if(params.appId){
  52. req.setStorage('appId',params.appId)
  53. }
  54. // if(params.userId){
  55. // req.setStorage('pidCode', params.userId);
  56. // }
  57. }
  58. if(options.x_code_id){
  59. console.log('options==',options)
  60. this.sceneId = options.x_code_id
  61. }
  62. await this.loadCodeParams()
  63. await this.getDetail();
  64. },
  65. onShow(){
  66. },
  67. methods: {
  68. monitor() {
  69. let that = this;
  70. let system = uni.getSystemInfoSync();
  71. let query = uni.createSelectorQuery();
  72. query.select('.viewMore').boundingClientRect(data=>{
  73. if(data){
  74. let height = data.height;
  75. if(height > system.windowHeight*2) {
  76. that.height = system.windowHeight *1.8 + 'px';
  77. that.viewMoress = true
  78. }
  79. }
  80. }).exec();
  81. },
  82. viewMores(){
  83. this.height = 'initial';
  84. this.viewMoress = false;
  85. },
  86. choose: function () {
  87. let freshen = false;
  88. this.$emit('freshen', {
  89. detail: freshen
  90. });
  91. },
  92. toIndex(){
  93. uni.switchTab({
  94. url: '/pages/index/index'
  95. })
  96. },
  97. loadCodeParams() {
  98. let _ts = this;
  99. return new Promise((resolve, reject) => {
  100. let form = {
  101. scene: _ts.sceneId
  102. };
  103. if (!_ts.sceneId) {
  104. resolve();
  105. return false;
  106. }
  107. req.getRequest(api.api_code_params, form, data => {
  108. let res = JSON.parse(data.scene);
  109. this.code = res.code;
  110. this.shareCode = res.shareCode
  111. this.rootCode = res.rootCode
  112. if(res.appId){
  113. req.setStorage('appId',res.appId)
  114. }
  115. resolve();
  116. });
  117. });
  118. },
  119. getDateTimeStamp(dateStr){
  120. return util.getDateDiff(Date.parse(dateStr.replace(/-/gi,"/")));
  121. },
  122. getDetail() {
  123. let that = this;
  124. let apiUrl = api.api_material_detail;
  125. return new Promise((resolve,reject)=>{
  126. req.getRequest(apiUrl,{ code: that.code,shareCode: that.shareCode }, res => {
  127. if(res.brief){
  128. res.brief = res.brief.replace(/\r\n/g,"<br>")
  129. res.brief = res.brief.replace(/\n/g,"<br>");
  130. res.brief = res.brief.replace(/↵/g,"<br>");
  131. }
  132. that.detaile = res;
  133. uni.setNavigationBarTitle({
  134. title: res.title
  135. })
  136. resolve();
  137. },true);
  138. })
  139. },
  140. getContentList() {
  141. let form = this.form;
  142. form.rootCode = this.rootCode;
  143. req.getRequest(api.api_material_library,form,res => {
  144. this.contentList = res.list;
  145. for (var i = 0; i < this.contentList.length; i++) {
  146. if (this.contentList[i].code == this.code){
  147. this.contentList.splice(i,1);
  148. }
  149. }
  150. });
  151. },
  152. //预览图片
  153. previewImg(index) {
  154. //预览合同图片
  155. var src = this.detaile.params.imageList[index].url;
  156. let imgs = [];
  157. this.detaile.params.imageList.map(it=>{
  158. imgs.push(it.url)
  159. })
  160. uni.previewImage({
  161. current: src, // 当前显示图片的http链接
  162. urls: imgs
  163. });
  164. },
  165. },
  166. filters: {
  167. /**
  168. * 处理富文本里的图片宽度自适应
  169. * 1.去掉img标签里的style、width、height属性
  170. * 2.img标签添加style属性:max-width:100%;height:auto
  171. * 3.修改所有style里的width属性为max-width:100%
  172. * 4.去掉<br/>标签
  173. * @param html
  174. * @returns {void|string|*}
  175. */
  176. formatRichText(html) {
  177. //控制小程序中图片大小
  178. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  179. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  180. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  181. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  182. return match;
  183. });
  184. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  185. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  186. return match;
  187. });
  188. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  189. newContent = newContent.replace(/<br[^>]*\/>/gi, '<p style="margin: 10px 0;"></p>');
  190. newContent = newContent.replace(/<br[^>]*\>/gi, '<p style="margin: 10px 0;"></p>');
  191. newContent = newContent.replace(/font-size:[^;]+;?/g,'');
  192. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:12rpx auto;"');
  193. return newContent;
  194. }
  195. }
  196. };
  197. </script>
  198. <style>
  199. @import './index.css';
  200. </style>