detail_seckill.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. import {
  2. aftersale,
  3. modifyClicks,
  4. addGoodsbrowse,
  5. goodsQrcode,
  6. seckillGoodsInfo
  7. } from "@/api/goods/goods"
  8. import {
  9. goodsCategoryInfo
  10. } from "@/api/goods/goodscategory"
  11. import {
  12. goodsSkuDetail,
  13. evaluateConfig
  14. } from "@/api/seckill"
  15. import {
  16. isCollect,
  17. addCollect,
  18. deleteCollect
  19. } from "@/api/goods/goods_collect"
  20. import {
  21. goodsEvaluateList,
  22. goodsEvaluateCount
  23. } from "@/api/goods/evaluate"
  24. import {
  25. mapGetters
  26. } from "vuex"
  27. import CountDown from "vue2-countdown"
  28. // import {
  29. // shopIsSubscribe,
  30. // addShopSubscribe,
  31. // deleteShopSubscribe
  32. // } from "@/api/shop"
  33. import {
  34. getArea
  35. } from "@/api/address"
  36. import {
  37. shopServiceOpen
  38. } from "@/api/website.js"
  39. export default {
  40. data: () => {
  41. return {
  42. id: 0,
  43. skuId: 0,
  44. loading: true,
  45. picZoomUrl: "",
  46. thumbPosition: 0,
  47. // 是否可以移动
  48. moveThumbLeft: false,
  49. moveThumbRight: false,
  50. // 商品详情
  51. goodsSkuDetail: {
  52. video_url: ""
  53. },
  54. seckillText: "距离结束仅剩",
  55. seckillTimeMachine: {
  56. currentTime: 0,
  57. startTime: 0,
  58. endTime: 0
  59. },
  60. qrcode: "",
  61. specBtnRepeat: false, //防止重复
  62. // 店铺详情
  63. shopInfo: {},
  64. whetherCollection: 0,
  65. score: 0,
  66. //评价
  67. currentPage: 1,
  68. pageSize: 10,
  69. total: 0,
  70. evaluaType: 0,//评价类型
  71. evaluteCount:{},//评价数量
  72. goodsEvaluateList: [],
  73. evaluate_show: false, //是否显示评论
  74. service: null,
  75. number: 1,
  76. tabName: "detail",
  77. playerOptions: {
  78. playbackRates: [0.5, 1.0, 1.5, 2.0, 3.0], // 可选的播放速度
  79. autoplay: false, // 如果为true,浏览器准备好时开始回放。
  80. muted: false, // 默认情况下将会消除任何音频。
  81. loop: false, // 是否视频一结束就重新开始。
  82. preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
  83. language: "zh-CN",
  84. aspectRatio: "16:9", // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
  85. fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
  86. sources: [{
  87. type: "video/mp4", // 类型
  88. src: "" // url地址
  89. }],
  90. poster: "", // 封面地址
  91. notSupportedMessage: "此视频暂无法播放,请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
  92. controlBar: {
  93. timeDivider: true, // 当前时间和持续时间的分隔符
  94. durationDisplay: true, // 显示持续时间
  95. remainingTimeDisplay: true, // 是否显示剩余时间功能
  96. fullscreenToggle: true // 是否显示全屏按钮
  97. }
  98. },
  99. switchMedia: "img",
  100. // 是否关注店铺
  101. hasFollow: false,
  102. // 客服配置
  103. kefuConfig: {
  104. system: '',
  105. open_pc: '',
  106. open_url: ''
  107. },
  108. // 省市区县
  109. provinceArr: {},
  110. cityArr: {},
  111. districtArr: {},
  112. // 省市区县 id
  113. currTabAddres: "province",
  114. hideRegion: false,
  115. selectedAddress: {},
  116. service_list: [],
  117. serverType: 'disable',
  118. serverThird: '',
  119. categoryNameArr:[]
  120. }
  121. },
  122. components: {
  123. CountDown
  124. },
  125. created() {
  126. this.id = this.$route.params.id;
  127. if (this.addonIsExit && this.addonIsExit.seckill != 1) {
  128. this.$message({
  129. message: '秒杀插件未安装',
  130. type: 'warning',
  131. duration: 2000,
  132. onClose: () => {
  133. this.$route.push('/');
  134. }
  135. });
  136. } else {
  137. this.getGoodsSkuDetail()
  138. this.getGoodsEvaluate()
  139. this.goodsEvaluCount()
  140. }
  141. },
  142. computed: {
  143. ...mapGetters(["token", "siteInfo", "defaultHeadImage", "defaultShopImage", "addonIsExit", 'locationRegion'])
  144. },
  145. watch: {
  146. $route(curr) {
  147. this.id = curr.query.id
  148. if (this.addonIsExit && this.addonIsExit.seckill == 1) {
  149. this.getGoodsSkuDetail()
  150. this.shopServiceOpen()
  151. } else {
  152. this.$message({
  153. message: '秒杀插件未安装',
  154. type: 'warning',
  155. duration: 2000,
  156. onClose: () => {
  157. this.$route.push('/');
  158. }
  159. });
  160. }
  161. },
  162. addonIsExit() {
  163. if (this.addonIsExit.seckill != 1) {
  164. this.$message({
  165. message: '秒杀插件未安装',
  166. type: 'warning',
  167. duration: 2000,
  168. onClose: () => {
  169. this.$route.push('/');
  170. }
  171. });
  172. } else {
  173. this.shopServiceOpen()
  174. }
  175. }
  176. },
  177. methods: {
  178. shopServiceOpen() {
  179. shopServiceOpen().then((res) => {
  180. if (res.code == 0) {
  181. this.kefuConfig = res.data;
  182. }
  183. })
  184. },
  185. tabChange(tab, event) {},
  186. bundlingChange(tab, event) {},
  187. getGoodsSkuDetail() {
  188. goodsSkuDetail({
  189. seckill_id: this.id
  190. })
  191. .then(res => {
  192. let data = res.data
  193. if (data.goods_sku_detail != null) {
  194. this.goodsSkuDetail = data.goods_sku_detail
  195. let categoryIdArr = data.goods_sku_detail.category_id.split(",")
  196. categoryIdArr = categoryIdArr.filter((item)=>{
  197. return item&&item.trim()
  198. });
  199. this.categorySearch(categoryIdArr[categoryIdArr.length-1]);
  200. // this.shopInfo = data.shop_info
  201. // let num = (Number(this.shopInfo.shop_desccredit) + Number(this.shopInfo.shop_servicecredit) + Number(this.shopInfo
  202. // .shop_deliverycredit)) / 3
  203. // this.score = Number(num.toFixed(1));
  204. this.service_list = data.goods_sku_detail.goods_service
  205. this.skuId = this.goodsSkuDetail.sku_id
  206. //秒杀倒计时
  207. let time = new Date(res.timestamp * 1000)
  208. let currentTime = time.getHours() * 60 * 60 + time.getMinutes() * 60 + time.getSeconds()
  209. if (this.goodsSkuDetail.seckill_start_time <= currentTime && currentTime < this.goodsSkuDetail.seckill_end_time) {
  210. let endTime = parseInt(time.getTime() / 1000) + (this.goodsSkuDetail.seckill_end_time - currentTime)
  211. this.seckillTimeMachine = {
  212. currentTime: res.timestamp,
  213. startTime: res.timestamp,
  214. endTime: endTime
  215. }
  216. } else if (this.goodsSkuDetail.seckill_start_time > currentTime && currentTime < this.goodsSkuDetail.seckill_end_time) {
  217. this.$message({
  218. message: '限时秒杀活动还未开始',
  219. type: 'warning',
  220. duration: 2000,
  221. onClose: () => {
  222. this.$router.push("/sku/" + this.goodsSkuDetail.sku_id)
  223. }
  224. });
  225. } else if (currentTime < this.goodsSkuDetail.seckill_start_time && currentTime > this.goodsSkuDetail.seckill_end_time) {
  226. this.$message({
  227. message: '限时秒杀活动已结束',
  228. type: 'warning',
  229. duration: 2000,
  230. onClose: () => {
  231. this.$router.push("/sku/" + this.goodsSkuDetail.sku_id)
  232. }
  233. });
  234. }
  235. if (this.goodsSkuDetail.sku_images) this.goodsSkuDetail.sku_images = this.goodsSkuDetail.sku_images.split(",");
  236. else this.goodsSkuDetail.sku_images = [];
  237. // 多规格时合并主图
  238. if (this.goodsSkuDetail.goods_spec_format && this.goodsSkuDetail.goods_image) {
  239. this.goodsSkuDetail.goods_image = this.goodsSkuDetail.goods_image.split(",");
  240. this.master_img = this.goodsSkuDetail.goods_image
  241. this.goodsSkuDetail.sku_images = this.goodsSkuDetail.sku_images.concat(this.goodsSkuDetail.goods_image);
  242. }
  243. //媒体
  244. if (this.goodsSkuDetail.video_url) {
  245. this.switchMedia = "video"
  246. this.playerOptions.poster = this.$img(this.goodsSkuDetail.sku_images[0])
  247. this.playerOptions.sources[0].src = this.$img(this.goodsSkuDetail.video_url)
  248. }
  249. this.picZoomUrl = this.goodsSkuDetail.sku_images[0]
  250. this.goodsSkuDetail.unit = this.goodsSkuDetail.unit || "件"
  251. // 当前商品SKU规格
  252. if (this.goodsSkuDetail.sku_spec_format) this.goodsSkuDetail.sku_spec_format = JSON.parse(this.goodsSkuDetail.sku_spec_format)
  253. // 商品属性
  254. if (this.goodsSkuDetail.goods_attr_format) {
  255. let goods_attr_format = JSON.parse(this.goodsSkuDetail.goods_attr_format);
  256. this.goodsSkuDetail.goods_attr_format = this.$util.unique(goods_attr_format, "attr_id");
  257. for (var i = 0; i < this.goodsSkuDetail.goods_attr_format.length; i++) {
  258. for (var j = 0; j < goods_attr_format.length; j++) {
  259. if (this.goodsSkuDetail.goods_attr_format[i].attr_id == goods_attr_format[j].attr_id && this.goodsSkuDetail.goods_attr_format[
  260. i].attr_value_id != goods_attr_format[j].attr_value_id) {
  261. this.goodsSkuDetail.goods_attr_format[i].attr_value_name += "、" + goods_attr_format[j].attr_value_name;
  262. }
  263. }
  264. }
  265. }
  266. // 商品SKU格式
  267. if (this.goodsSkuDetail.goods_spec_format) this.goodsSkuDetail.goods_spec_format = JSON.parse(this.goodsSkuDetail
  268. .goods_spec_format)
  269. console.debug(this.goodsSkuDetail.goods_spec_format,'format')
  270. window.document.title = `${this.goodsSkuDetail.sku_name} - ${this.siteInfo.site_name}`
  271. this.loading = false
  272. } else {
  273. this.$router.push("/")
  274. }
  275. })
  276. .then(res => {
  277. if (this.token != "") {
  278. this.getWhetherCollection()
  279. // this.isFollow()
  280. }
  281. // this.getAftersale()
  282. this.modifyGoodsInfo()
  283. this.getEvaluateConfig()
  284. this.getGoodsQrcode()
  285. this.getAddress('province', null, true);
  286. if (!this.locationRegion) {
  287. this.$store.commit("app/SET_LOCATION_REGION", {
  288. "level_1": {
  289. "id": 110000,
  290. "pid": 0,
  291. "name": "北京市",
  292. "shortname": "北京",
  293. "longitude": "116.40529",
  294. "latitude": "39.904987",
  295. "level": 1,
  296. "sort": 1,
  297. "status": 1,
  298. "default_data": 1
  299. },
  300. "level_2": {
  301. "id": 110100,
  302. "pid": 110000,
  303. "name": "北京市",
  304. "shortname": "北京",
  305. "longitude": "116.40529",
  306. "latitude": "39.904987",
  307. "level": 2,
  308. "sort": 1,
  309. "status": 1,
  310. "default_data": 1
  311. },
  312. "level_3": {
  313. "id": 110101,
  314. "pid": 110100,
  315. "name": "东城区",
  316. "shortname": "东城",
  317. "longitude": "116.418755",
  318. "latitude": "39.917545",
  319. "level": 3,
  320. "sort": 3,
  321. "status": 1,
  322. "default_data": 1
  323. },
  324. master_img: []
  325. });
  326. }
  327. this.selectedAddress = this.locationRegion;
  328. this.provinceId = this.selectedAddress.level_1.id
  329. this.getAddress('city', null, true, () => {
  330. this.cityId = this.selectedAddress.level_2.id
  331. if (this.cityId) this.getAddress('district', null, true)
  332. });
  333. })
  334. .catch(res => {
  335. this.loading = false
  336. this.$router.push("/")
  337. })
  338. },
  339. categorySearch(category_id) {
  340. goodsCategoryInfo({
  341. category_id: category_id
  342. }).then(res => {
  343. if (res.code == 0 && res.data) {
  344. this.categoryNameArr = [];
  345. try{
  346. let categoryArr = res.data.category_full_name.split("$_SPLIT_$");
  347. categoryArr.forEach((item,index)=>{
  348. let obj = {};
  349. obj.name = item;
  350. obj.category_id = res.data["category_id_"+(index+1)];
  351. this.categoryNameArr.push(obj);
  352. })
  353. }catch(e){
  354. this.categoryNameArr = [];
  355. }
  356. console.log("this.categoryNameArr",this.categoryNameArr);
  357. }
  358. }).catch(err => {
  359. })
  360. },
  361. getEvaluateConfig() {
  362. evaluateConfig()
  363. .then(res => {
  364. console.log(res,'getEvaluateConfig')
  365. if (res.code == 0) {
  366. var data = res.data;
  367. this.evaluateConfig = data;
  368. if (this.evaluateConfig.evaluate_show == 1) {
  369. //商品评论
  370. this.evaluate_show = true
  371. this.getGoodsEvaluate();
  372. }
  373. }
  374. })
  375. },
  376. service_link() {
  377. if (this.token) {
  378. this.$refs.servicerMessage.show()
  379. } else {
  380. this.$message({
  381. message: "您还未登录",
  382. type: "warning"
  383. })
  384. }
  385. },
  386. changeThumbImg(tag) {
  387. if (this.goodsSkuDetail.sku_images.length < 4) return
  388. let page = this.goodsSkuDetail.sku_images.length % 4 // 可见数量4个
  389. let position = 94
  390. if (page == 0) page = this.goodsSkuDetail.sku_images.length - 4 // 可见数量4个
  391. else if (page != 0 && page != 1 && page < 2) return
  392. if (tag == "prev") {
  393. if (this.thumbPosition != 0 && Math.round(this.thumbPosition, 2) != position) {
  394. this.thumbPosition += position
  395. // this.moveThumbLeft = true;
  396. } else {
  397. // this.moveThumbLeft = false;
  398. }
  399. } else if (tag == "next") {
  400. if (Math.round(this.thumbPosition, 2) != -Math.round(position * page, 2)) {
  401. this.thumbPosition -= position
  402. // this.moveThumbRight = true;
  403. } else {
  404. // this.moveThumbRight = false;
  405. }
  406. }
  407. },
  408. //获取用户是否关注
  409. getWhetherCollection() {
  410. isCollect({
  411. goods_id: this.goodsSkuDetail.goods_id
  412. }).then(res => {
  413. this.whetherCollection = res.data
  414. })
  415. },
  416. editCollection() {
  417. //未关注添加关注
  418. if (this.whetherCollection == 0) {
  419. addCollect({
  420. sku_id: this.skuId,
  421. goods_id: this.goodsSkuDetail.goods_id
  422. }).then(res => {
  423. var data = res.data
  424. if (data > 0) {
  425. this.whetherCollection = 1
  426. this.goodsSkuDetail.collect_num++
  427. }
  428. })
  429. } else {
  430. //已关注取消关注
  431. deleteCollect({
  432. goods_id: this.goodsSkuDetail.goods_id
  433. }).then(res => {
  434. var data = res.data
  435. if (data > 0) {
  436. this.whetherCollection = 0
  437. this.goodsSkuDetail.collect_num--
  438. }
  439. })
  440. }
  441. },
  442. // 售后保障
  443. getAftersale() {
  444. aftersale({}).then(res => {
  445. if (res.code == 0 && res.data) {
  446. let data = res.data.content
  447. if (res.data.content) this.service = res.data.content
  448. }
  449. })
  450. },
  451. //更新商品信息
  452. modifyGoodsInfo() {
  453. //更新商品点击量
  454. modifyClicks({
  455. sku_id: this.skuId,
  456. site_id: this.goodsSkuDetail.site_id
  457. })
  458. //添加足迹
  459. addGoodsbrowse({
  460. sku_id: this.skuId,
  461. goods_id: this.goodsSkuDetail.goods_id
  462. })
  463. },
  464. // 商品二维码
  465. getGoodsQrcode() {
  466. goodsQrcode({
  467. sku_id: this.skuId
  468. }).then(res => {
  469. let data = res.data
  470. if (data.path.h5.img) this.qrcode = this.$img(data.path.h5.img)
  471. })
  472. },
  473. //商品评价数量
  474. goodsEvaluCount(){
  475. goodsEvaluateCount({
  476. goods_id: this.id
  477. }).then(res =>{
  478. if(res.code == 0 && res.data){
  479. this.evaluteCount = res.data
  480. }
  481. })
  482. },
  483. // 商品评价列表
  484. getGoodsEvaluate() {
  485. goodsEvaluateList({
  486. page: this.currentPage,
  487. page_size: this.pageSize,
  488. goods_id: this.id,
  489. explain_type: this.evaluaType == 0 ? '' : this.evaluaType
  490. }).then(res => {
  491. let list = []
  492. let msg = res.message
  493. if (res.code == 0 && res.data) {
  494. list = res.data.list
  495. this.total = res.data.count
  496. }
  497. for (var i = 0; i < list.length; i++) {
  498. // 1好评2中评3差评
  499. if (list[i].explain_type == 1) {
  500. list[i].star = 5
  501. } else if (list[i].explain_type == 2) {
  502. list[i].star = 3
  503. } else if (list[i].explain_type == 3) {
  504. list[i].star = 1
  505. }
  506. if (list[i].images) {
  507. list[i].images = list[i].images.split(",")
  508. list[i].imagesFormat = []
  509. for (var k = 0; k < list[i].images.length; k++) {
  510. list[i].imagesFormat.push(this.$img(list[i].images[k]))
  511. }
  512. }
  513. if (list[i].again_images) {
  514. list[i].again_images = list[i].again_images.split(",")
  515. list[i].againImagesFormat = []
  516. for (var j = 0; j < list[i].again_images.length; j++) {
  517. list[i].againImagesFormat.push(this.$img(list[i].again_images[j]))
  518. }
  519. }
  520. if (list[i].is_anonymous == 1) list[i].member_name = list[i].member_name.replace(list[i].member_name.substring(1,
  521. list[i].member_name.length - 1), "***")
  522. }
  523. this.goodsEvaluateList = list
  524. })
  525. },
  526. // 图片加载失败
  527. imageErrorEvaluate(index) {
  528. this.goodsEvaluateList[index].member_headimg = this.defaultHeadImage
  529. },
  530. handlePageSizeChange(size) {
  531. this.pageSize = size
  532. this.getGoodsEvaluate()
  533. },
  534. handleCurrentPageChange(page) {
  535. this.currentPage = page
  536. this.getGoodsEvaluate()
  537. },
  538. changeSpec(skuId, spec_id, disabled) {
  539. if (disabled) return
  540. this.specBtnRepeat = false
  541. this.skuId = skuId
  542. // 清空选择
  543. for (var i = 0; i < this.goodsSkuDetail.goods_spec_format.length; i++) {
  544. var sku = this.goodsSkuDetail.goods_spec_format[i]
  545. for (var j = 0; j < sku.value.length; j++) {
  546. // 排除当前点击的规格值
  547. if (spec_id == this.goodsSkuDetail.goods_spec_format[i].value[j].spec_id) {
  548. this.goodsSkuDetail.goods_spec_format[i].value[j].selected = false
  549. }
  550. }
  551. }
  552. seckillGoodsInfo({
  553. sku_id: this.skuId,
  554. seckill_id: this.goodsSkuDetail.seckill_id
  555. }).then(res => {
  556. let data = res.data.goods_sku_detail
  557. if (data != null) {
  558. data.sku_images = data.sku_images.split(",")
  559. this.picZoomUrl = data.sku_images[0]
  560. this.playerOptions.poster = this.$img(data.sku_image)
  561. if(data.sku_images == ""){
  562. data.sku_images = this.master_img;
  563. this.picZoomUrl = data.sku_images[0]
  564. this.playerOptions.poster = this.$img(data.sku_image)
  565. }else{
  566. data.sku_images = data.sku_images.concat(this.master_img);
  567. }
  568. // 当前商品SKU规格
  569. if (data.sku_spec_format) data.sku_spec_format = JSON.parse(data.sku_spec_format)
  570. // 商品SKU格式
  571. if (data.goods_spec_format) data.goods_spec_format = JSON.parse(data.goods_spec_format)
  572. if (data.goods_attr_format) data.goods_attr_format = JSON.parse(data.goods_attr_format)
  573. this.keyInput(true)
  574. // 限时折扣
  575. if (data.promotion_type == 1) {
  576. this.discountTimeMachine = {
  577. currentTime: res.timestamp,
  578. startTime: res.timestamp,
  579. endTime: data.end_time
  580. }
  581. }
  582. this.specBtnRepeat = false
  583. Object.assign(this.goodsSkuDetail, data)
  584. } else {
  585. this.$router.push("/")
  586. }
  587. })
  588. },
  589. changeNum(tag) {
  590. if (this.goodsSkuDetail.stock == 0) return
  591. var stock = this.goodsSkuDetail.stock
  592. var min = 1
  593. if (tag == "+") {
  594. // 加
  595. if (this.number < stock) {
  596. this.number++
  597. } else {
  598. return
  599. }
  600. } else if (tag == "-") {
  601. // 减
  602. if (this.number > min) {
  603. this.number -= 1
  604. } else {
  605. return
  606. }
  607. }
  608. },
  609. blur() {
  610. let newNumber = parseInt(this.number)
  611. this.number = 0
  612. setTimeout(() => {
  613. this.number = newNumber
  614. }, 0)
  615. },
  616. //输入数量
  617. keyInput(flag, callback) {
  618. setTimeout(() => {
  619. var stock = this.goodsSkuDetail.stock
  620. // 库存为0
  621. if (this.goodsSkuDetail.stock == 0) {
  622. this.number = 0
  623. return
  624. }
  625. // 防止空
  626. if (flag && this.number.length == 0) this.number = 1
  627. // 防止输入0和负数、非法输入
  628. if (flag && (this.number <= 0 || isNaN(this.number))) this.number = 1
  629. if (this.number > stock) {
  630. this.number = stock
  631. }
  632. if (flag) this.number = parseInt(this.number)
  633. if (callback) callback()
  634. }, 0)
  635. },
  636. // 播放回调
  637. onPlayerPlay(player) {},
  638. // 暂停回调
  639. onPlayerPause(player) {},
  640. // 视频播完回调
  641. onPlayerEnded(player) {},
  642. // DOM元素上的readyState更改导致播放停止
  643. onPlayerWaiting(player) {},
  644. // 已开始播放回调
  645. onPlayerPlaying(player) {},
  646. // 当播放器在当前播放位置下载数据时触发
  647. onPlayerLoadeddata(player) {},
  648. // 当前播放位置发生变化时触发。
  649. onPlayerTimeupdate(player) {},
  650. //媒体的readyState为HAVE_FUTURE_DATA或更高
  651. onPlayerCanplay(player) {},
  652. //媒体的readyState为HAVE_ENOUGH_DATA或更高。这意味着可以在不缓冲的情况下播放整个媒体文件。
  653. onPlayerCanplaythrough(player) {},
  654. //播放状态改变回调
  655. playerStateChanged(playerCurrentState) {},
  656. //将侦听器绑定到组件的就绪状态。与事件监听器的不同之处在于,如果ready事件已经发生,它将立即触发该函数。。
  657. playerReadied(player) {},
  658. // 立即购买
  659. buyNow() {
  660. //纠正数量
  661. this.keyInput(true, () => {
  662. if (this.goodsSkuDetail.stock == 0) {
  663. this.$message({
  664. message: "商品已售罄",
  665. type: "warning"
  666. })
  667. return
  668. }
  669. if (this.number.length == 0 || this.number == 0) {
  670. this.$message({
  671. message: "购买数量不能为0",
  672. type: "warning"
  673. })
  674. return
  675. }
  676. // 秒杀
  677. var data = {
  678. seckill_id: this.goodsSkuDetail.seckill_id,
  679. num: this.number,
  680. sku_id: this.skuId
  681. };
  682. this.$store.dispatch("order/setSeckillOrderCreateData", data)
  683. this.$router.push({
  684. path: "/promotion/seckill/payment"
  685. })
  686. })
  687. },
  688. countDownS_cb() {},
  689. countDownE_cb() {
  690. this.seckillText = "活动已结束"
  691. this.$message({
  692. message: '限时秒杀活动已结束',
  693. type: 'warning',
  694. duration: 2000,
  695. onClose: () => {
  696. this.$router.push("/sku/" + this.goodsSkuDetail.sku_id)
  697. }
  698. });
  699. },
  700. //是否关注
  701. // isFollow() {
  702. // shopIsSubscribe({
  703. // site_id: this.goodsSkuDetail.site_id
  704. // }).then(res => {
  705. // if (res.code == 0) {
  706. // this.hasFollow = res.data
  707. // }
  708. // })
  709. // },
  710. // follow() {
  711. // if (this.hasFollow) {
  712. // deleteShopSubscribe({
  713. // site_id: this.goodsSkuDetail.site_id
  714. // }).then(res => {
  715. // if (res.code == 0 && res.data) {
  716. // this.hasFollow = !this.hasFollow
  717. // this.$message({
  718. // message: "取消成功",
  719. // type: "success"
  720. // })
  721. // }
  722. // })
  723. // } else {
  724. // addShopSubscribe({
  725. // site_id: this.goodsSkuDetail.site_id
  726. // }).then(res => {
  727. // if (res.code == 0 && res.data) {
  728. // this.hasFollow = !this.hasFollow
  729. // this.$message({
  730. // message: "关注成功",
  731. // type: "success"
  732. // })
  733. // }
  734. // })
  735. // }
  736. // },
  737. // 图片加载失败
  738. imageErrorSpec(index) {
  739. this.goodsSkuDetail.sku_images[index] = this.defaultGoodsImage
  740. this.picZoomUrl = this.defaultGoodsImage
  741. },
  742. /**
  743. * 获取地址
  744. * @param {Object} type
  745. * @param {Object} item
  746. * @param {Object} first 是否第一次
  747. */
  748. getAddress(type, item, first, callback) {
  749. let pid = 0
  750. switch (type) {
  751. case 'province':
  752. //加载省
  753. pid = 0
  754. break
  755. case 'city':
  756. //加载市
  757. if (item) {
  758. this.provinceId = item.id
  759. }
  760. pid = this.provinceId
  761. this.cityArr = {}
  762. this.districtArr = {}
  763. break
  764. case 'district':
  765. //加载区县
  766. if (item) this.cityId = item.id
  767. pid = this.cityId
  768. this.districtArr = {}
  769. break
  770. }
  771. if (item) {
  772. if (item.level <= 2) {
  773. let len = item.level;
  774. for (let i = len; i <= 3; i++) {
  775. delete this.selectedAddress['level_' + i];
  776. }
  777. }
  778. this.selectedAddress['level_' + item.level] = item;
  779. }
  780. if (!first) this.$store.commit("app/SET_LOCATION_REGION", this.selectedAddress)
  781. this.$forceUpdate();
  782. if (type == 'community') {
  783. this.hideRegion = true;
  784. setTimeout(() => {
  785. this.hideRegion = false;
  786. }, 10);
  787. return;
  788. }
  789. getArea({
  790. pid: pid
  791. })
  792. .then(res => {
  793. const {
  794. code,
  795. data
  796. } = res;
  797. if (data) {
  798. switch (type) {
  799. case 'province':
  800. //加载省
  801. this.provinceArr = data
  802. break
  803. case 'city':
  804. //加载市
  805. this.cityArr = data
  806. break
  807. case 'district':
  808. //加载区县
  809. this.districtArr = data
  810. break
  811. }
  812. this.currTabAddres = type
  813. if (callback) callback();
  814. }
  815. })
  816. .catch(err => {})
  817. }
  818. }
  819. }