activitySave.vue 11 KB

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