123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299 |
- <template>
- <view>
- <view v-if="(info || null) != null">
- <view class="pr">
- <!-- 头部 -->
- <view class="header" :style="'background-image: url('+info.banner+');'">
- <!-- 顶部 -->
- <view v-if="is_single_page == 0" class="header-top padding-horizontal-main" :style="'padding-top:'+(status_bar_height+8)+'px;'">
- <!-- 返回 -->
- <!-- #ifdef MP-WEIXIN || MP-QQ || MP-KUAISHOU || H5 || APP -->
- <view v-if="is_realstore_top_nav_back == 1" class="nav-back dis-inline-block round tc va-m" @tap="top_nav_left_back_event">
- <uni-icons type="arrowleft" size="20" color="#fff"></uni-icons>
- </view>
- <!-- #endif -->
- <!-- 搜索 -->
- <view :class="'fr va-m '+(is_realstore_top_nav_back == 1 ? 'nav-search' : 'wh-auto')">
- <!-- #ifndef H5 -->
- <component-search @onsearch="search_button_event" @onicon="search_icon_event" :propIsIconOnEvent="is_realstore_top_search_scan == 1" :propIsOnEvent="true" :propIsRequired="false" :propIcon="is_realstore_top_search_scan == 1 ? 'scan' : 'search'" propIconColor="#fff" propPlaceholderClass="cr-grey" propTextColor="#fff" propPlaceholder="商品搜索" propBgColor="rgba(0, 0, 0, 0.1)" propBrColor="rgb(205 205 205 / 60%)"></component-search>
- <!-- #endif -->
- <!-- #ifdef H5 -->
- <component-search @onsearch="search_button_event" :propIsRequired="false" propIconColor="#9A9A9A" propPlaceholderClass="cr-grey" propTextColor="#fff" propPlaceholder="商品搜索" propBgColor="rgba(0, 0, 0, 0.1)" propBrColor="rgb(205 205 205 / 60%)"></component-search>
- <!-- #endif -->
- </view>
- </view>
- <!-- 桌码 -->
- <view v-if="(tablecode || null) != null" class="tablecode dis-inline-block margin-left-main round cr-red">
- {{tablecode.name}}({{tablecode.code}})
- </view>
- </view>
- <!-- 头部基础内容 -->
- <view class="header-content margin-main padding-main border-radius-main bg-white pa br">
- <view class="base oh">
- <!-- 基础内容 -->
- <image :src="info.logo" mode="widthFix" class="logo circle fl br" :data-value="info.logo" @tap="image_show_event"></image>
- <view class="base-right fr">
- <view v-if="(info.buy_use_type_list || null) != null && info.buy_use_type_list.length > 0" class="use-type-icon pa text-size-xs cr-white bg-main" @tap="buy_use_type_event">
- <text class="va-m margin-right-xs">{{info.buy_use_type_list[buy_use_type_index]['name']}}</text>
- <view class="dis-inline-block va-m">
- <uni-icons type="arrowdown" size="32rpx" color="#fff"></uni-icons>
- </view>
- </view>
- <view :class="'title fw-b text-size single-text '+((info.buy_use_type_list || null) != null && info.buy_use_type_list.length > 0 ? 'title-length-limit' : '')">
- <text v-if="(info.alias || null) != null" class="va-m title-icon round br-main cr-main text-size-xs padding-left-sm padding-right-sm margin-right-xs">{{info.alias}}</text>
- <text class="va-m">{{info.name}}</text>
- </view>
- <view class="margin-top-xs text-size-xs cr-grey">
- <view v-if="(info.status_info.time || null) != null">营业时间:{{info.status_info.time}}</view>
- <view v-if="(info.distance || null) != null">距离您{{info.distance}}</view>
- </view>
- </view>
- </view>
- <!-- 地址 -->
- <view class="margin-top-sm oh cp">
- <view class="dis-inline-block va-m">
- <uni-icons type="location-filled" size="32rpx" color="#8d8d8d"></uni-icons>
- </view>
- <view class="address-content single-text cr-base margin-left-xs dis-inline-block text-size-sm va-m" :data-value="info.province_name+info.city_name+info.county_name+info.address" @tap="text_copy_event">{{info.province_name}}{{info.city_name}}{{info.county_name}}{{info.address}}</view>
- </view>
- <!-- 右侧操作 -->
- <view class="icon-list pa">
- <!-- #ifndef MP-KUAISHOU -->
- <view v-if="(info.lat != 0 && info.lng != 0)" class="icon-item bg-green circle dis-inline-block tc cp" @tap="address_map_event">
- <uni-icons type="paperplane-filled" size="32rpx" color="#fff"></uni-icons>
- </view>
- <!-- #endif -->
- <view v-if="(info.service_tel || null) != null" class="icon-item bg-yellow circle dis-inline-block tc cp" @tap="tel_event">
- <uni-icons type="phone-filled" size="32rpx" color="#fff"></uni-icons>
- </view>
- <view :class="'icon-item circle dis-inline-block tc cp pr '+((favor_info.status == 1) ? 'bg-red' : 'bg-gray')" @tap="favor_event">
- <uni-icons type="heart-filled" size="32rpx" color="#fff"></uni-icons>
- <view class="badge-icon pa">
- <component-badge :propNumber="favor_info.count"></component-badge>
- </view>
- </view>
- </view>
- </view>
- </view>
-
- <!-- 内容 -->
- <view class="content oh">
- <!-- 左侧 -->
- <scroll-view :scroll-y="true" class="left-content fl ht-auto bg-white">
- <view class="left-content-actual">
- <view :class="'item tc cr-base text-size-sm cp ' + (nav_active_index == -1 ? 'active cr-main border-color-main fw-b' : '')" :data-index="-1" :data-itemindex="-1" @tap="nav_event">全部</view>
- <block v-if="(goods_category || null) != null && goods_category.length > 0">
- <block v-for="(item, index) in goods_category" :key="index">
- <view :class="'item tc cr-base text-size-sm pr cp ' + (nav_active_index == index ? 'active cr-main border-color-main fw-b' : '')" :data-index="index" :data-itemindex="-1" @tap="nav_event">
- <text>{{item.name}}</text>
- <view v-if="(item.buy_number || 0) > 0" class="badge-icon pa">
- <component-badge :propNumber="item.buy_number"></component-badge>
- </view>
- </view>
- </block>
- </block>
- </view>
- </scroll-view>
- <!-- 右侧 -->
- <scroll-view :scroll-y="true" class="right-content padding-right-main fr ht-auto goods-list" :scroll-top="scroll_top" @scroll="scroll_event" @scrolltolower="scroll_lower" lower-threshold="60">
- <view class="right-content-actual pr">
- <!-- 二级分类 -->
- <view v-if="(goods_category || null) != null && goods_category.length > 0 && nav_active_index != -1 && (goods_category[nav_active_index]['items'] || null) != null && goods_category[nav_active_index]['items'].length > 0" class="word-list scroll-view-horizontal">
- <scroll-view :scroll-x="true" :scroll-with-animation="true" :scroll-into-view="'two-nav-item-'+nav_active_item_index">
- <view :class="'word-icon dis-inline-block text-size-sm round padding-top-xs padding-bottom-xs padding-left padding-right '+((nav_active_item_index == -1) ? 'bg-main-light br-main-light cr-main' : 'br-gray cr-gray')" :data-index="nav_active_index" :data-itemindex="-1" @tap="nav_event">全部</view>
- <block v-for="(cv, ci) in goods_category[nav_active_index]['items']" :key="ci">
- <view :class="'word-icon dis-inline-block text-size-sm round padding-top-xs padding-bottom-xs padding-left padding-right '+((nav_active_item_index != -1 && nav_active_item_index == ci) ? 'bg-main-light br-main-light cr-main' : 'br-gray cr-gray')" :id="'two-nav-item-'+ci" :data-index="nav_active_index" :data-itemindex="ci" @tap="nav_event">{{cv.name}}</view>
- </block>
- </scroll-view>
- </view>
- <!-- 右侧商品列表 -->
- <block v-if="(data_list || null) != null && data_list.length > 0">
- <view v-for="(item, index) in data_list" :key="index" class="item bg-white padding-main border-radius-main oh spacing-mb">
- <view :data-value="'/pages/goods-detail/goods-detail?id='+item.id+'&is_opt_back=1&buy_use_type_index='+buy_use_type_index+'&realstore_id='+info.id" @tap="url_event">
- <image :src="item.images" mode="widthFix" class="goods-img radius fl br"></image>
- <view class="goods-base fr">
- <view class="goods-base-content">
- <view class="goods-title text-size-sm single-text">{{item.title}}</view>
- <view v-if="(item.simple_desc || null) != null" class="simple-desc cr-red text-size-xs margin-top-xs multi-text">{{item.simple_desc}}</view>
- </view>
- <view class="margin-top-sm oh">
- <view class="sales-price text-size-sm single-text dis-inline-block va-m">{{currency_symbol}}{{item.min_price}}</view>
- <view class="tc fr">
- <block v-if="(item.is_error || 0) == 0">
- <view v-if="(item.buy_number || 0) > 0" class="dis-inline-block va-m cp" :data-index="index" data-type="0" @tap.stop="buy_number_event">
- <uni-icons type="minus" size="22" color="#f00"></uni-icons>
- </view>
- <view v-if="(item.buy_number || 0) > 0" class="buy-number dis-inline-block cr-base text-size-sm padding-left-xs padding-right-xs va-m">{{item.buy_number}}</view>
- <view class="dis-inline-block va-m cp" :data-index="index" data-type="1" @tap.stop="buy_number_event">
- <uni-icons type="plus" size="22" color="#1AAD19"></uni-icons>
- </view>
- </block>
- <block v-else>
- <text class="cr-grey text-size-xs">{{item.is_error_msg}}</text>
- </block>
- </view>
- </view>
- </view>
- </view>
- </view>
- </block>
- <block v-else>
- <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
- </block>
- </view>
- </scroll-view>
- </view>
- <!-- 购物车列表 -->
- <block v-if="cart_status">
- <view class="cart-mask wh-auto ht-auto pf" @tap="cart_event"></view>
- <view class="cart-content bg-white border-radius-main pa oh">
- <block v-if="(cart || null) != null && (cart.data || null) != null && cart.data.length > 0">
- <view class="oh br-b padding-vertical-main padding-horizontal-main">
- <text class="va-m text-size-xs cr-base">已选商品</text>
- <view class="dis-inline-block margin-left-xl text-size-xs">
- <text class="cr-red">没有已加购的商品?</text>
- <text class="br-green cr-green round padding-left padding-right padding-top-xs padding-bottom-xs cp" @tap="buy_use_type_event">切换下单类型</text>
- </view>
- <view class="fr cp" @tap="cart_all_delete_event">
- <view class="dis-inline-block va-m">
- <uni-icons type="trash" size="12" color="#f00"></uni-icons>
- </view>
- <text class="cr-red va-m text-size-xs margin-left-xs">清空</text>
- </view>
- </view>
- <scroll-view :scroll-y="true" class="cart-list goods-list">
- <view v-for="(goods, index) in cart.data" :key="index" class="item padding-main oh spacing-mb">
- <navigator :url="'/pages/goods-detail/goods-detail?id='+goods.goods_id+'&is_opt_back=1&buy_use_type_index='+buy_use_type_index+'&realstore_id='+info.id" hover-class="none">
- <image :src="goods.images" mode="widthFix" class="goods-img radius fl br"></image>
- <view class="goods-base fr">
- <view class="goods-base-content">
- <view class="goods-title text-size-sm single-text">{{goods.title}}</view>
- <view v-if="goods.spec != null" class="text-size-xs cr-grey margin-top-sm">
- <block v-for="(sv, si) in goods.spec" :key="si">
- <text v-if="si > 0" class="padding-left-xs padding-right-xs">;</text>
- <text>{{sv.value}}</text>
- </block>
- </view>
- </view>
- <view class="margin-top-sm oh">
- <view class="sales-price text-size-sm single-text dis-inline-block va-m">{{currency_symbol}}{{goods.price}}</view>
- <view class="tc fr">
- <view v-if="(goods.stock || 0) > 0" class="dis-inline-block va-m cp" :data-index="index" data-type="0" @tap.stop="cart_buy_number_event">
- <uni-icons type="minus" size="22" color="#f00"></uni-icons>
- </view>
- <view v-if="(goods.stock || 0) > 0" class="buy-number dis-inline-block cr-base text-size-sm padding-left-xs padding-right-xs va-m">{{goods.stock}}</view>
- <view class="dis-inline-block va-m cp" :data-index="index" data-type="1" @tap.stop="cart_buy_number_event">
- <uni-icons type="plus" size="22" color="#1AAD19"></uni-icons>
- </view>
- </view>
- </view>
- </view>
- </navigator>
- </view>
- </scroll-view>
- </block>
- <block v-else>
- <component-no-data propStatus="0" propMsg="请先选购商品"></component-no-data>
- <view class="padding-bottom-xxxl margin-bottom-xxxl tc text-size-xs margin-top-xxl">
- <text class="cr-red">没有已加购的商品?</text>
- <text class="br-green cr-green round padding-left padding-right padding-top-xs padding-bottom-xs cp" @tap="buy_use_type_event">切换下单类型</text>
- </view>
- </block>
- </view>
- </block>
- <!-- 购物车底部导航 -->
- <view class="botton-nav round pa bg-main-pair oh">
- <view class="cart dis-inline-block va-m margin-left-xxl pr cp" @tap="cart_event">
- <uni-icons type="cart" size="32rpx" color="#fff"></uni-icons>
- <view v-if="(cart || null) != null && (cart.buy_number || 0) > 0" class="badge-icon pa">
- <component-badge :propNumber="cart.buy_number"></component-badge>
- </view>
- </view>
- <view class="cart-total-price single-text dis-inline-block fw-b cr-white va-m margin-left-xl">
- <text class="text-size-sm">{{currency_symbol}}</text>
- <text class="text-size-lg">{{(cart || null) == null ? 0 : (cart.total_price || 0)}}</text>
- </view>
- <button type="default" size="mini" hover-class="none" @tap="buy_submit_event" :class="'text-size-sm pa radius-0 '+((info.status_info.status == 1) ? 'bg-main cr-white' : 'bg-gray cr-gray')">{{info.status_info.status == 1 ? '去结算' : info.status_info.msg}}</button>
- </view>
- <!-- 购物车抛物线 -->
- <component-cart-para-curve ref="cart_para_curve"></component-cart-para-curve>
- <!-- 商品购买 -->
- <component-goods-buy ref="goods_buy" v-on:CartSuccessEvent="goods_cart_back_event"></component-goods-buy>
- </view>
- <view v-else>
- <!-- 提示信息 -->
- <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
- </view>
- </view>
- </template>
- <script>
- const app = getApp();
- import base64 from '../../../../common/js/lib/base64.js';
- import componentGoodsBuy from "../../../../components/goods-buy/goods-buy";
- import componentNoData from "../../../../components/no-data/no-data";
- import componentSearch from "../../../../components/search/search";
- import componentBadge from "../../../../components/badge/badge";
- import componentPopup from "../../../../components/popup/popup";
- import componentCartParaCurve from '../../../../components/cart-para-curve/cart-para-curve';
- var common_static_url = app.globalData.get_static_url('common');
- export default {
- data() {
- return {
- status_bar_height: parseInt(app.globalData.get_system_info('statusBarHeight', 0)),
- common_static_url: common_static_url,
- data_list_loding_status: 1,
- data_list_loding_msg: '',
- currency_symbol: app.globalData.data.currency_symbol,
- cache_buy_use_type_index_key: 'cache_plugins_realstore_buy_use_type_index',
- buy_use_type_index: 0,
- params: null,
- is_first: 1,
- scroll_top: 0,
- scroll_top_old: 0,
- user: null,
- info: null,
- goods_category: [],
- data_list: [],
- data_total: 0,
- data_page_total: 0,
- data_page: 1,
- cart: null,
- goods_count: 0,
- data_base: null,
- favor_user: [],
- tablecode: null,
- category: [],
- goods_list: [],
- search_keywords_value: '',
- nav_active_index: -1,
- nav_active_item_index: -1,
- cart_status: false,
- popup_spec_status: false,
- goods_choose_data: {},
- // 收藏信息
- favor_info: {
- "text": "收藏",
- "status": 0,
- "count": 0
- },
- // 用户位置信息
- user_location: null,
- // 自定义分享信息
- share_info: {},
- // 是否单页预览
- is_single_page: app.globalData.is_current_single_page() || 0,
- // 顶部导航返回按钮
- is_realstore_top_nav_back: app.globalData.data.is_realstore_top_nav_back || 0,
- is_realstore_top_search_scan: app.globalData.data.is_realstore_top_search_scan || 0,
- // 临时操作数据
- temp_opt_data: null,
- };
- },
- components: {
- componentGoodsBuy,
- componentNoData,
- componentSearch,
- componentBadge,
- componentPopup,
- componentCartParaCurve
- },
- props: {},
- onLoad(params) {
- this.setData({
- params: app.globalData.launch_params_handle(params),
- user: app.globalData.get_user_cache_info()
- });
- },
- onShow() {
- // 类型选择
- this.setData({
- buy_use_type_index: this.get_buy_use_type_index()
- });
- // 用户位置初始化
- this.user_location_init();
- // 获取数据
- this.get_detail_init();
- // 初始化配置
- this.init_config();
- },
- // 下拉刷新
- onPullDownRefresh() {
- this.setData({
- data_page: 1
- });
- this.reset_scroll();
- this.get_detail_init();
- },
- methods: {
- // 初始化配置
- init_config(status) {
- if ((status || false) == true) {
- this.setData({
- currency_symbol: app.globalData.get_config('currency_symbol')
- });
- } else {
- app.globalData.is_config(this, 'init_config');
- }
- },
- // 获取数据-初始化
- get_detail_init() {
- uni.request({
- url: app.globalData.get_request_url("index", "detail", "realstore"),
- method: 'POST',
- data: this.request_params_merge({
- "id": this.params.id || 0
- }, 'init'),
- dataType: 'json',
- success: res => {
- uni.stopPullDownRefresh();
- if (res.data.code == 0) {
- var data = res.data.data;
- this.setData({
- data_base: data.base || null,
- info: data.info || null,
- goods_category: data.goods_category || [],
- favor_user: data.favor_user || [],
- tablecode: data.tablecode || null
- });
- // 下单类型是否存在索引
- this.setData({
- buy_use_type_index: this.get_buy_use_type_index()
- });
- // 收藏处理
- if ((this.info || null) != null) {
- // 收藏信息
- var status = this.favor_user.indexOf(this.info.id) != -1 ? 1 : 0;
- this.setData({
- favor_info: {
- "count": this.info.favor_count || 0,
- "status": status,
- "text": (status == 1 ? '已' : '') + '收藏'
- }
- });
- // 基础自定义分享
- this.setData({
- share_info: {
- title: this.info.seo_title || this.info.name,
- desc: this.info.seo_desc || this.info.describe,
- path: '/pages/plugins/realstore/detail/detail',
- query: 'id='+this.info.id,
- img: this.info.logo
- }
- });
- // 标题名称
- uni.setNavigationBarTitle({
- title: this.info.name
- });
-
- // 获取数据、仅首次调用
- // 获取列表接口和购物车
- if(this.is_first == 1) {
- this.get_data_list();
- this.get_cart_data(this.is_first);
- this.setData({is_first: 0});
- } else {
- // 非首次赋值购物车数据
- this.setData({
- cart: data.cart || null,
- });
- // 购物车更新列表数据处理
- this.cart_data_list_handle();
- }
- }
- } else {
- this.setData({
- data_list_loding_status: 2,
- data_list_loding_msg: res.data.msg
- });
- }
- // 分享菜单处理
- app.globalData.page_share_handle(this.share_info);
- },
- fail: () => {
- uni.stopPullDownRefresh();
- this.setData({
- data_list_loding_status: 2,
- data_list_loding_msg: '服务器请求出错'
- });
- app.globalData.showToast('服务器请求出错');
- }
- });
- },
- // 获取数据-商品列表
- get_data_list(is_mandatory) {
- // 分页是否还有数据
- if ((is_mandatory || 0) == 0) {
- if (this.data_bottom_line_status == true) {
- uni.stopPullDownRefresh();
- return false;
- }
- }
- // 加载loding
- uni.showLoading({
- title: '加载中...',
- mask: true
- });
- // 分类id
- var temp_category = this.goods_category;
- if(this.nav_active_item_index != -1) {
- var category_id = temp_category[this.nav_active_index]['items'][this.nav_active_item_index]['id'];
- } else {
- var category_id = (this.nav_active_index == -1) ? 0 : temp_category[this.nav_active_index]['id'];
- }
- // 获取数据
- uni.request({
- url: app.globalData.get_request_url("datalist", "detail", "realstore"),
- method: 'POST',
- data: this.request_params_merge({
- id: this.info.id || 0,
- page: this.data_page,
- keywords: this.search_keywords_value,
- category_id: category_id
- }, 'data'),
- dataType: 'json',
- success: res => {
- uni.hideLoading();
- uni.stopPullDownRefresh();
- if (res.data.code == 0) {
- var data = res.data.data;
- if (data.data.length > 0) {
- if (this.data_page <= 1) {
- var temp_data_list = data.data;
- } else {
- var temp_data_list = this.data_list || [];
- var temp_data = data.data;
- for (var i in temp_data) {
- temp_data_list.push(temp_data[i]);
- }
- }
- this.setData({
- data_list: temp_data_list,
- data_total: data.total,
- data_page_total: data.page_total,
- data_list_loding_status: 3,
- data_page: this.data_page + 1
- });
-
- // 是否还有数据
- this.setData({
- data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
- });
- } else {
- this.setData({
- data_list_loding_status: 0
- });
- if (this.data_page <= 1) {
- this.setData({
- data_list: [],
- data_bottom_line_status: false
- });
- }
- }
- } else {
- this.setData({
- data_list_loding_status: 0,
- data_list_loding_msg: res.data.msg
- });
- app.globalData.showToast(res.data.msg);
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.stopPullDownRefresh();
- this.setData({
- data_list_loding_status: 2,
- data_list_loding_msg: '服务器请求出错'
- });
- app.globalData.showToast('服务器请求出错');
- }
- });
- },
- // 收藏事件
- favor_event(e) {
- if(!app.globalData.is_single_page_check()) {
- return false;
- }
- var user = app.globalData.get_user_info(this, 'favor_event');
- if (user != false) {
- // 用户未绑定用户则转到登录页面
- if (app.globalData.user_is_need_login(user)) {
- uni.navigateTo({
- url: "/pages/login/login?event_callback=favor_event"
- });
- return false;
- } else {
- uni.showLoading({
- title: '处理中...'
- });
- uni.request({
- url: app.globalData.get_request_url("reversal", "favor", "realstore"),
- method: 'POST',
- data: {
- "id": this.info.id
- },
- dataType: 'json',
- success: res => {
- uni.hideLoading();
- if (res.data.code == 0) {
- this.setData({
- favor_info: res.data.data
- });
- app.globalData.showToast(res.data.msg, 'success');
- } else {
- if (app.globalData.is_login_check(res.data, this, 'favor_event')) {
- app.globalData.showToast(res.data.msg);
- }
- }
- },
- fail: () => {
- uni.hideLoading();
- app.globalData.showToast('服务器请求出错');
- }
- });
- }
- }
- },
- // 列表数据操作
- buy_number_event(e) {
- if(!app.globalData.is_single_page_check()) {
- return false;
- }
- var user = app.globalData.get_user_info(this);
- if (user != false) {
- // 用户未绑定用户则转到登录页面
- if (app.globalData.user_is_need_login(user)) {
- uni.navigateTo({
- url: "/pages/login/login?event_callback=buy_number_event"
- });
- return false;
- } else {
- var index = e.currentTarget.dataset.index;
- var type = parseInt(e.currentTarget.dataset.type) || 0;
- var temp_goods = this.data_list[index];
- this.setData({goods_choose_data: temp_goods});
- // 是否存在多规格
- if((temp_goods.is_exist_many_spec || 0) != 0) {
- // 是否购物车中操作
- if(type == 0) {
- this.setData({
- cart_status: true
- });
- app.globalData.showToast('不同规格的商品需在购物车减购');
- } else {
- if((this.$refs.goods_buy || null) != null) {
- var buy_params = this.params;
- buy_params['buy_event_type'] = 'cart';
- buy_params['buy_use_type_index'] = this.buy_use_type_index;
- buy_params['realstore_id'] = this.info.id;
- this.$refs.goods_buy.init(temp_goods, buy_params);
- }
- }
- return false;
- }
- // 数据操作处理
- this.buy_number_event_handle(e, type, temp_goods);
- }
- }
- },
- // 加入购物车成功回调
- goods_cart_back_event(e) {
- // 重新获取购物车数据
- this.get_cart_data();
- },
- // 列表数量事件处理
- buy_number_event_handle(e, type, goods, spec = '') {
- var res = this.buy_number_handle(type, goods, 'buy_number');
- if(res === false) {
- return false;
- }
- // 数据临时记录
- this.setData({
- temp_opt_data: {
- pos: e,
- goods: goods,
- type: type,
- }
- });
- // 为0或减操作则查询
- var cart_item = null;
- if(type == 0 || (type == 1 && goods['buy_number'] > 0)) {
- var cart_data = this.cart.data;
- var params_spec = ((spec || null) == null || typeof(spec) != 'object') ? '' : JSON.stringify(spec);
- for(var i in cart_data) {
- if(goods['id'] == cart_data[i]['goods_id']) {
- var cart_spec = ((cart_data[i]['spec'] || null) == null || typeof(cart_data[i]['spec']) != 'object') ? '' : JSON.stringify(cart_data[i]['spec']);
- if(type == 0 || (type == 1 && cart_spec == params_spec)) {
- cart_item = cart_data[i];
- }
- break;
- }
- }
- }
- // 操作类型
- if(res == 0) {
- if(cart_item == null) {
- app.globalData.showToast('购物车id有误');
- return false;
- }
- this.cart_delete(cart_item.id);
- } else if(cart_item == null) {
- this.cart_save(goods['id'], res, spec);
- } else {
- var number = (type == 0) ? parseInt(cart_item['stock'])-res : res+parseInt(cart_item['stock']);
- this.cart_update(cart_item.id, goods['id'], number);
- }
- return true;
- },
- // 购物车抛物线动画
- cart_para_curve_handle() {
- if((this.temp_opt_data || null) != null && (this.temp_opt_data.type || 0) == 1) {
- if((this.$refs.cart_para_curve || null) != null) {
- var self = this;
- uni.createSelectorQuery().select('.botton-nav .cart').boundingClientRect().exec(function(res) {
- self.$refs.cart_para_curve.init(res, self.temp_opt_data.pos, self.temp_opt_data.goods.images);
- });
- }
- }
- },
- // 购物车数量操作
- cart_buy_number_event(e) {
- if(!app.globalData.is_single_page_check()) {
- return false;
- }
- var user = app.globalData.get_user_info(this);
- if (user != false) {
- // 用户未绑定用户则转到登录页面
- if (app.globalData.user_is_need_login(user)) {
- uni.navigateTo({
- url: "/pages/login/login?event_callback=cart_buy_number_event"
- });
- return false;
- } else {
- var index = e.currentTarget.dataset.index;
- var type = parseInt(e.currentTarget.dataset.type) || 0;
- var temp_data = this.cart.data;
- var temp_goods = temp_data[index];
-
- // 数据操作处理
- var res = this.buy_number_handle(type, temp_goods, 'stock');
- if(res === false) {
- return false;
- }
- // 数据临时记录
- this.setData({
- temp_opt_data: {
- pos: e,
- goods: temp_goods,
- type: type,
- }
- });
- // 操作类型
- if(res == 0) {
- this.cart_delete(temp_goods['id']);
- } else {
- var number = (type == 0) ? parseInt(temp_goods['stock'])-res : res+parseInt(temp_goods['stock']);
- this.cart_update(temp_goods['id'], temp_goods['goods_id'], number);
- }
- }
- }
- },
- // 批量删除操作
- cart_all_delete_event(e) {
- uni.showModal({
- title: '温馨提示',
- content: '挑了这么久,真的要清空吗?',
- confirmText: '确认',
- cancelText: '暂不',
- success: result => {
- if (result.confirm) {
- var ids = [];
- var temp_data = this.cart.data;
- for (var i in temp_data) {
- ids.push(temp_data[i]['id']);
- }
- this.cart_delete(ids.join(','));
- }
- }
- });
- },
- // 数量操作处理
- buy_number_handle(type, goods, buy_number_field) {
- // 门店状态
- if(type == 1 && !this.is_status_check()) {
- return false;
- }
- // 加减处理
- var buy_number = parseInt(goods[buy_number_field]) || 0;
- if(type == 0) {
- buy_number -= 1;
- } else {
- buy_number += 1;
- }
- if(buy_number < 0) {
- buy_number = 0;
- }
-
- // 数据校验
- var buy_min_number = parseInt(goods['buy_min_number']) || 1;
- var buy_max_number = parseInt(goods['buy_max_number']) || 0;
- var spec_buy_min_number = parseInt(goods['spec_buy_min_number']) || 0;
- var spec_buy_max_number = parseInt(goods['spec_buy_max_number']) || 0;
- var inventory = parseInt(goods['inventory']);
- var inventory_unit = goods['inventory_unit'];
-
- // 最小起购数量
- var min = (spec_buy_min_number > 0) ? spec_buy_min_number : buy_min_number;
- if (min > 0) {
- if(type == 0) {
- if(buy_number < min) {
- buy_number = 0;
- }
- } else {
- if(buy_number < min) {
- buy_number = min;
- }
- }
- }
-
- // 最大购买数量
- var max = (spec_buy_max_number > 0) ? spec_buy_max_number : buy_max_number;
- if (max > 0 && buy_number > max) {
- buy_number = max;
- app.globalData.showToast('限购' + max + inventory_unit);
- return false;
- }
-
- // 数量是否改变
- if (goods[buy_number_field] == buy_number) {
- app.globalData.showToast('数量未改变');
- return false;
- }
-
- // 操作数量
- var opt_number = 1;
- if(type == 0) {
- if(buy_number <= 0) {
- opt_number = 0;
- }
- } else {
- if(buy_number > goods['buy_number']) {
- opt_number = buy_number-goods['buy_number'];
- }
- }
- return opt_number;
- },
-
- // 购物车添加
- cart_save(goods_id, buy_number, spec = '') {
- uni.request({
- url: app.globalData.get_request_url('save', 'cart'),
- method: 'POST',
- data: {
- "goods_id": goods_id,
- "stock": buy_number,
- "spec": spec
- },
- dataType: 'json',
- success: res => {
- if (res.data.code == 0) {
- this.cart_para_curve_handle();
- this.get_cart_data();
- } else {
- if (app.globalData.is_login_check(res.data)) {
- app.globalData.showToast(res.data.msg);
- }
- }
- },
- fail: () => {
- app.globalData.showToast('服务器请求出错');
- }
- });
- },
- // 购物车更新
- cart_update(cart_id, goods_id, buy_number) {
- uni.request({
- url: app.globalData.get_request_url("stock", "cart"),
- method: 'POST',
- data: {
- "id": cart_id,
- "goods_id": goods_id,
- "stock": buy_number
- },
- dataType: 'json',
- success: res => {
- if (res.data.code == 0) {
- this.cart_para_curve_handle();
- this.get_cart_data();
- } else {
- if (app.globalData.is_login_check(res.data)) {
- app.globalData.showToast(res.data.msg);
- } else {
- app.globalData.showToast('提交失败,请重试!');
- }
- }
- },
- fail: () => {
- app.globalData.showToast('服务器请求出错');
- }
- });
- },
- // 购物车删除
- cart_delete(cart_id) {
- uni.request({
- url: app.globalData.get_request_url('delete', 'cart'),
- method: 'POST',
- data: {
- "id": cart_id
- },
- dataType: 'json',
- success: res => {
- if (res.data.code == 0) {
- this.get_cart_data();
- } else {
- if (app.globalData.is_login_check(res.data)) {
- app.globalData.showToast(res.data.msg);
- } else {
- app.globalData.showToast('提交失败,请重试!');
- }
- }
- },
- fail: () => {
- app.globalData.showToast('服务器请求出错');
- }
- });
- },
- // 获取购物车数据、参数是否首次请求
- get_cart_data(is_first = 0) {
- uni.request({
- url: app.globalData.get_request_url("cartdata", "detail", "realstore"),
- method: 'POST',
- data: this.request_params_merge({
- "id": this.info.id || 0
- }, 'cart'),
- dataType: 'json',
- success: res => {
- if (res.data.code == 0) {
- this.setData({
- cart: res.data.data
- });
- this.cart_data_list_handle();
- // 首次判断是否需要开启购物车
- if(is_first == 1 && (this.params.is_show_cart || 0) == 1) {
- this.setData({
- cart_status: true
- });
- }
- } else {
- app.globalData.showToast('请求失败,请重试!');
- }
- },
- fail: () => {
- app.globalData.showToast('服务器请求出错');
- }
- });
- },
- // 购物车更新列表数据处理
- cart_data_list_handle() {
- var temp_cart = this.cart || null;
- if(temp_cart != null) {
- var temp_data_list = this.data_list;
- if(temp_data_list.length > 0) {
- for(var i in temp_data_list) {
- temp_data_list[i]['buy_number'] = 0;
- if(temp_cart.data.length > 0) {
- for(var k in temp_cart.data) {
- if(temp_cart.data[k]['goods_id'] == temp_data_list[i]['id']) {
- temp_data_list[i]['buy_number'] += parseInt(temp_cart.data[k]['stock']);
- }
- }
- }
- }
- }
- this.setData({
- data_list: temp_data_list
- });
- }
- },
- // 门店状态判断
- is_status_check() {
- if((this.info || null) == null) {
- app.globalData.showToast('门店信息有误');
- return false;
- } else {
- if(this.info.status_info.status != 1) {
- app.globalData.showToast(this.info.status_info.msg);
- return false;
- }
- }
- return true;
- },
- // 搜索事件
- search_button_event(e) {
- this.setData({
- search_keywords_value: e || '',
- data_page: 1
- });
- this.reset_scroll();
- this.get_data_list(1);
- },
- // 搜索icon扫码事件、扫码商品id实现加入购物车
- search_icon_event(e) {
- var user = app.globalData.get_user_info(this);
- if (user != false) {
- // 用户未绑定用户则转到登录页面
- if (app.globalData.user_is_need_login(user)) {
- uni.navigateTo({
- url: "/pages/login/login?event_callback=cart_buy_number_event"
- });
- return false;
- } else {
- // 门店状态
- if(!this.is_status_check()) {
- return false;
- }
- // 调用扫码
- var self = this;
- uni.scanCode({
- success: function (res) {
- uni.showLoading({
- title: '处理中...',
- mask: true
- });
- uni.request({
- url: app.globalData.get_request_url("scan", "detail", "realstore"),
- method: 'POST',
- data: self.request_params_merge({
- value: res.result
- }, 'buy'),
- dataType: 'json',
- success: res => {
- uni.hideLoading();
- if (res.data.code == 0) {
- if(res.data.data.is_error == 1) {
- app.globalData.showToast(res.data.data.is_error_msg);
- } else {
- // 加入购物车
- self.cart_save(res.data.data.goods_id, 1, res.data.data.spec);
- }
- } else {
- if (app.globalData.is_login_check(res.data)) {
- app.globalData.showToast(res.data.msg);
- } else {
- app.globalData.showToast('提交失败,请重试!');
- }
- }
- },
- fail: () => {
- uni.hideLoading();
- app.globalData.showToast('服务器请求出错');
- }
- });
- }
- });
- }
- }
- },
- // 购物车状态
- cart_event(e) {
- this.setData({
- cart_status: !this.cart_status
- });
- },
- // 购物车结算
- buy_submit_event(e) {
- if(!app.globalData.is_single_page_check()) {
- return false;
- }
- // 门店状态
- if(!this.is_status_check()) {
- return false;
- }
- // 获取购物车数据
- var ids = [];
- if((this.cart || null) != null) {
- var temp_data = this.cart.data || [];
- for (var i in temp_data) {
- ids.push(temp_data[i]['id']);
- }
- }
- if (ids.length <= 0) {
- app.globalData.showToast('请先选购商品');
- return false;
- }
- // 起步价
- var starting_price = parseFloat(this.info.starting_price) || 0;
- if(starting_price > 0 && this.cart.total_price < starting_price) {
- // 是否限制类型
- var limit_type = this.info.starting_price_limit_type_list || [];
- if(limit_type.length > 0) {
- var buy_use_type = this.info.buy_use_type_list[this.buy_use_type_index];
- if(limit_type.indexOf(buy_use_type['index']) != -1 || limit_type.indexOf(buy_use_type['index'].toString()) != -1) {
- app.globalData.showToast(buy_use_type['name']+'起步价'+starting_price+'元');
- return false;
- }
- } else {
- app.globalData.showToast('起步价'+starting_price+'元');
- return false;
- }
- }
- // 进入订单确认页面
- var data = this.request_params_merge({
- "buy_type": "cart",
- "ids": ids.join(',')
- }, 'buy');
- uni.navigateTo({
- url: '/pages/buy/buy?data=' + encodeURIComponent(base64.encode(JSON.stringify(data)))
- });
- },
- // 剪切板
- text_copy_event(e) {
- app.globalData.text_copy_event(e);
- },
- // 地图查看
- address_map_event(e) {
- var info = this.info;
- if (info.lat == 0 || info.lng == 0) {
- app.globalData.showToast("地址有误");
- return false;
- }
-
- // 打开地图
- var address = (info.province_name || '') + (info.city_name || '') + (info.county_name || '') + (info.address || '');
- app.globalData.open_location(info.lng, info.lat, info.name, address);
- },
- // 电话
- tel_event(e) {
- app.globalData.call_tel(this.info.service_tel || null);
- },
- // 图片预览
- image_show_event(e) {
- app.globalData.image_show_event(e);
- },
- // 导航事件
- nav_event(e) {
- this.setData({
- nav_active_index: e.currentTarget.dataset.index,
- nav_active_item_index: e.currentTarget.dataset.itemindex,
- data_page: 1
- });
- this.reset_scroll();
- this.get_data_list(1);
- },
-
- // 重置滑动位置
- reset_scroll() {
- this.setData({
- scroll_top: this.scroll_top_old
- });
- this.$nextTick(() => {
- this.setData({
- scroll_top: 0
- });
- });
- },
-
- // 滑动事件位置记录
- scroll_event(e) {
- this.setData({
- scroll_top_old: e.detail.scrollTop
- });
- },
-
- // 滚动加载
- scroll_lower(e) {
- this.get_data_list();
- },
-
- // 顶部返回操作
- top_nav_left_back_event(e) {
- var pages = getCurrentPages();
- if (pages.length <= 1) {
- uni.switchTab({
- url: app.globalData.data.tabbar_pages[0]
- });
- } else {
- uni.navigateBack();
- }
- },
-
- // 地址信息初始化
- user_location_init() {
- var result = uni.getStorageSync(app.globalData.data.cache_userlocation_key) || null;
- var data = null;
- if (result != null) {
- data = {
- name: result.name || null,
- address: result.address || null,
- lat: result.latitude || null,
- lng: result.longitude || null
- };
- }
- this.setData({
- user_location: data
- });
- },
- // 使用类型事件
- buy_use_type_event(e) {
- var self = this;
- uni.showActionSheet({
- itemList: this.info.buy_use_type_list.map(function(v) {return v.name}),
- success: function (res) {
- self.setData({
- buy_use_type_index: res.tapIndex,
- data_page: 1
- });
- uni.setStorageSync(self.cache_buy_use_type_index_key, res.tapIndex);
- self.reset_scroll();
- self.get_data_list(1);
- self.get_cart_data();
- }
- });
- },
- // 获取使用类型数据索引、默认在店0
- get_buy_use_type_index() {
- var index = uni.getStorageSync(this.cache_buy_use_type_index_key);
- if((this.info || null) != null) {
- // 用户未设置类型则使用默认的
- if(index === null || index === '') {
- // 是否默认类型
- if(this.info.default_buy_use_type != undefined && this.info.default_buy_use_type != -1) {
- // 不在店铺设置的类型列表则默认0
- var temp_index = null;
- for(var i in this.info.buy_use_type_list) {
- if(this.info.buy_use_type_list[i]['index'] == this.info.default_buy_use_type) {
- temp_index = i;
- }
- }
- if(temp_index !== null) {
- index = temp_index;
- }
- }
- }
- // 不在店铺设置的类型列表则默认0
- if(this.info.buy_use_type_list[index] == undefined) {
- index = 0;
- }
- }
- return index || 0;
- },
- // 请求参数处理
- // 默认增加使用类型参数
- // 下单 buy / 初始化 init / 获取数据 data / 获取购物车 cart
- request_params_merge(data, type = 'init') {
- // 用户使用类型
- var index = this.buy_use_type_index;
- if((this.info || null) != null && (this.info.buy_use_type_list || null) != null && this.info.buy_use_type_list.length > 0) {
- if(this.info.buy_use_type_list[index] == undefined) {
- index = 0;
- }
- data['buy_use_type_index'] = this.buy_use_type_index;
- }
- // 初始化
- if(type == 'init') {
- // 桌码
- if((this.params.tablecode_id || null) != null) {
- data['tablecode_id'] = this.params.tablecode_id;
- }
- }
- // 初始化、获取数据
- if(type == 'init' || type == 'data' || type == 'cart') {
- // 用户选择的位置
- var lng = 0;
- var lat = 0;
- if((this.user_location || null) != null) {
- lng = this.user_location.lng || 0;
- lat = this.user_location.lat || 0;
- }
- data['lng'] = lng;
- data['lat'] = lat;
- }
- // 提交订单
- if(type == 'buy') {
- // 门店id
- data['realstore_id'] = this.info.id;
- // 桌码
- if((this.tablecode || null) != null) {
- data['tablecode_id'] = this.tablecode.id;
- }
- }
- return data;
- },
- // url事件
- url_event(e) {
- app.globalData.url_event(e);
- }
- }
- };
- </script>
- <style>
- @import './detail.css';
- </style>
|