goods-buy.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <template>
  2. <view>
  3. <component-popup :propShow="popup_status" propPosition="bottom" @onclose="popup_close_event">
  4. <view class="goods-spec-choice-container padding-main bg-white pr">
  5. <view class="close fr oh">
  6. <view class="fr" @tap.stop="popup_close_event">
  7. <icon type="clear" size="20"></icon>
  8. </view>
  9. </view>
  10. <!-- 规格基础信息 -->
  11. <view class="goods-spec-base oh br-b pr">
  12. <image :src="goods_spec_base_images" mode="scaleToFill" class="radius br" @tap="goods_detail_images_view_event" :data-value="goods_spec_base_images"></image>
  13. <view class="goods-spec-base-content">
  14. <view class="goods-price">
  15. <view class="sales-price">{{currency_symbol}}{{goods_spec_base_price}}</view>
  16. <view v-if="(goods_spec_base_original_price || null) != null && goods_spec_base_original_price != 0" class="original-price margin-top-sm">{{currency_symbol}}{{goods_spec_base_original_price}}</view>
  17. </view>
  18. <view class="inventory text-size-xs margin-top-xs">
  19. <text class="cr-gray">库存</text>
  20. <text class="cr-base">{{goods_spec_base_inventory}}</text>
  21. <text class="cr-gray">{{goods.inventory_unit}}</text>
  22. </view>
  23. </view>
  24. </view>
  25. <block v-if="(goods.is_exist_many_spec || 0) == 1 && goods_spec_choose.length == 0">
  26. <view class="padding-top-xxxl padding-bottom-xxxl tc cr-red">规格数据有误</view>
  27. </block>
  28. <block v-else>
  29. <view class="goods-spec-choice-content">
  30. <!-- 商品规格 -->
  31. <view v-if="goods_spec_choose.length > 0" class="goods-spec-choose">
  32. <view v-for="(item, key) in goods_spec_choose" :key="key" class="item padding-top-xxl padding-bottom-xxl">
  33. <view class="text-size-sm">{{item.name}}</view>
  34. <view v-if="item.value.length > 0" class="spec margin-top-sm">
  35. <block v-for="(items, keys) in item.value" :key="keys">
  36. <button @tap.stop="goods_spec_choice_event" :data-key="key" :data-keys="keys" type="default" size="mini" hover-class="none" :class="'round '+items.is_active + ' ' + items.is_dont + ' ' + items.is_disabled">
  37. <image v-if="(items.images || null) != null" :src="items.images" mode="scaleToFill" class="va-m dis-inline-block round margin-right-sm"></image>
  38. <text class="va-m">{{items.name}}</text>
  39. </button>
  40. </block>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 购买数量 -->
  45. <view class="goods-buy-number oh pr margin-top-xl margin-bottom-xxl">
  46. <view class="fl margin-top">购买数量</view>
  47. <view class="number-content tc oh round">
  48. <view @tap="goods_buy_number_event" class="number-submit tc cr-gray fl va-m" data-type="0">-</view>
  49. <input @blur="goods_buy_number_blur" class="tc cr-gray bg-white fl va-m radius-0" type="number" :value="buy_number">
  50. <view @tap="goods_buy_number_event" class="number-submit tc cr-gray fl va-m" data-type="1">+</view>
  51. </view>
  52. </view>
  53. </view>
  54. <button class="bg-main br-main cr-white text-size-sm round" type="default" @tap.stop="spec_confirm_event" hover-class="none">确定</button>
  55. </block>
  56. </view>
  57. </component-popup>
  58. </view>
  59. </template>
  60. <script>
  61. const app = getApp();
  62. import base64 from '../../common/js/lib/base64.js';
  63. import componentPopup from "../../components/popup/popup";
  64. export default {
  65. data() {
  66. return {
  67. currency_symbol: app.globalData.get_config('currency_symbol', app.globalData.data.currency_symbol),
  68. params: {},
  69. back_data: {},
  70. popup_status: false,
  71. goods_spec_base_price: 0,
  72. goods_spec_base_original_price: 0,
  73. goods_spec_base_inventory: 0,
  74. goods_spec_base_buy_min_number: 0,
  75. goods_spec_base_buy_max_number: 0,
  76. goods_spec_base_images: '',
  77. goods: {},
  78. goods_spec_choose: [],
  79. buy_number: 1,
  80. buy_event_type: 'cart',
  81. is_direct_cart: 0,
  82. is_success_tips: 1,
  83. // 智能工具插件
  84. plugins_intellectstools_config: app.globalData.get_config('plugins_base.intellectstools.data'),
  85. plugins_intellectstools_timer: null,
  86. plugins_intellectstools_timerout: null,
  87. };
  88. },
  89. components: {
  90. componentPopup
  91. },
  92. created: function() {},
  93. methods: {
  94. // 初始化
  95. init(goods = {}, params = {}, back_data = null) {
  96. if(!app.globalData.is_single_page_check()) {
  97. return false;
  98. }
  99. params = params || {};
  100. // 状态默认开启弹窗
  101. var status = true;
  102. // 商品可选规格
  103. var goods_spec_choose = ((goods.specifications || null) != null) ? (goods.specifications.choose || []) : [];
  104. // 无规格是否直接操作
  105. var is_direct_cart = 0;
  106. if((params.is_direct_cart || 0) == 1 && parseInt(goods.is_exist_many_spec || 0) == 0 && goods_spec_choose.length == 0) {
  107. status = false;
  108. is_direct_cart = 1;
  109. }
  110. // 是否成功提示、默认提示
  111. var is_success_tips = (params.is_success_tips == undefined) ? 1 : params.is_success_tips || 0;
  112. // 直接加购、并且用户已经存在购物车则依次+1
  113. if(this.is_direct_cart == 1 && parseInt(this.goods.user_cart_count || 0) > 0) {
  114. var buy_number = 1;
  115. } else {
  116. var buy_number = goods.buy_min_number || 1;
  117. }
  118. // 设置数据
  119. this.setData({
  120. popup_status: status,
  121. params: params || {},
  122. back_data: back_data,
  123. goods: goods || {},
  124. goods_spec_choose: goods_spec_choose,
  125. goods_spec_base_price: goods.price,
  126. goods_spec_base_original_price: goods.original_price || 0,
  127. goods_spec_base_inventory: goods.inventory,
  128. goods_spec_base_images: goods.images,
  129. buy_number: buy_number,
  130. buy_event_type: params.buy_event_type || 'cart',
  131. is_direct_cart: is_direct_cart,
  132. is_success_tips: is_success_tips,
  133. });
  134. // 不能选择规格处理
  135. this.spec_handle_dont(0, 1);
  136. // 是否默认选中第一个规格
  137. this.plugins_intellectstools_selected_spec_handle();
  138. // 是否直接操作加入购物车
  139. if(is_direct_cart) {
  140. this.spec_confirm_event();
  141. }
  142. },
  143. // 默认选中第一个规格
  144. plugins_intellectstools_selected_spec_handle() {
  145. // 是否已选择
  146. var temp_data = this.goods_spec_choose;
  147. if (temp_data.length > 0) {
  148. var active_count = 0;
  149. for (var i in temp_data) {
  150. for (var k in temp_data[i]['value']) {
  151. if ((temp_data[i]['value'][k]['is_active'] || null) != null) {
  152. active_count++;
  153. }
  154. }
  155. }
  156. if (active_count > 0) {
  157. return false;
  158. }
  159. // 选择处理
  160. var self = this;
  161. // 销毁之前的任务
  162. clearInterval(self.plugins_intellectstools_timer);
  163. clearInterval(self.plugins_intellectstools_timerout);
  164. // 读取智能工具插件配置、是否开启
  165. var config = self.plugins_intellectstools_config || null;
  166. if(config != null && (config.is_goods_detail_selected_first_spec || 0) == 1) {
  167. // 必须存在购买和加入购物车任意一个、规格必须多个
  168. var buy = self.buy_button;
  169. var sku_count = app.globalData.get_length(temp_data);
  170. // 先清除价格展示信息
  171. self.setData({
  172. goods_spec_base_price: '...',
  173. goods_spec_base_original_price: '...'
  174. });
  175. var num = 0;
  176. var timer = setInterval(function() {
  177. for(var i in temp_data) {
  178. // 清除价格展示信息、避免获取价格类型赋值
  179. self.setData({
  180. goods_spec_base_price: '...',
  181. goods_spec_base_original_price: '...'
  182. });
  183. // 必须不存在已选择项
  184. var active = temp_data[i]['value'].map(function(v){return v.is_active}).join('') || null;
  185. if(active == null) {
  186. var status = false;
  187. for(var k in temp_data[i]['value']) {
  188. // 必须是可选和未选
  189. if(!status && (temp_data[i]['value'][k]['is_disabled'] || null) == null && (temp_data[i]['value'][k]['is_dont'] || null) == null) {
  190. self.goods_spec_choice_handle(i, k);
  191. status = true;
  192. num++;
  193. }
  194. }
  195. }
  196. }
  197. if(num >= sku_count) {
  198. clearInterval(self.plugins_intellectstools_timer);
  199. }
  200. }, 100);
  201. var timerout = setTimeout(function() {
  202. clearInterval(self.plugins_intellectstools_timerout);
  203. }, 20000);
  204. self.setData({
  205. plugins_intellectstools_timer: timer,
  206. plugins_intellectstools_timerout: timerout
  207. });
  208. }
  209. }
  210. },
  211. // 弹层关闭
  212. popup_close_event(e) {
  213. this.setData({
  214. popup_status: false
  215. });
  216. },
  217. // 规格事件
  218. goods_spec_choice_event(e) {
  219. var key = e.currentTarget.dataset.key || 0;
  220. var keys = e.currentTarget.dataset.keys || 0;
  221. this.goods_spec_choice_handle(key, keys);
  222. },
  223. // 规格选择处理
  224. goods_spec_choice_handle(key, keys) {
  225. var temp_spec = this.goods_spec_choose;
  226. // 不能选择和禁止选择跳过
  227. if ((temp_spec[key]['value'][keys]['is_dont'] || null) == null && (temp_spec[key]['value'][keys]['is_disabled'] || null) == null) {
  228. // 规格选择
  229. for (var i in temp_spec) {
  230. for (var k in temp_spec[i]['value']) {
  231. if ((temp_spec[i]['value'][k]['is_dont'] || null) == null && (temp_spec[i]['value'][k]['is_disabled'] || null) == null) {
  232. if (key == i) {
  233. if (keys == k && (temp_spec[i]['value'][k]['is_active'] || null) == null) {
  234. temp_spec[i]['value'][k]['is_active'] = 'cr-white bg-main br-main';
  235. } else {
  236. temp_spec[i]['value'][k]['is_active'] = '';
  237. }
  238. }
  239. }
  240. }
  241. }
  242. this.setData({
  243. spec: temp_spec
  244. });
  245. // 不能选择规格处理
  246. this.spec_handle_dont(key);
  247. // 获取下一个规格类型
  248. this.get_spec_type(key);
  249. // 获取规格详情
  250. this.get_spec_detail();
  251. }
  252. },
  253. // 获取下一个规格类型
  254. get_spec_type(key) {
  255. var temp_spec = this.goods_spec_choose;
  256. var active_index = parseInt(key) + 1;
  257. var sku_count = app.globalData.get_length(temp_spec);
  258. if (active_index <= 0 || active_index >= sku_count) {
  259. return false;
  260. }
  261. // 获取规格值
  262. var spec = [];
  263. for (var i in temp_spec) {
  264. for (var k in temp_spec[i]['value']) {
  265. if ((temp_spec[i]['value'][k]['is_active'] || null) != null) {
  266. spec.push({
  267. type: temp_spec[i]['name'],
  268. value: temp_spec[i]['value'][k]['name']
  269. });
  270. break;
  271. }
  272. }
  273. }
  274. if (spec.length <= 0) {
  275. return false;
  276. }
  277. // 获取数据
  278. var data = this.params;
  279. data['id'] = this.goods.id;
  280. data['spec'] = JSON.stringify(spec);
  281. uni.request({
  282. url: app.globalData.get_request_url('spectype', 'goods'),
  283. method: 'POST',
  284. data: data,
  285. dataType: 'json',
  286. success: (res) => {
  287. if (res.data.code == 0) {
  288. var spec_type = res.data.data.spec_type;
  289. var spec_count = spec.length;
  290. var index = spec_count > 0 ? spec_count : 0;
  291. if (index < sku_count) {
  292. for (var i in temp_spec) {
  293. for (var k in temp_spec[i]['value']) {
  294. if (index == i) {
  295. temp_spec[i]['value'][k]['is_dont'] = '';
  296. var temp_value = temp_spec[i]['value'][k]['name'];
  297. var temp_status = false;
  298. for (var t in spec_type) {
  299. if (spec_type[t] == temp_value) {
  300. temp_status = true;
  301. break;
  302. }
  303. }
  304. if (temp_status == true) {
  305. temp_spec[i]['value'][k]['is_disabled'] = '';
  306. } else {
  307. temp_spec[i]['value'][k]['is_disabled'] = 'spec-items-disabled';
  308. }
  309. }
  310. }
  311. }
  312. this.setData({
  313. spec: temp_spec
  314. });
  315. }
  316. } else {
  317. app.globalData.showToast(res.data.msg);
  318. }
  319. },
  320. fail: () => {
  321. app.globalData.showToast('服务器请求出错');
  322. }
  323. });
  324. },
  325. // 获取规格详情
  326. get_spec_detail() {
  327. // 获取规格值
  328. var spec = this.goods_selected_spec();
  329. // 存在规格的时候是否已完全选择规格
  330. var sku_count = this.goods_spec_choose.length;
  331. var active_count = spec.length;
  332. if (spec.length <= 0 || active_count < sku_count) {
  333. var buy_number = parseInt(this.buy_number);
  334. var buy_min_number = parseInt(this.goods.buy_min_number || 1);
  335. var buy_max_number = parseInt(this.goods.buy_max_number || 0);
  336. if(buy_number < buy_min_number) {
  337. buy_number = buy_min_number;
  338. }
  339. if(buy_max_number > 0 && buy_number > buy_max_number) {
  340. buy_number = buy_max_number;
  341. }
  342. this.setData({
  343. goods_spec_base_price: this.goods.price,
  344. goods_spec_base_original_price: this.goods.original_price || 0,
  345. goods_spec_base_inventory: this.goods.inventory,
  346. goods_spec_base_buy_min_number : 0,
  347. goods_spec_base_buy_max_number : 0,
  348. buy_number: buy_number
  349. });
  350. return false;
  351. }
  352. // 获取数据
  353. var data = this.params;
  354. data['id'] = this.goods.id;
  355. data['spec'] = JSON.stringify(spec);
  356. data['stock'] = this.buy_number;
  357. uni.request({
  358. url: app.globalData.get_request_url('specdetail', 'goods'),
  359. method: 'POST',
  360. data: data,
  361. dataType: 'json',
  362. success: res => {
  363. if (res.data.code == 0) {
  364. this.goods_spec_detail_back_handle(res.data.data);
  365. } else {
  366. app.globalData.showToast(res.data.msg);
  367. }
  368. },
  369. fail: () => {
  370. app.globalData.showToast('服务器请求出错');
  371. }
  372. });
  373. },
  374. // 商品规格详情返回数据处理
  375. goods_spec_detail_back_handle(data) {
  376. var spec_base = data.spec_base;
  377. var buy_number = parseInt(this.buy_number);
  378. var spec_buy_min_number = parseInt(spec_base.buy_min_number || 1);
  379. var spec_buy_max_number = parseInt(spec_base.buy_max_number || 0);
  380. if(spec_buy_min_number > 0 && buy_number < spec_buy_min_number) {
  381. buy_number = spec_buy_min_number;
  382. }
  383. if(spec_buy_max_number > 0 && buy_number > spec_buy_max_number) {
  384. buy_number = spec_buy_max_number;
  385. }
  386. this.setData({
  387. goods_spec_base_price: spec_base.price,
  388. goods_spec_base_original_price: spec_base.original_price || 0,
  389. goods_spec_base_inventory: parseInt(spec_base.inventory || 0),
  390. goods_spec_base_buy_min_number: spec_buy_min_number,
  391. goods_spec_base_buy_max_number: spec_buy_max_number,
  392. buy_number: buy_number
  393. });
  394. },
  395. // 已选的商品规格
  396. goods_selected_spec() {
  397. var spec = [];
  398. var temp_spec = this.goods_spec_choose;
  399. for (var i in temp_spec) {
  400. for (var k in temp_spec[i]['value']) {
  401. if ((temp_spec[i]['value'][k]['is_active'] || null) != null) {
  402. spec.push({
  403. type: temp_spec[i]['name'],
  404. value: temp_spec[i]['value'][k]['name']
  405. });
  406. break;
  407. }
  408. }
  409. }
  410. return spec;
  411. },
  412. // 不能选择规格处理
  413. spec_handle_dont(key, is_init = 0) {
  414. var temp_spec = this.goods_spec_choose || [];
  415. if (temp_spec.length <= 0) {
  416. return false;
  417. }
  418. // 是否不能选择
  419. key = parseInt(key);
  420. for (var i in temp_spec) {
  421. for (var k in temp_spec[i]['value']) {
  422. if (i > key) {
  423. temp_spec[i]['value'][k]['is_dont'] = 'spec-dont-choose';
  424. temp_spec[i]['value'][k]['is_disabled'] = '';
  425. temp_spec[i]['value'][k]['is_active'] = '';
  426. } else {
  427. if(is_init == 1) {
  428. temp_spec[i]['value'][k]['is_active'] = '';
  429. }
  430. }
  431. // 当只有一个规格的时候
  432. if (key == 0 && temp_spec.length == 1) {
  433. temp_spec[i]['value'][k]['is_disabled'] = (temp_spec[i]['value'][k]['is_only_level_one'] || null) != null && parseInt(temp_spec[i]['value'][k]['inventory'] || 0) <= 0 ? 'spec-items-disabled' : '';
  434. }
  435. }
  436. }
  437. this.setData({
  438. spec: temp_spec
  439. });
  440. },
  441. // 数量输入事件
  442. goods_buy_number_blur(e) {
  443. var number = parseInt(e.detail.value) || 1;
  444. if(isNaN(number)) {
  445. number = this.goods.buy_min_number || 1;
  446. }
  447. this.goods_buy_number_func(number);
  448. },
  449. // 数量操作事件
  450. goods_buy_number_event(e) {
  451. var type = parseInt(e.currentTarget.dataset.type || 0);
  452. var temp_number = parseInt(this.buy_number);
  453. var number = (type == 0) ? temp_number - 1 : temp_number + 1;
  454. this.goods_buy_number_func(number);
  455. },
  456. // 数量处理方法
  457. goods_buy_number_func(number) {
  458. var buy_min_number = parseInt(this.goods.buy_min_number || 1);
  459. var buy_max_number = parseInt(this.goods.buy_max_number || 0);
  460. var spec_buy_min_number = parseInt(this.goods_spec_base_buy_min_number || 0);
  461. var spec_buy_max_number = parseInt(this.goods_spec_base_buy_max_number || 0);
  462. var inventory = parseInt(this.goods_spec_base_inventory || 0);
  463. var inventory_unit = this.goods.inventory_unit;
  464. // 最小起购数量
  465. var min = (spec_buy_min_number > 0) ? spec_buy_min_number : buy_min_number;
  466. if (min > 0 && number < min) {
  467. number = min;
  468. app.globalData.showToast('起购' + min + inventory_unit);
  469. }
  470. // 最大购买数量
  471. var max = (spec_buy_max_number > 0) ? spec_buy_max_number : buy_max_number;
  472. if (max > 0 && number > max) {
  473. number = max;
  474. app.globalData.showToast('限购' + max + inventory_unit);
  475. }
  476. // 是否超过库存数量
  477. if (number > inventory) {
  478. number = inventory;
  479. app.globalData.showToast('库存数量' + inventory + inventory_unit);
  480. }
  481. this.setData({buy_number: number});
  482. // 存在规格的时候是否已完全选择规格
  483. var spec = this.goods_selected_spec();
  484. var sku_count = this.goods_spec_choose.length;
  485. var active_count = spec.length;
  486. if (sku_count > 0 && active_count < sku_count) {
  487. return false;
  488. }
  489. // 获取数据
  490. var data = this.params;
  491. data['id'] = this.goods.id;
  492. data['spec'] = spec;
  493. data['stock'] = this.buy_number;
  494. uni.request({
  495. url: app.globalData.get_request_url('stock', 'goods'),
  496. method: 'POST',
  497. data: data,
  498. dataType: 'json',
  499. success: res => {
  500. if (res.data.code == 0) {
  501. this.goods_spec_detail_back_handle(res.data.data);
  502. } else {
  503. app.globalData.showToast(res.data.msg);
  504. }
  505. },
  506. fail: () => {
  507. app.globalData.showToast('服务器请求出错');
  508. }
  509. });
  510. },
  511. // 详情图片查看
  512. goods_detail_images_view_event(e) {
  513. var value = e.currentTarget.dataset.value || null;
  514. if (value != null) {
  515. uni.previewImage({
  516. current: value,
  517. urls: [value]
  518. });
  519. }
  520. },
  521. // 规格确认事件
  522. spec_confirm_event(e) {
  523. var user = app.globalData.get_user_info(this, 'spec_confirm_event');
  524. if (user != false) {
  525. // 用户未绑定用户则转到登录页面
  526. if (app.globalData.user_is_need_login(user)) {
  527. uni.navigateTo({
  528. url: "/pages/login/login?event_callback=spec_confirm_event"
  529. });
  530. return false;
  531. } else {
  532. // 规格
  533. var temp_data = this.goods_spec_choose;
  534. var sku_count = temp_data.length;
  535. var active_count = 0;
  536. var spec = [];
  537. if (sku_count > 0) {
  538. for (var i in temp_data) {
  539. for (var k in temp_data[i]['value']) {
  540. if ((temp_data[i]['value'][k]['is_active'] || null) != null) {
  541. active_count++;
  542. spec.push({
  543. type: temp_data[i]['name'],
  544. value: temp_data[i]['value'][k]['name']
  545. });
  546. }
  547. }
  548. }
  549. if (active_count < sku_count) {
  550. app.globalData.showToast('请选择规格');
  551. return false;
  552. }
  553. }
  554. // 操作类型
  555. switch (this.buy_event_type) {
  556. case 'buy':
  557. // 进入订单确认页面
  558. var data = {
  559. buy_type: "goods",
  560. goods_data: encodeURIComponent(base64.encode(JSON.stringify([{
  561. goods_id: this.goods.id,
  562. stock: this.buy_number,
  563. spec: spec
  564. }])))
  565. };
  566. uni.navigateTo({
  567. url: '/pages/buy/buy?data=' + encodeURIComponent(base64.encode(JSON.stringify(data)))
  568. });
  569. this.popup_close_event();
  570. break;
  571. // 加入购物车
  572. case 'cart':
  573. this.goods_cart_event(spec);
  574. break;
  575. default:
  576. app.globalData.showToast("操作事件类型有误");
  577. }
  578. }
  579. }
  580. },
  581. // 加入购物车事件
  582. goods_cart_event(spec) {
  583. var data = this.params;
  584. data['goods_id'] = this.goods.id;
  585. data['spec'] = JSON.stringify(spec);
  586. data['stock'] = this.buy_number;
  587. uni.request({
  588. url: app.globalData.get_request_url('save', 'cart'),
  589. method: 'POST',
  590. data: data,
  591. dataType: 'json',
  592. success: res => {
  593. if (res.data.code == 0) {
  594. // 是否成功提示
  595. if(this.is_success_tips == 1) {
  596. app.globalData.showToast(res.data.msg, 'success');
  597. }
  598. var cart_number = res.data.data.buy_number;
  599. // 调用父级
  600. this.$emit('CartSuccessEvent', {
  601. goods_id: this.goods.id,
  602. spec: spec,
  603. stock: this.buy_number,
  604. cart_number: cart_number,
  605. back_data: this.back_data,
  606. });
  607. // 是否返回定义来源返回
  608. if(parseInt(this.params.is_opt_buy_status || 0) == 1 && this.is_opt_back == 1) {
  609. setTimeout(function() {
  610. uni.navigateBack();;
  611. }, 1000);
  612. } else {
  613. // 关闭购买弹窗窗口
  614. this.popup_close_event();
  615. }
  616. } else {
  617. if (app.globalData.is_login_check(res.data, this, 'spec_confirm_event')) {
  618. app.globalData.showToast(res.data.msg);
  619. }
  620. }
  621. },
  622. fail: () => {
  623. app.globalData.showToast('服务器请求出错');
  624. }
  625. });
  626. }
  627. }
  628. };
  629. </script>
  630. <style>
  631. .goods-spec-choice-container .close {
  632. position: absolute;
  633. top: 20rpx;
  634. right: 20rpx;
  635. z-index: 2;
  636. }
  637. .goods-spec-base {
  638. height: 230rpx;
  639. }
  640. .goods-spec-base image {
  641. width: 200rpx;
  642. height: 200rpx;
  643. position: absolute;
  644. left: 0;
  645. top: 0;
  646. }
  647. .goods-spec-base-content {
  648. position: absolute;
  649. left: 220rpx;
  650. top: 0;
  651. }
  652. .goods-spec-choice-content {
  653. max-height: 50vh;
  654. overflow-y: scroll;
  655. overflow-x: hidden;
  656. margin-top: 20rpx;
  657. }
  658. .goods-spec-choice-container .item .spec button {
  659. background-color: #f5f5f5;
  660. color: #666;
  661. border: 1px solid #ccc;
  662. }
  663. .goods-spec-choice-container .item .spec button:not(:last-child) {
  664. margin-right: 25rpx;
  665. }
  666. .goods-spec-choice-container .item .spec button image {
  667. width: 40rpx;
  668. height: 40rpx !important;
  669. }
  670. .goods-spec-choice-container .spec-dont-choose {
  671. color: #b4b3b3 !important;
  672. background-color: #ffffff !important;
  673. border: 1px solid #ebeaea !important;
  674. }
  675. .goods-spec-choice-container .spec-dont-choose image {
  676. opacity: 0.5;
  677. }
  678. .goods-spec-choice-container .spec-items-disabled {
  679. color: #d2cfcf !important;
  680. background-color: #ffffff !important;
  681. border: 1px dashed #d5d5d5 !important;
  682. }
  683. .goods-spec-choice-container .spec-items-disabled image {
  684. opacity: 0.3;
  685. }
  686. .goods-spec-choice-container .goods-buy-number {
  687. height: 70rpx;
  688. }
  689. .goods-spec-choice-container .number-content {
  690. position: absolute;
  691. right: 20rpx;
  692. top: 0;
  693. background: #eee;
  694. border: 1px solid #eee;
  695. }
  696. .goods-spec-choice-container .number-content .number-submit {
  697. width: 80rpx;
  698. font-weight: bold;
  699. }
  700. .goods-spec-choice-container .number-content input {
  701. width: 50px;
  702. }
  703. .goods-spec-choice-container .number-content .number-submit,
  704. .goods-spec-choice-container .number-content input {
  705. padding: 0;
  706. height: 60rpx;
  707. line-height: 60rpx;
  708. }
  709. </style>