index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <view class="signUp">
  3. <image class="good-img" :src="info.activityCover" mode="aspectFit"></image>
  4. <view class="goods-info">
  5. <view class="goods-name">
  6. {{ info.activityName }}
  7. </view>
  8. <view class="price-box" v-if="info.activityEnable == 1">
  9. <view class="left">
  10. <view class="unit">
  11. </view>
  12. <view class="price">
  13. {{ info.price }}
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="list">
  19. <view class="item">
  20. <view class="label">
  21. 活动时间
  22. </view>
  23. <view class="value">
  24. {{ info.activityStartTime }} 至 {{ info.activityEndTime }}
  25. </view>
  26. </view>
  27. <view class="item" v-if="info.activityEnable == 1">
  28. <view class="label">
  29. 报名时间
  30. </view>
  31. <view class="value">
  32. {{ info.signupStartTime }} 至 {{ info.signupEndTime }}
  33. </view>
  34. </view>
  35. <view class="item" v-if="info.address">
  36. <view class="label">
  37. 活动地址
  38. </view>
  39. <view class="value">
  40. {{ info.address }}
  41. </view>
  42. </view>
  43. </view>
  44. <view class="sub-title">
  45. 活动详情
  46. </view>
  47. <view class="desc-box">
  48. <rich-text @click="goImgDetials" class="goods-desc" :nodes="info.activityDetail"></rich-text>
  49. </view>
  50. <view class="buy-box" v-if="info.activityEnable == 1 && !isEnd">
  51. <button class="buy-btn" type="default" @click="handleSignUp">报名</button>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import { getActivityDetail } from '@/api/activity.js'
  57. export default {
  58. data() {
  59. return {
  60. id: 0,
  61. info: {},
  62. isEnd: false
  63. }
  64. },
  65. onshareAppMessage() {
  66. return {
  67. title: this.info.activityName,
  68. path: `/signUp/index?scene=${this.id}`
  69. }
  70. },
  71. methods: {
  72. extractImageSrcFromHtml(htmlString) {
  73. // 正则表达式用于匹配 <img> 标签的 src 属性
  74. const regex = /<img[^>]+src="([^"]+)"[^>]*>/gi;
  75. let match;
  76. const result = [];
  77. // 执行正则表达式匹配,并收集所有匹配到的 src 属性
  78. while ((match = regex.exec(htmlString)) !== null) {
  79. result.push(match[1]); // match[1] 是正则表达式中的第一个捕获组,即 src 属性的值
  80. }
  81. return result;
  82. },
  83. goImgDetials(e) {
  84. // console.log('e', e);
  85. // console.log(this.info.activityDetail)
  86. const imgArr = this.extractImageSrcFromHtml(this.info.activityDetail)
  87. // console.log('imgArr', imgArr);
  88. // let item = e.detail.node;
  89. // if (item.name == "img") {
  90. uni.previewImage({
  91. urls: imgArr,
  92. longPressActions: {
  93. itemList: ["保存到相册", "识别二维码"],
  94. itemColor: "#007AFF",
  95. success: function (data) {
  96. let {
  97. tapIndex,
  98. index
  99. } = data;
  100. // tapIndex 第几个按钮
  101. // index 第几张图片
  102. //#ifdef APP-PLUS
  103. if (tapIndex == 0) {
  104. // 保存到相册
  105. plus.gallery.save(imgArr[index], () => {
  106. uni.showToast({
  107. icon: "none",
  108. title: "保存成功!"
  109. })
  110. }, () => {
  111. uni.showToast({
  112. icon: "none",
  113. title: "保存失败!"
  114. })
  115. })
  116. } else {
  117. // 现将文件下载到本地
  118. uni.downloadFile({
  119. url: imgArr[index],
  120. success: (args) => {
  121. // 扫描二维码
  122. plus.barcode.scan(
  123. args.tempFilePath,
  124. (code, url) => {
  125. // 如果识别成功
  126. if (code == 0) {
  127. // 打开扫描结果
  128. plus.runtime.openURL(url)
  129. }
  130. },
  131. (err) => {
  132. uni.showToast({
  133. icon: 'none',
  134. title: "图中没有可识别的二维码"
  135. })
  136. console.log(err, 'err');
  137. },
  138. [plus.barcode.QR],
  139. true)
  140. },
  141. fail: () => {
  142. }
  143. })
  144. }
  145. //#endif
  146. }
  147. }
  148. })
  149. // }
  150. },
  151. handleSignUp() {
  152. let that = this
  153. let { activityStartTime, activityEndTime, limited, activityName, id, price, shopId } = this.info
  154. let obj = {
  155. activityStartTime,
  156. activityEndTime,
  157. limited,
  158. activityName,
  159. id,
  160. price,
  161. shopId
  162. }
  163. if (uni.getStorageSync('token')) {
  164. uni.setStorageSync('activity', JSON.stringify(obj))
  165. uni.navigateTo({
  166. url: '/signUp/makeOut?id=' + this.info.dataCollectId
  167. })
  168. } else {
  169. uni.showModal({
  170. title: '请登录',
  171. confirmText: '去登录',
  172. success(res) {
  173. console.log(res);
  174. if (res.confirm) {
  175. uni.navigateTo({
  176. url: `/login/login/login?redirect=/signUp/index&scene=${that.id}`
  177. })
  178. }
  179. }
  180. })
  181. }
  182. },
  183. getActivityDetail(id) {
  184. getActivityDetail({ id }).then(res => {
  185. if (res.state == 'Success') {
  186. this.info = res.content
  187. this.info.activityDetail = res.content.activityDetail.replace(/<img/gi, '<img class="img_class" ')
  188. uni.setNavigationBarTitle({
  189. title: this.info.activityName
  190. })
  191. if (new Date(this.info.activityEndTime).getTime() < new Date().getTime()) {//活动结束
  192. this.isEnd = true
  193. }
  194. }
  195. })
  196. }
  197. },
  198. onLoad(options) {
  199. console.log('options', options);
  200. this.id = decodeURIComponent(options.scene)
  201. this.getActivityDetail(this.id)
  202. }
  203. }
  204. </script>
  205. <style lang="scss">
  206. .signUp {
  207. background: #F9F9F9;
  208. padding-bottom: 200rpx;
  209. min-height: 100vh;
  210. .good-img {
  211. width: 100%;
  212. height: 750rpx;
  213. vertical-align: bottom;
  214. }
  215. .goods-info {
  216. padding: 24rpx;
  217. margin-bottom: 20rpx;
  218. background: #fff;
  219. .price-box {
  220. display: flex;
  221. justify-content: space-between;
  222. align-items: center;
  223. margin-top: 20rpx;
  224. .left {
  225. display: flex;
  226. align-items: flex-end;
  227. .unit {
  228. font-size: 20rpx;
  229. color: $uni-color-primary;
  230. font-weight: bold;
  231. }
  232. .price {
  233. font-size: 36rpx;
  234. color: $uni-color-primary;
  235. font-weight: bold;
  236. }
  237. }
  238. }
  239. .goods-name {
  240. font-size: 32rpx;
  241. color: #222222;
  242. font-weight: bold;
  243. }
  244. }
  245. .sub-title {
  246. font-weight: 600;
  247. font-size: 28rpx;
  248. color: #222222;
  249. padding: 24rpx;
  250. border-radius: 16rpx 16rpx 0 0;
  251. background: #fff;
  252. }
  253. .desc-box {
  254. .goods-desc {
  255. color: #222222;
  256. font-size: 24rpx;
  257. .img_class {
  258. max-width: 100% !important;
  259. vertical-align: bottom;
  260. }
  261. }
  262. }
  263. .list {
  264. background: #fff;
  265. margin-bottom: 20rpx;
  266. .item {
  267. padding: 24rpx;
  268. border-top: 1rpx solid #F0F0F0;
  269. .label {
  270. font-weight: 600;
  271. font-size: 28rpx;
  272. color: #222222;
  273. }
  274. .value {
  275. font-weight: 300;
  276. font-size: 24rpx;
  277. color: #AAAAAA;
  278. margin-top: 16rpx;
  279. line-height: 40rpx;
  280. }
  281. }
  282. }
  283. .buy-box {
  284. position: fixed;
  285. bottom: 0%;
  286. left: 0%;
  287. width: 100%;
  288. background: #fff;
  289. padding: 10rpx 24rpx env(safe-area-inset-bottom);
  290. border-top: 1rpx solid #EEEEEE;
  291. box-sizing: border-box;
  292. .buy-btn {
  293. width: 702rpx;
  294. height: 80rpx;
  295. line-height: 80rpx;
  296. text-align: center;
  297. background: $uni-color-primary;
  298. border-radius: 40rpx;
  299. font-weight: 600;
  300. font-size: 28rpx;
  301. color: #FFFFFF;
  302. }
  303. }
  304. }
  305. </style>