detail.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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" :style="{'color': getTheme.color}">¥{{total == 0 ? '0.00' : total}}</view>
  16. </view>
  17. <view class="discount" :style="{'color': getTheme.color}">已省¥{{max_discount}}</view>
  18. </view>
  19. <view @click="toBuy" class="submit-btn" :style="{'background-color': getTheme.background}">立即购买</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" :style="{'color': getTheme.color}">我知道了</view>
  33. </view>
  34. </view>
  35. <view class='no-tip' v-if="list.length == 0 && loading">
  36. <image src="../image/pull-off.png"></image>
  37. <view>您选购的套餐已下架</view>
  38. <view @click="toComposition" class="to-composition" :style="{'background-color': getTheme.background}">逛逛套餐专区</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) {
  224. this.total = e.total;
  225. if(e.max_discount) {
  226. this.max_discount = e.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. mask: true,
  303. title: '加载中'
  304. });
  305. that.$request({
  306. url: that.$api.composition.detail,
  307. data: {
  308. goods_id: that.goods_id,
  309. composition_id: that.composition_id,
  310. page: that.page
  311. }
  312. }).then(response=>{
  313. uni.hideLoading();
  314. if(response.code == 0) {
  315. if(response.data.list.length == 0) {
  316. this.noMore = true;
  317. return false;
  318. }
  319. that.page++;
  320. that.other = that.other.concat(response.data.list);
  321. for(let i in that.list) {
  322. that.list[i].choose = false;
  323. for(let idx in that.list[i].goods_list) {
  324. that.list[i].goods_list[idx].choose_attr = null;
  325. if(that.list[i].type == 2) {
  326. that.list[i].host_list[0].choose_attr = null;
  327. that.list[i].host_list[0].opacity = 1;
  328. that.list[i].goods_list[idx].choose_goods = false;
  329. that.list[i].host_list[0].choose_goods = false;
  330. }
  331. }
  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.$hideLoading();
  343. });
  344. },
  345. },
  346. onReachBottom() {
  347. if(!this.noMore) {
  348. this.getMore();
  349. }
  350. },
  351. onLoad(option) { this.$commonLoad.onload(option);
  352. let that = this;
  353. uni.getSystemInfo({
  354. success: function (res) {
  355. 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) {
  356. that.iphone_x = true;
  357. }
  358. }
  359. })
  360. this.goods_id = option.goods_id > 0 ? option.goods_id : '';
  361. this.composition_id = option.composition_id;
  362. that.getDetail();
  363. },
  364. }
  365. </script>
  366. <style scoped lang="scss">
  367. .no-tip {
  368. position: fixed;
  369. top: #{120rpx};
  370. left: 0;
  371. right: 0;
  372. margin: 0 auto;
  373. color: #666666;
  374. font-size: #{24rpx};
  375. width: #{240rpx};
  376. text-align: center;
  377. image {
  378. height: #{240rpx};
  379. width: #{240rpx};
  380. margin-bottom: #{20rpx};
  381. }
  382. .to-composition {
  383. border-radius: #{33rpx};
  384. width: #{246rpx};
  385. text-align: center;
  386. height: #{66rpx};
  387. line-height: #{66rpx};
  388. margin-top: #{38rpx};
  389. color: #fff;
  390. }
  391. }
  392. .list {
  393. padding: #{24rpx};
  394. .title {
  395. font-size: #{28rpx};
  396. color: #353535;
  397. }
  398. .item {
  399. margin-top: #{20rpx};
  400. padding: #{24rpx};
  401. border-radius: #{16rpx};
  402. background-color: #fff;
  403. }
  404. }
  405. .dialog-bg {
  406. position: fixed;
  407. top: 0;
  408. left: 0;
  409. width: 100%;
  410. height: 100%;
  411. background-color: rgba(0,0,0,.3);
  412. z-index: 202;
  413. .dialog {
  414. width: #{630rpx};
  415. margin: #{260rpx} auto 0;
  416. background-color: #fff;
  417. padding-top: #{40rpx};
  418. border-radius: #{16rpx};
  419. .dialog-title {
  420. text-align: center;
  421. font-size: #{26rpx};
  422. color: #999999;
  423. .dialog-big-title {
  424. font-size: #{32rpx};
  425. color: #353535;
  426. margin-bottom: #{10rpx};
  427. }
  428. }
  429. .dialog-goods-list {
  430. padding: 0 #{65rpx};
  431. margin: #{26rpx} 0 #{48rpx};
  432. .dialog-goods {
  433. width: #{80rpx};
  434. height: #{80rpx};
  435. border-radius: #{8rpx};
  436. margin: #{10rpx};
  437. image {
  438. border-radius: #{8rpx};
  439. width: #{80rpx};
  440. height: #{80rpx};
  441. }
  442. }
  443. }
  444. .dialog-close {
  445. width: #{630rpx};
  446. border-top: #{2rpx} solid #e2e2e2;
  447. font-size: #{32rpx};
  448. text-align: center;
  449. padding: #{25rpx} 0;
  450. }
  451. }
  452. }
  453. .bottom {
  454. width: 100%;
  455. height: #{120rpx};
  456. position: fixed;
  457. bottom: 0;
  458. left: 0;
  459. z-index: 30;
  460. background-color: #fff;
  461. border-top: #{2rpx} solid #e2e2e2;
  462. font-size: #{24rpx};
  463. color: #353535;
  464. padding: 0 #{20rpx};
  465. &.iphone_x {
  466. height: #{150rpx};
  467. padding-bottom: #{50rpx};
  468. }
  469. .total-price {
  470. font-size: #{36rpx};
  471. margin-left: #{8rpx};
  472. }
  473. .submit-btn {
  474. width: #{222rpx};
  475. height: #{78rpx};
  476. border-radius: #{39rpx};
  477. color: #fff;
  478. font-size: #{32rpx};
  479. line-height: #{78rpx};
  480. text-align: center;
  481. }
  482. .discount {
  483. font-size: #{24rpx};
  484. }
  485. }
  486. .bottom-space {
  487. height: #{110rpx};
  488. &.iphone_x {
  489. height: #{160rpx};
  490. }
  491. }
  492. </style>