app-list.vue 22 KB

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