123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- <template>
- <view class="content">
- <view class="info">
- <view class="one">
- <view class="one_1">
- <view class="name">
- {{shopInfo.name}}
- <!-- <uni-icons type="forward" size="20"></uni-icons> -->
- </view>
- <view class="num">
- <picker @change="tableChange" :value="shopInfo.table_name" :range="tableList" range-key="name">
- <view>
- 桌号:{{shopInfo.table_name||'请选择用餐桌号'}}
- </view>
- </picker>
- </view>
- </view>
- <!-- <view class="one_2">
- <view class="left">
- <text>领劵</text>
- <text class="left_1" v-for="(item,index) in shopInfo.coupon">{{item.name}}</text>
- </view>
- <view class="right">
- <text>去领劵</text>
- <uni-icons color="#C0C0C0" type="forward" size="14"></uni-icons>
- </view>
- </view> -->
- <view class="one_2">
- <view class="left">
- <text>公告</text>
- <text class="left_2">{{shopInfo.notice}}</text>
- </view>
- </view>
- <view class="one_3">
- <image :src="shopInfo.logo&&shopInfo.logo.length>0?shopInfo.logo[0].url:''" mode="scaleToFill">
- </image>
- </view>
- </view>
- <view class="two">
- <view class="two_1">
- <scroll-view scroll-y="true" class="scroll-view">
- <view class="list-scroll-view">
- <view class="list" :class="[active==index?'listActive':'']" v-for="(item,index) in typeList"
- :key="index" @tap="toChange(index,item)">
- <uni-badge :text="item.num" absolute="rightTop" size="small">
- <uni-icons color="#FF8C00" :type="item.icon" size="15"></uni-icons>
- <text class="name">{{item.name}}</text>
- </uni-badge>
- </view>
- </view>
- </scroll-view>
- </view>
- <view class="two_2">
- <scroll-view scroll-y="true" class="scroll-view">
- <view class="list-scroll-view">
- <view class="theme">{{tags.name}}</view>
- <view class="list" v-for="(tag,index) in marketList" :key="index">
- <view class="img">
- <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''" mode="">
- </image>
- </view>
- <view class="info">
- <view class="name textOver">
- <text>{{tag.name}}</text>
- </view>
- <view class="spec" v-if="tag.spec">
- <text>{{tag.spec}}</text>
- </view>
- <view class="money">
- <text>¥{{tag.price}}</text>
- <uni-number-box @change="bindChange(tag)" :min="0" :max="tag.stock" value="tag"
- background="#FF8C00" color="#fff" v-model="tag.num" />
- </view>
- </view>
- </view>
- </view>
- <view class="is_bottom" v-if="is_bottom">
- <text>已经到底了!</text>
- </view>
- </scroll-view>
- </view>
- </view>
- </view>
- <view class="foot" @tap="toView">
- <view class="foot_1">
- <uni-badge :text="cartNum.num" absolute="rightTop" size="small">
- <uni-icons color="#FF8C00" type="cart-filled" size="45"></uni-icons>
- </uni-badge>
- <text>合计</text>
- <text class="type">¥</text>
- <text class="money">{{cartNum.total||0}}</text>
- </view>
- <view class="foot_2">
- <button class="button" @tap.stop="toBuy">去结算</button>
- </view>
- </view>
- <!-- 规格 -->
- <uni-popup ref="specShow" background-color="#fff" type="bottom">
- <view class="popup">
- <view class="close">
- <view @click="toDelete">
- <uni-icons color="#858585" type="trash" size="17"></uni-icons>
- <text class="name">清空购物车</text>
- </view>
- </view>
- <view class="info_1" v-if="popupShow=='1'">
- <scroll-view scroll-y="true" class="scroll-view">
- <view class="list-scroll-view">
- <view class="list" v-for="(tag,index) in buyList" :key="index">
- <view class="img">
- <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''" mode="">
- </image>
- </view>
- <view class="info">
- <view class="name textOver">
- <text>{{tag.name}}</text>
- </view>
- <view class="spec" v-if="tag.spec">
- <text>{{tag.spec}}</text>
- </view>
- <view class="money">
- <text>¥{{tag.price}}</text>
- <uni-number-box @change="bindChange(tag)" :min="0" :max="tag.stock" value="tag"
- background="#FF8C00" color="#fff" v-model="tag.num" />
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- id: '',
- tableid:'',
- order: '0',
- shopInfo: {},
- list: [],
- active: '0',
- tags: {},
- // 数据是否触底
- is_bottom: false,
- scrollTop: 0,
- typeList: [],
- marketList: [],
- // 购物车
- buyList: [],
- // 购物车数量
- cartNum: {},
- is_show: false,
- // 规格弹框
- popupShow: '1',
- // 桌号
- tableList: [],
- }
- },
- onLoad: async function(e) {
- const that = this;
- console.log(e);
- that.$set(that, `tableid`, e.tableid);
- that.$set(that, `id`, e.id);
- that.$set(that, `order`, e.order);
- that.search();
- },
- onShow() {
- const that = this;
- },
- methods: {
- // 查询左侧一级列表
- async search() {
- const that = this;
- let res;
- res = await that.$api(`table`, 'GET', {});
- if (res.errcode == '0') that.$set(that, `tableList`, res.data);
- if(that.tableid){
- res = await that.$api(`table/${that.tableid}`, 'GET', {});
- if (res.errcode == '0') {
- that.$set(that.shopInfo, `table_name`, res.data.name);
- that.$set(that.shopInfo, `table`, res.data._id);
- }
- }
- res = await that.$api(`shop`, 'GET', {});
- if (res.errcode == '0') {
- let data = res.data[0]
- // data.table_name = that.tableList[0].name
- that.$set(that, `shopInfo`, data);
- }
- res = await that.$api(`goodsTags`, 'GET', {});
- if (res.errcode == '0') {
- that.$set(that, `typeList`, res.data);
- // 查询产品
- that.$set(that.tags, `code`, res.data[0].code)
- that.searchMarket()
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- },
- // 查询产品
- async searchMarket() {
- const that = this;
- let res = await that.$api(`goods`, 'GET', {
- type: that.tags.code
- });
- if (res.errcode == '0') {
- that.$nextTick(async () => {
- for (let val of that.buyList) {
- for (let s of res.data) {
- if (s._id == val._id) s.num = val.num
- }
- }
- that.$set(that, `marketList`, res.data)
- })
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- },
- // 改变数量
- async bindChange(e) {
- const that = this;
- that.$nextTick(async () => {
- let list = that.buyList.find(i => i._id == e._id)
- if (list) {
- if (list.num == 0) {
- let cart = that.buyList.filter(i => i._id !== e._id)
- if (cart) that.$set(that, `buyList`, cart)
- } else {
- for (let val of that.buyList) {
- if (val._id == e._id) val.num = e.num
- }
- }
- } else {
- if (e.num !== 0) that.buyList.push(e)
- }
- for (let s of that.typeList) {
- let num = that.buyList.filter(i => i.code == s.code)
- let buy = num.filter(i => i.num !== 0)
- if (buy) s.num = buy.length
- }
- await that.countMoney()
- })
- },
- // 计算总额
- countMoney() {
- const that = this;
- let list = that.buyList.filter(i => i.num !== 0)
- let totalMoney = 0;
- // 渲染结束执行下面方法
- that.$nextTick(() => {
- for (const val of list) {
- let total = that.$multiply(val.price, val.num);
- totalMoney += Number(total);
- }
- that.$set(that.cartNum, `num`, list.length)
- that.$set(that.cartNum, `total`, totalMoney)
- })
- },
- // 查看选择商品详情
- toView() {
- const that = this;
- let list = that.buyList.filter(i => i.num !== 0)
- that.$set(that, `buyList`, list)
- that.$set(that, `popupShow`, '1')
- that.$refs.specShow.open();
- },
- tableChange(e) {
- const that = this;
- let data = that.tableList[e.detail.value];
- if (data) {
- that.$set(that.shopInfo, `table_name`, data.name);
- that.$set(that.shopInfo, `table`, data._id);
- }
- },
- // 去购买
- async toBuy() {
- const that = this;
- let res;
- let list = that.buyList.filter(i => i.num !== 0)
- if (list.length > 0) {
- if (that.order) {
- res = await that.$api(`order/${that.order}`, 'GET', {});
- if (res.errcode == '0') {
- let is_add = true
- for (let val of res.data.list) {
- for (let i = 0; i < list.length; i++) {
- if (val._id == list[i]._id) {
- list[i].num = val.num + list[i].num
- is_add = false
- }
- }
- if (is_add) {
- list.push(val)
- }
- }
- let obj = {
- list: list,
- total: that.$plus(that.cartNum.total, res.data.money),
- }
- let update = await that.$api(`cart/${that.id}`, 'POST', obj);
- if (update.errcode == '0') {
- uni.navigateTo({
- url: `/pagesHome/order/add?id=${that.id}&order=${that.order}`
- })
- }
- }
- } else {
- if (that.shopInfo.table) {
- let obj = {
- list: list,
- total: that.cartNum.total,
- table: that.shopInfo.table
- }
- res = await that.$api(`cart`, 'POST', obj);
- if (res.errcode == '0') {
- uni.navigateTo({
- url: `/pagesHome/order/index?id=${res.data._id}`
- })
- }
- } else {
- uni.showToast({
- title: '请选择用餐桌号',
- icon: 'none'
- })
- }
- }
- }
- },
- //清空购物车
- toDelete() {
- const that = this;
- for (let val of that.typeList) val.num = 0
- that.$set(that, `buyList`, [])
- that.$set(that.cartNum, `num`, 0)
- that.$set(that.cartNum, `total`, 0)
- that.searchMarket()
- that.$refs.specShow.close();
- },
- // 左侧一级选择
- toChange(index, e) {
- const that = this;
- that.$set(that, `marketList`, []);
- that.$set(that, `active`, index);
- that.$set(that.tags, `code`, e.code);
- that.searchMarket();
- },
- }
- }
- </script>
- <style lang="scss">
- .content {
- font-family: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;
- .info {
- display: flex;
- flex-direction: column;
- position: relative;
- flex-grow: 1;
- .one {
- .one_1 {
- padding: 2vw;
- display: flex;
- justify-content: space-between;
- font-size: 18px;
- font-weight: bold;
- .name {
- display: flex;
- align-items: center;
- }
- }
- .one_2 {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 2vw;
- .left {
- text:first-child {
- font-size: 14px;
- margin: 0 1vw 0 0;
- font-weight: 600;
- }
- .left_1 {
- font-size: 12px;
- padding: 1vw;
- margin: 0 1vw 0 0;
- color: #FF7800;
- border: 1px solid #FF7800;
- border-radius: 2vw;
- }
- .left_2 {
- font-size: 12px;
- color: #808080;
- }
- }
- .right {
- font-size: 12px;
- color: #808080;
- }
- }
- .one_3 {
- padding: 2vw;
- text-align: center;
- background-color: #f1f1f1;
- image {
- width: 100%;
- border-radius: 2vw;
- height: 15vh;
- }
- }
- }
- .two {
- height: 61vh;
- display: flex;
- .two_1 {
- position: relative;
- width: 25vw;
- background-color: #fafafa;
- display: flex;
- flex-direction: column;
- .list {
- text-align: center;
- padding: 3vw 0;
- border-bottom: 1px solid #f1f1f1;
- .name {
- color: #858585;
- font-size: 12px;
- }
- }
- .listActive {
- background-color: #ffffff;
- }
- }
- .two_2 {
- flex-grow: 1;
- position: relative;
- display: flex;
- flex-direction: column;
- .theme {
- padding: 2vw;
- color: #858585;
- font-size: 12px;
- }
- .list {
- display: flex;
- width: 70vw;
- margin: 0 0 2vw 0;
- padding: 2vw;
- box-shadow: 0 0 5px #f1f1f1;
- border-radius: 5px;
- .img {
- width: 30vw;
- .image {
- width: 30vw;
- height: 20vw;
- border-radius: 5px;
- }
- }
- .info {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- width: 40vw;
- padding: 0 0 0 2vw;
- .name {
- font-size: 16px;
- }
- .spec {
- font-size: 12px;
- color: #858585;
- }
- .money {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 16px;
- color: #FF8C00;
- margin: 0 0 1vw 0;
- }
- }
- }
- }
- }
- }
- .foot {
- display: flex;
- justify-content: space-between;
- padding: 0 2vw;
- background-color: #ffffff;
- border-top: 1px solid #f1f1f1;
- z-index: 99999 !important;
- .foot_1 {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 14px;
- .type {
- color: #FF8C00;
- }
- .money {
- font-size: 25px;
- color: #FF8C00;
- }
- }
- .foot_2 {
- .button {
- background-color: #FF8C00;
- color: #ffffff;
- border-radius: 5vw;
- font-size: 16px;
- }
- }
- }
- .uni-popup {
- z-index: 9999 !important;
- }
- .popup {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 60vh;
- .close {
- text-align: right;
- padding: 2vw;
- .name {
- font-size: 14px;
- color: #858585;
- }
- }
- .info_1 {
- position: relative;
- display: flex;
- flex-direction: column;
- height: 54vh;
- margin-bottom: 12vw;
- .list {
- display: flex;
- width: 96vw;
- margin: 0 0 2vw 0;
- padding: 2vw;
- box-shadow: 0 0 5px #f1f1f1;
- border-radius: 5px;
- .img {
- width: 30vw;
- .image {
- width: 30vw;
- height: 20vw;
- border-radius: 5px;
- }
- }
- .info {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- width: 60vw;
- padding: 0 0 0 2vw;
- .name {
- font-size: 16px;
- }
- .spec {
- font-size: 12px;
- color: #858585;
- }
- .money {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 16px;
- color: #FF8C00;
- margin: 0 0 1vw 0;
- }
- }
- }
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- </style>
|