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