detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view>
  3. <view v-if="(data || null) != null" class="page-bottom-fixed">
  4. <view class="padding-horizontal-main padding-top-main">
  5. <!-- 基础信息 -->
  6. <view class="base-container tc pr padding-main border-radius-main bg-main oh spacing-mb" :style="'background-color:'+data.color+' !important;background-image:url('+data.images+')'">
  7. <view class="text cr-white pa bs-bb text-size wh-auto ht-auto">{{data.describe}}</view>
  8. </view>
  9. <view v-if="(data.goods || null) != null && data.goods.length > 0">
  10. <!-- 商品 -->
  11. <view class="data-list oh">
  12. <view v-for="(item, index) in data.goods" :key="index" :class="'item padding-main border-radius-main bg-white oh spacing-mb '+(item.is_error == 0 ? '' : 'br-red')">
  13. <image class="goods-img dis-block border-radius-main fl" :src="item.images" mode="aspectFit" :data-value="item.goods_url" @tap="url_event"></image>
  14. <view class="right-base fr">
  15. <label v-if="data.type == 1 && item.is_error == 0" class="fr" :data-index="index" @tap="goods_choice_event">
  16. <radio :checked="(item.checked == undefined || item.checked == true)" style="transform:scale(0.7)" />
  17. </label>
  18. <view :class="'multi-text '+(data.type == 1 ? 'padding-right' : '')">{{item.title}}</view>
  19. <view class="single-text margin-top-sm">
  20. <text class="sales-price">{{currency_symbol}}{{item.price}}</text>
  21. <text v-if="item.original_price != 0" class="original-price margin-left-sm">{{currency_symbol}}{{item.original_price}}</text>
  22. </view>
  23. <view class="margin-top-xs">
  24. <view v-if="item.is_error == 0">
  25. <view class="va-m dis-inline-block margin-right-xl pr" :data-index="index" @tap="goods_cart_event">
  26. <uni-icons type="cart" size="16" color="#999"></uni-icons>
  27. <view class="cart-badge-icon pa">
  28. <component-badge :propNumber="item.user_cart_count || 0"></component-badge>
  29. </view>
  30. </view>
  31. <text class="cr-gray text-size-xs">{{item.inventory}}{{item.inventory_unit}}</text>
  32. <view v-if="(item.is_exist_many_spec || 0) == 1" class="br-gray cr-gray round fr padding-left padding-right single-text text-size-xs spec-choice" :data-index="index" @tap="spec_choice_event">{{item.spec_choice_text || '选择规格'}}</view>
  33. </view>
  34. <view v-else class="cr-yellow text-size-xs">{{item.error_msg}}</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 导航 -->
  40. <view class="nav-button bottom-fixed padding-main pr">
  41. <view class="bottom-line-exclude oh">
  42. <view class="left-price fl">
  43. <view v-if="data.estimate_discount_price != 0" class="pa single-text estimate-discount-price">
  44. <text class="discount-icon cr-white text-size-xs">节省</text>
  45. <text class="cr-green">{{currency_symbol}}{{data.estimate_discount_price}}</text>
  46. </view>
  47. <view :class="'sales-price single-text margin-top-'+(data.estimate_discount_price == 0 ? 'sm' : 'xl')">{{currency_symbol}}{{data.estimate_price}}</view>
  48. </view>
  49. <view class="right-button fr tr">
  50. <button type="default" size="mini" class="bg-main br-main cr-white round dis-block text-size-sm" @tap="buy_event">立即购买</button>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view v-else>
  56. <!-- 提示信息 -->
  57. <component-no-data propStatus="0" propMsg="没有相关商品"></component-no-data>
  58. </view>
  59. </view>
  60. <!-- 结尾 -->
  61. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  62. </view>
  63. <view v-else>
  64. <!-- 提示信息 -->
  65. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  66. </view>
  67. <!-- 规格选择 -->
  68. <component-goods-spec-choice ref="goods_spec_choice" v-on:specConfirmEvent="spec_confirm_event"></component-goods-spec-choice>
  69. <!-- 商品购买 -->
  70. <component-goods-buy ref="goods_buy" v-on:CartSuccessEvent="goods_cart_back_event"></component-goods-buy>
  71. </view>
  72. </template>
  73. <script>
  74. const app = getApp();
  75. import base64 from '../../../../common/js/lib/base64.js';
  76. import componentNoData from "../../../../components/no-data/no-data";
  77. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  78. import componentGoodsSpecChoice from "../../../../components/goods-spec-choice/goods-spec-choice";
  79. import componentGoodsBuy from "../../../../components/goods-buy/goods-buy";
  80. import componentBadge from "../../../../components/badge/badge";
  81. export default {
  82. data() {
  83. return {
  84. data_bottom_line_status: false,
  85. data_list_loding_status: 1,
  86. data_list_loding_msg: '',
  87. currency_symbol: app.globalData.data.currency_symbol,
  88. params: null,
  89. user: null,
  90. data_base: null,
  91. data: null,
  92. // 自定义分享信息
  93. share_info: {}
  94. };
  95. },
  96. components: {
  97. componentNoData,
  98. componentBottomLine,
  99. componentGoodsSpecChoice,
  100. componentGoodsBuy,
  101. componentBadge
  102. },
  103. onLoad(params) {
  104. this.setData({
  105. params: params
  106. });
  107. },
  108. onShow() {
  109. // 初始化配置
  110. this.init_config();
  111. // 获取数据
  112. this.get_data();
  113. },
  114. // 下拉刷新
  115. onPullDownRefresh() {
  116. this.get_data();
  117. },
  118. methods: {
  119. // 初始化配置
  120. init_config(status) {
  121. if ((status || false) == true) {
  122. this.setData({
  123. currency_symbol: app.globalData.get_config('currency_symbol'),
  124. });
  125. } else {
  126. app.globalData.is_config(this, 'init_config');
  127. }
  128. },
  129. // 获取数据
  130. get_data() {
  131. uni.showLoading({
  132. title: '加载中...'
  133. });
  134. uni.request({
  135. url: app.globalData.get_request_url("detail", "index", "binding"),
  136. method: 'POST',
  137. data: {
  138. id: this.params.id || 0
  139. },
  140. dataType: 'json',
  141. success: res => {
  142. uni.hideLoading();
  143. uni.stopPullDownRefresh();
  144. if (res.data.code == 0) {
  145. var data = res.data.data;
  146. this.setData({
  147. data_base: data.base || null,
  148. data: data.data || null,
  149. data_list_loding_msg: '',
  150. data_list_loding_status: 0,
  151. data_bottom_line_status: ((data.data || null) != null && (data.data.goods || null) != null && data.data.goods.length > 0)
  152. });
  153. if ((this.data || null) != null) {
  154. // 基础自定义分享
  155. this.setData({
  156. share_info: {
  157. title: this.data.seo_title || this.data.title,
  158. desc: this.data.seo_desc || this.data.describe,
  159. path: '/pages/plugins/binding/detail/detail',
  160. query: 'id='+this.data.id,
  161. img: this.data.images
  162. }
  163. });
  164. // 标题
  165. if((this.data.title || null) != null) {
  166. uni.setNavigationBarTitle({
  167. title: this.data.title
  168. });
  169. }
  170. }
  171. } else {
  172. this.setData({
  173. data_bottom_line_status: false,
  174. data_list_loding_status: 2,
  175. data_list_loding_msg: res.data.msg
  176. });
  177. }
  178. // 分享菜单处理
  179. app.globalData.page_share_handle(this.share_info);
  180. },
  181. fail: () => {
  182. uni.hideLoading();
  183. uni.stopPullDownRefresh();
  184. this.setData({
  185. data_bottom_line_status: false,
  186. data_list_loding_status: 2,
  187. data_list_loding_msg: '服务器请求出错'
  188. });
  189. app.globalData.showToast('服务器请求出错');
  190. }
  191. });
  192. },
  193. // url事件
  194. url_event(e) {
  195. app.globalData.url_event(e);
  196. },
  197. // 商品选择事件
  198. goods_choice_event(e) {
  199. // 选择处理
  200. var index = e.currentTarget.dataset.index || 0;
  201. var temp_data = this.data;
  202. var goods = temp_data.goods;
  203. goods[index]['checked'] = (goods[index]['checked'] == undefined || goods[index]['checked'] == true) ? false : true;
  204. temp_data['goods'] = goods;
  205. // 已选商品
  206. var min_price = 0;
  207. var max_price = 0;
  208. var min_original_price = 0;
  209. var max_original_price = 0;
  210. var price = 0;
  211. var discount_price = 0;
  212. for(var i in goods) {
  213. if((goods[i]['checked'] == undefined || goods[i]['checked'] == true) && goods[i]['is_error'] == 0) {
  214. min_price += parseFloat(goods[i]['min_price'] || 0);
  215. max_price += parseFloat(goods[i]['max_price'] || 0);
  216. min_original_price += parseFloat(goods[i]['min_original_price'] || 0);
  217. max_original_price += parseFloat(goods[i]['max_original_price'] || 0);
  218. }
  219. }
  220. // 价格信息
  221. price = parseFloat(temp_data.price || 0);
  222. var rate = parseFloat(temp_data.rate || 0);
  223. // 组合价
  224. if(price > 0) {
  225. if(min_price == max_price) {
  226. var original_price = min_price;
  227. var dv = parseFloat(app.globalData.price_two_decimal(original_price-price));
  228. discount_price = (dv <= 0) ? 0 : dv;
  229. } else {
  230. var original_price = min_price+'-'+max_price;
  231. var d1 = parseFloat(app.globalData.price_two_decimal(min_price-price));
  232. var d2 = parseFloat(app.globalData.price_two_decimal(max_price-price));
  233. discount_price = (d1 == d2) ? d1 : ((d1 <= 0 && d2 <= 0) ? 0 : (d1 <= 0 ? 0 : d1)+'-'+(d2 <= 0 ? 0 : d2));
  234. }
  235. } else {
  236. // 折扣率
  237. if(rate > 0) {
  238. min_original_price = min_price;
  239. max_original_price = max_price;
  240. min_price = min_price*rate;
  241. max_price = max_price*rate;
  242. }
  243. price = (min_price != max_price) ? min_price+'-'+max_price : min_price;
  244. var original_price = (min_original_price != max_original_price) ? min_original_price+'-'+max_original_price : min_original_price;
  245. if(price.toString().indexOf('-') == -1 && original_price.toString().indexOf('-') == -1)
  246. {
  247. var dv = parseFloat(app.globalData.price_two_decimal(original_price-price));
  248. discount_price = (dv <= 0) ? 0 : dv;
  249. } else {
  250. var d1 = parseFloat(app.globalData.price_two_decimal(min_original_price-min_price));
  251. var d2 = parseFloat(app.globalData.price_two_decimal(max_original_price-max_price));
  252. discount_price = (d1 == d2) ? d1 : ((d1 <= 0 && d2 <= 0) ? 0 : (d1 <= 0 ? 0 : d1)+'-'+(d2 <= 0 ? 0 : d2));
  253. }
  254. }
  255. // 购买价格
  256. temp_data['estimate_price'] = price;
  257. // 节省价格
  258. temp_data['estimate_discount_price'] = discount_price;
  259. this.setData({data: temp_data});
  260. },
  261. // 规格选择
  262. spec_choice_event(e) {
  263. if((this.$refs.goods_spec_choice || null) != null) {
  264. var index = e.currentTarget.dataset.index || 0;
  265. var goods = this.data['goods'][index];
  266. this.$refs.goods_spec_choice.init(goods.id, goods['specifications']['choose'], goods.buy_min_number, index);
  267. }
  268. },
  269. // 规格确认回调事件
  270. spec_confirm_event(value) {
  271. var temp_data = this.data;
  272. temp_data['goods'][value.out_value]['spec_choice_data'] = value.spec;
  273. temp_data['goods'][value.out_value]['spec_choice_text'] = value.spec.map(function(v){return v.value;}).join(' / ');
  274. this.setData({data: temp_data});
  275. },
  276. // 立即购买
  277. buy_event(e) {
  278. // 是否需要选择商品
  279. var type = parseInt(this.data.type || 0);
  280. var goods_data = [];
  281. var temp_goods = this.data.goods;
  282. for(var i in temp_goods) {
  283. if(temp_goods[i]['is_error'] == 0) {
  284. var goods_id = null;
  285. if(type == 1) {
  286. if(temp_goods[i]['checked'] == undefined || temp_goods[i]['checked'] == true) {
  287. goods_id = temp_goods[i]['id'];
  288. }
  289. } else {
  290. goods_id = temp_goods[i]['id'];
  291. }
  292. if(goods_id !== null) {
  293. // 是否存在多规格
  294. if((temp_goods[i]['is_exist_many_spec'] || 0) == 1 && (temp_goods[i]['spec_choice_data'] || null) == null) {
  295. app.globalData.showToast('请选择第'+(parseInt(i)+1)+'个商品规格');
  296. return false;
  297. }
  298. goods_data.push({
  299. goods_id: goods_id,
  300. stock: temp_goods[i]['buy_min_number'] || 1,
  301. spec: temp_goods[i]['spec_choice_data'] || ''
  302. });
  303. }
  304. } else {
  305. // 组合搭配则每一个商品都需要正确状态
  306. if(type == 0) {
  307. app.globalData.showToast('第'+(parseInt(i)+1)+'个商品不可用');
  308. return false;
  309. }
  310. }
  311. }
  312. if(goods_data.length < 2) {
  313. app.globalData.showToast('请至少选择两个商品起');
  314. return false;
  315. }
  316. // 进入订单确认页面
  317. var data = {
  318. buy_type: "goods",
  319. goods_data: encodeURIComponent(base64.encode(JSON.stringify(goods_data)))
  320. };
  321. uni.navigateTo({
  322. url: '/pages/buy/buy?data=' + encodeURIComponent(base64.encode(JSON.stringify(data)))
  323. });
  324. },
  325. // 加入购物车
  326. goods_cart_event(e) {
  327. if((this.$refs.goods_buy || null) != null) {
  328. var index = e.currentTarget.dataset.index || 0;
  329. var goods = this.data['goods'][index];
  330. this.$refs.goods_buy.init(goods, {buy_event_type: 'cart', is_direct_cart: 1}, {index: index});
  331. }
  332. },
  333. // 加入购物车成功回调
  334. goods_cart_back_event(e) {
  335. // 增加数量
  336. var back = e.back_data;
  337. var temp = this.data;
  338. var goods = temp['goods'][back.index];
  339. goods['user_cart_count'] = parseInt(goods['user_cart_count'] || 0)+parseInt(e.stock);
  340. if(goods['user_cart_count'] > 99) {
  341. goods['user_cart_count'] = '99+';
  342. }
  343. temp['goods'][back.index] = goods;
  344. this.setData({data: temp});
  345. }
  346. }
  347. };
  348. </script>
  349. <style>
  350. @import './detail.css';
  351. </style>