detail.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <template>
  2. <app-layout>
  3. <app-list v-if="loading" :hidden="false" top="0" :theme="getTheme" :list="list" v-on:update="update" v-on:change="getTotal" v-on:updateList="updateList"></app-list>
  4. <view class="list" v-if="other.length > 0">
  5. <view class="title">其他套餐</view>
  6. <view v-for="(item, index) in other" :key="index" class="item dir-left-nowrap">
  7. <app-composition :theme="getTheme" @click="choose(item)" @look="choose(item)" :item="item"></app-composition>
  8. </view>
  9. </view>
  10. <view v-if="list.length > 0" :class="['bottom-space', `${iphone_x? 'iphone_x':''}`]"></view>
  11. <view v-if="list.length > 0" :class="['bottom','main-between','cross-center', `${iphone_x? 'iphone_x':''}`]">
  12. <view>
  13. <view class="dir-left-nowrap cross-center">
  14. <view>总计</view>
  15. <view class="total-price" :class="getTheme + '-m-text ' + getTheme">¥{{total == 0 ? '0.00' : total}}</view>
  16. </view>
  17. <view class="discount" :class="getTheme + '-m-text ' + getTheme">已省¥{{max_discount}}</view>
  18. </view>
  19. <view @click="toBuy" class="submit-btn" :class="getTheme + '-m-back ' + getTheme">立即购买</view>
  20. </view>
  21. <view class="dialog-bg" v-if="showNoAttr">
  22. <view class="dialog">
  23. <view class="dialog-title">
  24. <view class="dialog-big-title">以下商品未选择规格</view>
  25. <view>请选择规格后购买</view>
  26. </view>
  27. <view :class="[`${noAttrList.length > 4 ? 'dir-left-wrap' : 'main-center'}`,`dialog-goods-list`]">
  28. <view class="dialog-goods" v-for="(item, index) in noAttrList" :key="index">
  29. <image :src="item.cover_pic"></image>
  30. </view>
  31. </view>
  32. <view @click="close" class="dialog-close" :class="getTheme + '-m-text ' + getTheme">我知道了</view>
  33. </view>
  34. </view>
  35. <view class='no-tip' v-if="list.length == 0 && loading">
  36. <image src="/static/image/pull-off.png"></image>
  37. <view>您选购的套餐已下架</view>
  38. <view @click="toComposition" class="to-composition" :class="getTheme + '-m-back ' + getTheme">逛逛套餐专区</view>
  39. </view>
  40. </app-layout>
  41. </template>
  42. <script>
  43. import {mapGetters} from "vuex";
  44. import appList from '../components/app-list/app-list';
  45. import appComposition from "../../../components/basic-component/app-composition/app-composition.vue";
  46. export default {
  47. data() {
  48. return {
  49. list: [],
  50. other: [],
  51. total: 0,
  52. showNoAttr: false,
  53. noAttrList: [],
  54. goods_id: '',
  55. max_discount: '0.00',
  56. page: 2,
  57. hidden: false,
  58. iphone_x: false,
  59. noMore: false,
  60. composition_id: '',
  61. loading: false
  62. }
  63. },
  64. components: {
  65. 'app-list': appList,
  66. 'app-composition': appComposition
  67. },
  68. computed: {
  69. ...mapGetters('mallConfig', {
  70. getTheme: 'getTheme',
  71. })
  72. },
  73. methods: {
  74. choose(item) {
  75. this.composition_id = item.id;
  76. this.total = '0.00';
  77. this.max_discount = '0.00';
  78. this.getDetail();
  79. },
  80. toComposition() {
  81. uni.redirectTo({
  82. url: '/plugins/composition/index/index'
  83. });
  84. },
  85. isCanbuy(goods){
  86. console.log(goods)
  87. if (this.$user.isLogin() && this.$store.state.user.info) {
  88. let member_level =this.$store.state.user.info.identity.member_level;
  89. if(member_level<goods.member_level){
  90. uni.showModal({
  91. title:"提示",
  92. content:"套餐中有商品"+goods.name+"不能购买,需达到"+goods.member_name+"会员才可购买",
  93. showCancel:true,
  94. buttonText: '升级',
  95. success:(res)=>{
  96. if (res.confirm) {
  97. uni.navigateTo({
  98. // url:"/pages/member/index/index",
  99. url: '/pages/member/upgrade/upgrade?level=' + member_level + '&other=' +goods.member_level
  100. })
  101. return false;
  102. } else if (res.cancel) {
  103. console.log('用户点击取消');
  104. return true;
  105. }
  106. }
  107. })
  108. return true;
  109. }
  110. //return true;
  111. }
  112. },
  113. toBuy() {
  114. let that = this;
  115. let attr = [];
  116. let list = [
  117. {
  118. mch_id: 0,
  119. composition_list: []
  120. }
  121. ]
  122. let isCanbuy = true;
  123. for(let i in that.list) {
  124. // console.log(that.list[i])
  125. // if(!that.isCanbuy(that.list[i].host_list[0])){
  126. // isCanbuy = false;
  127. // }
  128. for(let j in that.list[i].goods_list){
  129. if(!that.isCanbuy(that.list[i].goods_list[j])){
  130. isCanbuy = false;
  131. }
  132. }
  133. }
  134. // if(!isCanbuy){
  135. // return;
  136. // }
  137. if(that.noAttrList.length > 0) {
  138. that.showNoAttr = true;
  139. // for(let i in that.noAttrList) {
  140. // if(!that.isCanbuy(that.noAttrList[i]))
  141. // return;
  142. // }
  143. }
  144. //else {
  145. for(let i in that.list) {
  146. attr = [];
  147. if(that.list[i].choose) {
  148. let arr = {
  149. composition_id: that.list[i].id,
  150. goods_list: []
  151. }
  152. if(that.list[i].host_list.length > 0) {
  153. for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
  154. attr.push({
  155. attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
  156. attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
  157. })
  158. }
  159. arr.goods_list.push({
  160. id: that.list[i].host_list[0].goods_id,
  161. num: 1,
  162. goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
  163. attr: []
  164. })
  165. }
  166. let goods_attr = [];
  167. for(let y in that.list[i].goods_list) {
  168. if(that.list[i].goods_list[y].choose_attr && that.list[i].goods_list[y].choose_attr.attr_list.length > 0) {
  169. for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
  170. attr.push({
  171. attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
  172. attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
  173. })
  174. }
  175. arr.goods_list.push({
  176. id: that.list[i].goods_list[y].goods_id,
  177. num: 1,
  178. goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
  179. attr: attr
  180. })
  181. }
  182. }
  183. list[0].composition_list.push(arr);
  184. }else {
  185. let arr = {
  186. composition_id: that.list[i].id,
  187. goods_list: []
  188. }
  189. if(that.list[i].host_list.length > 0 && that.list[i].host_list[0].choose_goods) {
  190. for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
  191. attr.push({
  192. attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
  193. attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
  194. })
  195. }
  196. arr.goods_list.push({
  197. id: that.list[i].host_list[0].goods_id,
  198. num: 1,
  199. goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
  200. attr: attr
  201. })
  202. }
  203. let noChoose = true;
  204. for(let y in that.list[i].goods_list) {
  205. if(that.list[i].goods_list[y].choose_goods && that.list[i].goods_list[y].choose_attr.attr_list) {
  206. noChoose = false;
  207. for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
  208. attr.push({
  209. attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
  210. attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
  211. })
  212. }
  213. arr.goods_list.push({
  214. id: that.list[i].goods_list[y].goods_id,
  215. num: 1,
  216. goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
  217. attr: attr
  218. })
  219. }
  220. }
  221. if(arr.goods_list.length > 0) {
  222. list[0].composition_list.push(arr);
  223. }
  224. }
  225. }
  226. if(list[0].composition_list.length == 0) {
  227. uni.showToast({
  228. title: '请选择套餐',
  229. icon: 'none',
  230. duration: 1000
  231. });
  232. }else {
  233. for(let i in list[0].composition_list) {
  234. if(list[0].composition_list[i].goods_list.length == 1) {
  235. list[0].composition_list.splice(i,1)
  236. }
  237. }
  238. if(list[0].composition_list.length == 0) {
  239. uni.showToast({
  240. title: '请选择搭配商品',
  241. icon: 'none',
  242. duration: 1000
  243. });
  244. }else {
  245. list[0].goods_list = [];
  246. for (let j in list[0].composition_list) {
  247. for (let y in list[0].composition_list[j].goods_list) {
  248. list[0].composition_list[j].goods_list[y].cart_id = 0;
  249. list[0].goods_list.push(list[0].composition_list[j].goods_list[y])
  250. }
  251. }
  252. let jump_url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(list)}`;
  253. jump_url += `&preview_url=${encodeURIComponent(this.$api.composition.order_preview)}&submit_url=${encodeURIComponent(this.$api.composition.order_submit)}&plugin=composition`;
  254. this.$jump({
  255. open_type: 'navigate',
  256. url: jump_url,
  257. });
  258. }
  259. }
  260. //}
  261. },
  262. close () {
  263. this.showNoAttr = false;
  264. },
  265. updateList(e) {
  266. this.list = e;
  267. },
  268. update(e) {
  269. this.noAttrList = e;
  270. },
  271. getTotal(e,max_discount) {
  272. this.total = e;
  273. if(max_discount) {
  274. this.max_discount = max_discount.toFixed(2)
  275. }
  276. },
  277. getDetail() {
  278. let that = this;
  279. that.loading = false;
  280. uni.showLoading({
  281. mask: true,
  282. title: '加载中...',
  283. });
  284. let para = {
  285. composition_id: that.composition_id
  286. }
  287. if(that.goods_id > 0) {
  288. para.goods_id = that.goods_id
  289. }
  290. that.$request({
  291. url: that.goods_id > 0 ? that.$api.composition.detail : that.$api.composition.composition_detail,
  292. data: para
  293. }).then(response=>{
  294. that.loading = true;
  295. uni.hideLoading();
  296. if(response.code == 0) {
  297. if(that.goods_id > 0) {
  298. that.list = response.data.other_list;
  299. that.other = response.data.list;
  300. }else {
  301. that.list = [];
  302. that.list[0] = response.data.composition;
  303. }
  304. if(that.other.length < 4) {
  305. that.noMore = true;
  306. }
  307. for(let i in that.list) {
  308. that.list[i].choose = false;
  309. for(let idx in that.list[i].goods_list) {
  310. that.list[i].goods_list[idx].choose_attr = null;
  311. if(that.list[i].goods_list[idx].goods_attr.length == 1) {
  312. that.list[i].goods_list[idx].choose_attr = that.list[i].goods_list[idx].goods_attr[0];
  313. that.list[i].goods_list[idx].choose_attr.number = 1;
  314. that.list[i].goods_list[idx].total_price = (+that.list[i].goods_list[idx].choose_attr.price - +that.list[i].goods_list[idx].price).toFixed(2)
  315. }
  316. if(that.list[i].type == 2) {
  317. that.list[i].host_list[0].choose_attr = null;
  318. if(that.list[i].host_list[0].goods_attr.length == 1) {
  319. that.list[i].host_list[0].choose_attr = that.list[i].host_list[0].goods_attr[0];
  320. that.list[i].host_list[0].choose_attr.number = 1;
  321. that.list[i].host_list[0].total_price = (+that.list[i].host_list[0].choose_attr.price - +that.list[i].host_list[0].price).toFixed(2)
  322. }
  323. that.list[i].goods_list[idx].choose_goods = false;
  324. that.list[i].host_list[0].choose_goods = true;
  325. that.list[i].host_list[0].opacity = 0.3;
  326. }
  327. }
  328. }
  329. if(that.list[0].type == 1) {
  330. that.list[0].choose = true;
  331. that.max_discount = that.list[0].max_discount;
  332. }
  333. }else {
  334. uni.hideLoading();
  335. uni.showToast({
  336. title: response.msg,
  337. icon: 'none',
  338. duration: 1000
  339. });
  340. }
  341. }).catch(response => {
  342. that.loading = true;
  343. uni.hideLoading();
  344. that.$hideLoading();
  345. });
  346. },
  347. getMore() {
  348. let that = this;
  349. uni.showLoading({
  350. title: '加载中'
  351. });
  352. that.$request({
  353. url: that.$api.composition.detail,
  354. data: {
  355. goods_id: that.goods_id,
  356. composition_id: that.composition_id,
  357. page: that.page
  358. }
  359. }).then(response=>{
  360. uni.hideLoading();
  361. if(response.code == 0) {
  362. if(response.data.list.length == 0) {
  363. this.noMore = true;
  364. return false;
  365. }
  366. that.page++;
  367. that.other = that.other.concat(response.data.list);
  368. for(let i in that.list) {
  369. that.list[i].choose = false;
  370. for(let idx in that.list[i].goods_list) {
  371. that.list[i].goods_list[idx].choose_attr = null;
  372. if(that.list[i].type == 2) {
  373. that.list[i].host_list[0].choose_attr = null;
  374. that.list[i].host_list[0].opacity = 1;
  375. that.list[i].goods_list[idx].choose_goods = false;
  376. that.list[i].host_list[0].choose_goods = false;
  377. }
  378. }
  379. }
  380. }else {
  381. uni.hideLoading();
  382. uni.showToast({
  383. title: response.msg,
  384. icon: 'none',
  385. duration: 1000
  386. });
  387. }
  388. }).catch(response => {
  389. that.$hideLoading();
  390. });
  391. },
  392. },
  393. onReachBottom() {
  394. if(!this.noMore) {
  395. this.getMore();
  396. }
  397. },
  398. onLoad(option) {
  399. let that = this;
  400. uni.getSystemInfo({
  401. success: function (res) {
  402. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  403. that.iphone_x = true;
  404. }
  405. }
  406. })
  407. this.goods_id = option.goods_id > 0 ? option.goods_id : '';
  408. this.composition_id = option.composition_id;
  409. that.getDetail();
  410. },
  411. }
  412. </script>
  413. <style scoped lang="scss">
  414. .no-tip {
  415. position: fixed;
  416. top: #{120rpx};
  417. left: 0;
  418. right: 0;
  419. margin: 0 auto;
  420. color: #666666;
  421. font-size: #{24rpx};
  422. width: #{240rpx};
  423. text-align: center;
  424. image {
  425. height: #{240rpx};
  426. width: #{240rpx};
  427. margin-bottom: #{20rpx};
  428. }
  429. .to-composition {
  430. border-radius: #{33rpx};
  431. width: #{246rpx};
  432. text-align: center;
  433. height: #{66rpx};
  434. line-height: #{66rpx};
  435. margin-top: #{38rpx};
  436. color: #fff;
  437. }
  438. }
  439. .list {
  440. padding: #{24rpx};
  441. .title {
  442. font-size: #{28rpx};
  443. color: #353535;
  444. }
  445. .item {
  446. margin-top: #{20rpx};
  447. padding: #{24rpx};
  448. border-radius: #{16rpx};
  449. background-color: #fff;
  450. }
  451. }
  452. .dialog-bg {
  453. position: fixed;
  454. top: 0;
  455. left: 0;
  456. width: 100%;
  457. height: 100%;
  458. background-color: rgba(0,0,0,.3);
  459. z-index: 202;
  460. .dialog {
  461. width: #{630rpx};
  462. margin: #{260rpx} auto 0;
  463. background-color: #fff;
  464. padding-top: #{40rpx};
  465. border-radius: #{16rpx};
  466. .dialog-title {
  467. text-align: center;
  468. font-size: #{26rpx};
  469. color: #999999;
  470. .dialog-big-title {
  471. font-size: #{32rpx};
  472. color: #353535;
  473. margin-bottom: #{10rpx};
  474. }
  475. }
  476. .dialog-goods-list {
  477. padding: 0 #{65rpx};
  478. margin: #{26rpx} 0 #{48rpx};
  479. .dialog-goods {
  480. width: #{80rpx};
  481. height: #{80rpx};
  482. border-radius: #{8rpx};
  483. margin: #{10rpx};
  484. image {
  485. border-radius: #{8rpx};
  486. width: #{80rpx};
  487. height: #{80rpx};
  488. }
  489. }
  490. }
  491. .dialog-close {
  492. width: #{630rpx};
  493. border-top: #{2rpx} solid #e2e2e2;
  494. font-size: #{32rpx};
  495. text-align: center;
  496. padding: #{25rpx} 0;
  497. }
  498. }
  499. }
  500. .bottom {
  501. width: 100%;
  502. height: #{120rpx};
  503. position: fixed;
  504. bottom: 0;
  505. left: 0;
  506. z-index: 30;
  507. background-color: #fff;
  508. border-top: #{2rpx} solid #e2e2e2;
  509. font-size: #{24rpx};
  510. color: #353535;
  511. padding: 0 #{20rpx};
  512. &.iphone_x {
  513. height: #{150rpx};
  514. padding-bottom: #{50rpx};
  515. }
  516. .total-price {
  517. font-size: #{36rpx};
  518. margin-left: #{8rpx};
  519. }
  520. .submit-btn {
  521. width: #{222rpx};
  522. height: #{78rpx};
  523. border-radius: #{39rpx};
  524. color: #fff;
  525. font-size: #{32rpx};
  526. line-height: #{78rpx};
  527. text-align: center;
  528. }
  529. .discount {
  530. font-size: #{24rpx};
  531. }
  532. }
  533. .bottom-space {
  534. height: #{110rpx};
  535. &.iphone_x {
  536. height: #{160rpx};
  537. }
  538. }
  539. </style>