index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. const WXAPI = require('apifm-wxapi')
  2. const app = getApp();
  3. const CONFIG = require('../../config.js')
  4. const AUTH = require('../../utils/auth')
  5. const SelectSizePrefix = "选择:"
  6. import Poster from 'wxa-plugin-canvas/poster/poster'
  7. Page({
  8. data: {
  9. wxlogin: true,
  10. goodsDetail: {},
  11. hasMoreSelect: false,
  12. selectSizePrice: 0,
  13. selectSizeOPrice: 0,
  14. totalScoreToPay: 0,
  15. shopNum: 0,
  16. hideShopPopup: true,
  17. buyNumber: 0,
  18. buyNumMin: 1,
  19. buyNumMax: 0,
  20. propertyChildIds: "",
  21. propertyChildNames: "",
  22. canSubmit: false, // 选中规格尺寸时候是否允许加入购物车
  23. shopType: "addShopCar", //购物类型,加入购物车或立即购买,默认为加入购物车
  24. },
  25. onLoad(e) {
  26. // e.id = 122843
  27. // 读取分享链接中的邀请人编号
  28. if (e && e.inviter_id) {
  29. wx.setStorageSync('referrer', e.inviter_id)
  30. }
  31. // 读取小程序码中的邀请人编号
  32. if (e && e.scene) {
  33. const scene = decodeURIComponent(e.scene) // 处理扫码进商品详情页面的逻辑
  34. if (scene && scene.split(',').length >= 2) {
  35. e.id = scene.split(',')[0]
  36. wx.setStorageSync('referrer', scene.split(',')[1])
  37. }
  38. }
  39. // 静默式授权注册/登陆
  40. AUTH.authorize().then(res => {
  41. })
  42. this.data.goodsId = e.id
  43. const that = this
  44. this.data.kjJoinUid = e.kjJoinUid
  45. let goodsDetailSkuShowType = wx.getStorageSync('goodsDetailSkuShowType')
  46. if (!goodsDetailSkuShowType) {
  47. goodsDetailSkuShowType = 0
  48. }
  49. this.setData({
  50. goodsDetailSkuShowType,
  51. curuid: wx.getStorageSync('uid')
  52. })
  53. this.reputation(e.id)
  54. this.shippingCartInfo()
  55. this.goodsAddition()
  56. },
  57. async goodsAddition(){
  58. const res = await WXAPI.goodsAddition(this.data.goodsId)
  59. if (res.code == 0) {
  60. this.setData({
  61. goodsAddition: res.data,
  62. hasMoreSelect: true,
  63. })
  64. }
  65. },
  66. async shippingCartInfo(){
  67. const token = wx.getStorageSync('token')
  68. if (!token) {
  69. return
  70. }
  71. const res = await WXAPI.shippingCarInfo(token)
  72. if (res.code == 0) {
  73. this.setData({
  74. shopNum: res.data.number
  75. })
  76. }
  77. },
  78. onShow (){
  79. AUTH.checkHasLogined().then(isLogined => {
  80. if (isLogined) {
  81. this.setData({
  82. wxlogin: isLogined
  83. })
  84. this.goodsFavCheck()
  85. }
  86. })
  87. this.getGoodsDetailAndKanjieInfo(this.data.goodsId)
  88. },
  89. async goodsFavCheck() {
  90. const res = await WXAPI.goodsFavCheck(wx.getStorageSync('token'), this.data.goodsId)
  91. if (res.code == 0) {
  92. this.setData({
  93. faved: true
  94. })
  95. } else {
  96. this.setData({
  97. faved: false
  98. })
  99. }
  100. },
  101. async addFav(){
  102. AUTH.checkHasLogined().then(isLogined => {
  103. this.setData({
  104. wxlogin: isLogined
  105. })
  106. if (isLogined) {
  107. if (this.data.faved) {
  108. // 取消收藏
  109. WXAPI.goodsFavDelete(wx.getStorageSync('token'), '', this.data.goodsId).then(res => {
  110. this.goodsFavCheck()
  111. })
  112. } else {
  113. // 加入收藏
  114. WXAPI.goodsFavPut(wx.getStorageSync('token'), this.data.goodsId).then(res => {
  115. this.goodsFavCheck()
  116. })
  117. }
  118. }
  119. })
  120. },
  121. async getGoodsDetailAndKanjieInfo(goodsId) {
  122. const token = wx.getStorageSync('token')
  123. const that = this;
  124. const goodsDetailRes = await WXAPI.goodsDetail(goodsId, token ? token : '')
  125. const goodsKanjiaSetRes = await WXAPI.kanjiaSet(goodsId)
  126. if (goodsDetailRes.code == 0) {
  127. if (goodsDetailRes.data.properties) {
  128. that.setData({
  129. hasMoreSelect: true,
  130. selectSizePrice: goodsDetailRes.data.basicInfo.minPrice,
  131. selectSizeOPrice: goodsDetailRes.data.basicInfo.originalPrice,
  132. totalScoreToPay: goodsDetailRes.data.basicInfo.minScore
  133. });
  134. }
  135. if (goodsDetailRes.data.basicInfo.shopId) {
  136. this.shopSubdetail(goodsDetailRes.data.basicInfo.shopId)
  137. }
  138. if (goodsDetailRes.data.basicInfo.pingtuan) {
  139. that.pingtuanList(goodsId)
  140. }
  141. that.data.goodsDetail = goodsDetailRes.data;
  142. if (goodsDetailRes.data.basicInfo.videoId) {
  143. that.getVideoSrc(goodsDetailRes.data.basicInfo.videoId);
  144. }
  145. let _data = {
  146. goodsDetail: goodsDetailRes.data,
  147. selectSizePrice: goodsDetailRes.data.basicInfo.minPrice,
  148. selectSizeOPrice: goodsDetailRes.data.basicInfo.originalPrice,
  149. totalScoreToPay: goodsDetailRes.data.basicInfo.minScore,
  150. buyNumMax: goodsDetailRes.data.basicInfo.stores,
  151. buyNumber: (goodsDetailRes.data.basicInfo.stores > 0) ? 1 : 0
  152. }
  153. if (goodsKanjiaSetRes.code == 0) {
  154. _data.curGoodsKanjia = goodsKanjiaSetRes.data[0]
  155. that.data.kjId = _data.curGoodsKanjia.id
  156. // 获取当前砍价进度
  157. if (!that.data.kjJoinUid) {
  158. that.data.kjJoinUid = wx.getStorageSync('uid')
  159. }
  160. const curKanjiaprogress = await WXAPI.kanjiaDetail(_data.curGoodsKanjia.id, that.data.kjJoinUid)
  161. const myHelpDetail = await WXAPI.kanjiaHelpDetail(wx.getStorageSync('token'), _data.curGoodsKanjia.id, that.data.kjJoinUid)
  162. if (curKanjiaprogress.code == 0) {
  163. _data.curKanjiaprogress = curKanjiaprogress.data
  164. }
  165. if (myHelpDetail.code == 0) {
  166. _data.myHelpDetail = myHelpDetail.data
  167. }
  168. }
  169. if (goodsDetailRes.data.basicInfo.pingtuan) {
  170. const pingtuanSetRes = await WXAPI.pingtuanSet(goodsId)
  171. if (pingtuanSetRes.code == 0) {
  172. _data.pingtuanSet = pingtuanSetRes.data
  173. // 如果是拼团商品, 默认显示拼团价格
  174. _data.selectSizePrice = goodsDetailRes.data.basicInfo.pingtuanPrice
  175. }
  176. }
  177. that.setData(_data)
  178. this.initShareQuanziProduct()
  179. }
  180. },
  181. async shopSubdetail(shopId){
  182. const res = await WXAPI.shopSubdetail(shopId)
  183. if (res.code == 0) {
  184. this.setData({
  185. shopSubdetail: res.data
  186. })
  187. }
  188. },
  189. goShopCar: function() {
  190. wx.reLaunch({
  191. url: "/pages/shop-cart/index"
  192. });
  193. },
  194. toAddShopCar: function() {
  195. this.setData({
  196. shopType: "addShopCar"
  197. })
  198. this.bindGuiGeTap();
  199. },
  200. tobuy: function() {
  201. this.setData({
  202. shopType: "tobuy"
  203. });
  204. this.bindGuiGeTap();
  205. },
  206. toPingtuan: function(e) {
  207. let pingtuanopenid = 0
  208. if (e.currentTarget.dataset.pingtuanopenid) {
  209. pingtuanopenid = e.currentTarget.dataset.pingtuanopenid
  210. }
  211. this.setData({
  212. shopType: "toPingtuan",
  213. selectSizePrice: this.data.goodsDetail.basicInfo.pingtuanPrice,
  214. selectSizeOPrice: this.data.goodsDetail.basicInfo.originalPrice,
  215. pingtuanopenid: pingtuanopenid,
  216. hideShopPopup: false,
  217. skuGoodsPic: this.data.goodsDetail.basicInfo.pic
  218. });
  219. },
  220. /**
  221. * 规格选择弹出框
  222. */
  223. bindGuiGeTap: function() {
  224. this.setData({
  225. hideShopPopup: false,
  226. selectSizePrice: this.data.goodsDetail.basicInfo.minPrice,
  227. selectSizeOPrice: this.data.goodsDetail.basicInfo.originalPrice,
  228. skuGoodsPic: this.data.goodsDetail.basicInfo.pic
  229. })
  230. },
  231. /**
  232. * 规格选择弹出框隐藏
  233. */
  234. closePopupTap: function() {
  235. this.setData({
  236. hideShopPopup: true
  237. })
  238. },
  239. stepChange(event) {
  240. this.setData({
  241. buyNumber: event.detail
  242. })
  243. },
  244. /**
  245. * 选择商品规格
  246. */
  247. async labelItemTap(e) {
  248. const propertyindex = e.currentTarget.dataset.propertyindex
  249. const propertychildindex = e.currentTarget.dataset.propertychildindex
  250. const property = this.data.goodsDetail.properties[propertyindex]
  251. const child = property.childsCurGoods[propertychildindex]
  252. // 取消该分类下的子栏目所有的选中状态
  253. property.childsCurGoods.forEach(child => {
  254. child.active = false
  255. })
  256. // 设置当前选中状态
  257. property.optionValueId = child.id
  258. child.active = true
  259. // 获取所有的选中规格尺寸数据
  260. const needSelectNum = this.data.goodsDetail.properties.length
  261. let curSelectNum = 0;
  262. let propertyChildIds = "";
  263. let propertyChildNames = "";
  264. this.data.goodsDetail.properties.forEach(p => {
  265. p.childsCurGoods.forEach(c => {
  266. if (c.active) {
  267. curSelectNum++;
  268. propertyChildIds = propertyChildIds + p.id + ":" + c.id + ",";
  269. propertyChildNames = propertyChildNames + p.name + ":" + c.name + " ";
  270. }
  271. })
  272. })
  273. let canSubmit = false;
  274. if (needSelectNum == curSelectNum) {
  275. canSubmit = true;
  276. }
  277. let skuGoodsPic = this.data.skuGoodsPic
  278. if (this.data.goodsDetail.subPics && this.data.goodsDetail.subPics.length > 0) {
  279. const _subPic = this.data.goodsDetail.subPics.find(ele => {
  280. return ele.optionValueId == child.id
  281. })
  282. if (_subPic) {
  283. skuGoodsPic = _subPic.pic
  284. }
  285. }
  286. this.setData({
  287. goodsDetail: this.data.goodsDetail,
  288. canSubmit,
  289. skuGoodsPic,
  290. propertyChildIds,
  291. propertyChildNames,
  292. })
  293. this.calculateGoodsPrice()
  294. },
  295. async calculateGoodsPrice() {
  296. // 计算最终的商品价格
  297. let price = this.data.goodsDetail.basicInfo.minPrice
  298. let originalPrice = this.data.goodsDetail.basicInfo.originalPrice
  299. let totalScoreToPay = this.data.goodsDetail.basicInfo.minScore
  300. let buyNumMax = this.data.goodsDetail.basicInfo.stores
  301. let buyNumber = this.data.goodsDetail.basicInfo.minBuyNumber
  302. if (this.data.shopType == 'toPingtuan') {
  303. price = this.data.goodsDetail.basicInfo.pingtuanPrice
  304. }
  305. // 计算 sku 价格
  306. if (this.data.canSubmit) {
  307. const token = wx.getStorageSync('token')
  308. const res = await WXAPI.goodsPriceV2({
  309. token: token ? token : '',
  310. goodsId: this.data.goodsDetail.basicInfo.id,
  311. propertyChildIds: this.data.propertyChildIds
  312. })
  313. if (res.code == 0) {
  314. price = res.data.price
  315. if (this.data.shopType == 'toPingtuan') {
  316. price = res.data.pingtuanPrice
  317. }
  318. originalPrice = res.data.originalPrice
  319. totalScoreToPay = res.data.score
  320. buyNumMax = res.data.stores
  321. }
  322. }
  323. // 计算配件价格
  324. if (this.data.goodsAddition) {
  325. this.data.goodsAddition.forEach(big => {
  326. big.items.forEach(small => {
  327. if (small.active) {
  328. price = (price*100 + small.price*100) / 100
  329. }
  330. })
  331. })
  332. }
  333. this.setData({
  334. selectSizePrice: price,
  335. selectSizeOPrice: originalPrice,
  336. totalScoreToPay: totalScoreToPay,
  337. buyNumMax,
  338. buyNumber: (buyNumMax > buyNumber) ? buyNumber : 0
  339. });
  340. },
  341. /**
  342. * 选择可选配件
  343. */
  344. async labelItemTap2(e) {
  345. const propertyindex = e.currentTarget.dataset.propertyindex
  346. const propertychildindex = e.currentTarget.dataset.propertychildindex
  347. const goodsAddition = this.data.goodsAddition
  348. const property = goodsAddition[propertyindex]
  349. const child = property.items[propertychildindex]
  350. if (child.active) {
  351. // 该操作为取消选择
  352. child.active = false
  353. this.setData({
  354. goodsAddition
  355. })
  356. this.calculateGoodsPrice()
  357. return
  358. }
  359. // 单选配件取消所有子栏目选中状态
  360. if (property.type == 0) {
  361. property.items.forEach(child => {
  362. child.active = false
  363. })
  364. }
  365. // 设置当前选中状态
  366. child.active = true
  367. this.setData({
  368. goodsAddition
  369. })
  370. this.calculateGoodsPrice()
  371. },
  372. /**
  373. * 加入购物车
  374. */
  375. async addShopCar() {
  376. if (this.data.goodsDetail.properties && !this.data.canSubmit) {
  377. if (!this.data.canSubmit) {
  378. wx.showToast({
  379. title: '请选择规格',
  380. icon: 'none'
  381. })
  382. }
  383. this.bindGuiGeTap()
  384. return
  385. }
  386. const goodsAddition = []
  387. if (this.data.goodsAddition) {
  388. let canSubmit = true
  389. this.data.goodsAddition.forEach(ele => {
  390. if (ele.required) {
  391. const a = ele.items.find(item => {return item.active})
  392. if (!a) {
  393. canSubmit = false
  394. }
  395. }
  396. ele.items.forEach(item => {
  397. if (item.active) {
  398. goodsAddition.push({
  399. id: item.id,
  400. pid: item.pid
  401. })
  402. }
  403. })
  404. })
  405. if (!canSubmit) {
  406. wx.showToast({
  407. title: '请选择配件',
  408. icon: 'none'
  409. })
  410. this.bindGuiGeTap()
  411. return
  412. }
  413. }
  414. if (this.data.buyNumber < 1) {
  415. wx.showToast({
  416. title: '请选择购买数量',
  417. icon: 'none'
  418. })
  419. return
  420. }
  421. const isLogined = await AUTH.checkHasLogined()
  422. if (!isLogined) {
  423. this.setData({
  424. wxlogin: false
  425. })
  426. return
  427. }
  428. const token = wx.getStorageSync('token')
  429. const goodsId = this.data.goodsDetail.basicInfo.id
  430. const sku = []
  431. if (this.data.goodsDetail.properties) {
  432. this.data.goodsDetail.properties.forEach(p => {
  433. sku.push({
  434. optionId: p.id,
  435. optionValueId: p.optionValueId
  436. })
  437. })
  438. }
  439. const res = await WXAPI.shippingCarInfoAddItem(token, goodsId, this.data.buyNumber, sku, goodsAddition)
  440. if (res.code != 0) {
  441. wx.showToast({
  442. title: res.msg,
  443. icon: 'none'
  444. })
  445. return
  446. }
  447. this.closePopupTap();
  448. wx.showToast({
  449. title: '加入购物车',
  450. icon: 'success'
  451. })
  452. this.shippingCartInfo()
  453. },
  454. /**
  455. * 立即购买
  456. */
  457. buyNow: function(e) {
  458. let that = this
  459. let shoptype = e.currentTarget.dataset.shoptype
  460. if (this.data.goodsDetail.properties && !this.data.canSubmit) {
  461. wx.showToast({
  462. title: '请选择规格',
  463. icon: 'none'
  464. })
  465. this.bindGuiGeTap()
  466. return;
  467. }
  468. if (this.data.goodsAddition) {
  469. let canSubmit = true
  470. this.data.goodsAddition.forEach(ele => {
  471. if (ele.required) {
  472. const a = ele.items.find(item => {return item.active})
  473. if (!a) {
  474. canSubmit = false
  475. }
  476. }
  477. })
  478. if (!canSubmit) {
  479. wx.showToast({
  480. title: '请选择配件',
  481. icon: 'none'
  482. })
  483. this.bindGuiGeTap()
  484. return
  485. }
  486. }
  487. if (this.data.buyNumber < 1) {
  488. wx.showModal({
  489. title: '提示',
  490. content: '购买数量不能为0!',
  491. showCancel: false
  492. })
  493. return;
  494. }
  495. //组建立即购买信息
  496. var buyNowInfo = this.buliduBuyNowInfo(shoptype);
  497. // 写入本地存储
  498. wx.setStorage({
  499. key: "buyNowInfo",
  500. data: buyNowInfo
  501. })
  502. this.closePopupTap();
  503. if (shoptype == 'toPingtuan') {
  504. if (this.data.pingtuanopenid) {
  505. wx.navigateTo({
  506. url: "/pages/to-pay-order/index?orderType=buyNow&pingtuanOpenId=" + this.data.pingtuanopenid
  507. })
  508. } else {
  509. WXAPI.pingtuanOpen(wx.getStorageSync('token'), that.data.goodsDetail.basicInfo.id).then(function(res) {
  510. if (res.code == 2000) {
  511. that.setData({
  512. wxlogin: false
  513. })
  514. return
  515. }
  516. if (res.code != 0) {
  517. wx.showToast({
  518. title: res.msg,
  519. icon: 'none',
  520. duration: 2000
  521. })
  522. return
  523. }
  524. wx.navigateTo({
  525. url: "/pages/to-pay-order/index?orderType=buyNow&pingtuanOpenId=" + res.data.id
  526. })
  527. })
  528. }
  529. } else {
  530. wx.navigateTo({
  531. url: "/pages/to-pay-order/index?orderType=buyNow"
  532. })
  533. }
  534. },
  535. /**
  536. * 组建立即购买信息
  537. */
  538. buliduBuyNowInfo: function(shoptype) {
  539. var shopCarMap = {};
  540. shopCarMap.goodsId = this.data.goodsDetail.basicInfo.id;
  541. shopCarMap.shopId = this.data.goodsDetail.basicInfo.shopId;
  542. shopCarMap.pic = this.data.goodsDetail.basicInfo.pic;
  543. shopCarMap.name = this.data.goodsDetail.basicInfo.name;
  544. // shopCarMap.label=this.data.goodsDetail.basicInfo.id; 规格尺寸
  545. shopCarMap.propertyChildIds = this.data.propertyChildIds;
  546. shopCarMap.label = this.data.propertyChildNames;
  547. shopCarMap.price = this.data.selectSizePrice;
  548. // if (shoptype == 'toPingtuan') { // 20190714 拼团价格注释掉
  549. // shopCarMap.price = this.data.goodsDetail.basicInfo.pingtuanPrice;
  550. // }
  551. shopCarMap.score = this.data.totalScoreToPay;
  552. shopCarMap.left = "";
  553. shopCarMap.active = true;
  554. shopCarMap.number = this.data.buyNumber;
  555. shopCarMap.logisticsType = this.data.goodsDetail.basicInfo.logisticsId;
  556. shopCarMap.logistics = this.data.goodsDetail.logistics;
  557. shopCarMap.weight = this.data.goodsDetail.basicInfo.weight;
  558. if (this.data.goodsAddition && this.data.goodsAddition.length > 0) {
  559. const additions = []
  560. this.data.goodsAddition.forEach(ele => {
  561. ele.items.forEach(item => {
  562. if (item.active) {
  563. additions.push({
  564. id: item.id,
  565. name: item.name,
  566. pid: ele.id,
  567. pname: ele.name
  568. })
  569. }
  570. })
  571. })
  572. if (additions.length > 0) {
  573. shopCarMap.additions = additions
  574. }
  575. }
  576. var buyNowInfo = {};
  577. buyNowInfo.shopNum = 0;
  578. buyNowInfo.shopList = [];
  579. buyNowInfo.shopList.push(shopCarMap);
  580. buyNowInfo.kjId = this.data.kjId;
  581. if (this.data.shopSubdetail) {
  582. buyNowInfo.shopInfo = this.data.shopSubdetail.info
  583. } else {
  584. buyNowInfo.shopInfo = {
  585. id: 0,
  586. name: "其他",
  587. pic: null,
  588. serviceDistance: 99999999,
  589. }
  590. }
  591. return buyNowInfo;
  592. },
  593. onShareAppMessage() {
  594. let _data = {
  595. title: this.data.goodsDetail.basicInfo.name,
  596. path: '/pages/goods-details/index?id=' + this.data.goodsDetail.basicInfo.id + '&inviter_id=' + wx.getStorageSync('uid'),
  597. success: function(res) {
  598. // 转发成功
  599. },
  600. fail: function(res) {
  601. // 转发失败
  602. }
  603. }
  604. if (this.data.kjJoinUid) {
  605. _data.title = this.data.curKanjiaprogress.joiner.nick + '邀请您帮TA砍价'
  606. _data.path += '&kjJoinUid=' + this.data.kjJoinUid
  607. }
  608. return _data
  609. },
  610. reputation: function(goodsId) {
  611. var that = this;
  612. WXAPI.goodsReputation({
  613. goodsId: goodsId
  614. }).then(function(res) {
  615. if (res.code == 0) {
  616. res.data.forEach(ele => {
  617. if (ele.goods.goodReputation == 0) {
  618. ele.goods.goodReputation = 1
  619. } else if (ele.goods.goodReputation == 1) {
  620. ele.goods.goodReputation = 3
  621. } else if (ele.goods.goodReputation == 2) {
  622. ele.goods.goodReputation = 5
  623. }
  624. })
  625. that.setData({
  626. reputation: res.data
  627. });
  628. }
  629. })
  630. },
  631. pingtuanList: function(goodsId) {
  632. var that = this;
  633. WXAPI.pingtuanList({
  634. goodsId: goodsId,
  635. status: 0
  636. }).then(function(res) {
  637. if (res.code == 0) {
  638. that.setData({
  639. pingtuanList: res.data.result
  640. });
  641. }
  642. })
  643. },
  644. getVideoSrc: function(videoId) {
  645. var that = this;
  646. WXAPI.videoDetail(videoId).then(function(res) {
  647. if (res.code == 0) {
  648. that.setData({
  649. videoMp4Src: res.data.fdMp4
  650. });
  651. }
  652. })
  653. },
  654. joinKanjia(){
  655. AUTH.checkHasLogined().then(isLogined => {
  656. if (isLogined) {
  657. this.doneJoinKanjia();
  658. } else {
  659. this.setData({
  660. wxlogin: false
  661. })
  662. }
  663. })
  664. },
  665. doneJoinKanjia: function() { // 报名参加砍价活动
  666. const _this = this;
  667. if (!_this.data.curGoodsKanjia) {
  668. return;
  669. }
  670. wx.showLoading({
  671. title: '加载中',
  672. mask: true
  673. })
  674. WXAPI.kanjiaJoin(wx.getStorageSync('token'), _this.data.curGoodsKanjia.id).then(function(res) {
  675. wx.hideLoading()
  676. if (res.code == 0) {
  677. _this.setData({
  678. kjJoinUid: wx.getStorageSync('uid'),
  679. myHelpDetail: null
  680. })
  681. _this.getGoodsDetailAndKanjieInfo(_this.data.goodsDetail.basicInfo.id)
  682. } else {
  683. wx.showToast({
  684. title: res.msg,
  685. icon: 'none'
  686. })
  687. }
  688. })
  689. },
  690. joinPingtuan: function(e) {
  691. let pingtuanopenid = e.currentTarget.dataset.pingtuanopenid
  692. wx.navigateTo({
  693. url: "/pages/to-pay-order/index?orderType=buyNow&pingtuanOpenId=" + pingtuanopenid
  694. })
  695. },
  696. goIndex() {
  697. wx.switchTab({
  698. url: '/pages/index/index',
  699. });
  700. },
  701. helpKanjia() {
  702. const _this = this;
  703. AUTH.checkHasLogined().then(isLogined => {
  704. _this.setData({
  705. wxlogin: isLogined
  706. })
  707. if (isLogined) {
  708. _this.helpKanjiaDone()
  709. }
  710. })
  711. },
  712. helpKanjiaDone(){
  713. const _this = this;
  714. WXAPI.kanjiaHelp(wx.getStorageSync('token'), _this.data.kjId, _this.data.kjJoinUid, '').then(function (res) {
  715. if (res.code != 0) {
  716. wx.showToast({
  717. title: res.msg,
  718. icon: 'none'
  719. })
  720. return;
  721. }
  722. _this.setData({
  723. myHelpDetail: res.data
  724. });
  725. wx.showModal({
  726. title: '成功',
  727. content: '成功帮TA砍掉 ' + res.data.cutPrice + ' 元',
  728. showCancel: false
  729. })
  730. _this.getGoodsDetailAndKanjieInfo(_this.data.goodsDetail.basicInfo.id)
  731. })
  732. },
  733. cancelLogin() {
  734. this.setData({
  735. wxlogin: true
  736. })
  737. },
  738. processLogin(e) {
  739. if (!e.detail.userInfo) {
  740. wx.showToast({
  741. title: '已取消',
  742. icon: 'none',
  743. })
  744. return;
  745. }
  746. AUTH.register(this);
  747. },
  748. closePop(){
  749. this.setData({
  750. posterShow: false
  751. })
  752. },
  753. async drawSharePic() {
  754. const _this = this
  755. const qrcodeRes = await WXAPI.wxaQrcode({
  756. scene: _this.data.goodsDetail.basicInfo.id + ',' + wx.getStorageSync('uid'),
  757. page: 'pages/goods-details/index',
  758. is_hyaline: true,
  759. autoColor: true,
  760. expireHours: 1
  761. })
  762. if (qrcodeRes.code != 0) {
  763. wx.showToast({
  764. title: qrcodeRes.msg,
  765. icon: 'none'
  766. })
  767. return
  768. }
  769. const qrcode = qrcodeRes.data
  770. const pic = _this.data.goodsDetail.basicInfo.pic
  771. wx.getImageInfo({
  772. src: pic,
  773. success(res) {
  774. const height = 490 * res.height / res.width
  775. _this.drawSharePicDone(height, qrcode)
  776. },
  777. fail(e) {
  778. console.error(e)
  779. }
  780. })
  781. },
  782. drawSharePicDone(picHeight, qrcode) {
  783. const _this = this
  784. const _baseHeight = 74 + (picHeight + 120)
  785. this.setData({
  786. posterConfig: {
  787. width: 750,
  788. height: picHeight + 660,
  789. backgroundColor: '#fff',
  790. debug: false,
  791. blocks: [
  792. {
  793. x: 76,
  794. y: 74,
  795. width: 604,
  796. height: picHeight + 120,
  797. borderWidth: 2,
  798. borderColor: '#c2aa85',
  799. borderRadius: 8
  800. }
  801. ],
  802. images: [
  803. {
  804. x: 133,
  805. y: 133,
  806. url: _this.data.goodsDetail.basicInfo.pic, // 商品图片
  807. width: 490,
  808. height: picHeight
  809. },
  810. {
  811. x: 76,
  812. y: _baseHeight + 199,
  813. url: qrcode, // 二维码
  814. width: 222,
  815. height: 222
  816. }
  817. ],
  818. texts: [
  819. {
  820. x: 375,
  821. y: _baseHeight + 80,
  822. width: 650,
  823. lineNum:2,
  824. text: _this.data.goodsDetail.basicInfo.name,
  825. textAlign: 'center',
  826. fontSize: 40,
  827. color: '#333'
  828. },
  829. {
  830. x: 375,
  831. y: _baseHeight + 180,
  832. text: '¥' + _this.data.goodsDetail.basicInfo.minPrice,
  833. textAlign: 'center',
  834. fontSize: 50,
  835. color: '#e64340'
  836. },
  837. {
  838. x: 352,
  839. y: _baseHeight + 320,
  840. text: '长按识别小程序码',
  841. fontSize: 28,
  842. color: '#999'
  843. }
  844. ],
  845. }
  846. }, () => {
  847. Poster.create();
  848. });
  849. },
  850. onPosterSuccess(e) {
  851. console.log('success:', e)
  852. this.setData({
  853. posterImg: e.detail,
  854. showposterImg: true
  855. })
  856. },
  857. onPosterFail(e) {
  858. console.error('fail:', e)
  859. },
  860. savePosterPic() {
  861. const _this = this
  862. wx.saveImageToPhotosAlbum({
  863. filePath: this.data.posterImg,
  864. success: (res) => {
  865. wx.showModal({
  866. content: '已保存到手机相册',
  867. showCancel: false,
  868. confirmText: '知道了',
  869. confirmColor: '#333'
  870. })
  871. },
  872. complete: () => {
  873. _this.setData({
  874. showposterImg: false
  875. })
  876. },
  877. fail: (res) => {
  878. wx.showToast({
  879. title: res.errMsg,
  880. icon: 'none',
  881. duration: 2000
  882. })
  883. }
  884. })
  885. },
  886. initShareQuanziProduct() {
  887. this.setData({
  888. shareQuanziProduct: {
  889. "item_code": this.data.goodsDetail.basicInfo.id + '',
  890. "title": this.data.goodsDetail.basicInfo.name,
  891. "category_list":[
  892. this.data.goodsDetail.category.name
  893. ],
  894. "image_list":[
  895. this.data.goodsDetail.basicInfo.pic
  896. ],
  897. "src_mini_program_path": '/pages/goods-details/index?id=' + this.data.goodsDetail.basicInfo.id
  898. }
  899. })
  900. },
  901. on_share_quanzi_error(e) {
  902. wx.showToast({
  903. title: '暂时无法推荐',
  904. icon: 'none'
  905. })
  906. console.error(e)
  907. },
  908. previewImage(e) {
  909. const url = e.currentTarget.dataset.url
  910. wx.previewImage({
  911. current: url, // 当前显示图片的http链接
  912. urls: [url] // 需要预览的图片http链接列表
  913. })
  914. }
  915. })