goods-detail.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { VueLikePage } from '../../utils/page'
  2. import GoodsApi from '../../apis/goods'
  3. import Router from '../../utils/routes'
  4. import ImSend from '../../utils/imSend'
  5. import CenSus from '../../apis/census'
  6. import CompanyApi from '../../apis/company'
  7. VueLikePage([], {
  8. data: {
  9. detail: {}
  10. },
  11. methods: {
  12. async onLoad (options) {
  13. const { goods_id } = options
  14. this.goods_id = goods_id
  15. const res = await this.getGoodsDetail()
  16. this.getGuide()
  17. this.getGoodsCollectStatus()
  18. this.setData({
  19. detail: res.data
  20. })
  21. const companyRes = await CompanyApi.getCompanyDetail(res.data.companyId)
  22. this.company = companyRes.data
  23. },
  24. getGoodsDetail () {
  25. return GoodsApi.getGoodsDetail(this.goods_id)
  26. },
  27. getGoodsCollectStatus () {
  28. return GoodsApi.getGoodsCollectStatus(this.goods_id).then(res => {
  29. this.setData({
  30. collectStatus: res.data
  31. })
  32. })
  33. },
  34. changeCollect () {
  35. const collectStatus = this.data.collectStatus
  36. const apiFn = collectStatus === 1 ? GoodsApi.cancleCollect : GoodsApi.collectGoods
  37. return apiFn(this.goods_id).then(res => {
  38. wx.showToast({
  39. title: `${collectStatus === 1 ? '取消' : '收藏'}成功`,
  40. })
  41. this.getGoodsCollectStatus()
  42. })
  43. },
  44. getGuide () {
  45. GoodsApi.getGuideByGoods(this.goods_id).then(res => {
  46. this.guide = res.data
  47. })
  48. },
  49. toChat () {
  50. if (!this.guide) return
  51. if (!getApp().globalData.token) {
  52. Router.push('login')
  53. return
  54. }
  55. CenSus.addGoodsQueryNum({
  56. goodsId: this.goods_id,
  57. sceneNum: this.company.sceneNum
  58. })
  59. ImSend.sendMsg({content:'你好', msgType:'text', toId:this.guide.viewerId}).then(() => {
  60. Router.push({
  61. url: 'chat',
  62. query: {
  63. toId: this.guide.viewerId
  64. }
  65. })
  66. })
  67. }
  68. }
  69. })