app-list.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <view>
  3. <view class="app-list" :style="{'margin-top': `${top}rpx`}">
  4. <view class="app-item" v-for="(item,index) in list" :key="item.id">
  5. <view class="item-goods main-between" v-for="(goods,index1) in item.host_list" :key="goods.id">
  6. <view class="main-left">
  7. <image @click="toDetail(goods.goods_id)" class="goods-img" :src="goods.cover_pic"></image>
  8. <view v-if="goods.stock == 0 || item.stock == 0" class="out-dialog">
  9. <image :src="appSetting.is_use_stock == '1' ? appImg.plugins_out : appSetting.sell_out_pic"></image>
  10. </view>
  11. <view class="dir-top-nowrap goods-info">
  12. <view class="item-good-name">{{goods.name}}</view>
  13. <!-- <view class="item-good-num">x1</view> -->
  14. <view class="item-good-attr" v-if="!goods.choose_attr" @click="chooseAttr(goods,index)">
  15. <view class="item-good-attr-text t-omit-two">未选择</view>
  16. <image class="item-good-attr-arrow" src="https://t17.9026.com/web/statics/image/index/arrow-right-A18353.png"></image>
  17. </view>
  18. <view class="item-good-attr" v-else @click="chooseAttr(goods,index)">
  19. <view class="item-good-attr-text t-omit-two">
  20. <!-- {{attr.attr_group_name}}: -->
  21. <text v-for="attr in goods.choose_attr.attr_list" :key="attr.attr_id">{{attr.attr_name}}</text>
  22. </view>
  23. <image class="item-good-attr-arrow" src="https://t17.9026.com/web/statics/image/index/arrow-right-A18353.png"></image>
  24. </view>
  25. <view class="price"><text class="ought_price">¥{{goods.max_price}}</text><text class="paid_price" v-show="goods.total_price">实付:¥<text>{{goods.total_price}}</text></text></view>
  26. </view>
  27. </view>
  28. <app-add-subtract :xStyle="2" :stock="goods.stock" :good_id="goods.id" :min="1" :value="goods.choose_attr.number" @change="addsubChange($event,goods,index,index1,0)"></app-add-subtract>
  29. </view>
  30. <view class="item-goods main-between" v-for="(goods,idx) in item.goods_list" :key="goods.id">
  31. <view class="main-left">
  32. <image @click="toDetail(goods.goods_id)" class="goods-img" :src="goods.cover_pic"></image>
  33. <view v-if="goods.stock == 0 || item.stock == 0" class="out-dialog">
  34. <image :src="appSetting.is_use_stock == '1' ? appImg.plugins_out : appSetting.sell_out_pic"></image>
  35. </view>
  36. <view class="dir-top-nowrap goods-info">
  37. <view class="item-good-name">{{goods.name}}</view>
  38. <!-- <view class="item-good-num">x1</view> -->
  39. <view class="item-good-attr" v-if="!goods.choose_attr" @click="chooseAttr(goods,index)">
  40. <view class="item-good-attr-text t-omit-two">未选择</view>
  41. <image class="item-good-attr-arrow" src="https://t17.9026.com/web/statics/image/index/arrow-right-A18353.png"></image>
  42. </view>
  43. <view class="item-good-attr" v-else @click="chooseAttr(goods,index)">
  44. <view class="item-good-attr-text t-omit-two">
  45. <text v-for="(attr,idx) in goods.choose_attr.attr_list" :key="attr.attr_id">
  46. <text v-if="idx > 0">,</text>
  47. <text>{{attr.attr_name}}</text>
  48. </text>
  49. </view>
  50. <image class="item-good-attr-arrow" src="https://t17.9026.com/web/statics/image/index/arrow-right-A18353.png"></image>
  51. </view>
  52. <view class="price"><text class="ought_price">¥{{goods.max_price}}</text><text class="paid_price" v-show="goods.total_price">实付:¥<text>{{goods.total_price}}</text></text></view>
  53. </view>
  54. </view>
  55. <app-add-subtract :xStyle="2" :stock="goods.stock" :good_id="goods.id" :min="0" :value="goods.choose_attr.number" @change="addsubChange($event,goods,index,idx,1)"></app-add-subtract>
  56. </view>
  57. <view class="app-price">
  58. <template v-if="item.total_price && hidden">
  59. <text>套餐价</text>
  60. <text :style="{'color': theme.color}">¥{{item.total_price > -0.01 ? item.total_price : '0.00'}}</text>
  61. </template>
  62. </view>
  63. </view>
  64. </view>
  65. <u-attr
  66. v-if="goods"
  67. v-model="attrShow"
  68. :goods="goods"
  69. rightText="确定"
  70. :is_show_left="cartShow"
  71. :is_choose_number="cartShow"
  72. :theme="theme"
  73. :checked="checked"
  74. @check="check"
  75. :again="attrShow"
  76. :right-func="true"
  77. @rightFunc="buyClick"
  78. ></u-attr>
  79. <!-- <app-attr v-if="goods" :goodsId="goods.goods_id"
  80. :goods="goods.detail"
  81. :attrGroupList="goods.attr_groups"
  82. :cartShow="cartShow"
  83. :chooseNumber="cartShow"
  84. buyText="确定"
  85. :buyClick="buyBool"
  86. :show="attrShow"
  87. :theme="theme"
  88. @buyClick="buyClick"></app-attr> -->
  89. </view>
  90. </template>
  91. <script>
  92. import { mapState } from "vuex";
  93. // import appAttr from "../../../../components/page-component/app-attr/app-attr.vue";
  94. import uAttr from "../../../../components/page-component/goods/u-attr.vue";
  95. import appAddSubtract from "../app-add-subtract/app-add-subtract.vue";
  96. export default {
  97. name: 'app-index',
  98. props: {
  99. list: {
  100. type: Array
  101. },
  102. top: {
  103. type: Number,
  104. default() {
  105. return 388
  106. }
  107. },
  108. search: {
  109. type: Boolean,
  110. default() {
  111. return false;
  112. }
  113. },
  114. allCount: {
  115. type: Boolean,
  116. default() {
  117. return false;
  118. }
  119. },
  120. hidden: {
  121. type: Boolean,
  122. default() {
  123. return true;
  124. }
  125. },
  126. theme: Object
  127. },
  128. data() {
  129. return {
  130. attrShow: 0,
  131. goods: null,
  132. cartShow: false,
  133. buyBool: true,
  134. max_discount: '0.00',
  135. noAttrList: [],
  136. checked: null,
  137. total: 0,
  138. }
  139. },
  140. computed: {
  141. ...mapState({
  142. appImg: state => state.mallConfig.__wxapp_img.mall,
  143. appSetting: state => state.mallConfig.mall.setting,
  144. })
  145. },
  146. components: {
  147. 'u-attr': uAttr,
  148. appAddSubtract
  149. },
  150. methods: {
  151. addsubChange(e,goods,index,index1,ss){
  152. if(ss===0){//固定商品
  153. this.list[index].host_list[index1].choose_attr.number=e.number
  154. }else{//搭配商品
  155. this.list[index].goods_list[index1].choose_attr.number=e.number
  156. }
  157. this.count();
  158. },
  159. // 规格选择
  160. check({item}) {
  161. this.checked = item;
  162. },
  163. toDetail(id) {
  164. uni.navigateTo({
  165. url: '/pages/goods/goods?id=' + id
  166. });
  167. },
  168. buyClick() {
  169. let that = this;
  170. let selectAttr = this.checked
  171. that.list[that.index].goods_list.forEach(v => {
  172. if(v.id == that.goods.id) {
  173. v.choose_attr = selectAttr;
  174. v.detail.selectAttr = selectAttr;
  175. for(let i in selectAttr.attr_list) {
  176. for(let j in v.attr_groups) {
  177. if(v.attr_groups[j].attr_group_id == selectAttr.attr_list[i].attr_group_id) {
  178. for(let z in v.attr_groups[j].attr_list) {
  179. v.attr_groups[j].attr_list[z].checked = false;
  180. if(v.attr_groups[j].attr_list[z].attr_id == selectAttr.attr_list[i].attr_id && v.attr_groups[j].attr_list[z].attr_name == selectAttr.attr_list[i].attr_name) {
  181. v.attr_groups[j].attr_list[z].checked = true;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. if(that.list[that.index].type == 2) {
  188. v.choose_goods = true;
  189. for (let i = 0; i < that.list[that.index].host_list.length; i++) {
  190. let item=that.list[that.index].host_list[i]
  191. item.choose_goods = true
  192. item.opacity = 0.3
  193. }
  194. }
  195. that.count();
  196. that.$forceUpdate();
  197. }
  198. })
  199. that.list[that.index].host_list.forEach(v => {
  200. if(v.id == that.goods.id) {
  201. for(let i in selectAttr.attr_list) {
  202. for(let j in v.attr_groups) {
  203. if(v.attr_groups[j].attr_group_id == selectAttr.attr_list[i].attr_group_id) {
  204. for(let z in v.attr_groups[j].attr_list) {
  205. v.attr_groups[j].attr_list[z].checked = false;
  206. if(v.attr_groups[j].attr_list[z].attr_id == selectAttr.attr_list[i].attr_id && v.attr_groups[j].attr_list[z].attr_name == selectAttr.attr_list[i].attr_name) {
  207. v.attr_groups[j].attr_list[z].checked = true;
  208. }
  209. }
  210. }
  211. }
  212. }
  213. v.choose_attr = selectAttr;
  214. v.detail.selectAttr = selectAttr;
  215. v.choose_goods = true;
  216. that.count();
  217. that.$forceUpdate();
  218. if (that.search) {
  219. that.$emit('search', v, 1);
  220. return false;
  221. }
  222. }
  223. })
  224. that.goods = null;
  225. that.checked = null;
  226. },
  227. chooseAttr(goods,index, type) {
  228. console.log(goods)
  229. this.goods = goods;
  230. this.index = index;
  231. this.attrShow = Math.random();
  232. },
  233. choose(index,item) {
  234. if(this.list[index].type == 2) {
  235. this.list[index].choose = !this.list[index].choose;
  236. for(let i in this.list[index].goods_list) {
  237. this.list[index].goods_list[i].choose_goods = this.list[index].choose
  238. }
  239. this.count();
  240. this.$forceUpdate();
  241. if (this.search) {
  242. this.$emit('search', item);
  243. }
  244. }
  245. },
  246. chooseGoods(idx,index,item) {
  247. this.list[index].goods_list[idx].choose_goods = !this.list[index].goods_list[idx].choose_goods;
  248. let all = true;
  249. for(let i in this.list[index].goods_list) {
  250. if(!this.list[index].goods_list[i].choose_goods) {
  251. all = false;
  252. }
  253. }
  254. this.list[index].choose = all;
  255. this.$forceUpdate();
  256. this.$emit("updateList",this.list);
  257. this.count();
  258. if (this.search) {
  259. this.$emit('search', item, 1);
  260. }
  261. },
  262. count() {
  263. let that = this;
  264. that.total = 0;
  265. that.noAttrList = [];
  266. that.max_discount = 0;
  267. let i = 0;
  268. if(that.list[i].type == 1) {
  269. that.list[i].total_price = 0;
  270. let allchoose = true;
  271. for(let x in that.list[i].goods_list) {
  272. if(that.list[i].goods_list[x].choose_attr) {
  273. if(that.list[i].goods_list[x].choose_attr.price > 0) {
  274. that.list[i].total_price += +that.list[i].goods_list[x].choose_attr.price;
  275. }
  276. }else {
  277. allchoose = false;
  278. }
  279. if(that.list[i].choose && that.list[i].goods_list[x].choose_attr == null ) {
  280. that.noAttrList.push(that.list[i].goods_list[x])
  281. }
  282. }
  283. if(that.list[i].total_price < 0) {
  284. that.list[i].total_price = 0
  285. }
  286. that.list[i].total_price = (+that.list[i].total_price - +that.list[i].price);
  287. if(that.list[i].total_price < 0) {
  288. that.list[i].total_price = 0
  289. }
  290. if(that.list[i].choose) {
  291. that.list[i].total_price = that.list[i].total_price.toFixed(2)
  292. }else {
  293. delete that.list[i].total_price
  294. }
  295. if(that.list[i].choose && allchoose) {
  296. that.total += +that.list[i].total_price
  297. }
  298. }else if(that.list[i].type == 2) {
  299. that.list[i].total_price = 0;
  300. for (let k = 0; k < that.list[i].host_list.length; k++) {
  301. let item=that.list[i].host_list[k]
  302. if(item.choose_attr) {
  303. that.list[i].total_price = (+item.choose_attr.price - +item.price)*item.choose_attr.number
  304. item.total_price = (+item.choose_attr.price - +item.price)*item.choose_attr.number
  305. that.max_discount += (+item.price)*item.choose_attr.number
  306. if(item.total_price < 0) {
  307. item.total_price = 0
  308. }else {
  309. item.total_price = +item.total_price.toFixed(2);
  310. }
  311. that.total += +item.total_price
  312. }else {
  313. that.noAttrList.push(item)
  314. }
  315. }
  316. for(let x in that.list[i].goods_list) {
  317. let item=that.list[i].goods_list[x]
  318. if(item.choose_goods && item.choose_attr) {
  319. item.total_price = (+item.choose_attr.price - +item.price)*item.choose_attr.number
  320. that.max_discount += (+item.price)*item.choose_attr.number
  321. if(item.total_price < 0) {
  322. item.total_price = 0
  323. }else {
  324. item.total_price = +item.total_price.toFixed(2);
  325. }
  326. that.total += +item.total_price
  327. if(that.list[i].total_price > 0) {
  328. that.list[i].total_price += +item.total_price
  329. }
  330. }
  331. if(item.choose_goods && item.choose_attr == null ) {
  332. that.noAttrList.push(item)
  333. }
  334. }
  335. if(that.list[i].total_price < 0) {
  336. that.list[i].total_price = 0
  337. }
  338. that.list[i].total_price = +that.list[i].total_price.toFixed(2);
  339. that.max_discount = +that.max_discount.toFixed(2);
  340. }
  341. that.total = that.total.toFixed(2);
  342. that.$emit("updateList",that.list);
  343. that.$emit("change",{
  344. total:that.total,
  345. max_discount:that.max_discount
  346. });
  347. that.$emit("update",that.noAttrList);
  348. },
  349. },
  350. mounted() {
  351. let that = this;
  352. let get = setInterval(function(){
  353. if(that.list.length > 0) {
  354. clearInterval(get)
  355. that.count();
  356. }
  357. },500)
  358. }
  359. }
  360. </script>
  361. <style scoped lang="scss">
  362. .app-list {
  363. .app-item {
  364. background-color: #fff;
  365. // margin: #{10rpx} #{24rpx};
  366. // border-radius: #{16rpx};
  367. padding: #{24rpx};
  368. padding-top: 20rpx;
  369. padding-left: 35rpx;
  370. .app-price {
  371. line-height: #{74rpx};
  372. height: #{74rpx};
  373. text-align: right;
  374. color: #353535;
  375. font-size: #{28rpx};
  376. .max-discount {
  377. font-size: #{24rpx};
  378. color: #f39800;
  379. margin-left: #{16rpx};
  380. }
  381. }
  382. .app-item-title {
  383. padding-right: #{24rpx};
  384. height: #{64rpx};
  385. font-size: #{28rpx};
  386. color: #353535;
  387. font-weight: bold;
  388. .check-icon {
  389. padding: #{28rpx} #{20rpx} 0 #{24rpx};
  390. width: #{72rpx};
  391. height: #{64rpx};
  392. image {
  393. height: #{32rpx};
  394. width: #{32rpx};
  395. border-radius: #{16rpx};
  396. display: block;
  397. }
  398. }
  399. .item-type {
  400. margin-top: #{24rpx};
  401. flex-shrink: 0;
  402. height: #{40rpx};
  403. line-height: #{38rpx};
  404. padding: 0 #{12rpx};
  405. border-radius: #{20rpx};
  406. margin-right: #{16rpx};
  407. border: #{2rpx} solid;
  408. font-weight: 400;
  409. }
  410. .item-name {
  411. margin-top: #{24rpx};
  412. overflow: hidden;
  413. text-overflow: ellipsis;
  414. white-space: nowrap;
  415. word-break: break-all;
  416. }
  417. }
  418. .item-goods {
  419. margin-top: #{28rpx};
  420. // margin-left: #{76rpx};
  421. padding-bottom: #{28rpx};
  422. // border-bottom: #{2rpx} solid #e2e2e2;
  423. position: relative;
  424. .out-dialog {
  425. width: #{180rpx};
  426. height: #{180rpx};
  427. border-radius: #{16rpx};
  428. position: absolute;
  429. top: 0;
  430. left: 0;
  431. z-index: 10;
  432. background-color: rgba(0,0,0,.5);
  433. image {
  434. width: #{180rpx};
  435. height: #{180rpx};
  436. border-radius: #{16rpx};
  437. }
  438. }
  439. .check-icon {
  440. position: absolute;
  441. left: #{-76rpx};
  442. top: 50%;
  443. margin-top: #{-52rpx};
  444. padding: #{24rpx};
  445. width: #{80rpx};
  446. height: #{80rpx};
  447. image {
  448. height: #{32rpx};
  449. width: #{32rpx};
  450. border-radius: #{16rpx};
  451. display: block;
  452. }
  453. }
  454. .goods-img {
  455. height: #{100rpx};
  456. width: #{100rpx};
  457. border-radius: #{8rpx};
  458. margin-right: #{24rpx};
  459. position: relative;
  460. }
  461. .goods-info {
  462. font-size: #{28rpx};
  463. color: #353535;
  464. position: relative;
  465. .item-good-name {
  466. width: #{336rpx};
  467. max-height: #{90rpx};
  468. word-break: break-all;
  469. overflow: hidden;
  470. text-overflow: ellipsis;
  471. white-space: nowrap;
  472. font-size: 26rpx;
  473. font-weight: 500;
  474. color: #222222;
  475. }
  476. .item-good-num {
  477. position: absolute;
  478. right: 0;
  479. top: 0;
  480. }
  481. .choose_price {
  482. font-size: #{28rpx};
  483. margin-top: #{20rpx};
  484. }
  485. .price {
  486. .ought_price{
  487. font-size: 20rpx;
  488. font-weight: 500;
  489. color: #999999;
  490. margin-right: 32rpx;
  491. }
  492. .paid_price{
  493. font-size: 22rpx;
  494. font-weight: 500;
  495. color: #F93F3F;
  496. text{
  497. font-weight: 600;
  498. }
  499. }
  500. }
  501. .item-good-attr {
  502. margin-top: #{10rpx};
  503. display: inline-block;
  504. position: relative;
  505. width: 110rpx;
  506. padding-right: 20rpx;
  507. height: 30rpx;
  508. background: #EFDDC4;
  509. border: 1px solid #A18353;
  510. border-radius: 4rpx;
  511. overflow: hidden;
  512. .item-good-attr-text {
  513. line-height: #{30rpx};
  514. max-height: #{62rpx};
  515. font-size: 20rpx;
  516. font-weight: 500;
  517. color: #A6824F;
  518. }
  519. .item-good-attr-arrow {
  520. position: absolute;
  521. right: #{8rpx};
  522. top: 50%;
  523. margin-top: #{-6rpx};
  524. height: #{15.1rpx};
  525. width: #{9.9rpx};
  526. }
  527. }
  528. }
  529. }
  530. .item-goods:last-of-type {
  531. border-bottom: 0
  532. }
  533. }
  534. }
  535. </style>