detail.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. import {
  2. goodsSkuDetail,
  3. aftersale,
  4. modifyClicks,
  5. addGoodsbrowse,
  6. goodsSkuInfo,
  7. goodsQrcode,
  8. evaluateConfig
  9. } from "@/api/goods/goods"
  10. import {
  11. goodsCategoryInfo
  12. } from "@/api/goods/goodscategory"
  13. import {
  14. isCollect,
  15. addCollect,
  16. deleteCollect
  17. } from "@/api/goods/goods_collect"
  18. import {
  19. couponTypeList,
  20. couponReceive,
  21. goodsCoupon
  22. } from "@/api/coupon"
  23. import {
  24. bundlingList
  25. } from "@/api/bundling"
  26. import {
  27. goodsEvaluateList,
  28. goodsEvaluateCount
  29. } from "@/api/goods/evaluate"
  30. import {
  31. mapGetters
  32. } from "vuex"
  33. import CountDown from "vue2-countdown"
  34. // import {
  35. // shopIsSubscribe,
  36. // addShopSubscribe,
  37. // deleteShopSubscribe
  38. // } from "@/api/shop";
  39. import {
  40. getArea
  41. } from "@/api/address";
  42. import {
  43. shopServiceOpen
  44. } from "@/api/website.js"
  45. import {
  46. cartList
  47. } from "@/api/goods/cart"
  48. import {
  49. getToken
  50. } from '@/utils/auth.js'
  51. export default {
  52. data: () => {
  53. return {
  54. id: 0,
  55. skuId: 0,
  56. loading: true,
  57. picZoomUrl: "",
  58. thumbPosition: 0,
  59. // 是否可以移动
  60. moveThumbLeft: false,
  61. moveThumbRight: false,
  62. // 商品详情
  63. goodsSkuDetail: {
  64. video_url: ""
  65. },
  66. evaluate_show: false, //评论是否显示
  67. discountText: "距离结束仅剩",
  68. discountTimeMachine: {
  69. currentTime: 0,
  70. startTime: 0,
  71. endTime: 0
  72. },
  73. qrcode: "",
  74. specDisabled: false,
  75. specBtnRepeat: false, //防止重复
  76. btnSwitch: false,
  77. // 店铺详情
  78. whetherCollection: 0,
  79. couponList: [], //优惠券列表
  80. couponBtnRepeat: false, //获取优惠券防止重复提交
  81. manjian: {}, //满减活动列表
  82. //评价
  83. currentPage: 1,
  84. pageSize: 10,
  85. total: 0,
  86. evaluaType: 0, //评价类型
  87. evaluteCount: {}, //评价数量
  88. goodsEvaluateList: [],
  89. //组合套餐
  90. bundling: [{
  91. bundling_goods: {
  92. bl_name: "",
  93. sku_image: ""
  94. }
  95. }],
  96. service: null,
  97. service_is_display: '', //售后保障
  98. number: 1,
  99. tabName: "detail",
  100. tabBundling: "",
  101. playerOptions: {
  102. playbackRates: [0.5, 1.0, 1.5, 2.0, 3.0], // 可选的播放速度
  103. autoplay: false, // 如果为true,浏览器准备好时开始回放。
  104. muted: false, // 默认情况下将会消除任何音频。
  105. loop: false, // 是否视频一结束就重新开始。
  106. preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
  107. language: "zh-CN",
  108. aspectRatio: "16:9", // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
  109. fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
  110. sources: [{
  111. type: "video/mp4", // 类型
  112. src: "" // url地址
  113. }],
  114. poster: "", // 封面地址
  115. notSupportedMessage: "此视频暂无法播放,请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
  116. controlBar: {
  117. timeDivider: true, // 当前时间和持续时间的分隔符
  118. durationDisplay: true, // 显示持续时间
  119. remainingTimeDisplay: true, // 是否显示剩余时间功能
  120. fullscreenToggle: true // 是否显示全屏按钮
  121. }
  122. },
  123. switchMedia: "img",
  124. // 是否关注店铺
  125. hasFollow: false,
  126. // 客服配置
  127. kefuConfig: {
  128. system: '',
  129. open_pc: '',
  130. open_url: ''
  131. },
  132. // 省市区县
  133. provinceArr: {},
  134. cityArr: {},
  135. districtArr: {},
  136. // 省市区县 id
  137. currTabAddres: "province",
  138. hideRegion: false,
  139. selectedAddress: {},
  140. service_list: [], //商品服务
  141. cartListNum: 0, //购物车列表下当前商品的数量
  142. listNum: false, //限购是
  143. shopNum: "",
  144. seoInfo: {
  145. title: '',
  146. keywords: ''
  147. },
  148. categoryNameArr: []
  149. }
  150. },
  151. components: {
  152. CountDown
  153. },
  154. head() {
  155. return {
  156. title: this.seoInfo.title,
  157. meta: [{
  158. name: "description",
  159. content: this.seoInfo.title
  160. },
  161. {
  162. name: "keyword",
  163. content: this.seoInfo.keywords
  164. }
  165. ]
  166. }
  167. },
  168. asyncData({
  169. params
  170. }) {
  171. return goodsSkuInfo({
  172. sku_id: params.id
  173. })
  174. .then(res => {
  175. if (res.code == 0 && res.data) {
  176. let data = res.data
  177. return {
  178. seoInfo: {
  179. title: data.goods_name,
  180. keywords: data.keywords
  181. }
  182. }
  183. }
  184. }).catch(res => {})
  185. },
  186. created() {
  187. this.skuId = this.$route.params.id
  188. this.getGoodsSkuDetail()
  189. },
  190. computed: {
  191. ...mapGetters(["token", "siteInfo", "defaultHeadImage", "defaultShopImage", "defaultGoodsImage", "addonIsExit",
  192. 'locationRegion'
  193. ])
  194. },
  195. watch: {
  196. $route: function(curr) {
  197. this.skuId = curr.params.id
  198. this.getGoodsSkuDetail()
  199. }
  200. },
  201. methods: {
  202. shopServiceOpen() {
  203. shopServiceOpen().then((res) => {
  204. if (res.code == 0) {
  205. this.kefuConfig = res.data;
  206. }
  207. })
  208. },
  209. service_link() {
  210. if (this.token) {
  211. this.$refs.servicerMessage.show();
  212. } else {
  213. this.$message({
  214. message: "您还未登录",
  215. type: "warning"
  216. })
  217. }
  218. },
  219. tabChange(tab, event) {},
  220. bundlingChange(tab, event) {},
  221. getGoodsSkuDetail() {
  222. goodsSkuDetail({
  223. sku_id: this.skuId
  224. })
  225. .then(res => {
  226. let data = res.data
  227. if (data.goods_sku_detail != null) {
  228. let categoryIdArr = data.goods_sku_detail.category_id.split(",")
  229. categoryIdArr = categoryIdArr.filter((item) => {
  230. return item && item.trim()
  231. });
  232. this.categorySearch(categoryIdArr[categoryIdArr.length - 1]);
  233. this.goodsSkuDetail = data.goods_sku_detail
  234. this.service_list = data.goods_sku_detail.goods_service
  235. if (this.min_buy > 0) this.number = this.min_buy
  236. this.id = this.goodsSkuDetail.goods_id
  237. if (this.skuId == 0) this.skuId = this.goodsSkuDetail.sku_id
  238. if (this.goodsSkuDetail.sku_images) this.goodsSkuDetail.sku_images = this.goodsSkuDetail.sku_images.split(
  239. ",");
  240. else this.goodsSkuDetail.sku_images = [];
  241. // 多规格时合并主图
  242. if (this.goodsSkuDetail.goods_spec_format && this.goodsSkuDetail.goods_image) {
  243. this.goodsSkuDetail.goods_image = this.goodsSkuDetail.goods_image.split(",");
  244. this.master_img = this.goodsSkuDetail.goods_image
  245. this.goodsSkuDetail.sku_images = this.goodsSkuDetail.goods_image.concat(this.goodsSkuDetail.sku_images);
  246. }
  247. //媒体
  248. if (this.goodsSkuDetail.video_url) {
  249. this.switchMedia = "video"
  250. this.playerOptions.poster = this.$img(this.goodsSkuDetail.sku_images[0])
  251. this.playerOptions.sources[0].src = this.$img(this.goodsSkuDetail.video_url)
  252. }
  253. this.picZoomUrl = this.goodsSkuDetail.sku_images[0]
  254. this.goodsSkuDetail.unit = this.goodsSkuDetail.unit || "件"
  255. // 当前商品SKU规格
  256. if (this.goodsSkuDetail.sku_spec_format) this.goodsSkuDetail.sku_spec_format = JSON.parse(this
  257. .goodsSkuDetail.sku_spec_format)
  258. // 商品属性
  259. if (this.goodsSkuDetail.goods_attr_format) {
  260. let goods_attr_format = JSON.parse(this.goodsSkuDetail.goods_attr_format);
  261. this.goodsSkuDetail.goods_attr_format = this.$util.unique(goods_attr_format, "attr_id");
  262. for (var i = 0; i < this.goodsSkuDetail.goods_attr_format.length; i++) {
  263. for (var j = 0; j < goods_attr_format.length; j++) {
  264. if (this.goodsSkuDetail.goods_attr_format[i].attr_id == goods_attr_format[j].attr_id && this
  265. .goodsSkuDetail.goods_attr_format[
  266. i].attr_value_id != goods_attr_format[j].attr_value_id) {
  267. this.goodsSkuDetail.goods_attr_format[i].attr_value_name += "、" + goods_attr_format[j]
  268. .attr_value_name;
  269. }
  270. }
  271. }
  272. }
  273. // 商品SKU格式
  274. if (this.goodsSkuDetail.goods_spec_format) this.goodsSkuDetail.goods_spec_format = JSON.parse(this
  275. .goodsSkuDetail
  276. .goods_spec_format)
  277. window.document.title = `${this.goodsSkuDetail.sku_name} - ${this.siteInfo.site_name}`
  278. // 限时折扣
  279. if (this.goodsSkuDetail.promotion_type == 1 && this.addonIsExit.discount) {
  280. //检测倒计时
  281. if (this.goodsSkuDetail.end_time - res.timestamp > 0) {
  282. this.discountTimeMachine = {
  283. currentTime: res.timestamp,
  284. startTime: res.timestamp,
  285. endTime: this.goodsSkuDetail.end_time
  286. }
  287. } else {
  288. this.goodsSkuDetail.promotion_type = 0
  289. }
  290. }
  291. // 满减
  292. if (this.goodsSkuDetail.manjian) this.getManjian(this.goodsSkuDetail.manjian);
  293. // 优惠券
  294. if (this.goodsSkuDetail.coupon_list) {
  295. this.couponList = this.goodsSkuDetail.coupon_list;
  296. this.couponList.forEach(v => {
  297. if (v.count == v.lead_count) v.useState = 2;
  298. else if (v.max_fetch != 0 && v.member_coupon_num && v
  299. .member_coupon_num >= v.max_fetch) v.useState = 1;
  300. else v.useState = 0;
  301. });
  302. this.couponList = this.couponList.sort(this.sortBy('useState'))
  303. }
  304. // 组合套餐
  305. if (this.goodsSkuDetail.bundling_list) {
  306. this.handleBundlingData(this.goodsSkuDetail.bundling_list);
  307. }
  308. this.shopServiceOpen()
  309. // this.evaluteCount = this.goodsSkuDetail.evaluate_count;
  310. this.evaluateConfig = this.goodsSkuDetail.evaluate_config;
  311. if (this.evaluateConfig.evaluate_show == 1) {
  312. //商品评论
  313. this.evaluate_show = true
  314. this.goodsEvaluCount();
  315. this.getGoodsEvaluate();
  316. }
  317. this.loading = false
  318. } else {
  319. this.$router.push("/")
  320. }
  321. })
  322. .then(res => {
  323. if (this.token != "") {
  324. this.getWhetherCollection()
  325. // this.isFollow()
  326. }
  327. this.getAftersale()
  328. this.modifyGoodsInfo()
  329. this.getGoodsQrcode()
  330. this.getAddress('province', null, true);
  331. if (!this.locationRegion) {
  332. this.$store.commit("app/SET_LOCATION_REGION", {
  333. "level_1": {
  334. "id": 110000,
  335. "pid": 0,
  336. "name": "北京市",
  337. "shortname": "北京",
  338. "longitude": "116.40529",
  339. "latitude": "39.904987",
  340. "level": 1,
  341. "sort": 1,
  342. "status": 1,
  343. "default_data": 1
  344. },
  345. "level_2": {
  346. "id": 110100,
  347. "pid": 110000,
  348. "name": "北京市",
  349. "shortname": "北京",
  350. "longitude": "116.40529",
  351. "latitude": "39.904987",
  352. "level": 2,
  353. "sort": 1,
  354. "status": 1,
  355. "default_data": 1
  356. },
  357. "level_3": {
  358. "id": 110101,
  359. "pid": 110100,
  360. "name": "东城区",
  361. "shortname": "东城",
  362. "longitude": "116.418755",
  363. "latitude": "39.917545",
  364. "level": 3,
  365. "sort": 3,
  366. "status": 1,
  367. "default_data": 1
  368. },
  369. master_img: []
  370. });
  371. }
  372. this.selectedAddress = this.locationRegion;
  373. this.provinceId = this.selectedAddress.level_1.id
  374. this.getAddress('city', null, true, () => {
  375. this.cityId = this.selectedAddress.level_2.id
  376. if (this.cityId) this.getAddress('district', null, true)
  377. });
  378. })
  379. .catch(res => {
  380. this.loading = false
  381. this.$router.push("/")
  382. })
  383. },
  384. categorySearch(category_id) {
  385. goodsCategoryInfo({
  386. category_id: category_id
  387. }).then(res => {
  388. if (res.code == 0 && res.data) {
  389. this.categoryNameArr = [];
  390. try {
  391. let categoryArr = res.data.category_full_name.split("$_SPLIT_$");
  392. categoryArr.forEach((item, index) => {
  393. let obj = {};
  394. obj.name = item;
  395. obj.category_id = res.data["category_id_" + (index + 1)];
  396. this.categoryNameArr.push(obj);
  397. })
  398. } catch (e) {
  399. this.categoryNameArr = [];
  400. }
  401. }
  402. }).catch(err => {
  403. })
  404. },
  405. sortBy(field) {
  406. //根据传过来的字段进行排序,y-x 得分从高到低,x-y 从低到高
  407. return (y, x) => {
  408. return y[field] - x[field]
  409. }
  410. },
  411. changeThumbImg(tag) {
  412. if (this.goodsSkuDetail.sku_images.length < 4) return
  413. let page = this.goodsSkuDetail.sku_images.length % 4 // 可见数量4个
  414. let position = 94
  415. if (page == 0) page = this.goodsSkuDetail.sku_images.length - 4 // 可见数量4个
  416. else if (page != 0 && page != 1 && page < 2) return
  417. if (tag == "prev") {
  418. if (this.thumbPosition != 0 && Math.round(this.thumbPosition, 2) != position) {
  419. this.thumbPosition += position
  420. // this.moveThumbLeft = true;
  421. } else {
  422. // this.moveThumbLeft = false;
  423. }
  424. } else if (tag == "next") {
  425. if (Math.round(this.thumbPosition, 2) != -Math.round(position * page, 2)) {
  426. this.thumbPosition -= position
  427. // this.moveThumbRight = true;
  428. } else {
  429. // this.moveThumbRight = false;
  430. }
  431. }
  432. },
  433. //获取用户是否关注
  434. getWhetherCollection() {
  435. isCollect({
  436. goods_id: this.goodsSkuDetail.goods_id
  437. }).then(res => {
  438. this.whetherCollection = res.data
  439. })
  440. },
  441. editCollection() {
  442. //未关注添加关注
  443. if (this.whetherCollection == 0) {
  444. addCollect({
  445. sku_id: this.skuId,
  446. goods_id: this.goodsSkuDetail.goods_id
  447. }).then(res => {
  448. var data = res.data
  449. if (data > 0) {
  450. this.whetherCollection = 1
  451. this.goodsSkuDetail.collect_num++
  452. }
  453. })
  454. .catch(err => {
  455. if (err.message == '您尚未登录,请先进行登录') {
  456. this.$router.push('/auth/login');
  457. }
  458. this.btnSwitch = false
  459. })
  460. } else {
  461. //已关注取消关注
  462. deleteCollect({
  463. goods_id: this.goodsSkuDetail.goods_id
  464. }).then(res => {
  465. var data = res.data
  466. if (data > 0) {
  467. this.whetherCollection = 0
  468. this.goodsSkuDetail.collect_num--
  469. }
  470. })
  471. .catch(err => {
  472. if (err.message == '您尚未登录,请先进行登录') {
  473. this.$router.push('/auth/login');
  474. }
  475. this.btnSwitch = false
  476. })
  477. }
  478. },
  479. //获取满减信息
  480. getManjian(data) {
  481. this.manjian = data;
  482. let limit = data.type == 0 ? '元' : '件';
  483. Object.keys(data.rule_json).forEach((key) => {
  484. var item = data.rule_json[key];
  485. if (item.coupon_data) {
  486. for (var i = 0; i < item.coupon_data.length; i++) {
  487. item.coupon_data[i].coupon_num = item.coupon_num[i]
  488. }
  489. }
  490. item.limit = data.type == 0 ? parseFloat(item.limit).toFixed(2) :
  491. parseInt(item.limit);
  492. // 满减
  493. if (item.discount_money != undefined) {
  494. if (this.manjian.manjian == undefined) {
  495. this.manjian.manjian = '满' + item.limit + limit + '减' + item
  496. .discount_money + '元';
  497. } else {
  498. this.manjian.manjian += ';满' + item.limit + limit + '减' + item
  499. .discount_money + '元';
  500. }
  501. }
  502. // 满送
  503. if (item.point != undefined || item.coupon != undefined) {
  504. let text = '';
  505. if (item.point != undefined) {
  506. text = '送' + item.point + '积分';
  507. }
  508. if (item.coupon != undefined && item.coupon_data != undefined) {
  509. item.coupon_data.forEach((couponItem, couponIndex) => {
  510. if (couponItem.type == 'discount') {
  511. if (text == '') text = '送' + item.coupon_num[
  512. couponIndex] + '张' + parseFloat(
  513. couponItem.discount) + '折优惠券';
  514. else text += '、送' + item.coupon_num[
  515. couponIndex] + '张' + parseFloat(
  516. couponItem
  517. .discount) + '折优惠券';
  518. } else {
  519. if (text == '') text = '送' + item.coupon_num[
  520. couponIndex] + '张' + parseFloat(
  521. couponItem.money) + '元优惠券';
  522. else text += '、送' + item.coupon_num[
  523. couponIndex] + '张' + parseFloat(
  524. couponItem
  525. .money) + '元优惠券';
  526. }
  527. })
  528. }
  529. if (this.manjian.mansong == undefined) {
  530. this.manjian.mansong = '满' + item.limit + limit + text;
  531. } else {
  532. this.manjian.mansong += ';' + '满' + item.limit + limit + text;
  533. }
  534. }
  535. // 包邮
  536. if (item.free_shipping != undefined) {
  537. if (this.manjian.free_shipping == undefined) {
  538. this.manjian.free_shipping = '满' + item.limit + limit + '包邮';
  539. } else {
  540. this.manjian.free_shipping += ';满' + item.limit + limit + '包邮';
  541. }
  542. }
  543. });
  544. },
  545. // 领取优惠券
  546. receiveCoupon(couponTypeId) {
  547. if (!getToken()) {
  548. this.$router.push('/auth/login');
  549. return
  550. }
  551. if (this.couponBtnRepeat) return
  552. this.couponBtnRepeat = true
  553. couponReceive({
  554. coupon_type_id: couponTypeId,
  555. site_id: this.goodsSkuDetail.site_id,
  556. get_type: 2 //获取方式:1订单2.直接领取3.活动领取
  557. })
  558. .then(res => {
  559. var data = res.data
  560. let msg = res.message
  561. if (res.code == 0) {
  562. msg = "领取成功"
  563. }
  564. this.$message({
  565. message: msg,
  566. type: "success"
  567. })
  568. this.couponBtnRepeat = false
  569. })
  570. .catch(res => {
  571. this.$message({
  572. message: res.message,
  573. type: "error"
  574. })
  575. this.couponBtnRepeat = false
  576. })
  577. },
  578. // 组合套餐
  579. handleBundlingData(data) {
  580. this.bundling = data;
  581. if (this.bundling.length) {
  582. this.tabBundling = "bundling_" + this.bundling[0].bl_id;
  583. for (var i = 0; i < this.bundling.length; i++) {
  584. for (var j = 0; j < this.bundling[i].bundling_goods.length; j++) {
  585. if (this.bundling[i].bundling_goods[j].sku_id == this.skuId) {
  586. this.bundling[i].bundling_goods.splice(j, 1);
  587. }
  588. }
  589. }
  590. }
  591. },
  592. //切换评价
  593. evaluationType(value) {
  594. this.evaluaType = value
  595. this.getGoodsEvaluate()
  596. },
  597. // 售后保障
  598. getAftersale() {
  599. aftersale({}).then(res => {
  600. if (res.code == 0 && res.data) {
  601. this.service_is_display = res.data
  602. let data = res.data.content
  603. if (res.data.content) this.service = res.data
  604. }
  605. })
  606. },
  607. //更新商品信息
  608. modifyGoodsInfo() {
  609. //更新商品点击量
  610. modifyClicks({
  611. sku_id: this.skuId,
  612. site_id: this.goodsSkuDetail.site_id
  613. })
  614. //添加足迹
  615. addGoodsbrowse({
  616. sku_id: this.skuId,
  617. goods_id: this.goodsSkuDetail.goods_id
  618. })
  619. },
  620. // 商品二维码
  621. getGoodsQrcode() {
  622. goodsQrcode({
  623. sku_id: this.skuId
  624. }).then(res => {
  625. let data = res.data
  626. if (data.path.h5.img) this.qrcode = this.$img(data.path.h5.img)
  627. })
  628. },
  629. //商品评价数量
  630. goodsEvaluCount(){
  631. goodsEvaluateCount({
  632. goods_id: this.goodsSkuDetail.goods_id
  633. }).then(res =>{
  634. if(res.code == 0 && res.data){
  635. this.evaluteCount = res.data
  636. }
  637. })
  638. },
  639. // 商品评价列表
  640. getGoodsEvaluate() {
  641. goodsEvaluateList({
  642. page: this.currentPage,
  643. page_size: this.pageSize,
  644. goods_id: this.id,
  645. explain_type: this.evaluaType == 0 ? '' : this.evaluaType
  646. }).then(res => {
  647. let list = []
  648. let msg = res.message
  649. if (res.code == 0 && res.data) {
  650. list = res.data.list
  651. this.total = res.data.count
  652. }
  653. for (var i = 0; i < list.length; i++) {
  654. // 1好评2中评3差评
  655. if (list[i].explain_type == 1) {
  656. list[i].star = 5
  657. } else if (list[i].explain_type == 2) {
  658. list[i].star = 3
  659. } else if (list[i].explain_type == 3) {
  660. list[i].star = 1
  661. }
  662. if (list[i].images) {
  663. list[i].images = list[i].images.split(",")
  664. list[i].imagesFormat = []
  665. for (var k = 0; k < list[i].images.length; k++) {
  666. list[i].imagesFormat.push(this.$img(list[i].images[k]))
  667. }
  668. }
  669. if (list[i].again_images) {
  670. list[i].again_images = list[i].again_images.split(",")
  671. list[i].againImagesFormat = []
  672. for (var j = 0; j < list[i].again_images.length; j++) {
  673. list[i].againImagesFormat.push(this.$img(list[i].again_images[j]))
  674. }
  675. }
  676. if (list[i].is_anonymous == 1) list[i].member_name = list[i].member_name.replace(list[i].member_name
  677. .substring(1,
  678. list[i].member_name.length - 1), "***")
  679. }
  680. this.goodsEvaluateList = list
  681. })
  682. },
  683. // 图片加载失败
  684. imageErrorEvaluate(index) {
  685. this.goodsEvaluateList[index].member_headimg = this.defaultHeadImage
  686. },
  687. handlePageSizeChange(size) {
  688. this.pageSize = size
  689. this.getGoodsEvaluate()
  690. },
  691. handleCurrentPageChange(page) {
  692. this.currentPage = page
  693. this.getGoodsEvaluate()
  694. },
  695. changeSpec(skuId, spec_id) {
  696. if (this.specDisabled) return
  697. this.specBtnRepeat = false
  698. this.skuId = skuId
  699. // 清空选择
  700. for (var i = 0; i < this.goodsSkuDetail.goods_spec_format.length; i++) {
  701. var sku = this.goodsSkuDetail.goods_spec_format[i]
  702. for (var j = 0; j < sku.value.length; j++) {
  703. // 排除当前点击的规格值
  704. if (spec_id == this.goodsSkuDetail.goods_spec_format[i].value[j].spec_id) {
  705. this.goodsSkuDetail.goods_spec_format[i].value[j].selected = false
  706. }
  707. }
  708. }
  709. goodsSkuInfo({
  710. sku_id: this.skuId
  711. }).then(res => {
  712. let data = res.data
  713. if (data != null) {
  714. data.sku_images = data.sku_images.split(",")
  715. this.picZoomUrl = data.sku_images[0]
  716. this.playerOptions.poster = this.$img(data.sku_image)
  717. if (data.sku_images == "") {
  718. data.sku_images = this.master_img;
  719. this.picZoomUrl = data.sku_images[0]
  720. this.playerOptions.poster = this.$img(data.sku_image)
  721. } else {
  722. data.sku_images = data.sku_images.concat(this.master_img);
  723. }
  724. // 当前商品SKU规格
  725. if (data.sku_spec_format) data.sku_spec_format = JSON.parse(data.sku_spec_format)
  726. // 商品SKU格式
  727. if (data.goods_spec_format) data.goods_spec_format = JSON.parse(data.goods_spec_format)
  728. if (data.goods_attr_format) data.goods_attr_format = JSON.parse(data.goods_attr_format)
  729. this.keyInput(true)
  730. // 限时折扣
  731. if (data.promotion_type == 1) {
  732. this.discountTimeMachine = {
  733. currentTime: res.timestamp,
  734. startTime: res.timestamp,
  735. endTime: data.end_time
  736. }
  737. }
  738. this.specBtnRepeat = false
  739. Object.assign(this.goodsSkuDetail, data)
  740. } else {
  741. this.$router.push("/")
  742. }
  743. })
  744. },
  745. changeNum(tag) {
  746. if (this.goodsSkuDetail.stock == 0) return
  747. var stock = this.goodsSkuDetail.stock
  748. var min = 1
  749. if (tag == "+") {
  750. // 加
  751. if (this.number < stock) {
  752. this.number++
  753. } else {
  754. return
  755. }
  756. } else if (tag == "-") {
  757. // 减
  758. if (this.number > min) {
  759. this.number -= 1
  760. } else {
  761. return
  762. }
  763. }
  764. this.purchase()
  765. },
  766. // 判断是否限购
  767. purchase() {
  768. if (this.goodsSkuDetail.is_limit == 1) {
  769. if (this.goodsSkuDetail.limit_type == 1) {
  770. if (this.number > this.goodsSkuDetail.max_buy) {
  771. this.$message({
  772. message: '该商品最多购买' + this.goodsSkuDetail.max_buy + '件',
  773. type: 'warning'
  774. });
  775. this.number = this.goodsSkuDetail.max_buy
  776. }
  777. } else if (this.goodsSkuDetail.limit_type == 2) {
  778. this.shopNum = this.goodsSkuDetail.max_buy - this.goodsSkuDetail.purchased_num
  779. console.log(this.shopNum)
  780. var title = ''
  781. if (this.goodsSkuDetail.purchased_num == 0) {
  782. title = '该商品每人限购' + this.goodsSkuDetail.max_buy + '件'
  783. } else if (this.goodsSkuDetail.purchased_num > 0) {
  784. title = '该商品每人限购' + this.goodsSkuDetail.max_buy + '件,您已购买' + this.goodsSkuDetail.purchased_num + '件'
  785. }
  786. if (this.number > this.shopNum) {
  787. console.log("进入添加")
  788. this.$message({
  789. message: title,
  790. type: 'warning'
  791. });
  792. this.number = this.shopNum
  793. }
  794. }
  795. }
  796. },
  797. //输入数量
  798. keyInput() {
  799. var stock = this.goodsSkuDetail.stock
  800. // 库存为0
  801. if (this.goodsSkuDetail.stock == 0) {
  802. this.number = 0
  803. return
  804. }
  805. // 防止空
  806. if (this.number == 0 || this.number == '') this.number = 1
  807. var re = /^\d+$/
  808. if (re.test(parseInt(this.number))) {
  809. if (this.number > stock) {
  810. this.number = stock
  811. }
  812. this.number = parseInt(this.number)
  813. } else {
  814. this.number = 1
  815. }
  816. this.purchase()
  817. },
  818. // 播放回调
  819. onPlayerPlay(player) {},
  820. // 暂停回调
  821. onPlayerPause(player) {},
  822. // 视频播完回调
  823. onPlayerEnded(player) {},
  824. // DOM元素上的readyState更改导致播放停止
  825. onPlayerWaiting(player) {},
  826. // 已开始播放回调
  827. onPlayerPlaying(player) {},
  828. // 当播放器在当前播放位置下载数据时触发
  829. onPlayerLoadeddata(player) {},
  830. // 当前播放位置发生变化时触发。
  831. onPlayerTimeupdate(player) {},
  832. //媒体的readyState为HAVE_FUTURE_DATA或更高
  833. onPlayerCanplay(player) {},
  834. //媒体的readyState为HAVE_ENOUGH_DATA或更高。这意味着可以在不缓冲的情况下播放整个媒体文件。
  835. onPlayerCanplaythrough(player) {},
  836. //播放状态改变回调
  837. playerStateChanged(playerCurrentState) {},
  838. //将侦听器绑定到组件的就绪状态。与事件监听器的不同之处在于,如果ready事件已经发生,它将立即触发该函数。。
  839. playerReadied(player) {},
  840. // 加入购物车
  841. joinCart() {
  842. //纠正数量
  843. if (this.goodsSkuDetail.stock == 0) {
  844. this.$message({
  845. message: "商品已售罄",
  846. type: "warning"
  847. })
  848. return
  849. }
  850. if (this.number.length == 0 || this.number == 0) {
  851. this.$message({
  852. message: "购买数量不能为0",
  853. type: "warning"
  854. })
  855. return
  856. }
  857. if (this.btnSwitch) return
  858. this.btnSwitch = true
  859. this.$store.dispatch("cart/add_to_cart", {
  860. site_id: this.goodsSkuDetail.site_id,
  861. sku_id: this.goodsSkuDetail.sku_id,
  862. num: this.number
  863. }).then(res => {
  864. console.log("添加成功")
  865. var data = res.data
  866. if (data > 0) {
  867. this.$message({
  868. message: "加入购物车成功",
  869. type: "success"
  870. })
  871. }
  872. this.btnSwitch = false
  873. })
  874. .catch(err => {
  875. if (err.message == '您尚未登录,请先进行登录') {
  876. this.$router.push('/auth/login');
  877. } else {
  878. this.$message.error(err.message)
  879. }
  880. this.btnSwitch = false
  881. })
  882. console.log(this.cartListNum)
  883. },
  884. // 立即购买
  885. buyNow() {
  886. if (this.goodsSkuDetail.stock == 0) {
  887. this.$message({
  888. message: "商品已售罄",
  889. type: "warning"
  890. })
  891. return
  892. }
  893. if (this.number.length == 0 || this.number == 0) {
  894. this.$message({
  895. message: "购买数量不能为0",
  896. type: "warning"
  897. })
  898. return
  899. }
  900. if (parseInt(this.number) + parseInt(this.goodsSkuDetail.purchased_num) > this.goodsSkuDetail.max_buy && this
  901. .goodsSkuDetail
  902. .max_buy != 0) {
  903. let _newNum = parseInt(this.goodsSkuDetail.max_buy) - parseInt(this.goodsSkuDetail.purchased_num)
  904. this.$message({
  905. message: '商品限购' + this.goodsSkuDetail.max_buy + '件,现在已经购买' + this.goodsSkuDetail.purchased_num +
  906. '件,还能购买' +
  907. _newNum + '件',
  908. type: "warning"
  909. })
  910. return
  911. }
  912. var data = {
  913. sku_id: this.skuId,
  914. num: this.number
  915. }
  916. this.$store.dispatch("order/setOrderCreateData", data)
  917. this.$router.push({
  918. path: "/order/payment"
  919. })
  920. },
  921. countDownS_cb() {},
  922. countDownE_cb() {
  923. this.discountText = "活动已结束"
  924. },
  925. //是否关注
  926. // isFollow() {
  927. // shopIsSubscribe({
  928. // site_id: this.goodsSkuDetail.site_id
  929. // }).then(res => {
  930. // if (res.code == 0) {
  931. // this.hasFollow = res.data
  932. // }
  933. // })
  934. // },
  935. // follow() {
  936. // if (this.hasFollow) {
  937. // deleteShopSubscribe({
  938. // site_id: this.goodsSkuDetail.site_id
  939. // }).then(res => {
  940. // if (res.code == 0 && res.data) {
  941. // this.hasFollow = !this.hasFollow
  942. // this.$message({
  943. // message: "取消成功",
  944. // type: "success"
  945. // })
  946. // }
  947. // })
  948. // } else {
  949. // addShopSubscribe({
  950. // site_id: this.goodsSkuDetail.site_id
  951. // }).then(res => {
  952. // if (res.code == 0 && res.data) {
  953. // this.hasFollow = !this.hasFollow
  954. // this.$message({
  955. // message: "关注成功",
  956. // type: "success"
  957. // })
  958. // }
  959. // })
  960. // }
  961. // },
  962. // 图片加载失败
  963. imageErrorSpec(index) {
  964. this.goodsSkuDetail.sku_images[index] = this.defaultGoodsImage
  965. this.picZoomUrl = this.defaultGoodsImage
  966. },
  967. /**
  968. * 获取地址
  969. * @param {Object} type
  970. * @param {Object} item
  971. * @param {Object} first 是否第一次
  972. */
  973. getAddress(type, item, first, callback) {
  974. let pid = 0
  975. switch (type) {
  976. case 'province':
  977. //加载省
  978. pid = 0
  979. break
  980. case 'city':
  981. //加载市
  982. if (item) {
  983. this.provinceId = item.id
  984. }
  985. pid = this.provinceId
  986. this.cityArr = {}
  987. this.districtArr = {}
  988. break
  989. case 'district':
  990. //加载区县
  991. if (item) this.cityId = item.id
  992. pid = this.cityId
  993. this.districtArr = {}
  994. break
  995. }
  996. if (item) {
  997. if (item.level <= 2) {
  998. let len = item.level;
  999. for (let i = len; i <= 3; i++) {
  1000. delete this.selectedAddress['level_' + i];
  1001. }
  1002. }
  1003. this.selectedAddress['level_' + item.level] = item;
  1004. }
  1005. if (!first) this.$store.commit("app/SET_LOCATION_REGION", this.selectedAddress)
  1006. this.$forceUpdate();
  1007. if (type == 'community') {
  1008. this.hideRegion = true;
  1009. setTimeout(() => {
  1010. this.hideRegion = false;
  1011. }, 10);
  1012. return;
  1013. }
  1014. getArea({
  1015. pid: pid
  1016. })
  1017. .then(res => {
  1018. const {
  1019. code,
  1020. data
  1021. } = res;
  1022. if (data) {
  1023. switch (type) {
  1024. case 'province':
  1025. //加载省
  1026. this.provinceArr = data
  1027. break
  1028. case 'city':
  1029. //加载市
  1030. this.cityArr = data
  1031. break
  1032. case 'district':
  1033. //加载区县
  1034. this.districtArr = data
  1035. break
  1036. }
  1037. this.currTabAddres = type
  1038. if (callback) callback();
  1039. }
  1040. })
  1041. .catch(err => {})
  1042. }
  1043. }
  1044. }