123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- <template>
- <div class="product">
- <!-- <van-nav-bar title="产品" class="van-nav-bar-my-fixed" fixed /> -->
- <div class="bgImg">
- <!-- <img src="@/assets/images/product/bgImg.png" alt="" />-->
- <div class="title">
- <p>藏金 · 1745产品</p>
- </div>
- <div class="tags">
- <img src="@/assets/images/product/tags.png" alt="" />
- </div>
- </div>
- <div v-loading="loading">
- <div class="product-baozhuang">
- <div class="productPack">
- <div class="packageBox">
- <li @click="handleClick(0)">
- <!-- <img :src="currIndex == '0' ? selectActive : select" alt="" /> -->
- <div class="box" :class="{'selected':currIndex==0}">
- <img src="@/assets/images/product/box.png" alt="" />
- <p>藏金·1745-实惠装</p>
- <span>可用库存:{{ canStockBag }}</span>
- </div>
- </li>
- <li @click="handleClick(1)">
- <div class="box" :class="{'selected':currIndex==1}">
- <img src="@/assets/images/product/bag.png" alt="" />
- <p>藏金·1745-礼盒装</p>
- <span>可用库存:{{ canStockBox }}</span>
- </div>
- </li>
- </div>
- <div v-if="ad && ad.id" @click="getaddress" class="item-ad clear">
- <p class="item-ad__name">
- <span>{{ ad.name }} </span><span class="tel">{{ ad.mobile }}</span>
- </p>
- <p class="item-ad__address">
- <van-icon name="location-o" size="14"/> <span>{{ ad.address }}</span>
- </p>
- </div>
- <div class="kongParents" v-else>
- <div @click="getaddress" class="kong clear">
- <img src="@/assets/images/product/add.png" alt="" />
- <span>添加地址</span>
- </div>
- </div>
- </div>
- <div class="product-footer clear">
- <div class="fl">
- <input-number :numb="num" :max="stock" @backNum="backNum" />
- </div>
- <div>
- <van-button
- type="info"
- class="fr"
- @click="placeOrder"
- >确认下单</van-button>
- </div>
- </div>
- </div>
- <!-- <div class="product-kucun clear">
- <ul>
- <li
- v-for="(pitem, index) in productList"
- :key="pitem + index"
- @click="changePitem(index)"
- >
- <div class="input-radio" :class="{ checked: radioV === pitem.id }">
- <div class="radio-box">
- <div class="radio-check"></div>
- </div>
- </div>
- <img :src="pitem.img" alt="" />
- <div>
- <p>{{ pitem.name }}</p>
- <p>
- 可用库存:{{ pitem.stock }}{{ pitem.unit }}/{{ pitem.weight }}kg
- </p>
- </div>
- </li>
- </ul>
- </div> -->
- </div>
- </div>
- </template>
- <script>
- import { Dialog } from "vant";
- import resToken from "@/mixins/resToken";
- import asyncRequest from "@/apis/product/index";
- import { getGoodsUnit, getGoodsNum, getAd } from "@/utils/auth";
- export default {
- mixins: [resToken],
- data() {
- return {
- select: "/static/img/select.bed55bd9.png",
- selectActive: "@/assets/images/product/select-active.png",
- currIndex: null,
- num: 0,
- total: 0,
- radioV: "",
- address: [],
- unitist: [],
- productList: [],
- stock: 0,
- ad: null,
- canStockBox: "",
- canStockBag: "",
- isce:''
- };
- },
- mounted() {
- this.ad = getAd() ? JSON.parse(getAd()) : {};
- this.num = isNaN(getGoodsNum()) ? 0 : parseInt(getGoodsNum());
- if (this.ad && this.ad.id) {
- this.initData(this.ad.id);
- } else {
- this.address = [];
- }
- this.getStock();
- },
- methods: {
- changePitem(index) {
- this.radioV = this.productList[index].id;
- this.stock = this.productList[index].stock;
- if (this.num > this.stock) {
- this.num = this.stock;
- }
- },
- async getaddress() {
- let numRes = await this.set_user_goodsNum(this.num);
- let unitRes = await this.set_user_goodsUnit(this.radioV);
- if (numRes && numRes.code === 0 && unitRes && unitRes.code === 0) {
- window.vm.$router.push({
- path: "/address",
- query: {
- id: this.ad && this.ad.id ? this.ad.id : "0",
- },
- });
- }
- },
- async getStock() {
- if (!this.loading) {
- let res = await asyncRequest.get_stock({});
- if (res && res.code == 0) {
- let { limit, stock } = res.data;
- if (!(limit && limit.length > 0)) {
- limit = [];
- }
- this.canStockBag = res.data.stock;
- this.canStockBox = res.data.stock;
- this.distributeGoods(limit);
- // await this.getUnitist(limit);
- this.total = parseInt(stock + "");
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.total = 0;
- }
- }
- },
- // async getUnitist(list) {
- // if (!this.loading) {
- // let res = await asyncRequest.unitist({});
- // if (res && res.code == 0 && res.data && res.data.list) {
- // this.unitist = res.data.list;
- // this.distributeGoods();
- // } else if (res && res.code >= 100 && res.code <= 104) {
- // await this.logout();
- // } else {
- // this.unitist = [];
- // }
- // }
- // },
- distributeGoods(list) {
- if (list.length > 0) {
- this.productList = [];
- list.forEach((v1) => {
- let item = {
- id: v1.id,
- name: v1.id === "1" ? "藏金1745普通装" : "藏金1745礼盒",
- img: require(`@/assets/images/product/unit${v1.id}.png`),
- stock: parseInt(v1.limit_num + ""),
- weight: v1.weight,
- unit: v1.name,
- };
- this.productList.push(item);
- });
- let index = this.productList.findIndex((v1) => {
- return v1.id == getGoodsUnit() + "";
- });
- this.changePitem(index === -1 ? 0 : index);
- }
- },
- async initData(id) {
- const res = await asyncRequest.addrdetail({ id: id });
- if (res && res.code === 0) {
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$store.dispatch("user/set_ad", {}).then((res) => {});
- }
- },
- backNum(e) {
- console.log(e, "eeee");
- this.num = e;
- console.log(this.num);
- },
- async placeOrder() {
- if (!this.loading) {
- if (this.ad && this.ad.id) {
- this.num = this.num;
- if (isNaN(this.num)) {
- this.num = 0;
- }
- if (this.stock === 0) {
- this.show_title("当前商品库存为0,无法购买!");
- return;
- }
- if (this.num === 0) {
- this.show_title("购买数量不能为0!");
- return;
- }
- Dialog.confirm({
- title: "确认下单?",
- })
- .then(async () => {
- await this.placeHttpOrder();
- })
- .catch(() => {});
- } else {
- this.show_title("请选择收货地址!");
- }
- }
- },
- async placeHttpOrder() {
- this.loading = true;
- let model = {
- addrid: this.ad.id,
- num: this.num + "",
- unit_id: this.radioV,
- };
- let res = await asyncRequest.add(model);
- this.loading = false;
- if (res && res.code == 0) {
- let setRes = await this.set_user_goodsNum(0);
- if (setRes && setRes.code === 0) {
- window.vm.$router.push({
- path: "/orderRes",
- query: {
- id: res.data.orderid,
- },
- });
- }
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.show_title(res.msg);
- }
- },
- async set_user_goodsNum(num) {
- return new Promise((resolve, reject) => {
- this.$store.dispatch("user/set_goodsNum", num).then((res) => {
- resolve(res);
- });
- });
- },
- async set_user_goodsUnit(unit) {
- return new Promise((resolve, reject) => {
- this.$store.dispatch("user/set_goodsUnit", unit).then((res) => {
- resolve(res);
- });
- });
- },
- handleClick(e) {
- this.currIndex = e;
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .product {
- background: #FCFCF0!important;
- .bgImg {
- width: 100%;
- height: 50%;
- background: url("../../assets/images/product/bgImg.png") no-repeat center;
- background-size:100% 100%;
- position: relative;
- img {
- width: 100%;
- }
- .title {
- width: 50%;
- height: 100%;
- display: inline-block;
- font-size: 1.4em;
- font-family: Source Han Sans CN;
- font-weight: 500;
- color: #daac70;
- position: relative;
- p{
- position: absolute;
- top:50%;
- left:5%;
- }
- }
- .tags {
- width: 50%;
- height:100%;
- display: inline-block;
- position: relative;
- img {
- position: absolute;
- width: 50px;
- right: 10%;
- top: 10%;
- }
- }
- }
- .product-baozhuang {
- width:100%;
- position: absolute;
- top:40%;
- left:0;
- }
- .productPack {
- width: 90%;
- z-index: 100;
- margin: 0 auto;
- position: relative;
- margin-bottom: 100px;
- .packageBox{
- display: flex;
- justify-content: space-between;
- }
- li {
- list-style: none;
- width:calc(50% - 10px);
- display: inline-block;
- padding: 5px;
- .box{
- background: #E6E6DC;
- border-radius: 13px;
- padding: 5px;
- img {
- width: 100%;
- }
- p {
- margin: 10px 0 5px 10px;
- font-size:1.2em;
- font-family: Source Han Sans CN;
- font-weight: 600;
- color: #1A1A1A;
- }
- span {
- margin-left: 10px;
- font-size: 1em;
- font-family: Source Han Sans CN;
- font-weight: 400;
- color: #4D4D4D;
- }
- }
- .selected{
- background: linear-gradient(0deg, #A57D4B, #EFC180, #EFC180);
- }
- }
- }
- .product-kucun {
- width: 100%;
- padding: 0 0 30px 0;
- ul {
- float: left;
- width: 100%;
- li {
- float: left;
- width: 100%;
- padding: 24px 0 0 0;
- &:hover {
- cursor: pointer;
- }
- .input-radio {
- height: 80px;
- width: 15px;
- padding: 0;
- float: left;
- line-height: 80px;
- margin: 0 8px 0 0;
- padding: 0 1px;
- .radio-box {
- width: 15px;
- height: 15px;
- border-radius: 50%;
- border: 1px solid #c0c0c0;
- padding: 2px;
- margin: 33px 0 0 0;
- box-sizing: border-box;
- .radio-check {
- width: 9px;
- height: 9px;
- background: transparent;
- box-sizing: border-box;
- border-radius: 50%;
- }
- }
- &.checked {
- .radio-box {
- border: 1px solid #f4d022;
- .radio-check {
- // background: #f4d022;
- background: linear-gradient(0deg, #f2c482, #a07947);
- }
- }
- }
- }
- input {
- float: left;
- height: 80px;
- width: 17px;
- padding: 0;
- margin: 0 8px 0 0;
- }
- img {
- float: left;
- height: 84px;
- width: 130px;
- box-sizing: border-box;
- padding: 0 5px;
- }
- p {
- float: left;
- width: calc(100% - 155px);
- margin: 0;
- box-sizing: border-box;
- padding: 0 0 0 10px;
- &:first-child {
- margin-top: 8px;
- font-size: 17px;
- color: #333;
- height: 38px;
- line-height: 38px;
- font-weight: bolder;
- }
- &:last-child {
- height: 28px;
- line-height: 28px;
- font-size: 12px;
- color: #666;
- }
- }
- }
- }
- }
- .item-ad {
- background-color: #e6e6dc;
- color: #999999;
- padding: 10px 16px;
- box-sizing: border-box;
- width: 100%;
- margin-top: 30px;
- opacity: 1;
- border-radius: 8px;
- .item-ad__name {
- font-size: 1.2em;
- font-family: Source Han Sans CN;
- font-weight: 600;
- color: #111111;
- margin: 5px 0;
- }
- .item-ad__address {
- text-align: justify;
- font-size: 1.2em;
- font-family: Source Han Sans CN;
- color:#999999;
- margin: 5px 0;
- span{
- margin-left: 5px;
- }
- }
- }
- .kongParents {
- width: calc(100vw - 30px);
- // top: 199.5px;
- margin-top: 50px;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .kong {
- top: 199.5px;
- left: 76px;
- height: 34px;
- line-height: 40px;
- color: #333;
- text-align: center;
- width: 180px;
- border-radius: 17px;
- background: linear-gradient(0deg, #f2c482, #a07947);
- img {
- width: 13px;
- height: 13px;
- vertical-align: -2px;
- }
- span {
- padding: 0 0 0 4px;
- width: 47.5px;
- height: 11px;
- font-size: 12px;
- font-family: Source Han Sans CN;
- font-weight: 400;
- color: #111111;
- line-height: 3px;
- }
- }
- .product-footer {
- position: fixed;
- width: 100%;
- background: #E6E6DC;
- left: 0;
- bottom: 50px;
- z-index: 3;
- .fl {
- font-size: 1.4em;
- padding: 10px;
- font-family: DIN;
- font-weight: 500;
- color: #111111;
- }
- button {
- background: #E6E6DC;
- color:#292929;
- padding: 0;
- border: 0px;
- line-height: 56px;
- height: 56px;
- width: 40vw;
- border-left: 2px solid #FCFCF0;
- //background: linear-gradient(0deg, #9e7746, #f4c583);
- //color: #333;
- //border: 1px solid #9e7746;
- //border-radius: 10px;
- //overflow: hidden;
- //margin: 0 16px 0 0;
- //list-style: none;
- }
- }
- //@media screen and (max-width: 320px) {
- // .item-ad {
- // width: 90vw;
- // top: 160px;
- // font-size: 12px;
- // height: 70px;
- // p {
- // margin: 0;
- // }
- // }
- // .kongParents {
- // top: 174px;
- // }
- // // .product-baozhuang {
- // // margin: -15vh 0 0 0;
- // // }
- // .productPack {
- // .box {
- // p {
- // margin: 8.5px 0 7px 6px;
- // }
- // span {
- // margin: 12.5px 0 0px 6px;
- // }
- // }
- // .bag {
- // p {
- // margin: 8.5px 0 7px 10px;
- // }
- // }
- // }
- //}
- //@media screen and (max-width: 375px) and (max-width: 414px) {
- // .product-baozhuang {
- // margin: -80px 0 0 0;
- // }
- //}
- //@media screen and (min-width: 414px) {
- // .product-baozhuang {
- // margin: -80px 0 0 0;
- // }
- //}
- }
- </style>
|