activitySave.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <view style="height: 100%; background: #F8F9FA;">
  3. <view class="huodong-ccontent" >
  4. <view style=" height:176rpx;width:176rpx">
  5. <van-image
  6. height="176rpx"
  7. :src="activityInfo.cover"
  8. width="176rpx"
  9. />
  10. </view>
  11. <view class="activity-content">
  12. <view class="activity-title">{{activityInfo.name}}</view>
  13. <view class="activity-date">
  14. <span >{{activityInfo.start_time}}</span>
  15. </view>
  16. <view class="activity-price">
  17. <span ><span style="font-size: 32rpx;color: #C29556">¥{{activityInfo.fee}}</span></span>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="activity-content-title">
  22. 报名信息
  23. </view>
  24. <van-cell-group>
  25. <van-field
  26. v-model="formData.username"
  27. label="姓名"
  28. placeholder="请填写联系人姓名"
  29. :readonly="is_entry&&MyActivityInfo.status==3"
  30. input-align="right"
  31. @change="onChangeUsername"
  32. />
  33. <van-field
  34. v-model="formData.mobile"
  35. :readonly="is_entry&&MyActivityInfo.status==3"
  36. label="联系电话"
  37. type="number"
  38. placeholder="请填写电话号码"
  39. input-align="right"
  40. @change="onChangeMobiler"
  41. />
  42. <van-cell title="报名人数" >
  43. <template #default>
  44. <van-stepper v-model="formData.num" :disabled="is_entry" @change="onChangeStepper"/>
  45. </template>
  46. </van-cell>
  47. <van-cell title="报名时间" v-if="is_entry" :value="MyActivityInfo.created_at"/>
  48. <van-cell title="报名状态" v-if=" (MyActivityInfo.status==4||MyActivityInfo.status==0||MyActivityInfo.status==-1)" :value="statusDisplay"/>
  49. </van-cell-group>
  50. <van-toast id="van-toast"/>
  51. <view class="bottom-navigation" v-if=" !(MyActivityInfo.status==4|| MyActivityInfo.status==0|| MyActivityInfo.status==-1)" >
  52. <view class="bottom-navigation-div" v-if="!is_entry">
  53. 应付款: <span>¥<span style="font-size: 40rpx;">{{ (activityInfo.fee && formData.num ? (activityInfo.fee * formData.num).toFixed(2) : '0.00') }}</span></span>
  54. </view>
  55. <view class="bottom-navigation-div" v-else-if="is_entry&&(MyActivityInfo.status==1||MyActivityInfo.status==1)">
  56. 应付款: <span>¥<span style="font-size: 40rpx;">{{parseFloat(MyActivityInfo.amount_real) .toFixed(2)}}</span></span>
  57. </view>
  58. <view class="bottom-navigation-div" v-else-if="is_entry&&MyActivityInfo.status==3">
  59. 已付款: <span>¥<span style="font-size: 40rpx;">{{ parseFloat(MyActivityInfo.amount_real).toFixed(2)}}</span></span>
  60. </view>
  61. <button class="activity-button" v-if="!is_entry" @click="handleRegister">立即报名</button>
  62. <button class="activity-button" v-if="is_entry&&3!==MyActivityInfo.status" style="margin-right: 12rpx;min-width: 260rpx!important;" @click="handleEntryUpdate">修改报名信息</button>
  63. <button class="activity-button" v-if="is_entry&&[1, 2].includes(MyActivityInfo.status)" @click="toPay">立即付款</button>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import Toast from "../../wxcomponents/vant/dist/toast/toast";
  69. import {
  70. getActivityDetail,
  71. addActivityEntry,
  72. getMyActivity,
  73. entryUpdate,
  74. addActivityPayment
  75. } from "../../common/api/activity";
  76. import {toWechatPayActivitySave} from "../../common/utils/tools";
  77. export default {
  78. components: {
  79. },
  80. data() {
  81. return {
  82. data: [],
  83. activityId: 0,
  84. activityInfo:{},
  85. MyActivityInfo:{},
  86. orderFlag:false,
  87. is_entry:false,
  88. entryId:0,
  89. formData:{
  90. mobile:"",
  91. username:'',
  92. num:1,
  93. }
  94. };
  95. },
  96. onLoad: function (option) {
  97. this.activityId = option.activityId
  98. this.entryId = option.orderId
  99. if (option.orderFlag){
  100. this.orderFlag = true
  101. }
  102. },
  103. onShow() {
  104. this.getActivityDetail()
  105. },
  106. onReachBottom() {
  107. },
  108. onShareAppMessage(res) {
  109. let params = {};
  110. params = {
  111. activityId: this.activityId
  112. };
  113. let configs = uni.getStorageSync('configs') || {};
  114. return {
  115. title: configs.shop_share_title,
  116. imageUrl: configs.shop_share_img,
  117. path: `/subPages/activityDetail/activityDetail${this.$stringPageOptions(params)}`
  118. };
  119. },
  120. onShareTimeline(res) {
  121. let params = {};
  122. params = {
  123. activityId: this.activityId
  124. };
  125. let configs = uni.getStorageSync('configs') || {};
  126. return {
  127. title: configs.shop_share_title,
  128. imageUrl: configs.shop_share_img,
  129. path: `/subPages/activityDetail/activityDetail${this.$stringPageOptions(params)}`
  130. };
  131. },
  132. computed: {
  133. statusDisplay() {
  134. switch (this.MyActivityInfo.status) {
  135. case -1:
  136. return '已退款'
  137. case 0:
  138. return '已取消'
  139. case 1:
  140. return '待支付'
  141. case 2:
  142. return '支付中'
  143. case 3:
  144. return '已支付'
  145. case 4:
  146. return '已成功'
  147. default:
  148. return ''
  149. }
  150. },
  151. },
  152. watch: {},
  153. methods: {
  154. toPay() {
  155. // 立即付款
  156. toWechatPayActivitySave(this.MyActivityInfo.order_no)
  157. },
  158. getActivityDetail() {
  159. if (this.orderFlag){
  160. this.getMyActivity()
  161. }else{
  162. getActivityDetail({id: this.activityId}).then(({data}) => {
  163. this.activityInfo = data
  164. this.activityInfo.start_time = (new Date(this.activityInfo.start_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  165. this.activityInfo.end_time = (new Date(this.activityInfo.end_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  166. this.activityInfo.entry_end = (new Date(this.activityInfo.entry_end.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  167. var entryInfo = data.entry_info;
  168. if (entryInfo){
  169. entryInfo.sort(function(a, b) {
  170. return b.id - a.id;
  171. });
  172. entryInfo=entryInfo[0]
  173. if (entryInfo != []&&entryInfo.id &&(entryInfo.status!=-1&&entryInfo.status!=0)) {
  174. this.entryId=entryInfo.id
  175. this.is_entry=true
  176. this.getMyActivity()
  177. this.MyActivityInfo = entryInfo
  178. this.formData.username=entryInfo.username
  179. this.formData.mobile=entryInfo.mobile
  180. this.formData.num=entryInfo.num
  181. }
  182. }
  183. });
  184. }
  185. },
  186. getMyActivity() {
  187. getMyActivity({id:this.entryId}).then(({data}) => {
  188. this.MyActivityInfo = data
  189. this.is_entry=true
  190. this.formData.username=data.username
  191. this.formData.mobile=data.mobile
  192. this.formData.num=data.num
  193. if (data.activity){
  194. this.activityInfo = data.activity
  195. this.activityInfo.start_time = (new Date(this.activityInfo.start_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  196. this.activityInfo.end_time = (new Date(this.activityInfo.end_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  197. this.activityInfo.entry_end = (new Date(this.activityInfo.entry_end.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  198. }
  199. });
  200. },
  201. addActivityEntry() {
  202. addActivityEntry(this.formData).then(({data}) => {
  203. if (data.status !== 3) {
  204. Toast('报名成功,请尽快支付!');
  205. toWechatPayActivitySave(data.order_no, data.order_remark)
  206. }else{
  207. Toast('报名成功!');
  208. }
  209. this.getActivityDetail()
  210. });
  211. }, handleRegister() {
  212. if (!this.formData.username){
  213. Toast('请输入姓名');
  214. }
  215. if (!this.formData.mobile){
  216. Toast('请输入手机号');
  217. }
  218. // 正则判断纯数字
  219. if (!/^[0-9]*$/.test(this.formData.mobile)) {
  220. Toast('手机号格式不正确');
  221. return;
  222. }
  223. // 正则判断纯数字
  224. if (this.formData.mobile.length!==11) {
  225. Toast('请输入11位的手机号');
  226. return;
  227. }
  228. this.formData.id=this.activityId
  229. this.addActivityEntry();
  230. },
  231. handleEntryUpdate() {
  232. if (!this.formData.username){
  233. Toast('请输入姓名');
  234. }
  235. if (!this.formData.mobile){
  236. Toast('请输入手机号');
  237. }
  238. // 正则判断纯数字
  239. if (!/^[0-9]*$/.test(this.formData.mobile)) {
  240. Toast('手机号格式不正确');
  241. return;
  242. }
  243. // 正则判断纯数字
  244. if (this.formData.mobile.length!==11) {
  245. Toast('请输入11位的手机号');
  246. return;
  247. }
  248. this.formData.id=this.entryId
  249. entryUpdate(this.formData).then(({data}) => {
  250. Toast('修改成功');
  251. this.getActivityDetail()
  252. });
  253. },
  254. onChangeStepper(event){
  255. this.formData.num=event.detail
  256. },
  257. onChangeMobiler(event){
  258. this.formData.mobile=event.detail
  259. },
  260. onChangeUsername(event){
  261. this.formData.username=event.detail
  262. }
  263. },
  264. };
  265. </script>
  266. <style lang="scss" scoped>
  267. .common-page {
  268. height: 100%;
  269. padding: 30rpx;
  270. }
  271. .bottom-navigation{
  272. position: fixed;
  273. // 文字垂直居中
  274. display: flex;
  275. align-items: center;
  276. bottom: 0;
  277. height: 100rpx;
  278. width: calc(100% - 40rpx);
  279. background: #FFFFFF;
  280. box-shadow: 0rpx -2rpx 0rpx 0rpx #F1F3F6;
  281. border-radius: 24rpx 24rpx 0rpx 0rpx;
  282. border: 0rpx solid #979797;
  283. padding: 20rpx 20rpx 68rpx 20rpx ;
  284. &-div{
  285. height: 76rpx;
  286. width: 404rpx;
  287. // 文字垂直居中
  288. font-family: PingFang SC, PingFang SC;
  289. font-weight: 400;
  290. font-size: 28rpx;
  291. padding-top: 10rpx;
  292. color: #333333;
  293. line-height: 40rpx;
  294. text-align: left;
  295. font-style: normal;
  296. text-transform: none;
  297. display: flex;
  298. align-items: center;
  299. span{
  300. font-family: PingFang SC, PingFang SC;
  301. font-weight: 400;
  302. font-size: 24rpx;
  303. color: #C29556;
  304. line-height: 32rpx;
  305. text-align: left;
  306. font-style: normal;
  307. text-transform: none;
  308. }
  309. }
  310. .activity-button {
  311. width: 264rpx;
  312. height: 80rpx;
  313. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  314. border-radius: 292rpx 292rpx 292rpx 292rpx;
  315. font-family: PingFang SC, PingFang SC;
  316. font-weight: 400;
  317. font-size: 28rpx;
  318. color: #FFFFFF;
  319. line-height: 36rpx;
  320. text-align: center;
  321. font-style: normal;
  322. text-transform: none;
  323. // 文字垂直居中
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. }
  328. }
  329. .activity-content-title {
  330. margin: 30rpx auto;
  331. width: 680rpx;
  332. // 垂直居中
  333. font-family: PingFang SC, PingFang SC;
  334. font-weight: 400;
  335. font-size: 32rpx;
  336. color: #333333;
  337. line-height: 40rpx;
  338. text-align: left;
  339. font-style: normal;
  340. text-transform: none;
  341. }
  342. .huodong-ccontent {
  343. position: relative; /* 相对定位 */
  344. width: 650rpx;
  345. padding: 0rpx;
  346. margin: 30rpx auto;
  347. margin-bottom: 0;
  348. padding: 30rpx;
  349. background: #FFFFFF;
  350. border-radius: 16rpx 16rpx 16rpx 16rpx;
  351. display: flex;
  352. align-items: center;
  353. .activity-content {
  354. margin: 30rpx 0rpx 0rpx 30rpx;
  355. .activity-title {
  356. font-family: PingFang SC, PingFang SC;
  357. font-weight: 400;
  358. font-size: 28rpx;
  359. color: #333333;
  360. line-height: 40rpx;
  361. text-align: left;
  362. font-style: normal;
  363. text-transform: none;
  364. font-weight: bold;
  365. margin-bottom: 10rpx;
  366. }
  367. .activity-date {
  368. font-weight: 400;
  369. font-size: 24rpx;
  370. color: #666666;
  371. line-height: 36rpx;
  372. text-align: left;
  373. font-style: normal;
  374. text-transform: none;
  375. margin-bottom: 10rpx;
  376. display: flex;
  377. align-items: center;
  378. }
  379. .activity-price {
  380. height: 44rpx;
  381. font-weight: 400;
  382. font-size: 22rpx;
  383. color: #666666;
  384. line-height: 40rpx;
  385. text-align: left;
  386. font-style: normal;
  387. text-transform: none;
  388. margin-bottom: 24rpx;
  389. display: flex;
  390. align-items: center;
  391. }
  392. }
  393. }
  394. </style>