index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <up-popup :show="showPopup" :closeOnClickOverlay="true" @close="close" closeable>
  3. <view
  4. class="product-window"
  5. :class="(iSbnt ? 'join' : '') + ' ' + (iScart ? 'joinCart' : '')"
  6. >
  7. <view class="popup-title">请选择规格</view>
  8. <view class="textpic acea-row">
  9. <view class="pictrue">
  10. <image :src="attr.productSelect.image"></image>
  11. </view>
  12. <view class="text">
  13. <!-- <view class="line1">-->
  14. <!-- {{ attr.productSelect.storeName }}-->
  15. <!-- </view>-->
  16. <view class="money font-color">
  17. ¥<text class="num">{{ calcNumPrice }}</text>
  18. </view>
  19. <view class="font-color" >
  20. <text class="stock"
  21. >工费: {{ attr.productSelect.price || 0 }}元/g</text
  22. >
  23. <text class="stock"
  24. >附加费: {{ attr.productSelect.additionalAmount || "0" }}元</text
  25. >
  26. </view>
  27. <view class="font-color" >
  28. <view class="carnum acea-row row-left">
  29. <view
  30. class="item reduce"
  31. :class="attr.productSelect.cart_num <= 1 ? 'on' : ''"
  32. @click="CartNumDes"
  33. >
  34. -
  35. </view>
  36. <view class="item num">
  37. <input
  38. type="number"
  39. v-model="attr.productSelect.cart_num"
  40. data-name="productSelect.cart_num"
  41. @input="bindCode(attr.productSelect.cart_num)"
  42. />
  43. </view>
  44. <view
  45. v-if="iSplus"
  46. class="item plus"
  47. :class="
  48. attr.productSelect.cart_num >= attr.productSelect.stock
  49. ? 'on'
  50. : ''
  51. "
  52. @click="CartNumAdd"
  53. >
  54. +
  55. </view>
  56. <view
  57. v-else
  58. class="item plus"
  59. :class="
  60. attr.productSelect.cart_num >= attr.productSelect.quota ||
  61. attr.productSelect.cart_num >= attr.productSelect.stock ||
  62. attr.productSelect.cart_num >= attr.productSelect.num
  63. ? 'on'
  64. : ''
  65. "
  66. @click="CartNumAdd"
  67. >+</view
  68. >
  69. </view>
  70. <text class="stock font333" v-if="isShow"
  71. >库存: {{ attr.productSelect.stock }}</text
  72. >
  73. <text class="stock font333" v-if="limitNum"
  74. >限量: {{ attr.productSelect.quota }}</text
  75. >
  76. </view>
  77. </view>
  78. <view class="iconfont icon-guanbi" @click="close"></view>
  79. </view>
  80. <view class="rollTop">
  81. <view class="productWinList">
  82. <view
  83. class="item"
  84. v-for="(item, indexw) in attr.productAttr"
  85. :key="indexw"
  86. >
  87. <view class="title">{{ item.attrName }}</view>
  88. <view class="listn acea-row row-middle">
  89. <view
  90. class="itemn"
  91. :class="item.index === itemn ? 'on' : ''"
  92. v-for="(itemn, indexn) in item.attrValues"
  93. @click="tapAttr(indexw, indexn)"
  94. :key="indexn"
  95. >
  96. {{ itemn }}
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. <!-- <view class="cart acea-row row-between-wrapper">-->
  102. <!-- <view class="title">数量</view>-->
  103. <!-- <view class="carnum acea-row row-left">-->
  104. <!-- <view-->
  105. <!-- class="item reduce"-->
  106. <!-- :class="attr.productSelect.cart_num <= 1 ? 'on' : ''"-->
  107. <!-- @click="CartNumDes"-->
  108. <!-- >-->
  109. <!-- - -->
  110. <!-- </view>-->
  111. <!-- <view class="item num">-->
  112. <!-- <input-->
  113. <!-- type="number"-->
  114. <!-- v-model="attr.productSelect.cart_num"-->
  115. <!-- data-name="productSelect.cart_num"-->
  116. <!-- @input="bindCode(attr.productSelect.cart_num)"-->
  117. <!-- />-->
  118. <!-- </view>-->
  119. <!-- <view-->
  120. <!-- v-if="iSplus"-->
  121. <!-- class="item plus"-->
  122. <!-- :class="-->
  123. <!-- attr.productSelect.cart_num >= attr.productSelect.stock-->
  124. <!-- ? 'on'-->
  125. <!-- : ''-->
  126. <!-- "-->
  127. <!-- @click="CartNumAdd"-->
  128. <!-- >-->
  129. <!-- +-->
  130. <!-- </view>-->
  131. <!-- <view-->
  132. <!-- v-else-->
  133. <!-- class="item plus"-->
  134. <!-- :class="-->
  135. <!-- attr.productSelect.cart_num >= attr.productSelect.quota ||-->
  136. <!-- attr.productSelect.cart_num >= attr.productSelect.stock ||-->
  137. <!-- attr.productSelect.cart_num >= attr.productSelect.num-->
  138. <!-- ? 'on'-->
  139. <!-- : ''-->
  140. <!-- "-->
  141. <!-- @click="CartNumAdd"-->
  142. <!-- >+</view-->
  143. <!-- >-->
  144. <!-- </view>-->
  145. <!-- </view>-->
  146. </view>
  147. <view class="footer-box">
  148. <button
  149. v-if="attr.productSelect.stock > 0"
  150. class="confirm-btn"
  151. @click="submit"
  152. type="primary"
  153. >确定</button>
  154. <button
  155. v-else
  156. class="confirm-btn"
  157. @click="submit"
  158. type="primary"
  159. >已售罄</button>
  160. </view>
  161. </view>
  162. </up-popup>
  163. </template>
  164. <script setup>
  165. import { computed,watch } from "vue";
  166. const props = defineProps({
  167. attr: {
  168. type: Object,
  169. default: () => ({}),
  170. },
  171. showPopup: {
  172. type: Boolean,
  173. default: false,
  174. },
  175. limitNum: {
  176. type: Number,
  177. default: 0,
  178. },
  179. isShow: {
  180. type: Number,
  181. default: 0,
  182. },
  183. iSbnt: {
  184. type: Number,
  185. default: 0,
  186. },
  187. iSplus: {
  188. type: Number,
  189. default: 0,
  190. },
  191. iScart: {
  192. type: Number,
  193. default: 0,
  194. },
  195. });
  196. const emit = defineEmits([
  197. "goCat",
  198. "iptCartNum",
  199. "myevent",
  200. "ChangeCartNum",
  201. "attrVal",
  202. "ChangeAttr",
  203. "submit",
  204. "closePopup",
  205. "updatePrice"
  206. ]);
  207. const calcNumPrice = computed(() => {
  208. // 检查数据是否存在
  209. if (!props.attr?.productSelect) {
  210. return "0.00";
  211. }
  212. const { price, cart_num, additionalAmount, weight } =
  213. props.attr.productSelect;
  214. // 计算总价并保留两位小数
  215. const total =
  216. (Number(price) * Number(weight) + Number(additionalAmount || 0)) *
  217. Number(cart_num);
  218. return total.toFixed(2);
  219. });
  220. // 监听 calcNumPrice 变化并传递给父组件
  221. watch(calcNumPrice, (newPrice) => {
  222. emit("updatePrice", newPrice);
  223. }, { immediate: true });
  224. function goCat() {
  225. emit("goCat");
  226. }
  227. function bindCode() {
  228. emit("iptCartNum", props.attr.productSelect.cart_num);
  229. }
  230. function close() {
  231. emit("closePopup");
  232. }
  233. function submit() {
  234. emit("submit");
  235. }
  236. function CartNumDes() {
  237. emit("ChangeCartNum", false);
  238. }
  239. function CartNumAdd() {
  240. emit("ChangeCartNum", true);
  241. }
  242. function tapAttr(indexw, indexn) {
  243. emit("attrVal", { indexw, indexn });
  244. // 直接修改 props 不推荐,建议父组件传递响应式对象
  245. if (props.attr.productAttr && props.attr.productAttr[indexw]) {
  246. props.attr.productAttr[indexw].index =
  247. props.attr.productAttr[indexw].attrValues[indexn];
  248. }
  249. const value = getCheckedValue().join(",");
  250. emit("ChangeAttr", value);
  251. }
  252. function getCheckedValue() {
  253. const productAttr = props.attr.productAttr || [];
  254. const value = [];
  255. for (let i = 0; i < productAttr.length; i++) {
  256. for (let j = 0; j < productAttr[i].attrValues.length; j++) {
  257. if (productAttr[i].index === productAttr[i].attrValues[j]) {
  258. value.push(productAttr[i].attrValues[j]);
  259. }
  260. }
  261. }
  262. return value;
  263. }
  264. </script>
  265. <style scoped lang="scss">
  266. .product-window {
  267. width: 100%;
  268. background-color: #fff;
  269. border-radius: 16rpx 16rpx 0 0;
  270. padding-bottom: 40rpx;
  271. &.join,
  272. &.joinCart {
  273. padding-bottom: 30rpx;
  274. }
  275. &.joinCart {
  276. z-index: 999;
  277. }
  278. .textpic {
  279. padding: 0 30rpx 0 30rpx;
  280. margin-top: 29rpx;
  281. position: relative;
  282. align-items: center;
  283. .pictrue {
  284. width: 150rpx;
  285. height: 150rpx;
  286. image {
  287. width: 100%;
  288. height: 100%;
  289. border-radius: 10rpx;
  290. }
  291. }
  292. .text {
  293. //width: 430rpx;
  294. width: 70%;
  295. font-size: 32rpx;
  296. color: #333333;
  297. padding-left: 30rpx;
  298. .money {
  299. font-size: 24rpx;
  300. //margin-top: 40rpx;
  301. }
  302. .num {
  303. font-size: 36rpx;
  304. }
  305. .stock {
  306. font-size: 24rpx;
  307. color: #666;
  308. margin-left: 18rpx;
  309. }
  310. }
  311. .iconfont {
  312. position: absolute;
  313. right: 30rpx;
  314. top: -5rpx;
  315. font-size: 35rpx;
  316. color: #8a8a8a;
  317. }
  318. }
  319. .rollTop {
  320. max-height: 500rpx;
  321. overflow: auto;
  322. margin-top: 36rpx;
  323. }
  324. .footer-box {
  325. padding: 0 30rpx;
  326. margin: 30rpx 0 0 0;
  327. .confirm-btn {
  328. height: 88rpx;
  329. line-height: 88rpx;
  330. color: #333;
  331. border-radius: 16rpx;
  332. background-color: $header-color;
  333. border-color: $header-color;
  334. }
  335. }
  336. .productWinList {
  337. .item {
  338. & + .item {
  339. margin-top: 36rpx;
  340. }
  341. .title {
  342. font-size: 28rpx;
  343. color: #333;
  344. padding: 0 30rpx;
  345. }
  346. .listn {
  347. padding: 0 30rpx 0 16rpx;
  348. .itemn {
  349. height: 60rpx;
  350. border: 1px solid #f2f2f2;
  351. font-size: 26rpx;
  352. color: #282828;
  353. padding: 7rpx 33rpx;
  354. border-radius: 10rpx;
  355. margin: 20rpx 0 0 14rpx;
  356. background-color: #f2f2f2;
  357. &.on {
  358. color: $theme-color;
  359. background: rgba(248, 192, 8, 0.10);
  360. border-color: $border-color;
  361. }
  362. &.limit {
  363. color: #999;
  364. text-decoration: line-through;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. .cart {
  371. margin-top: 36rpx;
  372. padding: 0 30rpx;
  373. .title {
  374. font-size: 30rpx;
  375. color: #999;
  376. }
  377. }
  378. .carnum {
  379. height: 54rpx;
  380. margin-top: 24rpx;
  381. border: 2rpx solid #DCDFE6;
  382. display: inline-flex;
  383. view {
  384. width: 84rpx;
  385. text-align: center;
  386. height: 100%;
  387. line-height: 54rpx;
  388. color: #282828;
  389. }
  390. .reduce {
  391. width: 58rpx;
  392. border-right: 0;
  393. border-radius: 6rpx 0 0 6rpx;
  394. line-height: 48rpx;
  395. &.on {
  396. color: #8C8C8C;
  397. font-size: 44rpx;
  398. background-color: #DCDFE6;
  399. }
  400. }
  401. .plus {
  402. width: 58rpx;
  403. border-left: 0;
  404. border-radius: 0 6rpx 6rpx 0;
  405. line-height: 46rpx;
  406. &.on {
  407. border-color: #e3e3e3;
  408. color: #8C8C8C;
  409. background-color: #DCDFE6;
  410. }
  411. }
  412. .num {
  413. background: #fff;
  414. color: #333;
  415. font-size: 24rpx;
  416. border-radius: 12rpx;
  417. line-height: 29px;
  418. height: 54rpx;
  419. input {
  420. display: -webkit-inline-box;
  421. }
  422. }
  423. }
  424. .joinBnt {
  425. font-size: 30rpx;
  426. width: 620rpx;
  427. height: 86rpx;
  428. border-radius: 50rpx;
  429. text-align: center;
  430. line-height: 86rpx;
  431. color: #fff;
  432. margin: 21rpx auto 0 auto;
  433. &.on {
  434. background-color: #bbb;
  435. color: #fff;
  436. }
  437. }
  438. }
  439. .popup-title{
  440. height: 100rpx;
  441. line-height: 100rpx;
  442. font-size: 36rpx;
  443. color: #333;
  444. text-align: center;
  445. }
  446. </style>