detail.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. }
  103. }
  104. })
  105. return false;
  106. }else{
  107. return true;
  108. }
  109. }
  110. },
  111. toBuy() {
  112. let that = this;
  113. let attr = [];
  114. let list = [
  115. {
  116. mch_id: 0,
  117. composition_list: []
  118. }
  119. ]
  120. let isCanbuy = true;
  121. for(let i in that.list) {
  122. // console.log(that.list[i])
  123. // if(!that.isCanbuy(that.list[i].host_list[0])){
  124. // isCanbuy = false;
  125. // }
  126. for(let j in that.list[i].goods_list){
  127. if(!that.isCanbuy(that.list[i].goods_list[j])){
  128. isCanbuy = false;
  129. }
  130. }
  131. }
  132. if(!isCanbuy){
  133. return;
  134. }
  135. if(that.noAttrList.length > 0) {
  136. that.showNoAttr = true;
  137. // for(let i in that.noAttrList) {
  138. // if(!that.isCanbuy(that.noAttrList[i]))
  139. // return;
  140. // }
  141. }
  142. //else {
  143. for(let i in that.list) {
  144. attr = [];
  145. if(that.list[i].choose) {
  146. let arr = {
  147. composition_id: that.list[i].id,
  148. goods_list: []
  149. }
  150. if(that.list[i].host_list.length > 0) {
  151. for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
  152. attr.push({
  153. attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
  154. attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
  155. })
  156. }
  157. arr.goods_list.push({
  158. id: that.list[i].host_list[0].goods_id,
  159. num: 1,
  160. goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
  161. attr: []
  162. })
  163. }
  164. let goods_attr = [];
  165. for(let y in that.list[i].goods_list) {
  166. if(that.list[i].goods_list[y].choose_attr && that.list[i].goods_list[y].choose_attr.attr_list.length > 0) {
  167. for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
  168. attr.push({
  169. attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
  170. attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
  171. })
  172. }
  173. arr.goods_list.push({
  174. id: that.list[i].goods_list[y].goods_id,
  175. num: 1,
  176. goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
  177. attr: attr,
  178. service_label:that.list[i].goods_list[y].choose_attr.service_label
  179. })
  180. }
  181. }
  182. list[0].composition_list.push(arr);
  183. }else {
  184. let arr = {
  185. composition_id: that.list[i].id,
  186. goods_list: []
  187. }
  188. if(that.list[i].host_list.length > 0 && that.list[i].host_list[0].choose_goods) {
  189. for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
  190. attr.push({
  191. attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
  192. attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
  193. })
  194. }
  195. arr.goods_list.push({
  196. id: that.list[i].host_list[0].goods_id,
  197. num: 1,
  198. goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
  199. attr: attr
  200. })
  201. }
  202. let noChoose = true;
  203. for(let y in that.list[i].goods_list) {
  204. if(that.list[i].goods_list[y].choose_goods && that.list[i].goods_list[y].choose_attr.attr_list) {
  205. noChoose = false;
  206. for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
  207. attr.push({
  208. attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
  209. attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
  210. })
  211. }
  212. arr.goods_list.push({
  213. id: that.list[i].goods_list[y].goods_id,
  214. num: 1,
  215. goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
  216. attr: attr,
  217. service_label:that.list[i].goods_list[y].choose_attr.service_label
  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. console.log(e)
  267. this.list = e;
  268. },
  269. update(e) {
  270. this.noAttrList = e;
  271. },
  272. getTotal(e,max_discount) {
  273. this.total = e;
  274. if(max_discount) {
  275. this.max_discount = max_discount.toFixed(2)
  276. }
  277. },
  278. getDetail() {
  279. let that = this;
  280. that.loading = false;
  281. uni.showLoading({
  282. mask: true,
  283. title: '加载中...',
  284. });
  285. let para = {
  286. composition_id: that.composition_id
  287. }
  288. if(that.goods_id > 0) {
  289. para.goods_id = that.goods_id
  290. }
  291. that.$request({
  292. url: that.goods_id > 0 ? that.$api.composition.detail : that.$api.composition.composition_detail,
  293. data: para
  294. }).then(response=>{
  295. that.loading = true;
  296. uni.hideLoading();
  297. if(response.code == 0) {
  298. if(that.goods_id > 0) {
  299. that.list = response.data.other_list;
  300. that.other = response.data.list;
  301. }else {
  302. that.list = [];
  303. that.list[0] = response.data.composition;
  304. }
  305. if(that.other.length < 4) {
  306. that.noMore = true;
  307. }
  308. for(let i in that.list) {
  309. that.list[i].choose = false;
  310. for(let idx in that.list[i].goods_list) {
  311. that.list[i].goods_list[idx].choose_attr = null;
  312. if(that.list[i].goods_list[idx].goods_attr.length == 1) {
  313. that.list[i].goods_list[idx].choose_attr = that.list[i].goods_list[idx].goods_attr[0];
  314. that.list[i].goods_list[idx].choose_attr.number = 1;
  315. 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)
  316. }
  317. if(that.list[i].type == 2) {
  318. that.list[i].host_list[0].choose_attr = null;
  319. if(that.list[i].host_list[0].goods_attr.length == 1) {
  320. that.list[i].host_list[0].choose_attr = that.list[i].host_list[0].goods_attr[0];
  321. that.list[i].host_list[0].choose_attr.number = 1;
  322. 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)
  323. }
  324. that.list[i].goods_list[idx].choose_goods = false;
  325. that.list[i].host_list[0].choose_goods = true;
  326. that.list[i].host_list[0].opacity = 0.3;
  327. }
  328. }
  329. }
  330. if(that.list[0].type == 1) {
  331. that.list[0].choose = true;
  332. that.max_discount = that.list[0].max_discount;
  333. }
  334. }else {
  335. uni.hideLoading();
  336. uni.showToast({
  337. title: response.msg,
  338. icon: 'none',
  339. duration: 1000
  340. });
  341. }
  342. }).catch(response => {
  343. that.loading = true;
  344. uni.hideLoading();
  345. that.$hideLoading();
  346. });
  347. },
  348. getMore() {
  349. let that = this;
  350. uni.showLoading({
  351. title: '加载中'
  352. });
  353. that.$request({
  354. url: that.$api.composition.detail,
  355. data: {
  356. goods_id: that.goods_id,
  357. composition_id: that.composition_id,
  358. page: that.page
  359. }
  360. }).then(response=>{
  361. uni.hideLoading();
  362. if(response.code == 0) {
  363. if(response.data.list.length == 0) {
  364. this.noMore = true;
  365. return false;
  366. }
  367. that.page++;
  368. that.other = that.other.concat(response.data.list);
  369. for(let i in that.list) {
  370. that.list[i].choose = false;
  371. for(let idx in that.list[i].goods_list) {
  372. that.list[i].goods_list[idx].choose_attr = null;
  373. if(that.list[i].type == 2) {
  374. that.list[i].host_list[0].choose_attr = null;
  375. that.list[i].host_list[0].opacity = 1;
  376. that.list[i].goods_list[idx].choose_goods = false;
  377. that.list[i].host_list[0].choose_goods = false;
  378. }
  379. }
  380. }
  381. }else {
  382. uni.hideLoading();
  383. uni.showToast({
  384. title: response.msg,
  385. icon: 'none',
  386. duration: 1000
  387. });
  388. }
  389. }).catch(response => {
  390. that.$hideLoading();
  391. });
  392. },
  393. },
  394. onReachBottom() {
  395. if(!this.noMore) {
  396. this.getMore();
  397. }
  398. },
  399. onLoad(option) {
  400. let that = this;
  401. uni.getSystemInfo({
  402. success: function (res) {
  403. 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) {
  404. that.iphone_x = true;
  405. }
  406. }
  407. })
  408. this.goods_id = option.goods_id > 0 ? option.goods_id : '';
  409. this.composition_id = option.composition_id;
  410. that.getDetail();
  411. },
  412. }
  413. </script>
  414. <style scoped lang="scss">
  415. .no-tip {
  416. position: fixed;
  417. top: #{120rpx};
  418. left: 0;
  419. right: 0;
  420. margin: 0 auto;
  421. color: #666666;
  422. font-size: #{24rpx};
  423. width: #{240rpx};
  424. text-align: center;
  425. image {
  426. height: #{240rpx};
  427. width: #{240rpx};
  428. margin-bottom: #{20rpx};
  429. }
  430. .to-composition {
  431. border-radius: #{33rpx};
  432. width: #{246rpx};
  433. text-align: center;
  434. height: #{66rpx};
  435. line-height: #{66rpx};
  436. margin-top: #{38rpx};
  437. color: #fff;
  438. }
  439. }
  440. .list {
  441. padding: #{24rpx};
  442. .title {
  443. font-size: #{28rpx};
  444. color: #353535;
  445. }
  446. .item {
  447. margin-top: #{20rpx};
  448. padding: #{24rpx};
  449. border-radius: #{16rpx};
  450. background-color: #fff;
  451. }
  452. }
  453. .dialog-bg {
  454. position: fixed;
  455. top: 0;
  456. left: 0;
  457. width: 100%;
  458. height: 100%;
  459. background-color: rgba(0,0,0,.3);
  460. z-index: 202;
  461. .dialog {
  462. width: #{630rpx};
  463. margin: #{260rpx} auto 0;
  464. background-color: #fff;
  465. padding-top: #{40rpx};
  466. border-radius: #{16rpx};
  467. .dialog-title {
  468. text-align: center;
  469. font-size: #{26rpx};
  470. color: #999999;
  471. .dialog-big-title {
  472. font-size: #{32rpx};
  473. color: #353535;
  474. margin-bottom: #{10rpx};
  475. }
  476. }
  477. .dialog-goods-list {
  478. padding: 0 #{65rpx};
  479. margin: #{26rpx} 0 #{48rpx};
  480. .dialog-goods {
  481. width: #{80rpx};
  482. height: #{80rpx};
  483. border-radius: #{8rpx};
  484. margin: #{10rpx};
  485. image {
  486. border-radius: #{8rpx};
  487. width: #{80rpx};
  488. height: #{80rpx};
  489. }
  490. }
  491. }
  492. .dialog-close {
  493. width: #{630rpx};
  494. border-top: #{2rpx} solid #e2e2e2;
  495. font-size: #{32rpx};
  496. text-align: center;
  497. padding: #{25rpx} 0;
  498. }
  499. }
  500. }
  501. .bottom {
  502. width: 100%;
  503. height: #{120rpx};
  504. position: fixed;
  505. bottom: 0;
  506. left: 0;
  507. z-index: 30;
  508. background-color: #fff;
  509. border-top: #{2rpx} solid #e2e2e2;
  510. font-size: #{24rpx};
  511. color: #353535;
  512. padding: 0 #{20rpx};
  513. &.iphone_x {
  514. height: #{150rpx};
  515. padding-bottom: #{50rpx};
  516. }
  517. .total-price {
  518. font-size: #{36rpx};
  519. margin-left: #{8rpx};
  520. }
  521. .submit-btn {
  522. width: #{222rpx};
  523. height: #{78rpx};
  524. border-radius: #{39rpx};
  525. color: #fff;
  526. font-size: #{32rpx};
  527. line-height: #{78rpx};
  528. text-align: center;
  529. }
  530. .discount {
  531. font-size: #{24rpx};
  532. }
  533. }
  534. .bottom-space {
  535. height: #{110rpx};
  536. &.iphone_x {
  537. height: #{160rpx};
  538. }
  539. }
  540. </style>