studyGoodsDetail.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view class="studyGoodsDetail">
  3. <image class="banner" :src="info.studyItem" mode="aspectFill"></image>
  4. <view class="goods-info">
  5. <view class="goods-name">
  6. {{info.goodsName}}
  7. </view>
  8. <view class="price-box">
  9. <view class="left">
  10. <view class="price">
  11. ¥{{info.price}}
  12. </view>
  13. /人起
  14. </view>
  15. <view class="right">
  16. {{info.reservationNum}}人已购
  17. </view>
  18. </view>
  19. </view>
  20. <view class="time-box">
  21. <view class="title">
  22. 出发日期选择
  23. </view>
  24. <view class="choose-box">
  25. <view class="choose-item" :class="query.reservationTime == item.date?'active':''" v-for="item in dateList" :key="item.date" @click="handleTime(item)">
  26. <view class="time">
  27. {{item.date | filterDate}}
  28. </view>
  29. <view class="price">
  30. {{item.num+'人'}}
  31. </view>
  32. </view>
  33. <view class="more" @click="chooseTime">
  34. 更多
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 时间选择 -->
  39. <u-calendar
  40. startText="住店"
  41. endText="离店"
  42. title="请选择出发日期"
  43. :show="show"
  44. :mode="mode"
  45. :defaultDate="query.reservationTime"
  46. :maxDate="maxDate"
  47. @confirm="confirm"
  48. @close="close"
  49. closeOnClickOverlay
  50. :rowHeight="110"
  51. color="#3879F9"
  52. ref="calendar"
  53. >
  54. </u-calendar>
  55. <rich-text :nodes="info.goodsDescribe"></rich-text>
  56. <view class="btn-box">
  57. <button class="subscribe-btn" type="default" @click="subscribe">预约</button>
  58. <button class="buy-btn" type="default" @click="buy">立即购买</button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import {studyGoodsDetail,subscribe} from '@/api/study.js'
  64. export default {
  65. data() {
  66. return {
  67. that:this,
  68. show: false,
  69. mode: 'single',
  70. maxDate:new Date().getTime()+1000*60*60*24*31,
  71. userId:'',
  72. dateList:[],
  73. query:{
  74. "goodsId": "",
  75. "id": 0,
  76. "reservationTime": "",
  77. "shopId": "",
  78. "userId": ""
  79. },
  80. info:{
  81. day: 0,
  82. goodsDescribe: "",
  83. goodsImg: "",
  84. goodsName: "",
  85. price: 0,
  86. reservationNum: null,
  87. studyItem: "",
  88. useEndTime: null,
  89. useStartTime: null,
  90. useType: 1,
  91. statistics:null
  92. }
  93. }
  94. },
  95. filters: {
  96. filterDate: function(value) {
  97. let m = value.split('-')[1]
  98. let d = value.split('-')[2]
  99. let day = new Date(value).getDay()
  100. let w = day ? day: 7
  101. let zhArray = ['', '一', '二', '三', '四', '五', '六', '天']; // 数字对应中文
  102. let string = String(w)
  103. .split('')
  104. .reverse()
  105. .map((item, index) => {
  106. // 把数字切割成数组并倒序排列,然后进行遍历转成中文
  107. // 如果当前位为0,直接输出数字, 否则输出 数字 + 进位填充字符
  108. item = zhArray[Number(item)];
  109. return item;
  110. })
  111. .reverse()
  112. .join(''); // 倒叙回来数组,拼接成字符串
  113. return `${m}/${d} 周${string}` ;
  114. }
  115. },
  116. methods: {
  117. handleTime(item){
  118. this.query.reservationTime = item.date
  119. },
  120. chooseTime(){
  121. this.show = true
  122. this.$nextTick(()=>{
  123. // 如果需要兼容微信小程序的话,需要用此写法
  124. this.$refs.calendar.setFormatter(this.formatter)
  125. })
  126. },
  127. close(){
  128. this.show = false
  129. },
  130. confirm(e) {
  131. this.show = false
  132. console.log(e);
  133. this.query.reservationTime = e[0]
  134. },
  135. formatter(day,that) {
  136. var list = JSON.parse(uni.getStorageSync('list'))
  137. if(list&&list.length){
  138. list.map(item=>{
  139. let month = Number(item.date.split('-')[1])
  140. let date = Number(item.date.split('-')[2])
  141. if(day.month == month && day.day == date)
  142. {
  143. day.bottomInfo = item.num + '人'
  144. }
  145. })
  146. }
  147. return day
  148. },
  149. subscribe(){
  150. if(!uni.getStorageSync('token')){
  151. return uni.showModal({
  152. title:'请登录',
  153. confirmText:'去登录',
  154. success(res){
  155. console.log(res);
  156. if(res.confirm){
  157. uni.navigateTo({
  158. url:'/login/login/login'
  159. })
  160. }
  161. }
  162. })
  163. }else if(!this.query.reservationTime){
  164. uni.showToast({
  165. title:'请选择出发时间',
  166. icon:'none'
  167. })
  168. }else{
  169. let that = this
  170. uni.showModal({
  171. title:'预约确认',
  172. content:`确认预约${this.query.reservationTime}出发`,
  173. confirmText:'确认',
  174. success(res){
  175. if(res.confirm){
  176. that.query.shopId = that.info.shopId
  177. that.query.userId = JSON.parse(uni.getStorageSync('userInfo')).userId
  178. subscribe(that.query).then(r=>{
  179. if(r.state == 'Success'){
  180. uni.showToast({
  181. title:'预约成功',
  182. })
  183. }
  184. })
  185. }
  186. }
  187. })
  188. }
  189. },
  190. buy(){
  191. if(!uni.getStorageSync('token')){
  192. return uni.showModal({
  193. title:'请登录',
  194. confirmText:'去登录',
  195. success(res){
  196. console.log(res);
  197. if(res.confirm){
  198. uni.navigateTo({
  199. url:'/login/login/login'
  200. })
  201. }
  202. }
  203. })
  204. }else if(!this.query.reservationTime){
  205. uni.showToast({
  206. title:'请选择出发时间',
  207. icon:'none'
  208. })
  209. }else{
  210. let that = this
  211. uni.navigateTo({
  212. url:'/pay/pay',
  213. success: function(res) {
  214. // 通过eventChannel向被打开页面传送数据
  215. that.info.buyPrice = that.info.price
  216. that.info.reservationTime = that.query.reservationTime
  217. res.eventChannel.emit('pay', that.info)
  218. }
  219. })
  220. }
  221. },
  222. studyGoodsDetail(goodsId){
  223. studyGoodsDetail({goodsId,userId:this.userId}).then(res=>{
  224. if(res.state == 'Success'){
  225. this.info = res.content
  226. this.info.goodsId = goodsId
  227. uni.setStorageSync('list',JSON.stringify(res.content.statistics))
  228. this.dateList = res.content.statistics.splice(0,4)
  229. }
  230. })
  231. }
  232. },
  233. onLoad(options) {
  234. if(uni.getStorageSync('userInfo')){
  235. this.userId = JSON.parse(uni.getStorageSync('userInfo')).userId
  236. }
  237. this.studyGoodsDetail(options.id)
  238. this.query.goodsId = options.id
  239. },
  240. onReady() {
  241. // // 如果需要兼容微信小程序的话,需要用此写法
  242. // this.$refs.calendar.setFormatter(this.formatter)
  243. },
  244. beforeDestroy() {
  245. uni.removeStorageSync('list')
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .studyGoodsDetail{
  251. background: #F9F9F9;
  252. padding-bottom: 180rpx;
  253. .banner{
  254. width: 100%;
  255. height: 420rpx;
  256. }
  257. .goods-info{
  258. padding: 30rpx;
  259. background: #fff;
  260. border-radius: 16rpx 16rpx 0rpx 0rpx;
  261. margin-top: -30rpx;
  262. position: relative;
  263. .goods-name{
  264. font-weight: bold;
  265. color: #222222;
  266. }
  267. .desc{
  268. font-size: 24rpx;
  269. font-weight: 400;
  270. color: #AAAAAA;
  271. line-height: 36rpx;
  272. }
  273. .price-box{
  274. display: flex;
  275. align-items: flex-end;
  276. justify-content: space-between;
  277. margin-top: 30rpx;
  278. .left{
  279. font-weight: 400;
  280. color: #AAAAAA;
  281. font-size: 24rpx;
  282. display: flex;
  283. align-items: center;
  284. vertical-align: bottom;
  285. .price{
  286. font-size: 36rpx;
  287. font-weight: 800;
  288. color: #FF4C3A;
  289. }
  290. }
  291. .right{
  292. font-weight: 400;
  293. color: #AAAAAA;
  294. font-size: 24rpx;
  295. }
  296. }
  297. }
  298. .time-box{
  299. padding: 30rpx;
  300. background: #fff;
  301. margin-top: 20rpx;
  302. .title{
  303. font-weight: bold;
  304. color: #222222;
  305. font-size: 28rpx;
  306. margin: 0 0 22rpx;
  307. }
  308. .choose-box{
  309. display: flex;
  310. justify-content: space-between;
  311. .choose-item.active{
  312. background: rgba(38,128,235,0.1);
  313. border: 1rpx solid #3879F9;
  314. }
  315. .choose-item{
  316. width: 136rpx;
  317. height: 84rpx;
  318. border-radius: 8rpx;
  319. background: #F6F6F6;
  320. display: flex;
  321. flex-direction: column;
  322. justify-content: space-around;
  323. box-sizing: border-box;
  324. .time{
  325. font-weight: bold;
  326. color: #222222;
  327. font-size: 22rpx;
  328. text-align: center;
  329. }
  330. .price{
  331. font-weight: 400;
  332. color: #FF4C3A;
  333. font-size: 22rpx;
  334. text-align: center;
  335. }
  336. }
  337. .more{
  338. width: 84rpx;
  339. height: 84rpx;
  340. line-height: 84rpx;
  341. text-align: center;
  342. background: #F6F6F6;
  343. border-radius: 8rpx;
  344. font-size: 22rpx;
  345. font-weight: 400;
  346. color: #222222;
  347. }
  348. }
  349. }
  350. .goods-detail{
  351. width: 100%;
  352. }
  353. .btn-box{
  354. padding: 10rpx 20rpx 40rpx;
  355. background: #fff;
  356. position: fixed;
  357. bottom: 0%;
  358. left: 0;
  359. width: 100%;
  360. box-sizing: border-box;
  361. display: flex;
  362. align-items: center;
  363. justify-content: space-between;
  364. font-size: 28rpx;
  365. .subscribe-btn{
  366. width: 346rpx;
  367. height: 80rpx;
  368. line-height: 80rpx;
  369. background: #FFF;
  370. border-radius: 40rpx;
  371. border: 2rpx solid #3879F9;
  372. color: #3879F9;
  373. font-weight: bold;
  374. }
  375. .buy-btn{
  376. width: 346rpx;
  377. height: 80rpx;
  378. line-height: 80rpx;
  379. background: #3879F9;
  380. border-radius: 40rpx;
  381. font-weight: bold;
  382. color: #FFFFFF;
  383. }
  384. }
  385. }
  386. </style>