1
0

detail.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. toBuy() {
  86. let that = this;
  87. let attr = [];
  88. let list = [
  89. {
  90. mch_id: 0,
  91. composition_list: []
  92. }
  93. ]
  94. if(that.noAttrList.length > 0) {
  95. that.showNoAttr = true;
  96. }else {
  97. for(let i in that.list) {
  98. attr = [];
  99. if(that.list[i].choose) {
  100. let arr = {
  101. composition_id: that.list[i].id,
  102. goods_list: []
  103. }
  104. if(that.list[i].host_list.length > 0) {
  105. for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
  106. attr.push({
  107. attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
  108. attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
  109. })
  110. }
  111. arr.goods_list.push({
  112. id: that.list[i].host_list[0].goods_id,
  113. num: 1,
  114. goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
  115. attr: []
  116. })
  117. }
  118. let goods_attr = [];
  119. for(let y in that.list[i].goods_list) {
  120. if(that.list[i].goods_list[y].choose_attr && that.list[i].goods_list[y].choose_attr.attr_list.length > 0) {
  121. for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
  122. attr.push({
  123. attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
  124. attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
  125. })
  126. }
  127. arr.goods_list.push({
  128. id: that.list[i].goods_list[y].goods_id,
  129. num: 1,
  130. goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
  131. attr: attr
  132. })
  133. }
  134. }
  135. list[0].composition_list.push(arr);
  136. }else {
  137. let arr = {
  138. composition_id: that.list[i].id,
  139. goods_list: []
  140. }
  141. if(that.list[i].host_list.length > 0 && that.list[i].host_list[0].choose_goods) {
  142. for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
  143. attr.push({
  144. attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
  145. attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
  146. })
  147. }
  148. arr.goods_list.push({
  149. id: that.list[i].host_list[0].goods_id,
  150. num: 1,
  151. goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
  152. attr: attr
  153. })
  154. }
  155. let noChoose = true;
  156. for(let y in that.list[i].goods_list) {
  157. if(that.list[i].goods_list[y].choose_goods && that.list[i].goods_list[y].choose_attr.attr_list) {
  158. noChoose = false;
  159. for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
  160. attr.push({
  161. attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
  162. attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
  163. })
  164. }
  165. arr.goods_list.push({
  166. id: that.list[i].goods_list[y].goods_id,
  167. num: 1,
  168. goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
  169. attr: attr
  170. })
  171. }
  172. }
  173. if(arr.goods_list.length > 0) {
  174. list[0].composition_list.push(arr);
  175. }
  176. }
  177. }
  178. if(list[0].composition_list.length == 0) {
  179. uni.showToast({
  180. title: '请选择套餐',
  181. icon: 'none',
  182. duration: 1000
  183. });
  184. }else {
  185. for(let i in list[0].composition_list) {
  186. if(list[0].composition_list[i].goods_list.length == 1) {
  187. list[0].composition_list.splice(i,1)
  188. }
  189. }
  190. if(list[0].composition_list.length == 0) {
  191. uni.showToast({
  192. title: '请选择搭配商品',
  193. icon: 'none',
  194. duration: 1000
  195. });
  196. }else {
  197. list[0].goods_list = [];
  198. for (let j in list[0].composition_list) {
  199. for (let y in list[0].composition_list[j].goods_list) {
  200. list[0].composition_list[j].goods_list[y].cart_id = 0;
  201. list[0].goods_list.push(list[0].composition_list[j].goods_list[y])
  202. }
  203. }
  204. let jump_url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(list)}`;
  205. jump_url += `&preview_url=${encodeURIComponent(this.$api.composition.order_preview)}&submit_url=${encodeURIComponent(this.$api.composition.order_submit)}&plugin=composition`;
  206. this.$jump({
  207. open_type: 'navigate',
  208. url: jump_url,
  209. });
  210. }
  211. }
  212. }
  213. },
  214. close () {
  215. this.showNoAttr = false;
  216. },
  217. updateList(e) {
  218. this.list = e;
  219. },
  220. update(e) {
  221. this.noAttrList = e;
  222. },
  223. getTotal(e,max_discount) {
  224. this.total = e;
  225. if(max_discount) {
  226. this.max_discount = max_discount.toFixed(2)
  227. }
  228. },
  229. getDetail() {
  230. let that = this;
  231. that.loading = false;
  232. uni.showLoading({
  233. mask: true,
  234. title: '加载中...',
  235. });
  236. let para = {
  237. composition_id: that.composition_id
  238. }
  239. if(that.goods_id > 0) {
  240. para.goods_id = that.goods_id
  241. }
  242. that.$request({
  243. url: that.goods_id > 0 ? that.$api.composition.detail : that.$api.composition.composition_detail,
  244. data: para
  245. }).then(response=>{
  246. that.loading = true;
  247. uni.hideLoading();
  248. if(response.code == 0) {
  249. if(that.goods_id > 0) {
  250. that.list = response.data.other_list;
  251. that.other = response.data.list;
  252. }else {
  253. that.list = [];
  254. that.list[0] = response.data.composition;
  255. }
  256. if(that.other.length < 4) {
  257. that.noMore = true;
  258. }
  259. for(let i in that.list) {
  260. that.list[i].choose = false;
  261. for(let idx in that.list[i].goods_list) {
  262. that.list[i].goods_list[idx].choose_attr = null;
  263. if(that.list[i].goods_list[idx].goods_attr.length == 1) {
  264. that.list[i].goods_list[idx].choose_attr = that.list[i].goods_list[idx].goods_attr[0];
  265. that.list[i].goods_list[idx].choose_attr.number = 1;
  266. 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)
  267. }
  268. if(that.list[i].type == 2) {
  269. that.list[i].host_list[0].choose_attr = null;
  270. if(that.list[i].host_list[0].goods_attr.length == 1) {
  271. that.list[i].host_list[0].choose_attr = that.list[i].host_list[0].goods_attr[0];
  272. that.list[i].host_list[0].choose_attr.number = 1;
  273. 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)
  274. }
  275. that.list[i].goods_list[idx].choose_goods = false;
  276. that.list[i].host_list[0].choose_goods = true;
  277. that.list[i].host_list[0].opacity = 0.3;
  278. }
  279. }
  280. }
  281. if(that.list[0].type == 1) {
  282. that.list[0].choose = true;
  283. that.max_discount = that.list[0].max_discount;
  284. }
  285. }else {
  286. uni.hideLoading();
  287. uni.showToast({
  288. title: response.msg,
  289. icon: 'none',
  290. duration: 1000
  291. });
  292. }
  293. }).catch(response => {
  294. that.loading = true;
  295. uni.hideLoading();
  296. that.$hideLoading();
  297. });
  298. },
  299. getMore() {
  300. let that = this;
  301. uni.showLoading({
  302. title: '加载中'
  303. });
  304. that.$request({
  305. url: that.$api.composition.detail,
  306. data: {
  307. goods_id: that.goods_id,
  308. composition_id: that.composition_id,
  309. page: that.page
  310. }
  311. }).then(response=>{
  312. uni.hideLoading();
  313. if(response.code == 0) {
  314. if(response.data.list.length == 0) {
  315. this.noMore = true;
  316. return false;
  317. }
  318. that.page++;
  319. that.other = that.other.concat(response.data.list);
  320. for(let i in that.list) {
  321. that.list[i].choose = false;
  322. for(let idx in that.list[i].goods_list) {
  323. that.list[i].goods_list[idx].choose_attr = null;
  324. if(that.list[i].type == 2) {
  325. that.list[i].host_list[0].choose_attr = null;
  326. that.list[i].host_list[0].opacity = 1;
  327. that.list[i].goods_list[idx].choose_goods = false;
  328. that.list[i].host_list[0].choose_goods = false;
  329. }
  330. }
  331. }
  332. }else {
  333. uni.hideLoading();
  334. uni.showToast({
  335. title: response.msg,
  336. icon: 'none',
  337. duration: 1000
  338. });
  339. }
  340. }).catch(response => {
  341. that.$hideLoading();
  342. });
  343. },
  344. },
  345. onReachBottom() {
  346. if(!this.noMore) {
  347. this.getMore();
  348. }
  349. },
  350. onLoad(option) {
  351. let that = this;
  352. uni.getSystemInfo({
  353. success: function (res) {
  354. 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) {
  355. that.iphone_x = true;
  356. }
  357. }
  358. })
  359. this.goods_id = option.goods_id > 0 ? option.goods_id : '';
  360. this.composition_id = option.composition_id;
  361. that.getDetail();
  362. },
  363. }
  364. </script>
  365. <style scoped lang="scss">
  366. .no-tip {
  367. position: fixed;
  368. top: #{120rpx};
  369. left: 0;
  370. right: 0;
  371. margin: 0 auto;
  372. color: #666666;
  373. font-size: #{24rpx};
  374. width: #{240rpx};
  375. text-align: center;
  376. image {
  377. height: #{240rpx};
  378. width: #{240rpx};
  379. margin-bottom: #{20rpx};
  380. }
  381. .to-composition {
  382. border-radius: #{33rpx};
  383. width: #{246rpx};
  384. text-align: center;
  385. height: #{66rpx};
  386. line-height: #{66rpx};
  387. margin-top: #{38rpx};
  388. color: #fff;
  389. }
  390. }
  391. .list {
  392. padding: #{24rpx};
  393. .title {
  394. font-size: #{28rpx};
  395. color: #353535;
  396. }
  397. .item {
  398. margin-top: #{20rpx};
  399. padding: #{24rpx};
  400. border-radius: #{16rpx};
  401. background-color: #fff;
  402. }
  403. }
  404. .dialog-bg {
  405. position: fixed;
  406. top: 0;
  407. left: 0;
  408. width: 100%;
  409. height: 100%;
  410. background-color: rgba(0,0,0,.3);
  411. z-index: 202;
  412. .dialog {
  413. width: #{630rpx};
  414. margin: #{260rpx} auto 0;
  415. background-color: #fff;
  416. padding-top: #{40rpx};
  417. border-radius: #{16rpx};
  418. .dialog-title {
  419. text-align: center;
  420. font-size: #{26rpx};
  421. color: #999999;
  422. .dialog-big-title {
  423. font-size: #{32rpx};
  424. color: #353535;
  425. margin-bottom: #{10rpx};
  426. }
  427. }
  428. .dialog-goods-list {
  429. padding: 0 #{65rpx};
  430. margin: #{26rpx} 0 #{48rpx};
  431. .dialog-goods {
  432. width: #{80rpx};
  433. height: #{80rpx};
  434. border-radius: #{8rpx};
  435. margin: #{10rpx};
  436. image {
  437. border-radius: #{8rpx};
  438. width: #{80rpx};
  439. height: #{80rpx};
  440. }
  441. }
  442. }
  443. .dialog-close {
  444. width: #{630rpx};
  445. border-top: #{2rpx} solid #e2e2e2;
  446. font-size: #{32rpx};
  447. text-align: center;
  448. padding: #{25rpx} 0;
  449. }
  450. }
  451. }
  452. .bottom {
  453. width: 100%;
  454. height: #{120rpx};
  455. position: fixed;
  456. bottom: 0;
  457. left: 0;
  458. z-index: 30;
  459. background-color: #fff;
  460. border-top: #{2rpx} solid #e2e2e2;
  461. font-size: #{24rpx};
  462. color: #353535;
  463. padding: 0 #{20rpx};
  464. &.iphone_x {
  465. height: #{150rpx};
  466. padding-bottom: #{50rpx};
  467. }
  468. .total-price {
  469. font-size: #{36rpx};
  470. margin-left: #{8rpx};
  471. }
  472. .submit-btn {
  473. width: #{222rpx};
  474. height: #{78rpx};
  475. border-radius: #{39rpx};
  476. color: #fff;
  477. font-size: #{32rpx};
  478. line-height: #{78rpx};
  479. text-align: center;
  480. }
  481. .discount {
  482. font-size: #{24rpx};
  483. }
  484. }
  485. .bottom-space {
  486. height: #{110rpx};
  487. &.iphone_x {
  488. height: #{160rpx};
  489. }
  490. }
  491. </style>