index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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" style="display: flex;align-items: center;margin-top: 24rpx;" >
  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. console.log("calcNumberPrice=======>",{ price, cart_num, additionalAmount, weight })
  215. // 计算总价并保留两位小数
  216. const total =
  217. (Number(price) * Number(weight) + Number(additionalAmount || 0)) *
  218. Number(cart_num);
  219. return total.toFixed(2);
  220. });
  221. // // 监听 calcNumPrice 变化并传递给父组件
  222. // watch(calcNumPrice, (newPrice) => {
  223. // emit("updatePrice", newPrice);
  224. // }, { immediate: true });
  225. // function goCat() {
  226. // emit("goCat");
  227. // }
  228. function bindCode() {
  229. emit("iptCartNum", props.attr.productSelect.cart_num);
  230. }
  231. function close() {
  232. emit("closePopup");
  233. }
  234. function submit() {
  235. emit("updatePrice", calcNumPrice);
  236. emit("submit");
  237. }
  238. function CartNumDes() {
  239. emit("ChangeCartNum", false);
  240. }
  241. function CartNumAdd() {
  242. emit("ChangeCartNum", true);
  243. }
  244. function tapAttr(indexw, indexn) {
  245. emit("attrVal", { indexw, indexn });
  246. // 直接修改 props 不推荐,建议父组件传递响应式对象
  247. if (props.attr.productAttr && props.attr.productAttr[indexw]) {
  248. props.attr.productAttr[indexw].index =
  249. props.attr.productAttr[indexw].attrValues[indexn];
  250. }
  251. const value = getCheckedValue().join(",");
  252. emit("ChangeAttr", value);
  253. }
  254. function getCheckedValue() {
  255. const productAttr = props.attr.productAttr || [];
  256. const value = [];
  257. for (let i = 0; i < productAttr.length; i++) {
  258. for (let j = 0; j < productAttr[i].attrValues.length; j++) {
  259. if (productAttr[i].index === productAttr[i].attrValues[j]) {
  260. value.push(productAttr[i].attrValues[j]);
  261. }
  262. }
  263. }
  264. return value;
  265. }
  266. </script>
  267. <style scoped lang="scss">
  268. .product-window {
  269. width: 100%;
  270. background-color: #fff;
  271. border-radius: 16rpx 16rpx 0 0;
  272. padding-bottom: 40rpx;
  273. &.join,
  274. &.joinCart {
  275. padding-bottom: 30rpx;
  276. }
  277. &.joinCart {
  278. z-index: 999;
  279. }
  280. .textpic {
  281. padding: 0 30rpx 0 30rpx;
  282. margin-top: 29rpx;
  283. position: relative;
  284. align-items: center;
  285. .pictrue {
  286. width: 150rpx;
  287. height: 150rpx;
  288. image {
  289. width: 100%;
  290. height: 100%;
  291. border-radius: 10rpx;
  292. }
  293. }
  294. .text {
  295. //width: 430rpx;
  296. width: 70%;
  297. font-size: 32rpx;
  298. color: #333333;
  299. padding-left: 30rpx;
  300. .money {
  301. font-size: 24rpx;
  302. //margin-top: 40rpx;
  303. }
  304. .num {
  305. font-size: 36rpx;
  306. }
  307. .stock {
  308. font-size: 24rpx;
  309. color: #666;
  310. margin-left: 18rpx;
  311. }
  312. }
  313. .iconfont {
  314. position: absolute;
  315. right: 30rpx;
  316. top: -5rpx;
  317. font-size: 35rpx;
  318. color: #8a8a8a;
  319. }
  320. }
  321. .rollTop {
  322. max-height: 500rpx;
  323. overflow: auto;
  324. margin-top: 36rpx;
  325. }
  326. .footer-box {
  327. padding: 0 30rpx;
  328. margin: 30rpx 0 0 0;
  329. .confirm-btn {
  330. height: 88rpx;
  331. line-height: 88rpx;
  332. color: #333;
  333. border-radius: 16rpx;
  334. background-color: #F8C008;
  335. border-color: #F8C008;
  336. }
  337. }
  338. .productWinList {
  339. .item {
  340. & + .item {
  341. margin-top: 36rpx;
  342. }
  343. .title {
  344. font-size: 28rpx;
  345. color: #333;
  346. padding: 0 30rpx;
  347. }
  348. .listn {
  349. padding: 0 30rpx 0 16rpx;
  350. .itemn {
  351. height: 60rpx;
  352. line-height: 56rpx;
  353. border: 1px solid #f2f2f2;
  354. font-size: 26rpx;
  355. color: #282828;
  356. padding: 0rpx 33rpx;
  357. border-radius: 10rpx;
  358. margin: 20rpx 0 0 14rpx;
  359. background-color: #f2f2f2;
  360. &.on {
  361. color: $theme-color;
  362. background: rgba(248, 192, 8, 0.10);
  363. border-color: $border-color;
  364. }
  365. &.limit {
  366. color: #999;
  367. text-decoration: line-through;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. .cart {
  374. margin-top: 36rpx;
  375. padding: 0 30rpx;
  376. .title {
  377. font-size: 30rpx;
  378. color: #999;
  379. }
  380. }
  381. .carnum {
  382. height: 54rpx;
  383. border: 2rpx solid #DCDFE6;
  384. display: inline-flex;
  385. border-radius: 4rpx;
  386. view {
  387. width: 84rpx;
  388. text-align: center;
  389. height: 100%;
  390. line-height: 54rpx;
  391. color: #282828;
  392. border-left: 2rpx solid #DCDFE6;
  393. border-right: 2rpx solid #DCDFE6;
  394. }
  395. .reduce {
  396. width: 58rpx;
  397. border: 0;
  398. //border-radius: 4rpx 0 0 4rpx;
  399. line-height: 46rpx;
  400. background: #F5F7FA;
  401. &.on {
  402. color: #8C8C8C;
  403. font-size: 44rpx;
  404. background-color: #DCDFE6;
  405. }
  406. }
  407. .plus {
  408. width: 58rpx;
  409. border: 0;
  410. //border-radius: 0 4rpx 4rpx 0;
  411. line-height: 46rpx;
  412. background: #F5F7FA;
  413. &.on {
  414. border-color: #e3e3e3;
  415. color: #8C8C8C;
  416. background-color: #DCDFE6;
  417. }
  418. }
  419. .num {
  420. background: #fff;
  421. color: #333;
  422. font-size: 24rpx;
  423. //border-radius: 12rpx;
  424. line-height: 46rpx;
  425. height: 100%;
  426. input {
  427. display: -webkit-inline-box;
  428. }
  429. }
  430. }
  431. .joinBnt {
  432. font-size: 30rpx;
  433. width: 620rpx;
  434. height: 86rpx;
  435. border-radius: 50rpx;
  436. text-align: center;
  437. line-height: 86rpx;
  438. color: #fff;
  439. margin: 21rpx auto 0 auto;
  440. &.on {
  441. background-color: #bbb;
  442. color: #fff;
  443. }
  444. }
  445. }
  446. .popup-title{
  447. height: 100rpx;
  448. line-height: 100rpx;
  449. font-size: 36rpx;
  450. color: #333;
  451. text-align: center;
  452. }
  453. </style>