You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
7.9 KiB

1 week ago
  1. <template>
  2. <view class="augmented">
  3. <view class="product-container">
  4. <view>
  5. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/details/pic_augmented.png" alt=""
  6. style="width:100%;margin-bottom: 10px;" mode="widthFix">
  7. </view>
  8. <uni-collapse v-for="(item,i) in products" class="product" :key="i">
  9. <uni-collapse-item :title="item.itemName" :open="item.isOpen">
  10. <view v-for="(subItem,j) in item.subItem" class="product-content" :key="subItem.id">
  11. <radio :checked="subItem.isSelected" @click="changeSelect(i,j)"
  12. style="transform:scale(0.7);margin-right: 5px;" color="#FFB13F" />
  13. <img class="product-img" style="min-width: 98px; max-width: 98px; height:98px;"
  14. :src="subItem.pic" alt="">
  15. <view class="product-text">
  16. <view class="product-name">
  17. {{subItem.name}}
  18. </view>
  19. <view class="product-desc">
  20. {{subItem.shortDescription}}
  21. </view>
  22. <view class="product-price-number">
  23. <view class="product-price">
  24. <text style="font-size: 18px;">{{subItem.price}}</text>/
  25. </view>
  26. <uni-number-box v-if="!(subItem.name.indexOf('提前熟悉')>-1)" class="product-number"
  27. background="#fff" @change="e=>changeNumber(e,i,j)" :value="subItem.quantity"
  28. :min="0" :max="999">
  29. </uni-number-box>
  30. </view>
  31. </view>
  32. </view>
  33. </uni-collapse-item>
  34. </uni-collapse>
  35. </view>
  36. <view class="payment">
  37. <view class="total-price">
  38. <text class="total-price-text">应付价格</text>
  39. <text class="total-price-value">{{totalPrice}}</text>
  40. </view>
  41. <button class="payment-btn" @click="goNext">下一步</button>
  42. </view>
  43. <Kefu></Kefu>
  44. </view>
  45. </template>
  46. <script>
  47. import Kefu from '../common/kefu.vue'
  48. import {
  49. getProductList
  50. } from "@/api/system/user"
  51. export default {
  52. data() {
  53. return {
  54. totalPrice: 0,
  55. basePrice: 0,
  56. products: [],
  57. selectProducts: [],
  58. categoryIds: [78, 82, 79, 80, 81],
  59. }
  60. },
  61. components:{
  62. Kefu
  63. },
  64. mounted() {
  65. this.basePrice = this.$globalData.submitData.totalPrice;
  66. this.getTotalPrice()
  67. this.getProductList()
  68. },
  69. methods: {
  70. getProductList() {
  71. getProductList({
  72. "publishStatus": 1,
  73. "categoryIds": this.categoryIds,
  74. "needSku": true
  75. }).then(response => {
  76. if (response && response.content && response.content.length > 0) {
  77. const produtNumberSelect = response.content.map(item => {
  78. Object.assign(item, {
  79. isSelected: false,
  80. quantity: 0
  81. })
  82. })
  83. // const groupByCategory = response.content.groupBy(product => {
  84. // return product.categoryId;
  85. // });
  86. const groupedAndSortedRes = response.content.reduce((result, obj) => {
  87. const categoryId = obj.categoryId;
  88. // 检查结果中是否已存在该 categoryId 的分组
  89. const existingGroup = result.find(group => group.key === categoryId);
  90. if (existingGroup) {
  91. // 如果已存在分组,则将当前对象添加到该分组的数组中
  92. existingGroup.values.push(obj);
  93. } else {
  94. // 如果不存在分组,则创建一个新的分组并添加到结果中
  95. result.push({
  96. key: categoryId,
  97. values: [obj]
  98. });
  99. }
  100. return result;
  101. }, [])
  102. .sort((a, b) => {
  103. const indexA = this.categoryIds.indexOf(a.key);
  104. const indexB = this.categoryIds.indexOf(b.key);
  105. return indexA - indexB;
  106. });
  107. this.products = []
  108. for (let category in groupedAndSortedRes) {
  109. let productCategoryName = groupedAndSortedRes[category].values[0].productCategoryName
  110. let productObj = {
  111. id: category,
  112. isOpen: true,
  113. itemName: productCategoryName,
  114. subItem: groupedAndSortedRes[category].values
  115. }
  116. this.products.push(productObj)
  117. }
  118. console.log(this.products);
  119. }
  120. })
  121. },
  122. changeSelect(i, j) {
  123. const outerObj = this.products[i];
  124. const innerObj = outerObj.subItem[j];
  125. innerObj.isSelected = !innerObj.isSelected;
  126. if(innerObj.isSelected){
  127. innerObj.quantity = 1;
  128. }else{
  129. innerObj.quantity = 0;
  130. }
  131. this.getTotalPrice();
  132. console.log(this.products);
  133. },
  134. changeNumber(e, i, j) {
  135. const outerObj = this.products[i];
  136. const innerObj = outerObj.subItem[j];
  137. if(e>0){
  138. innerObj.isSelected=true
  139. } else {
  140. innerObj.isSelected=false
  141. }
  142. innerObj.quantity = e;
  143. this.getTotalPrice();
  144. console.log(this.products);
  145. },
  146. getTotalPrice() {
  147. let currentPrice = 0
  148. let tempSelectProducts = []
  149. for (let i = 0; i < this.products.length; i++) {
  150. for (let j = 0; j < this.products[i].subItem.length; j++) {
  151. if (this.products[i].subItem[j].isSelected) {
  152. tempSelectProducts.push(this.products[i].subItem[j])
  153. currentPrice += this.products[i].subItem[j].quantity * this.products[i].subItem[j].price;
  154. }
  155. }
  156. }
  157. this.selectProducts = tempSelectProducts;
  158. this.totalPrice = currentPrice + this.basePrice;
  159. },
  160. goNext() {
  161. this.$globalData.submitData.totalPrice = this.totalPrice;
  162. this.setItemPrices()
  163. uni.navigateTo({
  164. url: '/pages/details/confirm'
  165. });
  166. },
  167. setItemPrices() {
  168. let itemPrices = [];
  169. let productSkus = [];
  170. for (let i = 0; i < this.selectProducts.length; i++) {
  171. if (this.selectProducts[i].quantity > 0) {
  172. let itemPrice = {
  173. itemType: this.selectProducts[i].productCategoryName + '-' + this.selectProducts[i].name,
  174. price: this.selectProducts[i].price,
  175. quantity: this.selectProducts[i].quantity,
  176. unit: this.selectProducts[i].unit
  177. }
  178. itemPrices.push(itemPrice)
  179. let productSku = {
  180. "skuId": this.selectProducts[i].skus[0].id,
  181. "quantity": this.selectProducts[i].quantity
  182. }
  183. productSkus.push(productSku)
  184. }
  185. }
  186. this.$globalData.itemPrices = itemPrices;
  187. this.$globalData.augmentedSku = [...productSkus];
  188. },
  189. }
  190. }
  191. </script>
  192. <style lang="scss">
  193. .product-container {
  194. padding: 10px;
  195. background-color: #F5F5F7;
  196. .product {
  197. border-radius: 8px;
  198. background-color: #ffffff;
  199. .product-content {
  200. padding: 14px 10px;
  201. display: flex;
  202. align-items: center;
  203. .product-img {
  204. width: 98px;
  205. height: 98px;
  206. border-radius: 4px;
  207. }
  208. .product-text {
  209. padding: 0 5px;
  210. display: flex;
  211. flex-wrap: wrap;
  212. align-content: space-between;
  213. .product-name {
  214. font-size: 16px;
  215. color: #333;
  216. line-height: 16px;
  217. margin-left: 5px;
  218. }
  219. .product-desc {
  220. color: #A94F20;
  221. font-size: 11px;
  222. line-height: 14px;
  223. display: flex;
  224. align-items: center;
  225. background-color: #FFFCF2;
  226. padding: 5px;
  227. margin: 5px 0;
  228. width: 100%;
  229. min-height: 48px;
  230. }
  231. .product-price-number {
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. width: 100%;
  236. .product-price {
  237. color: #FF530A;
  238. font-size: 14px;
  239. line-height: 16px;
  240. }
  241. .product-number {
  242. border: 1px solid #FFE8C6;
  243. border-radius: 4px;
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. .augmented {
  251. position: relative;
  252. height: 100%;
  253. padding-bottom: 58px;
  254. .payment {
  255. height: 58px;
  256. position: fixed;
  257. bottom: 0;
  258. width: 100%;
  259. margin-top: 10px;
  260. padding: 10px 20px;
  261. background-color: #ffffff;
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. z-index: 100;
  266. .total-price-text {
  267. color: #333;
  268. font-size: 16px;
  269. font-weight: blob;
  270. line-height: 16px;
  271. }
  272. .total-price-value {
  273. color: #FF530A;
  274. font-size: 22px;
  275. font-weight: blob;
  276. line-height: 16px;
  277. }
  278. .payment-btn {
  279. width: 140px;
  280. height: 38px;
  281. border-radius: 6px;
  282. background: #FFB13F;
  283. color: #fff;
  284. font-size: 16px;
  285. margin: 0;
  286. display: flex;
  287. align-items: center;
  288. justify-content: center;
  289. }
  290. }
  291. }
  292. </style>