index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template>
  2. <div class="product">
  3. <!-- <van-nav-bar title="产品" class="van-nav-bar-my-fixed" fixed /> -->
  4. <div class="bgImg">
  5. <!-- <img src="@/assets/images/product/bgImg.png" alt="" />-->
  6. <div class="title">
  7. <p>藏金 · 1745产品</p>
  8. </div>
  9. <div class="tags">
  10. <img src="@/assets/images/product/tags.png" alt="" />
  11. </div>
  12. </div>
  13. <div v-loading="loading">
  14. <div class="product-baozhuang">
  15. <div class="productPack">
  16. <div class="packageBox">
  17. <li @click="handleClick(0)">
  18. <!-- <img :src="currIndex == '0' ? selectActive : select" alt="" /> -->
  19. <div class="box" :class="{'selected':currIndex==0}">
  20. <img src="@/assets/images/product/box.png" alt="" />
  21. <p>藏金·1745-实惠装</p>
  22. <span>可用库存:{{ canStockBag }}</span>
  23. </div>
  24. </li>
  25. <li @click="handleClick(1)">
  26. <div class="box" :class="{'selected':currIndex==1}">
  27. <img src="@/assets/images/product/bag.png" alt="" />
  28. <p>藏金·1745-礼盒装</p>
  29. <span>可用库存:{{ canStockBox }}</span>
  30. </div>
  31. </li>
  32. </div>
  33. <div v-if="ad && ad.id" @click="getaddress" class="item-ad clear">
  34. <p class="item-ad__name">
  35. <span>{{ ad.name }} </span><span class="tel">{{ ad.mobile }}</span>
  36. </p>
  37. <p class="item-ad__address">
  38. <van-icon name="location-o" size="14"/> <span>{{ ad.address }}</span>
  39. </p>
  40. </div>
  41. <div class="kongParents" v-else>
  42. <div @click="getaddress" class="kong clear">
  43. <img src="@/assets/images/product/add.png" alt="" />
  44. <span>添加地址</span>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="product-footer clear">
  49. <div class="fl">
  50. <input-number :numb="num" :max="stock" @backNum="backNum" />
  51. </div>
  52. <div>
  53. <van-button
  54. type="info"
  55. class="fr"
  56. @click="placeOrder"
  57. >确认下单</van-button>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- <div class="product-kucun clear">
  62. <ul>
  63. <li
  64. v-for="(pitem, index) in productList"
  65. :key="pitem + index"
  66. @click="changePitem(index)"
  67. >
  68. <div class="input-radio" :class="{ checked: radioV === pitem.id }">
  69. <div class="radio-box">
  70. <div class="radio-check"></div>
  71. </div>
  72. </div>
  73. <img :src="pitem.img" alt="" />
  74. <div>
  75. <p>{{ pitem.name }}</p>
  76. <p>
  77. 可用库存:{{ pitem.stock }}{{ pitem.unit }}/{{ pitem.weight }}kg
  78. </p>
  79. </div>
  80. </li>
  81. </ul>
  82. </div> -->
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { Dialog } from "vant";
  88. import resToken from "@/mixins/resToken";
  89. import asyncRequest from "@/apis/product/index";
  90. import { getGoodsUnit, getGoodsNum, getAd } from "@/utils/auth";
  91. export default {
  92. mixins: [resToken],
  93. data() {
  94. return {
  95. select: "/static/img/select.bed55bd9.png",
  96. selectActive: "@/assets/images/product/select-active.png",
  97. currIndex: null,
  98. num: 0,
  99. total: 0,
  100. radioV: "",
  101. address: [],
  102. unitist: [],
  103. productList: [],
  104. stock: 0,
  105. ad: null,
  106. canStockBox: "",
  107. canStockBag: "",
  108. isce:''
  109. };
  110. },
  111. mounted() {
  112. this.ad = getAd() ? JSON.parse(getAd()) : {};
  113. this.num = isNaN(getGoodsNum()) ? 0 : parseInt(getGoodsNum());
  114. if (this.ad && this.ad.id) {
  115. this.initData(this.ad.id);
  116. } else {
  117. this.address = [];
  118. }
  119. this.getStock();
  120. },
  121. methods: {
  122. changePitem(index) {
  123. this.radioV = this.productList[index].id;
  124. this.stock = this.productList[index].stock;
  125. if (this.num > this.stock) {
  126. this.num = this.stock;
  127. }
  128. },
  129. async getaddress() {
  130. let numRes = await this.set_user_goodsNum(this.num);
  131. let unitRes = await this.set_user_goodsUnit(this.radioV);
  132. if (numRes && numRes.code === 0 && unitRes && unitRes.code === 0) {
  133. window.vm.$router.push({
  134. path: "/address",
  135. query: {
  136. id: this.ad && this.ad.id ? this.ad.id : "0",
  137. },
  138. });
  139. }
  140. },
  141. async getStock() {
  142. if (!this.loading) {
  143. let res = await asyncRequest.get_stock({});
  144. if (res && res.code == 0) {
  145. let { limit, stock } = res.data;
  146. if (!(limit && limit.length > 0)) {
  147. limit = [];
  148. }
  149. this.canStockBag = res.data.stock;
  150. this.canStockBox = res.data.stock;
  151. this.distributeGoods(limit);
  152. // await this.getUnitist(limit);
  153. this.total = parseInt(stock + "");
  154. } else if (res && res.code >= 100 && res.code <= 104) {
  155. await this.logout();
  156. } else {
  157. this.total = 0;
  158. }
  159. }
  160. },
  161. // async getUnitist(list) {
  162. // if (!this.loading) {
  163. // let res = await asyncRequest.unitist({});
  164. // if (res && res.code == 0 && res.data && res.data.list) {
  165. // this.unitist = res.data.list;
  166. // this.distributeGoods();
  167. // } else if (res && res.code >= 100 && res.code <= 104) {
  168. // await this.logout();
  169. // } else {
  170. // this.unitist = [];
  171. // }
  172. // }
  173. // },
  174. distributeGoods(list) {
  175. if (list.length > 0) {
  176. this.productList = [];
  177. list.forEach((v1) => {
  178. let item = {
  179. id: v1.id,
  180. name: v1.id === "1" ? "藏金1745普通装" : "藏金1745礼盒",
  181. img: require(`@/assets/images/product/unit${v1.id}.png`),
  182. stock: parseInt(v1.limit_num + ""),
  183. weight: v1.weight,
  184. unit: v1.name,
  185. };
  186. this.productList.push(item);
  187. });
  188. let index = this.productList.findIndex((v1) => {
  189. return v1.id == getGoodsUnit() + "";
  190. });
  191. this.changePitem(index === -1 ? 0 : index);
  192. }
  193. },
  194. async initData(id) {
  195. const res = await asyncRequest.addrdetail({ id: id });
  196. if (res && res.code === 0) {
  197. } else if (res && res.code >= 100 && res.code <= 104) {
  198. await this.logout();
  199. } else {
  200. this.$store.dispatch("user/set_ad", {}).then((res) => {});
  201. }
  202. },
  203. backNum(e) {
  204. console.log(e, "eeee");
  205. this.num = e;
  206. console.log(this.num);
  207. },
  208. async placeOrder() {
  209. if (!this.loading) {
  210. if (this.ad && this.ad.id) {
  211. this.num = this.num;
  212. if (isNaN(this.num)) {
  213. this.num = 0;
  214. }
  215. if (this.stock === 0) {
  216. this.show_title("当前商品库存为0,无法购买!");
  217. return;
  218. }
  219. if (this.num === 0) {
  220. this.show_title("购买数量不能为0!");
  221. return;
  222. }
  223. Dialog.confirm({
  224. title: "确认下单?",
  225. })
  226. .then(async () => {
  227. await this.placeHttpOrder();
  228. })
  229. .catch(() => {});
  230. } else {
  231. this.show_title("请选择收货地址!");
  232. }
  233. }
  234. },
  235. async placeHttpOrder() {
  236. this.loading = true;
  237. let model = {
  238. addrid: this.ad.id,
  239. num: this.num + "",
  240. unit_id: this.radioV,
  241. };
  242. let res = await asyncRequest.add(model);
  243. this.loading = false;
  244. if (res && res.code == 0) {
  245. let setRes = await this.set_user_goodsNum(0);
  246. if (setRes && setRes.code === 0) {
  247. window.vm.$router.push({
  248. path: "/orderRes",
  249. query: {
  250. id: res.data.orderid,
  251. },
  252. });
  253. }
  254. } else if (res && res.code >= 100 && res.code <= 104) {
  255. await this.logout();
  256. } else {
  257. this.show_title(res.msg);
  258. }
  259. },
  260. async set_user_goodsNum(num) {
  261. return new Promise((resolve, reject) => {
  262. this.$store.dispatch("user/set_goodsNum", num).then((res) => {
  263. resolve(res);
  264. });
  265. });
  266. },
  267. async set_user_goodsUnit(unit) {
  268. return new Promise((resolve, reject) => {
  269. this.$store.dispatch("user/set_goodsUnit", unit).then((res) => {
  270. resolve(res);
  271. });
  272. });
  273. },
  274. handleClick(e) {
  275. this.currIndex = e;
  276. },
  277. },
  278. };
  279. </script>
  280. <style lang="scss" scoped>
  281. .product {
  282. background: #FCFCF0!important;
  283. .bgImg {
  284. width: 100%;
  285. height: 50%;
  286. background: url("../../assets/images/product/bgImg.png") no-repeat center;
  287. background-size:100% 100%;
  288. position: relative;
  289. img {
  290. width: 100%;
  291. }
  292. .title {
  293. width: 50%;
  294. height: 100%;
  295. display: inline-block;
  296. font-size: 1.4em;
  297. font-family: Source Han Sans CN;
  298. font-weight: 500;
  299. color: #daac70;
  300. position: relative;
  301. p{
  302. position: absolute;
  303. top:50%;
  304. left:5%;
  305. }
  306. }
  307. .tags {
  308. width: 50%;
  309. height:100%;
  310. display: inline-block;
  311. position: relative;
  312. img {
  313. position: absolute;
  314. width: 50px;
  315. right: 10%;
  316. top: 10%;
  317. }
  318. }
  319. }
  320. .product-baozhuang {
  321. width:100%;
  322. position: absolute;
  323. top:40%;
  324. left:0;
  325. }
  326. .productPack {
  327. width: 90%;
  328. z-index: 100;
  329. margin: 0 auto;
  330. position: relative;
  331. margin-bottom: 100px;
  332. .packageBox{
  333. display: flex;
  334. justify-content: space-between;
  335. }
  336. li {
  337. list-style: none;
  338. width:calc(50% - 10px);
  339. display: inline-block;
  340. padding: 5px;
  341. .box{
  342. background: #E6E6DC;
  343. border-radius: 13px;
  344. padding: 5px;
  345. img {
  346. width: 100%;
  347. }
  348. p {
  349. margin: 10px 0 5px 10px;
  350. font-size:1.2em;
  351. font-family: Source Han Sans CN;
  352. font-weight: 600;
  353. color: #1A1A1A;
  354. }
  355. span {
  356. margin-left: 10px;
  357. font-size: 1em;
  358. font-family: Source Han Sans CN;
  359. font-weight: 400;
  360. color: #4D4D4D;
  361. }
  362. }
  363. .selected{
  364. background: linear-gradient(0deg, #A57D4B, #EFC180, #EFC180);
  365. }
  366. }
  367. }
  368. .product-kucun {
  369. width: 100%;
  370. padding: 0 0 30px 0;
  371. ul {
  372. float: left;
  373. width: 100%;
  374. li {
  375. float: left;
  376. width: 100%;
  377. padding: 24px 0 0 0;
  378. &:hover {
  379. cursor: pointer;
  380. }
  381. .input-radio {
  382. height: 80px;
  383. width: 15px;
  384. padding: 0;
  385. float: left;
  386. line-height: 80px;
  387. margin: 0 8px 0 0;
  388. padding: 0 1px;
  389. .radio-box {
  390. width: 15px;
  391. height: 15px;
  392. border-radius: 50%;
  393. border: 1px solid #c0c0c0;
  394. padding: 2px;
  395. margin: 33px 0 0 0;
  396. box-sizing: border-box;
  397. .radio-check {
  398. width: 9px;
  399. height: 9px;
  400. background: transparent;
  401. box-sizing: border-box;
  402. border-radius: 50%;
  403. }
  404. }
  405. &.checked {
  406. .radio-box {
  407. border: 1px solid #f4d022;
  408. .radio-check {
  409. // background: #f4d022;
  410. background: linear-gradient(0deg, #f2c482, #a07947);
  411. }
  412. }
  413. }
  414. }
  415. input {
  416. float: left;
  417. height: 80px;
  418. width: 17px;
  419. padding: 0;
  420. margin: 0 8px 0 0;
  421. }
  422. img {
  423. float: left;
  424. height: 84px;
  425. width: 130px;
  426. box-sizing: border-box;
  427. padding: 0 5px;
  428. }
  429. p {
  430. float: left;
  431. width: calc(100% - 155px);
  432. margin: 0;
  433. box-sizing: border-box;
  434. padding: 0 0 0 10px;
  435. &:first-child {
  436. margin-top: 8px;
  437. font-size: 17px;
  438. color: #333;
  439. height: 38px;
  440. line-height: 38px;
  441. font-weight: bolder;
  442. }
  443. &:last-child {
  444. height: 28px;
  445. line-height: 28px;
  446. font-size: 12px;
  447. color: #666;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. .item-ad {
  454. background-color: #e6e6dc;
  455. color: #999999;
  456. padding: 10px 16px;
  457. box-sizing: border-box;
  458. width: 100%;
  459. margin-top: 30px;
  460. opacity: 1;
  461. border-radius: 8px;
  462. .item-ad__name {
  463. font-size: 1.2em;
  464. font-family: Source Han Sans CN;
  465. font-weight: 600;
  466. color: #111111;
  467. margin: 5px 0;
  468. }
  469. .item-ad__address {
  470. text-align: justify;
  471. font-size: 1.2em;
  472. font-family: Source Han Sans CN;
  473. color:#999999;
  474. margin: 5px 0;
  475. span{
  476. margin-left: 5px;
  477. }
  478. }
  479. }
  480. .kongParents {
  481. width: calc(100vw - 30px);
  482. // top: 199.5px;
  483. margin-top: 50px;
  484. display: flex;
  485. justify-content: center;
  486. align-items: center;
  487. }
  488. .kong {
  489. top: 199.5px;
  490. left: 76px;
  491. height: 34px;
  492. line-height: 40px;
  493. color: #333;
  494. text-align: center;
  495. width: 180px;
  496. border-radius: 17px;
  497. background: linear-gradient(0deg, #f2c482, #a07947);
  498. img {
  499. width: 13px;
  500. height: 13px;
  501. vertical-align: -2px;
  502. }
  503. span {
  504. padding: 0 0 0 4px;
  505. width: 47.5px;
  506. height: 11px;
  507. font-size: 12px;
  508. font-family: Source Han Sans CN;
  509. font-weight: 400;
  510. color: #111111;
  511. line-height: 3px;
  512. }
  513. }
  514. .product-footer {
  515. position: fixed;
  516. width: 100%;
  517. background: #E6E6DC;
  518. left: 0;
  519. bottom: 50px;
  520. z-index: 3;
  521. .fl {
  522. font-size: 1.4em;
  523. padding: 10px;
  524. font-family: DIN;
  525. font-weight: 500;
  526. color: #111111;
  527. }
  528. button {
  529. background: #E6E6DC;
  530. color:#292929;
  531. padding: 0;
  532. border: 0px;
  533. line-height: 56px;
  534. height: 56px;
  535. width: 40vw;
  536. border-left: 2px solid #FCFCF0;
  537. //background: linear-gradient(0deg, #9e7746, #f4c583);
  538. //color: #333;
  539. //border: 1px solid #9e7746;
  540. //border-radius: 10px;
  541. //overflow: hidden;
  542. //margin: 0 16px 0 0;
  543. //list-style: none;
  544. }
  545. }
  546. //@media screen and (max-width: 320px) {
  547. // .item-ad {
  548. // width: 90vw;
  549. // top: 160px;
  550. // font-size: 12px;
  551. // height: 70px;
  552. // p {
  553. // margin: 0;
  554. // }
  555. // }
  556. // .kongParents {
  557. // top: 174px;
  558. // }
  559. // // .product-baozhuang {
  560. // // margin: -15vh 0 0 0;
  561. // // }
  562. // .productPack {
  563. // .box {
  564. // p {
  565. // margin: 8.5px 0 7px 6px;
  566. // }
  567. // span {
  568. // margin: 12.5px 0 0px 6px;
  569. // }
  570. // }
  571. // .bag {
  572. // p {
  573. // margin: 8.5px 0 7px 10px;
  574. // }
  575. // }
  576. // }
  577. //}
  578. //@media screen and (max-width: 375px) and (max-width: 414px) {
  579. // .product-baozhuang {
  580. // margin: -80px 0 0 0;
  581. // }
  582. //}
  583. //@media screen and (min-width: 414px) {
  584. // .product-baozhuang {
  585. // margin: -80px 0 0 0;
  586. // }
  587. //}
  588. }
  589. </style>