detail.vue 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. <template>
  2. <view>
  3. <view v-if="(info || null) != null">
  4. <view class="pr">
  5. <!-- 头部 -->
  6. <view class="header" :style="'background-image: url('+info.banner+');'">
  7. <!-- 顶部 -->
  8. <view v-if="is_single_page == 0" class="header-top padding-horizontal-main" :style="'padding-top:'+(status_bar_height+8)+'px;'">
  9. <!-- 返回 -->
  10. <!-- #ifdef MP-WEIXIN || MP-QQ || MP-KUAISHOU || H5 || APP -->
  11. <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">
  12. <uni-icons type="arrowleft" size="20" color="#fff"></uni-icons>
  13. </view>
  14. <!-- #endif -->
  15. <!-- 搜索 -->
  16. <view :class="'fr va-m '+(is_realstore_top_nav_back == 1 ? 'nav-search' : 'wh-auto')">
  17. <!-- #ifndef H5 -->
  18. <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>
  19. <!-- #endif -->
  20. <!-- #ifdef H5 -->
  21. <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>
  22. <!-- #endif -->
  23. </view>
  24. </view>
  25. <!-- 桌码 -->
  26. <view v-if="(tablecode || null) != null" class="tablecode dis-inline-block margin-left-main round cr-red">
  27. {{tablecode.name}}({{tablecode.code}})
  28. </view>
  29. </view>
  30. <!-- 头部基础内容 -->
  31. <view class="header-content margin-main padding-main border-radius-main bg-white pa br">
  32. <view class="base oh">
  33. <!-- 基础内容 -->
  34. <image :src="info.logo" mode="widthFix" class="logo circle fl br" :data-value="info.logo" @tap="image_show_event"></image>
  35. <view class="base-right fr">
  36. <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">
  37. <text class="va-m margin-right-xs">{{info.buy_use_type_list[buy_use_type_index]['name']}}</text>
  38. <view class="dis-inline-block va-m">
  39. <uni-icons type="arrowdown" size="32rpx" color="#fff"></uni-icons>
  40. </view>
  41. </view>
  42. <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' : '')">
  43. <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>
  44. <text class="va-m">{{info.name}}</text>
  45. </view>
  46. <view class="margin-top-xs text-size-xs cr-grey">
  47. <view v-if="(info.status_info.time || null) != null">营业时间:{{info.status_info.time}}</view>
  48. <view v-if="(info.distance || null) != null">距离您{{info.distance}}</view>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 地址 -->
  53. <view class="margin-top-sm oh cp">
  54. <view class="dis-inline-block va-m">
  55. <uni-icons type="location-filled" size="32rpx" color="#8d8d8d"></uni-icons>
  56. </view>
  57. <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>
  58. </view>
  59. <!-- 右侧操作 -->
  60. <view class="icon-list pa">
  61. <!-- #ifndef MP-KUAISHOU -->
  62. <view v-if="(info.lat != 0 && info.lng != 0)" class="icon-item bg-green circle dis-inline-block tc cp" @tap="address_map_event">
  63. <uni-icons type="paperplane-filled" size="32rpx" color="#fff"></uni-icons>
  64. </view>
  65. <!-- #endif -->
  66. <view v-if="(info.service_tel || null) != null" class="icon-item bg-yellow circle dis-inline-block tc cp" @tap="tel_event">
  67. <uni-icons type="phone-filled" size="32rpx" color="#fff"></uni-icons>
  68. </view>
  69. <view :class="'icon-item circle dis-inline-block tc cp pr '+((favor_info.status == 1) ? 'bg-red' : 'bg-gray')" @tap="favor_event">
  70. <uni-icons type="heart-filled" size="32rpx" color="#fff"></uni-icons>
  71. <view class="badge-icon pa">
  72. <component-badge :propNumber="favor_info.count"></component-badge>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 内容 -->
  79. <view class="content oh">
  80. <!-- 左侧 -->
  81. <scroll-view :scroll-y="true" class="left-content fl ht-auto bg-white">
  82. <view class="left-content-actual">
  83. <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>
  84. <block v-if="(goods_category || null) != null && goods_category.length > 0">
  85. <block v-for="(item, index) in goods_category" :key="index">
  86. <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">
  87. <text>{{item.name}}</text>
  88. <view v-if="(item.buy_number || 0) > 0" class="badge-icon pa">
  89. <component-badge :propNumber="item.buy_number"></component-badge>
  90. </view>
  91. </view>
  92. </block>
  93. </block>
  94. </view>
  95. </scroll-view>
  96. <!-- 右侧 -->
  97. <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">
  98. <view class="right-content-actual pr">
  99. <!-- 二级分类 -->
  100. <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">
  101. <scroll-view :scroll-x="true" :scroll-with-animation="true" :scroll-into-view="'two-nav-item-'+nav_active_item_index">
  102. <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>
  103. <block v-for="(cv, ci) in goods_category[nav_active_index]['items']" :key="ci">
  104. <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>
  105. </block>
  106. </scroll-view>
  107. </view>
  108. <!-- 右侧商品列表 -->
  109. <block v-if="(data_list || null) != null && data_list.length > 0">
  110. <view v-for="(item, index) in data_list" :key="index" class="item bg-white padding-main border-radius-main oh spacing-mb">
  111. <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">
  112. <image :src="item.images" mode="widthFix" class="goods-img radius fl br"></image>
  113. <view class="goods-base fr">
  114. <view class="goods-base-content">
  115. <view class="goods-title text-size-sm single-text">{{item.title}}</view>
  116. <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>
  117. </view>
  118. <view class="margin-top-sm oh">
  119. <view class="sales-price text-size-sm single-text dis-inline-block va-m">{{currency_symbol}}{{item.min_price}}</view>
  120. <view class="tc fr">
  121. <block v-if="(item.is_error || 0) == 0">
  122. <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">
  123. <uni-icons type="minus" size="22" color="#f00"></uni-icons>
  124. </view>
  125. <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>
  126. <view class="dis-inline-block va-m cp" :data-index="index" data-type="1" @tap.stop="buy_number_event">
  127. <uni-icons type="plus" size="22" color="#1AAD19"></uni-icons>
  128. </view>
  129. </block>
  130. <block v-else>
  131. <text class="cr-grey text-size-xs">{{item.is_error_msg}}</text>
  132. </block>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. </view>
  138. </block>
  139. <block v-else>
  140. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  141. </block>
  142. </view>
  143. </scroll-view>
  144. </view>
  145. <!-- 购物车列表 -->
  146. <block v-if="cart_status">
  147. <view class="cart-mask wh-auto ht-auto pf" @tap="cart_event"></view>
  148. <view class="cart-content bg-white border-radius-main pa oh">
  149. <block v-if="(cart || null) != null && (cart.data || null) != null && cart.data.length > 0">
  150. <view class="oh br-b padding-vertical-main padding-horizontal-main">
  151. <text class="va-m text-size-xs cr-base">已选商品</text>
  152. <view class="dis-inline-block margin-left-xl text-size-xs">
  153. <text class="cr-red">没有已加购的商品?</text>
  154. <text class="br-green cr-green round padding-left padding-right padding-top-xs padding-bottom-xs cp" @tap="buy_use_type_event">切换下单类型</text>
  155. </view>
  156. <view class="fr cp" @tap="cart_all_delete_event">
  157. <view class="dis-inline-block va-m">
  158. <uni-icons type="trash" size="12" color="#f00"></uni-icons>
  159. </view>
  160. <text class="cr-red va-m text-size-xs margin-left-xs">清空</text>
  161. </view>
  162. </view>
  163. <scroll-view :scroll-y="true" class="cart-list goods-list">
  164. <view v-for="(goods, index) in cart.data" :key="index" class="item padding-main oh spacing-mb">
  165. <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">
  166. <image :src="goods.images" mode="widthFix" class="goods-img radius fl br"></image>
  167. <view class="goods-base fr">
  168. <view class="goods-base-content">
  169. <view class="goods-title text-size-sm single-text">{{goods.title}}</view>
  170. <view v-if="goods.spec != null" class="text-size-xs cr-grey margin-top-sm">
  171. <block v-for="(sv, si) in goods.spec" :key="si">
  172. <text v-if="si > 0" class="padding-left-xs padding-right-xs">;</text>
  173. <text>{{sv.value}}</text>
  174. </block>
  175. </view>
  176. </view>
  177. <view class="margin-top-sm oh">
  178. <view class="sales-price text-size-sm single-text dis-inline-block va-m">{{currency_symbol}}{{goods.price}}</view>
  179. <view class="tc fr">
  180. <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">
  181. <uni-icons type="minus" size="22" color="#f00"></uni-icons>
  182. </view>
  183. <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>
  184. <view class="dis-inline-block va-m cp" :data-index="index" data-type="1" @tap.stop="cart_buy_number_event">
  185. <uni-icons type="plus" size="22" color="#1AAD19"></uni-icons>
  186. </view>
  187. </view>
  188. </view>
  189. </view>
  190. </navigator>
  191. </view>
  192. </scroll-view>
  193. </block>
  194. <block v-else>
  195. <component-no-data propStatus="0" propMsg="请先选购商品"></component-no-data>
  196. <view class="padding-bottom-xxxl margin-bottom-xxxl tc text-size-xs margin-top-xxl">
  197. <text class="cr-red">没有已加购的商品?</text>
  198. <text class="br-green cr-green round padding-left padding-right padding-top-xs padding-bottom-xs cp" @tap="buy_use_type_event">切换下单类型</text>
  199. </view>
  200. </block>
  201. </view>
  202. </block>
  203. <!-- 购物车底部导航 -->
  204. <view class="botton-nav round pa bg-main-pair oh">
  205. <view class="cart dis-inline-block va-m margin-left-xxl pr cp" @tap="cart_event">
  206. <uni-icons type="cart" size="32rpx" color="#fff"></uni-icons>
  207. <view v-if="(cart || null) != null && (cart.buy_number || 0) > 0" class="badge-icon pa">
  208. <component-badge :propNumber="cart.buy_number"></component-badge>
  209. </view>
  210. </view>
  211. <view class="cart-total-price single-text dis-inline-block fw-b cr-white va-m margin-left-xl">
  212. <text class="text-size-sm">{{currency_symbol}}</text>
  213. <text class="text-size-lg">{{(cart || null) == null ? 0 : (cart.total_price || 0)}}</text>
  214. </view>
  215. <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>
  216. </view>
  217. <!-- 购物车抛物线 -->
  218. <component-cart-para-curve ref="cart_para_curve"></component-cart-para-curve>
  219. <!-- 商品购买 -->
  220. <component-goods-buy ref="goods_buy" v-on:CartSuccessEvent="goods_cart_back_event"></component-goods-buy>
  221. </view>
  222. <view v-else>
  223. <!-- 提示信息 -->
  224. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  225. </view>
  226. </view>
  227. </template>
  228. <script>
  229. const app = getApp();
  230. import base64 from '../../../../common/js/lib/base64.js';
  231. import componentGoodsBuy from "../../../../components/goods-buy/goods-buy";
  232. import componentNoData from "../../../../components/no-data/no-data";
  233. import componentSearch from "../../../../components/search/search";
  234. import componentBadge from "../../../../components/badge/badge";
  235. import componentPopup from "../../../../components/popup/popup";
  236. import componentCartParaCurve from '../../../../components/cart-para-curve/cart-para-curve';
  237. var common_static_url = app.globalData.get_static_url('common');
  238. export default {
  239. data() {
  240. return {
  241. status_bar_height: parseInt(app.globalData.get_system_info('statusBarHeight', 0)),
  242. common_static_url: common_static_url,
  243. data_list_loding_status: 1,
  244. data_list_loding_msg: '',
  245. currency_symbol: app.globalData.data.currency_symbol,
  246. cache_buy_use_type_index_key: 'cache_plugins_realstore_buy_use_type_index',
  247. buy_use_type_index: 0,
  248. params: null,
  249. is_first: 1,
  250. scroll_top: 0,
  251. scroll_top_old: 0,
  252. user: null,
  253. info: null,
  254. goods_category: [],
  255. data_list: [],
  256. data_total: 0,
  257. data_page_total: 0,
  258. data_page: 1,
  259. cart: null,
  260. goods_count: 0,
  261. data_base: null,
  262. favor_user: [],
  263. tablecode: null,
  264. category: [],
  265. goods_list: [],
  266. search_keywords_value: '',
  267. nav_active_index: -1,
  268. nav_active_item_index: -1,
  269. cart_status: false,
  270. popup_spec_status: false,
  271. goods_choose_data: {},
  272. // 收藏信息
  273. favor_info: {
  274. "text": "收藏",
  275. "status": 0,
  276. "count": 0
  277. },
  278. // 用户位置信息
  279. user_location: null,
  280. // 自定义分享信息
  281. share_info: {},
  282. // 是否单页预览
  283. is_single_page: app.globalData.is_current_single_page() || 0,
  284. // 顶部导航返回按钮
  285. is_realstore_top_nav_back: app.globalData.data.is_realstore_top_nav_back || 0,
  286. is_realstore_top_search_scan: app.globalData.data.is_realstore_top_search_scan || 0,
  287. // 临时操作数据
  288. temp_opt_data: null,
  289. };
  290. },
  291. components: {
  292. componentGoodsBuy,
  293. componentNoData,
  294. componentSearch,
  295. componentBadge,
  296. componentPopup,
  297. componentCartParaCurve
  298. },
  299. props: {},
  300. onLoad(params) {
  301. this.setData({
  302. params: app.globalData.launch_params_handle(params),
  303. user: app.globalData.get_user_cache_info()
  304. });
  305. },
  306. onShow() {
  307. // 类型选择
  308. this.setData({
  309. buy_use_type_index: this.get_buy_use_type_index()
  310. });
  311. // 用户位置初始化
  312. this.user_location_init();
  313. // 获取数据
  314. this.get_detail_init();
  315. // 初始化配置
  316. this.init_config();
  317. },
  318. // 下拉刷新
  319. onPullDownRefresh() {
  320. this.setData({
  321. data_page: 1
  322. });
  323. this.reset_scroll();
  324. this.get_detail_init();
  325. },
  326. methods: {
  327. // 初始化配置
  328. init_config(status) {
  329. if ((status || false) == true) {
  330. this.setData({
  331. currency_symbol: app.globalData.get_config('currency_symbol')
  332. });
  333. } else {
  334. app.globalData.is_config(this, 'init_config');
  335. }
  336. },
  337. // 获取数据-初始化
  338. get_detail_init() {
  339. uni.request({
  340. url: app.globalData.get_request_url("index", "detail", "realstore"),
  341. method: 'POST',
  342. data: this.request_params_merge({
  343. "id": this.params.id || 0
  344. }, 'init'),
  345. dataType: 'json',
  346. success: res => {
  347. uni.stopPullDownRefresh();
  348. if (res.data.code == 0) {
  349. var data = res.data.data;
  350. this.setData({
  351. data_base: data.base || null,
  352. info: data.info || null,
  353. goods_category: data.goods_category || [],
  354. favor_user: data.favor_user || [],
  355. tablecode: data.tablecode || null
  356. });
  357. // 下单类型是否存在索引
  358. this.setData({
  359. buy_use_type_index: this.get_buy_use_type_index()
  360. });
  361. // 收藏处理
  362. if ((this.info || null) != null) {
  363. // 收藏信息
  364. var status = this.favor_user.indexOf(this.info.id) != -1 ? 1 : 0;
  365. this.setData({
  366. favor_info: {
  367. "count": this.info.favor_count || 0,
  368. "status": status,
  369. "text": (status == 1 ? '已' : '') + '收藏'
  370. }
  371. });
  372. // 基础自定义分享
  373. this.setData({
  374. share_info: {
  375. title: this.info.seo_title || this.info.name,
  376. desc: this.info.seo_desc || this.info.describe,
  377. path: '/pages/plugins/realstore/detail/detail',
  378. query: 'id='+this.info.id,
  379. img: this.info.logo
  380. }
  381. });
  382. // 标题名称
  383. uni.setNavigationBarTitle({
  384. title: this.info.name
  385. });
  386. // 获取数据、仅首次调用
  387. // 获取列表接口和购物车
  388. if(this.is_first == 1) {
  389. this.get_data_list();
  390. this.get_cart_data(this.is_first);
  391. this.setData({is_first: 0});
  392. } else {
  393. // 非首次赋值购物车数据
  394. this.setData({
  395. cart: data.cart || null,
  396. });
  397. // 购物车更新列表数据处理
  398. this.cart_data_list_handle();
  399. }
  400. }
  401. } else {
  402. this.setData({
  403. data_list_loding_status: 2,
  404. data_list_loding_msg: res.data.msg
  405. });
  406. }
  407. // 分享菜单处理
  408. app.globalData.page_share_handle(this.share_info);
  409. },
  410. fail: () => {
  411. uni.stopPullDownRefresh();
  412. this.setData({
  413. data_list_loding_status: 2,
  414. data_list_loding_msg: '服务器请求出错'
  415. });
  416. app.globalData.showToast('服务器请求出错');
  417. }
  418. });
  419. },
  420. // 获取数据-商品列表
  421. get_data_list(is_mandatory) {
  422. // 分页是否还有数据
  423. if ((is_mandatory || 0) == 0) {
  424. if (this.data_bottom_line_status == true) {
  425. uni.stopPullDownRefresh();
  426. return false;
  427. }
  428. }
  429. // 加载loding
  430. uni.showLoading({
  431. title: '加载中...',
  432. mask: true
  433. });
  434. // 分类id
  435. var temp_category = this.goods_category;
  436. if(this.nav_active_item_index != -1) {
  437. var category_id = temp_category[this.nav_active_index]['items'][this.nav_active_item_index]['id'];
  438. } else {
  439. var category_id = (this.nav_active_index == -1) ? 0 : temp_category[this.nav_active_index]['id'];
  440. }
  441. // 获取数据
  442. uni.request({
  443. url: app.globalData.get_request_url("datalist", "detail", "realstore"),
  444. method: 'POST',
  445. data: this.request_params_merge({
  446. id: this.info.id || 0,
  447. page: this.data_page,
  448. keywords: this.search_keywords_value,
  449. category_id: category_id
  450. }, 'data'),
  451. dataType: 'json',
  452. success: res => {
  453. uni.hideLoading();
  454. uni.stopPullDownRefresh();
  455. if (res.data.code == 0) {
  456. var data = res.data.data;
  457. if (data.data.length > 0) {
  458. if (this.data_page <= 1) {
  459. var temp_data_list = data.data;
  460. } else {
  461. var temp_data_list = this.data_list || [];
  462. var temp_data = data.data;
  463. for (var i in temp_data) {
  464. temp_data_list.push(temp_data[i]);
  465. }
  466. }
  467. this.setData({
  468. data_list: temp_data_list,
  469. data_total: data.total,
  470. data_page_total: data.page_total,
  471. data_list_loding_status: 3,
  472. data_page: this.data_page + 1
  473. });
  474. // 是否还有数据
  475. this.setData({
  476. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  477. });
  478. } else {
  479. this.setData({
  480. data_list_loding_status: 0
  481. });
  482. if (this.data_page <= 1) {
  483. this.setData({
  484. data_list: [],
  485. data_bottom_line_status: false
  486. });
  487. }
  488. }
  489. } else {
  490. this.setData({
  491. data_list_loding_status: 0,
  492. data_list_loding_msg: res.data.msg
  493. });
  494. app.globalData.showToast(res.data.msg);
  495. }
  496. },
  497. fail: () => {
  498. uni.hideLoading();
  499. uni.stopPullDownRefresh();
  500. this.setData({
  501. data_list_loding_status: 2,
  502. data_list_loding_msg: '服务器请求出错'
  503. });
  504. app.globalData.showToast('服务器请求出错');
  505. }
  506. });
  507. },
  508. // 收藏事件
  509. favor_event(e) {
  510. if(!app.globalData.is_single_page_check()) {
  511. return false;
  512. }
  513. var user = app.globalData.get_user_info(this, 'favor_event');
  514. if (user != false) {
  515. // 用户未绑定用户则转到登录页面
  516. if (app.globalData.user_is_need_login(user)) {
  517. uni.navigateTo({
  518. url: "/pages/login/login?event_callback=favor_event"
  519. });
  520. return false;
  521. } else {
  522. uni.showLoading({
  523. title: '处理中...'
  524. });
  525. uni.request({
  526. url: app.globalData.get_request_url("reversal", "favor", "realstore"),
  527. method: 'POST',
  528. data: {
  529. "id": this.info.id
  530. },
  531. dataType: 'json',
  532. success: res => {
  533. uni.hideLoading();
  534. if (res.data.code == 0) {
  535. this.setData({
  536. favor_info: res.data.data
  537. });
  538. app.globalData.showToast(res.data.msg, 'success');
  539. } else {
  540. if (app.globalData.is_login_check(res.data, this, 'favor_event')) {
  541. app.globalData.showToast(res.data.msg);
  542. }
  543. }
  544. },
  545. fail: () => {
  546. uni.hideLoading();
  547. app.globalData.showToast('服务器请求出错');
  548. }
  549. });
  550. }
  551. }
  552. },
  553. // 列表数据操作
  554. buy_number_event(e) {
  555. if(!app.globalData.is_single_page_check()) {
  556. return false;
  557. }
  558. var user = app.globalData.get_user_info(this);
  559. if (user != false) {
  560. // 用户未绑定用户则转到登录页面
  561. if (app.globalData.user_is_need_login(user)) {
  562. uni.navigateTo({
  563. url: "/pages/login/login?event_callback=buy_number_event"
  564. });
  565. return false;
  566. } else {
  567. var index = e.currentTarget.dataset.index;
  568. var type = parseInt(e.currentTarget.dataset.type) || 0;
  569. var temp_goods = this.data_list[index];
  570. this.setData({goods_choose_data: temp_goods});
  571. // 是否存在多规格
  572. if((temp_goods.is_exist_many_spec || 0) != 0) {
  573. // 是否购物车中操作
  574. if(type == 0) {
  575. this.setData({
  576. cart_status: true
  577. });
  578. app.globalData.showToast('不同规格的商品需在购物车减购');
  579. } else {
  580. if((this.$refs.goods_buy || null) != null) {
  581. var buy_params = this.params;
  582. buy_params['buy_event_type'] = 'cart';
  583. buy_params['buy_use_type_index'] = this.buy_use_type_index;
  584. buy_params['realstore_id'] = this.info.id;
  585. this.$refs.goods_buy.init(temp_goods, buy_params);
  586. }
  587. }
  588. return false;
  589. }
  590. // 数据操作处理
  591. this.buy_number_event_handle(e, type, temp_goods);
  592. }
  593. }
  594. },
  595. // 加入购物车成功回调
  596. goods_cart_back_event(e) {
  597. // 重新获取购物车数据
  598. this.get_cart_data();
  599. },
  600. // 列表数量事件处理
  601. buy_number_event_handle(e, type, goods, spec = '') {
  602. var res = this.buy_number_handle(type, goods, 'buy_number');
  603. if(res === false) {
  604. return false;
  605. }
  606. // 数据临时记录
  607. this.setData({
  608. temp_opt_data: {
  609. pos: e,
  610. goods: goods,
  611. type: type,
  612. }
  613. });
  614. // 为0或减操作则查询
  615. var cart_item = null;
  616. if(type == 0 || (type == 1 && goods['buy_number'] > 0)) {
  617. var cart_data = this.cart.data;
  618. var params_spec = ((spec || null) == null || typeof(spec) != 'object') ? '' : JSON.stringify(spec);
  619. for(var i in cart_data) {
  620. if(goods['id'] == cart_data[i]['goods_id']) {
  621. var cart_spec = ((cart_data[i]['spec'] || null) == null || typeof(cart_data[i]['spec']) != 'object') ? '' : JSON.stringify(cart_data[i]['spec']);
  622. if(type == 0 || (type == 1 && cart_spec == params_spec)) {
  623. cart_item = cart_data[i];
  624. }
  625. break;
  626. }
  627. }
  628. }
  629. // 操作类型
  630. if(res == 0) {
  631. if(cart_item == null) {
  632. app.globalData.showToast('购物车id有误');
  633. return false;
  634. }
  635. this.cart_delete(cart_item.id);
  636. } else if(cart_item == null) {
  637. this.cart_save(goods['id'], res, spec);
  638. } else {
  639. var number = (type == 0) ? parseInt(cart_item['stock'])-res : res+parseInt(cart_item['stock']);
  640. this.cart_update(cart_item.id, goods['id'], number);
  641. }
  642. return true;
  643. },
  644. // 购物车抛物线动画
  645. cart_para_curve_handle() {
  646. if((this.temp_opt_data || null) != null && (this.temp_opt_data.type || 0) == 1) {
  647. if((this.$refs.cart_para_curve || null) != null) {
  648. var self = this;
  649. uni.createSelectorQuery().select('.botton-nav .cart').boundingClientRect().exec(function(res) {
  650. self.$refs.cart_para_curve.init(res, self.temp_opt_data.pos, self.temp_opt_data.goods.images);
  651. });
  652. }
  653. }
  654. },
  655. // 购物车数量操作
  656. cart_buy_number_event(e) {
  657. if(!app.globalData.is_single_page_check()) {
  658. return false;
  659. }
  660. var user = app.globalData.get_user_info(this);
  661. if (user != false) {
  662. // 用户未绑定用户则转到登录页面
  663. if (app.globalData.user_is_need_login(user)) {
  664. uni.navigateTo({
  665. url: "/pages/login/login?event_callback=cart_buy_number_event"
  666. });
  667. return false;
  668. } else {
  669. var index = e.currentTarget.dataset.index;
  670. var type = parseInt(e.currentTarget.dataset.type) || 0;
  671. var temp_data = this.cart.data;
  672. var temp_goods = temp_data[index];
  673. // 数据操作处理
  674. var res = this.buy_number_handle(type, temp_goods, 'stock');
  675. if(res === false) {
  676. return false;
  677. }
  678. // 数据临时记录
  679. this.setData({
  680. temp_opt_data: {
  681. pos: e,
  682. goods: temp_goods,
  683. type: type,
  684. }
  685. });
  686. // 操作类型
  687. if(res == 0) {
  688. this.cart_delete(temp_goods['id']);
  689. } else {
  690. var number = (type == 0) ? parseInt(temp_goods['stock'])-res : res+parseInt(temp_goods['stock']);
  691. this.cart_update(temp_goods['id'], temp_goods['goods_id'], number);
  692. }
  693. }
  694. }
  695. },
  696. // 批量删除操作
  697. cart_all_delete_event(e) {
  698. uni.showModal({
  699. title: '温馨提示',
  700. content: '挑了这么久,真的要清空吗?',
  701. confirmText: '确认',
  702. cancelText: '暂不',
  703. success: result => {
  704. if (result.confirm) {
  705. var ids = [];
  706. var temp_data = this.cart.data;
  707. for (var i in temp_data) {
  708. ids.push(temp_data[i]['id']);
  709. }
  710. this.cart_delete(ids.join(','));
  711. }
  712. }
  713. });
  714. },
  715. // 数量操作处理
  716. buy_number_handle(type, goods, buy_number_field) {
  717. // 门店状态
  718. if(type == 1 && !this.is_status_check()) {
  719. return false;
  720. }
  721. // 加减处理
  722. var buy_number = parseInt(goods[buy_number_field]) || 0;
  723. if(type == 0) {
  724. buy_number -= 1;
  725. } else {
  726. buy_number += 1;
  727. }
  728. if(buy_number < 0) {
  729. buy_number = 0;
  730. }
  731. // 数据校验
  732. var buy_min_number = parseInt(goods['buy_min_number']) || 1;
  733. var buy_max_number = parseInt(goods['buy_max_number']) || 0;
  734. var spec_buy_min_number = parseInt(goods['spec_buy_min_number']) || 0;
  735. var spec_buy_max_number = parseInt(goods['spec_buy_max_number']) || 0;
  736. var inventory = parseInt(goods['inventory']);
  737. var inventory_unit = goods['inventory_unit'];
  738. // 最小起购数量
  739. var min = (spec_buy_min_number > 0) ? spec_buy_min_number : buy_min_number;
  740. if (min > 0) {
  741. if(type == 0) {
  742. if(buy_number < min) {
  743. buy_number = 0;
  744. }
  745. } else {
  746. if(buy_number < min) {
  747. buy_number = min;
  748. }
  749. }
  750. }
  751. // 最大购买数量
  752. var max = (spec_buy_max_number > 0) ? spec_buy_max_number : buy_max_number;
  753. if (max > 0 && buy_number > max) {
  754. buy_number = max;
  755. app.globalData.showToast('限购' + max + inventory_unit);
  756. return false;
  757. }
  758. // 数量是否改变
  759. if (goods[buy_number_field] == buy_number) {
  760. app.globalData.showToast('数量未改变');
  761. return false;
  762. }
  763. // 操作数量
  764. var opt_number = 1;
  765. if(type == 0) {
  766. if(buy_number <= 0) {
  767. opt_number = 0;
  768. }
  769. } else {
  770. if(buy_number > goods['buy_number']) {
  771. opt_number = buy_number-goods['buy_number'];
  772. }
  773. }
  774. return opt_number;
  775. },
  776. // 购物车添加
  777. cart_save(goods_id, buy_number, spec = '') {
  778. uni.request({
  779. url: app.globalData.get_request_url('save', 'cart'),
  780. method: 'POST',
  781. data: {
  782. "goods_id": goods_id,
  783. "stock": buy_number,
  784. "spec": spec
  785. },
  786. dataType: 'json',
  787. success: res => {
  788. if (res.data.code == 0) {
  789. this.cart_para_curve_handle();
  790. this.get_cart_data();
  791. } else {
  792. if (app.globalData.is_login_check(res.data)) {
  793. app.globalData.showToast(res.data.msg);
  794. }
  795. }
  796. },
  797. fail: () => {
  798. app.globalData.showToast('服务器请求出错');
  799. }
  800. });
  801. },
  802. // 购物车更新
  803. cart_update(cart_id, goods_id, buy_number) {
  804. uni.request({
  805. url: app.globalData.get_request_url("stock", "cart"),
  806. method: 'POST',
  807. data: {
  808. "id": cart_id,
  809. "goods_id": goods_id,
  810. "stock": buy_number
  811. },
  812. dataType: 'json',
  813. success: res => {
  814. if (res.data.code == 0) {
  815. this.cart_para_curve_handle();
  816. this.get_cart_data();
  817. } else {
  818. if (app.globalData.is_login_check(res.data)) {
  819. app.globalData.showToast(res.data.msg);
  820. } else {
  821. app.globalData.showToast('提交失败,请重试!');
  822. }
  823. }
  824. },
  825. fail: () => {
  826. app.globalData.showToast('服务器请求出错');
  827. }
  828. });
  829. },
  830. // 购物车删除
  831. cart_delete(cart_id) {
  832. uni.request({
  833. url: app.globalData.get_request_url('delete', 'cart'),
  834. method: 'POST',
  835. data: {
  836. "id": cart_id
  837. },
  838. dataType: 'json',
  839. success: res => {
  840. if (res.data.code == 0) {
  841. this.get_cart_data();
  842. } else {
  843. if (app.globalData.is_login_check(res.data)) {
  844. app.globalData.showToast(res.data.msg);
  845. } else {
  846. app.globalData.showToast('提交失败,请重试!');
  847. }
  848. }
  849. },
  850. fail: () => {
  851. app.globalData.showToast('服务器请求出错');
  852. }
  853. });
  854. },
  855. // 获取购物车数据、参数是否首次请求
  856. get_cart_data(is_first = 0) {
  857. uni.request({
  858. url: app.globalData.get_request_url("cartdata", "detail", "realstore"),
  859. method: 'POST',
  860. data: this.request_params_merge({
  861. "id": this.info.id || 0
  862. }, 'cart'),
  863. dataType: 'json',
  864. success: res => {
  865. if (res.data.code == 0) {
  866. this.setData({
  867. cart: res.data.data
  868. });
  869. this.cart_data_list_handle();
  870. // 首次判断是否需要开启购物车
  871. if(is_first == 1 && (this.params.is_show_cart || 0) == 1) {
  872. this.setData({
  873. cart_status: true
  874. });
  875. }
  876. } else {
  877. app.globalData.showToast('请求失败,请重试!');
  878. }
  879. },
  880. fail: () => {
  881. app.globalData.showToast('服务器请求出错');
  882. }
  883. });
  884. },
  885. // 购物车更新列表数据处理
  886. cart_data_list_handle() {
  887. var temp_cart = this.cart || null;
  888. if(temp_cart != null) {
  889. var temp_data_list = this.data_list;
  890. if(temp_data_list.length > 0) {
  891. for(var i in temp_data_list) {
  892. temp_data_list[i]['buy_number'] = 0;
  893. if(temp_cart.data.length > 0) {
  894. for(var k in temp_cart.data) {
  895. if(temp_cart.data[k]['goods_id'] == temp_data_list[i]['id']) {
  896. temp_data_list[i]['buy_number'] += parseInt(temp_cart.data[k]['stock']);
  897. }
  898. }
  899. }
  900. }
  901. }
  902. this.setData({
  903. data_list: temp_data_list
  904. });
  905. }
  906. },
  907. // 门店状态判断
  908. is_status_check() {
  909. if((this.info || null) == null) {
  910. app.globalData.showToast('门店信息有误');
  911. return false;
  912. } else {
  913. if(this.info.status_info.status != 1) {
  914. app.globalData.showToast(this.info.status_info.msg);
  915. return false;
  916. }
  917. }
  918. return true;
  919. },
  920. // 搜索事件
  921. search_button_event(e) {
  922. this.setData({
  923. search_keywords_value: e || '',
  924. data_page: 1
  925. });
  926. this.reset_scroll();
  927. this.get_data_list(1);
  928. },
  929. // 搜索icon扫码事件、扫码商品id实现加入购物车
  930. search_icon_event(e) {
  931. var user = app.globalData.get_user_info(this);
  932. if (user != false) {
  933. // 用户未绑定用户则转到登录页面
  934. if (app.globalData.user_is_need_login(user)) {
  935. uni.navigateTo({
  936. url: "/pages/login/login?event_callback=cart_buy_number_event"
  937. });
  938. return false;
  939. } else {
  940. // 门店状态
  941. if(!this.is_status_check()) {
  942. return false;
  943. }
  944. // 调用扫码
  945. var self = this;
  946. uni.scanCode({
  947. success: function (res) {
  948. uni.showLoading({
  949. title: '处理中...',
  950. mask: true
  951. });
  952. uni.request({
  953. url: app.globalData.get_request_url("scan", "detail", "realstore"),
  954. method: 'POST',
  955. data: self.request_params_merge({
  956. value: res.result
  957. }, 'buy'),
  958. dataType: 'json',
  959. success: res => {
  960. uni.hideLoading();
  961. if (res.data.code == 0) {
  962. if(res.data.data.is_error == 1) {
  963. app.globalData.showToast(res.data.data.is_error_msg);
  964. } else {
  965. // 加入购物车
  966. self.cart_save(res.data.data.goods_id, 1, res.data.data.spec);
  967. }
  968. } else {
  969. if (app.globalData.is_login_check(res.data)) {
  970. app.globalData.showToast(res.data.msg);
  971. } else {
  972. app.globalData.showToast('提交失败,请重试!');
  973. }
  974. }
  975. },
  976. fail: () => {
  977. uni.hideLoading();
  978. app.globalData.showToast('服务器请求出错');
  979. }
  980. });
  981. }
  982. });
  983. }
  984. }
  985. },
  986. // 购物车状态
  987. cart_event(e) {
  988. this.setData({
  989. cart_status: !this.cart_status
  990. });
  991. },
  992. // 购物车结算
  993. buy_submit_event(e) {
  994. if(!app.globalData.is_single_page_check()) {
  995. return false;
  996. }
  997. // 门店状态
  998. if(!this.is_status_check()) {
  999. return false;
  1000. }
  1001. // 获取购物车数据
  1002. var ids = [];
  1003. if((this.cart || null) != null) {
  1004. var temp_data = this.cart.data || [];
  1005. for (var i in temp_data) {
  1006. ids.push(temp_data[i]['id']);
  1007. }
  1008. }
  1009. if (ids.length <= 0) {
  1010. app.globalData.showToast('请先选购商品');
  1011. return false;
  1012. }
  1013. // 起步价
  1014. var starting_price = parseFloat(this.info.starting_price) || 0;
  1015. if(starting_price > 0 && this.cart.total_price < starting_price) {
  1016. // 是否限制类型
  1017. var limit_type = this.info.starting_price_limit_type_list || [];
  1018. if(limit_type.length > 0) {
  1019. var buy_use_type = this.info.buy_use_type_list[this.buy_use_type_index];
  1020. if(limit_type.indexOf(buy_use_type['index']) != -1 || limit_type.indexOf(buy_use_type['index'].toString()) != -1) {
  1021. app.globalData.showToast(buy_use_type['name']+'起步价'+starting_price+'元');
  1022. return false;
  1023. }
  1024. } else {
  1025. app.globalData.showToast('起步价'+starting_price+'元');
  1026. return false;
  1027. }
  1028. }
  1029. // 进入订单确认页面
  1030. var data = this.request_params_merge({
  1031. "buy_type": "cart",
  1032. "ids": ids.join(',')
  1033. }, 'buy');
  1034. uni.navigateTo({
  1035. url: '/pages/buy/buy?data=' + encodeURIComponent(base64.encode(JSON.stringify(data)))
  1036. });
  1037. },
  1038. // 剪切板
  1039. text_copy_event(e) {
  1040. app.globalData.text_copy_event(e);
  1041. },
  1042. // 地图查看
  1043. address_map_event(e) {
  1044. var info = this.info;
  1045. if (info.lat == 0 || info.lng == 0) {
  1046. app.globalData.showToast("地址有误");
  1047. return false;
  1048. }
  1049. // 打开地图
  1050. var address = (info.province_name || '') + (info.city_name || '') + (info.county_name || '') + (info.address || '');
  1051. app.globalData.open_location(info.lng, info.lat, info.name, address);
  1052. },
  1053. // 电话
  1054. tel_event(e) {
  1055. app.globalData.call_tel(this.info.service_tel || null);
  1056. },
  1057. // 图片预览
  1058. image_show_event(e) {
  1059. app.globalData.image_show_event(e);
  1060. },
  1061. // 导航事件
  1062. nav_event(e) {
  1063. this.setData({
  1064. nav_active_index: e.currentTarget.dataset.index,
  1065. nav_active_item_index: e.currentTarget.dataset.itemindex,
  1066. data_page: 1
  1067. });
  1068. this.reset_scroll();
  1069. this.get_data_list(1);
  1070. },
  1071. // 重置滑动位置
  1072. reset_scroll() {
  1073. this.setData({
  1074. scroll_top: this.scroll_top_old
  1075. });
  1076. this.$nextTick(() => {
  1077. this.setData({
  1078. scroll_top: 0
  1079. });
  1080. });
  1081. },
  1082. // 滑动事件位置记录
  1083. scroll_event(e) {
  1084. this.setData({
  1085. scroll_top_old: e.detail.scrollTop
  1086. });
  1087. },
  1088. // 滚动加载
  1089. scroll_lower(e) {
  1090. this.get_data_list();
  1091. },
  1092. // 顶部返回操作
  1093. top_nav_left_back_event(e) {
  1094. var pages = getCurrentPages();
  1095. if (pages.length <= 1) {
  1096. uni.switchTab({
  1097. url: app.globalData.data.tabbar_pages[0]
  1098. });
  1099. } else {
  1100. uni.navigateBack();
  1101. }
  1102. },
  1103. // 地址信息初始化
  1104. user_location_init() {
  1105. var result = uni.getStorageSync(app.globalData.data.cache_userlocation_key) || null;
  1106. var data = null;
  1107. if (result != null) {
  1108. data = {
  1109. name: result.name || null,
  1110. address: result.address || null,
  1111. lat: result.latitude || null,
  1112. lng: result.longitude || null
  1113. };
  1114. }
  1115. this.setData({
  1116. user_location: data
  1117. });
  1118. },
  1119. // 使用类型事件
  1120. buy_use_type_event(e) {
  1121. var self = this;
  1122. uni.showActionSheet({
  1123. itemList: this.info.buy_use_type_list.map(function(v) {return v.name}),
  1124. success: function (res) {
  1125. self.setData({
  1126. buy_use_type_index: res.tapIndex,
  1127. data_page: 1
  1128. });
  1129. uni.setStorageSync(self.cache_buy_use_type_index_key, res.tapIndex);
  1130. self.reset_scroll();
  1131. self.get_data_list(1);
  1132. self.get_cart_data();
  1133. }
  1134. });
  1135. },
  1136. // 获取使用类型数据索引、默认在店0
  1137. get_buy_use_type_index() {
  1138. var index = uni.getStorageSync(this.cache_buy_use_type_index_key);
  1139. if((this.info || null) != null) {
  1140. // 用户未设置类型则使用默认的
  1141. if(index === null || index === '') {
  1142. // 是否默认类型
  1143. if(this.info.default_buy_use_type != undefined && this.info.default_buy_use_type != -1) {
  1144. // 不在店铺设置的类型列表则默认0
  1145. var temp_index = null;
  1146. for(var i in this.info.buy_use_type_list) {
  1147. if(this.info.buy_use_type_list[i]['index'] == this.info.default_buy_use_type) {
  1148. temp_index = i;
  1149. }
  1150. }
  1151. if(temp_index !== null) {
  1152. index = temp_index;
  1153. }
  1154. }
  1155. }
  1156. // 不在店铺设置的类型列表则默认0
  1157. if(this.info.buy_use_type_list[index] == undefined) {
  1158. index = 0;
  1159. }
  1160. }
  1161. return index || 0;
  1162. },
  1163. // 请求参数处理
  1164. // 默认增加使用类型参数
  1165. // 下单 buy / 初始化 init / 获取数据 data / 获取购物车 cart
  1166. request_params_merge(data, type = 'init') {
  1167. // 用户使用类型
  1168. var index = this.buy_use_type_index;
  1169. if((this.info || null) != null && (this.info.buy_use_type_list || null) != null && this.info.buy_use_type_list.length > 0) {
  1170. if(this.info.buy_use_type_list[index] == undefined) {
  1171. index = 0;
  1172. }
  1173. data['buy_use_type_index'] = this.buy_use_type_index;
  1174. }
  1175. // 初始化
  1176. if(type == 'init') {
  1177. // 桌码
  1178. if((this.params.tablecode_id || null) != null) {
  1179. data['tablecode_id'] = this.params.tablecode_id;
  1180. }
  1181. }
  1182. // 初始化、获取数据
  1183. if(type == 'init' || type == 'data' || type == 'cart') {
  1184. // 用户选择的位置
  1185. var lng = 0;
  1186. var lat = 0;
  1187. if((this.user_location || null) != null) {
  1188. lng = this.user_location.lng || 0;
  1189. lat = this.user_location.lat || 0;
  1190. }
  1191. data['lng'] = lng;
  1192. data['lat'] = lat;
  1193. }
  1194. // 提交订单
  1195. if(type == 'buy') {
  1196. // 门店id
  1197. data['realstore_id'] = this.info.id;
  1198. // 桌码
  1199. if((this.tablecode || null) != null) {
  1200. data['tablecode_id'] = this.tablecode.id;
  1201. }
  1202. }
  1203. return data;
  1204. },
  1205. // url事件
  1206. url_event(e) {
  1207. app.globalData.url_event(e);
  1208. }
  1209. }
  1210. };
  1211. </script>
  1212. <style>
  1213. @import './detail.css';
  1214. </style>