project-detail.js 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. var width = 0
  2. var height = 0
  3. var ctx
  4. var _request = require('../../../utils/request.js')
  5. var _handle = require('../../../utils/handle.js')
  6. var WxParse = require('../../../utils/wxParse/wxParse.js')
  7. var util = require('../../../utils/accounting.min.js')
  8. var fomldsJSON = ''
  9. Page({
  10. posterImage: {},
  11. posterLoading: 0,
  12. canvasLoading: false,
  13. qcodeError: false,
  14. data: {
  15. productId: 0,
  16. indicatorDots: false,
  17. autoplay: false,
  18. interval: 5000,
  19. duration: 1000,
  20. project: {},
  21. projectComment:{},
  22. showDialog: false,
  23. showCartDialog: false,
  24. animationData: {},
  25. count: 1,
  26. image: {},
  27. bindTel: false,
  28. balance: 0,
  29. posterPopup: false,
  30. posterImage: null,
  31. imgindex: 1,
  32. popup: false,
  33. hour: '00',
  34. min: '00',
  35. second: '00',
  36. timer: '',
  37. leftTime: '0',
  38. // msecond: '00',
  39. clock: '',
  40. todaysend: Date.parse(new Date()) / 1000,
  41. showpay: true,
  42. productSize:'',//产品规格
  43. size_list:0,
  44. color_list:0,
  45. cname:'',
  46. sname:'',
  47. canpay:true,
  48. checkbox:'',
  49. noproduct:false,
  50. check:{},
  51. readOnly:0,
  52. showsharetips:false,
  53. backTopValue:false,
  54. lvList:[
  55.     '/images/star_a_l.png',
  56.     '/images/star_a_r.png',
  57.     '/images/star_a_l.png',
  58.     '/images/star_a_r.png',
  59. '/images/star_a_l.png',
  60.     '/images/star_a_r.png',
  61. '/images/star_a_l.png',
  62.     '/images/star_a_r.png',
  63. '/images/star_a_l.png',
  64.     '/images/star_a_r.png'
  65.   ],//星星个数
  66.   lvListActive1: '/images/star_a_l.png',//选中的
  67.   lvListActive2:'/images/star_d_l.png',//未选中的
  68. lvListActive3: '/images/star_a_r.png',//选中的
  69.   lvListActive4:'/images/star_d_r.png',//未选中的
  70. kfqr:'',//客服二维码
  71. showqr:false
  72. },
  73. onLoad: function (options) {
  74. this.data.productId = options.id;
  75. this.setData({
  76. readOnly: options.read ? options.read : 0
  77. })
  78. if(options.read != 0){
  79. wx.hideShareMenu();
  80. }
  81. this.getBalanceInfo()
  82. },
  83. onShow: function () {
  84. this.getIphoneX()
  85. this.getProjectDetail()
  86. this.getProjectComment()
  87. // this.check()
  88. this.info()
  89. this.getqcode()
  90. },
  91. onHide: function () {
  92. this.getneedshare()
  93. },
  94. dpi: function (val) {
  95. return val
  96. },
  97. onSlideChangeEnd: function(e) {
  98. var that = this;
  99. that.setData({
  100. imgindex: e.detail.current + 1
  101. })
  102. },
  103. info(){
  104. console.log('oninfo');
  105. var that = this
  106. var url = 'v1/user/info'
  107. var params = {}
  108. var success = function (res) {
  109. console.log(res)
  110. that.setData({
  111. info: res.data,
  112. bindTel: res.data.user.tel ? true : false
  113. })
  114. if (res.data.wx_user_id > 0) {
  115. that.getneedshare()
  116. }
  117. }
  118. _request.$get(url, params, success)
  119. },
  120. check () {
  121. var that = this
  122. var url = 'v1/user/check'
  123. var params = {
  124. }
  125. var success = function (res) {
  126. that.setData({check:res.data})
  127. if (res.data.user_id > 0) {
  128. that.setData({
  129. bindTel: true
  130. })
  131. }
  132. if (res.data.wx_user_id > 0) {
  133. that.getneedshare()
  134. }
  135. }
  136. _request.$get(url, params, success)
  137. },
  138. onShareTimeline:function(options){
  139. this.shareInfo()
  140. this.setData({
  141. showpay: true
  142. })
  143. return _request.share({
  144. title: this.data.project.share_content || this.data.project.name,
  145. path: '/pages/start/start?url=pages/projects/project-detail/project-detail&id=' + this.data.productId,
  146. imageUrl: this.data.project.share_img ? this.data.project.share_img : this.data.project.cover,
  147. sc: 'xcx_product',
  148. ri: this.data.productId,
  149. rp: this.data.productId,
  150. },true)
  151. },
  152. onShareAppMessage: function (options) {
  153. this.shareInfo()
  154. this.setData({
  155. showpay: true
  156. })
  157. return _request.share({
  158. title: this.data.project.share_content || this.data.project.name,
  159. path: '/pages/start/start?url=pages/projects/project-detail/project-detail&id=' + this.data.productId,
  160. imageUrl: this.data.project.share_img ? this.data.project.share_img : this.data.project.cover,
  161. sc: 'xcx_product',
  162. ri: this.data.productId,
  163. rp: this.data.productId,
  164. })
  165. },
  166. // imageLoad: function (e) {
  167. // var _width = e.detail.width,
  168. // _height = e.detail.height,
  169. // ratio = _width / _height;
  170. // var viewWidth = 750,
  171. // viewHeight = 750 / ratio;
  172. // var image = this.data.image;
  173. // image[e.target.dataset.index]={
  174. // width:viewWidth,
  175. // height:viewHeight
  176. // }
  177. // this.setData({
  178. // images:image
  179. // })
  180. // },
  181. shareInfo () {
  182. var that = this
  183. var url = "v1/share/info"
  184. var params = {
  185. sc: 'xcx_product',
  186. ri: that.data.productId,
  187. rp: that.data.productId,
  188. to: 'group'
  189. }
  190. var success = function (val) {
  191. console.log(val)
  192. }
  193. _request.$post(url, params, success)
  194. },
  195. detailImg: function (event) {
  196. var src = event.currentTarget.dataset.src;
  197. var imgList = event.currentTarget.dataset.list;
  198. var imgLists = []
  199. for (var i = 0; i < imgList.length; i++) {
  200. imgLists.push(imgList[i].img)
  201. }
  202. wx.previewImage({
  203. current: src,
  204. urls: imgLists
  205. })
  206. },
  207. getProjectDetail () {
  208. var that = this
  209. var url = "v1/product/" + that.data.productId;
  210. var params = {}
  211. var success = function (val) {
  212. //新增,如果can_buy等于true时才继续,否则退回首页
  213. if(!val.data.can_buy){
  214. wx.switchTab({
  215. url:'../../home/home'
  216. })
  217. }
  218. var p = val.data.detail
  219. let cbox = [];
  220. for(let i in val.data){
  221. if(i != 'product' && val.data[i]) cbox.push(i);
  222. }
  223. console.log('cbox',cbox);
  224. that.setData({
  225. project: val.data,
  226. productSize: val.data,
  227. checkbox:cbox,
  228. clock: val.data.seckill_end
  229. });
  230. WxParse.wxParse('parse', 'html', p, that, 10)
  231. if (val.data.seckill_state == 'seckill') {
  232. that.starttime()
  233. }
  234. if(val.data.have_size){
  235. that.getProductSize();
  236. }
  237. }
  238. var error = function(err){
  239. console.log('project item error',err);
  240. if(err.data.err_code == "productOffSale"){
  241. setTimeout(function(){
  242. wx.switchTab({
  243. url:'../../home/home'
  244. })
  245. },1500);
  246. }
  247. }
  248. _request.$get(url, params, success,error)
  249. },
  250. wxParseTagATap: function(e){
  251. var href = e.currentTarget.dataset.src;
  252. console.log(href);
  253. //我们可以在这里进行一些路由处理
  254. if(href){
  255. //跳转的方法根据项目需求的不同自己替换,也可以加参数,
  256. e.currentTarget.stop
  257. wx.navigateTo({
  258. url: href
  259. })
  260. }
  261. },
  262. wxParseImgTap:function(e){
  263. return false;
  264. },
  265. getProjectComment() {
  266. var that = this
  267. var url = "v1/product/" + that.data.productId +'/commends';
  268. var params = {}
  269. var success = function (val) {
  270. var comdata = val.data.list;
  271. // console.log('comdata',comdata)
  272. var showcom = [];
  273. let index = 0;
  274. for(let i in comdata){
  275. if(index<3){
  276. console.log('comdata[i].score * 2 / 10 - 1',comdata[i].score * 2 / 10 - 1)
  277. comdata[i]['star'] = that.evaluateLvS(comdata[i].score * 2 / 10 - 1);
  278. console.log("comdata[i]",comdata[i])
  279. showcom.push(comdata[i]);
  280. }
  281. index++;
  282. }
  283. console.log('showcom',showcom)
  284. that.setData({
  285. projectComment: showcom
  286. });
  287. }
  288. _request.$get(url, params, success)
  289. },
  290. getProductSize(){
  291. var that = this
  292. var url = "v1/product_size/" + that.data.productId;
  293. var params = {}
  294. var success = function (val) {
  295. let cbox = [];
  296. for(let i in val.data){
  297. if(i != 'product' && val.data[i]) cbox.push(i);
  298. }
  299. console.log('cbox',cbox)
  300. that.setData({
  301. productSize: val.data,
  302. checkbox:cbox
  303. });
  304. }
  305. _request.$get(url, params, success)
  306. },
  307. getProductDetail () {
  308. var that = this;
  309. console.log(that.data.size_list);
  310. console.log(that.data.color_list);
  311. console.log(that.data.productId);
  312. var url = "v1/product_detail/" + that.data.productId + "/" + that.data.size_list + "/" + that.data.color_list;
  313. var params = {}
  314. var success = function (val) {
  315. console.log('val',val)
  316. if(val.data.product){
  317. that.setData({
  318. canpay:true,
  319. project:val.data.product,
  320. productId:val.data.product.id,
  321. noproduct:false
  322. })
  323. that.setData({
  324. canpay:true,
  325. project:val.data.product,
  326. productId:val.data.product.id,
  327. noproduct:false
  328. })
  329. }else{
  330. that.setData({
  331. canpay:false,
  332. noproduct:true
  333. })
  334. }
  335. }
  336. var fail = function(err){
  337. }
  338. _request.$get(url, params, success, fail)
  339. },
  340. add: function () {
  341. if(this.data.project.package){
  342. var count = this.data.count + 1
  343. this.setData({
  344. count: count
  345. })
  346. }else{
  347. if (this.data.count < this.data.project.left_count) {
  348. var count = this.data.count + 1
  349. this.setData({
  350. count: count
  351. })
  352. }else{
  353. wx.showToast({
  354. title: '已达到商品库存上限',
  355. icon: 'none',
  356. duration: 1000
  357. })
  358. }
  359. }
  360. },
  361. mius: function () {
  362. if (this.data.count > 1) {
  363. var count = this.data.count - 1
  364. this.setData({
  365. count: count
  366. })
  367. }else{
  368. wx.showToast({
  369. title: '不可以小于1',
  370. icon: 'none',
  371. duration: 1000
  372. })
  373. }
  374. },
  375. changeCount: function (val) {
  376. var count = val.detail.value
  377. if (count <= 0) {
  378. wx.showToast({
  379. title: '不可以小于1',
  380. icon: 'none',
  381. duration: 1000
  382. })
  383. this.setData({
  384. count: 1
  385. })
  386. } else if (!this.data.project.package && count > this.data.project.left_count) {
  387. wx.showToast({
  388. title: '已达到商品库存上限',
  389. icon: 'none',
  390. duration: 1000
  391. })
  392. this.setData({
  393. count: this.data.project.left_count
  394. })
  395. } else {
  396. this.setData({
  397. count: count
  398. })
  399. }
  400. },
  401. // 显示弹框
  402. showModal: function (type) {
  403. var animation = wx.createAnimation({
  404. duration: 200,
  405. timingFunction: "ease-out"
  406. })
  407. this.animation = animation
  408. animation.translateY(500).step()
  409. if(type == 1){
  410. this.setData({
  411. animationData: animation.export(),
  412. showDialog: true
  413. })
  414. }else{
  415. this.setData({
  416. animationData: animation.export(),
  417. showCartDialog: true
  418. })
  419. }
  420. setTimeout(function () {
  421. animation.translateY(0).step()
  422. this.setData({
  423. animationData: animation.export()
  424. })
  425. }.bind(this), 200)
  426. },
  427. // 隐藏弹框
  428. hideModal: function (type = 1) {
  429. var animation = wx.createAnimation({
  430. duration: 200,
  431. timingFunction: "ease-out"
  432. })
  433. this.animation = animation
  434. animation.translateY(500).step()
  435. this.setData({
  436. animationData: animation.export(),
  437. })
  438. setTimeout(function () {
  439. animation.translateY(0).step()
  440. if(type == 1){
  441. this.setData({
  442. animationData: animation.export(),
  443. showDialog: false
  444. })
  445. }else{
  446. this.setData({
  447. animationData: animation.export(),
  448. showCartDialog: false
  449. })
  450. }
  451. }.bind(this), 200)
  452. },
  453. getneedshare () {
  454. var that = this
  455. var url = "v1/product/" + that.data.productId + "/share"
  456. var params = {
  457. }
  458. var success = function (val) {
  459. if (val.data.need_share == 1) {
  460. that.setData({
  461. showpay: false
  462. })
  463. }
  464. }
  465. _request.$get(url, params, success)
  466. },
  467. toPay: function (e) {
  468. _handle.setFormId(e)
  469. if (this.data.bindTel) {
  470. var that = this
  471. that.data.showDialog = !that.data.showDialog
  472. if (that.data.showDialog) {
  473. that.showModal(1)
  474. } else {
  475. that.hideModal(1)
  476. }
  477. } else {
  478. wx.navigateTo({
  479. url: '/packageUser/pages/user/bind/bind'
  480. })
  481. }
  482. },
  483. toCart: function (e) {
  484. _handle.setFormId(e)
  485. if (this.data.bindTel) {
  486. var that = this
  487. that.data.showCartDialog = !that.data.showCartDialog
  488. if (that.data.showCartDialog) {
  489. that.showModal(2)
  490. } else {
  491. that.hideModal(2)
  492. }
  493. } else {
  494. //设置绑定后返回的页面
  495. wx.setStorageSync('backToDetail',true);
  496. wx.navigateTo({
  497. url: '/packageUser/pages/user/bind/bind'
  498. })
  499. }
  500. },
  501. pay: function (e) {
  502. _handle.setFormId(e)
  503. var that = this
  504. //规格
  505. let cflag = true;
  506. for(let i in that.data.checkbox){
  507. if(that.data[that.data.checkbox[i]] == 0) cflag = false;
  508. }
  509. if(!cflag){
  510. wx.showToast({
  511. title: '请先选择商品规格~',
  512. icon: 'none',
  513. duration: 2000
  514. })
  515. return false;
  516. }
  517. var url = "v1/product/" + that.data.productId + "/order/" + that.data.count
  518. var params = {}
  519. var success = function (res) {
  520. if (res.data.order_id) {
  521. wx.navigateTo({
  522. url: '../../pay/pay?orderId=' + res.data.order_id
  523. })
  524. that.hideModal()
  525. that.setData({
  526. count: 1
  527. })
  528. }
  529. }
  530. if(this.data.project.package){
  531. _request.$post(url, params, success)
  532. }else{
  533. if (that.data.count <= that.data.project.left_count) {
  534. _request.$post(url, params, success)
  535. } else {
  536. wx.showToast({
  537. title: '库存不足~',
  538. icon: 'none',
  539. duration: 2000
  540. })
  541. }
  542. }
  543. },
  544. addCart:function(){
  545. var that = this;
  546. //规格
  547. let cflag = true;
  548. for(let i in that.data.checkbox){
  549. if(that.data[that.data.checkbox[i]] == 0) cflag = false;
  550. }
  551. if(!cflag){
  552. wx.showToast({
  553. title: '请先选择商品规格~',
  554. icon: 'none',
  555. duration: 2000
  556. })
  557. return false;
  558. }
  559. console.log('that.data.productId',that.data.productId)
  560. var url = "v1/cart/" + that.data.productId + "/" + that.data.count
  561. var params = {}
  562. var success = function (res) {
  563. if(res.data.result){
  564. //添加购物车后,更新本地数量
  565. var localcl = wx.getStorageSync('localCartList') ? wx.getStorageSync('localCartList') : [];
  566. if(localcl.length > 0){
  567. for(let i in localcl){
  568. if(localcl[i]['product_id'] == that.data.productId){
  569. localcl[i]['count'] = localcl[i]['count'] + that.data.count;
  570. }
  571. }
  572. //setlocalcartlist
  573. wx.setStorageSync('localCartList',localcl);
  574. }
  575. console.log('localcl',localcl);
  576. that.hideModal(2);
  577. wx.showToast({
  578. title: '添加成功,请到购物车查看~',
  579. icon: 'none',
  580. duration: 2000
  581. })
  582. }
  583. // if (res.data.order_id) {
  584. // wx.navigateTo({
  585. // url: '../../pay/pay?orderId=' + res.data.order_id
  586. // })
  587. // that.hideModal()
  588. // that.setData({
  589. // count: 1
  590. // })
  591. // }
  592. }
  593. if (that.data.count <= that.data.project.left_count) {
  594. _request.$post(url, params, success)
  595. } else {
  596. wx.showToast({
  597. title: '库存不足~',
  598. icon: 'none',
  599. duration: 2000
  600. })
  601. }
  602. },
  603. getIphoneX () {
  604. var that = this
  605. wx.getSystemInfo({
  606. success: function (res) {
  607. if (res.model.toLowerCase().indexOf('iphone x') > -1) {
  608. that.setData({
  609. value: 34
  610. })
  611. }
  612. }
  613. })
  614. },
  615. getBalanceInfo () {
  616. var that = this
  617. var url = 'v1/user/balance/info'
  618. var params = {
  619. }
  620. var success = function (res) {
  621. var result = res.data.total
  622. that.setData({
  623. balance: result
  624. })
  625. }
  626. _request.$get(url, params, success)
  627. },
  628. projectImageLoading () {
  629. console.log('do projectImageLoading');
  630. var that = this
  631. wx.getImageInfo({
  632. src: 'https://cfohow.hiwavo.com/xcx/poster6.jpg',
  633. success: function (res) {
  634. that.posterImage.bg = res
  635. that.posterLoading++
  636. if (that.posterLoading === 4) {
  637. that.createCtx()
  638. }
  639. }
  640. })
  641. if (this.data.project.pics.length > 0) {
  642. wx.getImageInfo({
  643. src: this.data.project.pics[0].img,
  644. success: function (res) {
  645. that.posterImage.project = res
  646. that.posterLoading++
  647. if (that.posterLoading === 4) {
  648. that.createCtx()
  649. }
  650. }
  651. })
  652. }
  653. var url = 'v1/poster/' + this.data.productId
  654. var params = {
  655. type: 'project'
  656. }
  657. var success = function (res) {
  658. var wxhead = res.data.wx_head;
  659. if(!wxhead){
  660. wx.getUserProfile({
  661. desc: '用户头像无法获取,请从新授权', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  662. success: function(res3) {
  663. var url = 'xcx/save_wx_user/info'
  664. console.log(JSON.stringify(res3.userInfo));
  665. var params = {
  666. userinfo: JSON.stringify(res3.userInfo)
  667. }
  668. var success = function (res4) {
  669. console.log('authorize',res4)
  670. wxhead = res4.data.head;
  671. console.log(wxhead);
  672. that.posterLoading = 0;
  673. that.projectImageLoading();
  674. }
  675. _request.$post(url, params, success)
  676. },
  677. fail: function(err){
  678. wx.showToast({
  679. title: '用户头像获取失败,生成海报失败',
  680. icon: 'none',
  681. duration: 2000
  682. })
  683. wx.hideLoading();
  684. return;
  685. }
  686. })
  687. }else{
  688. wx.getImageInfo({
  689. src: res.data.qrcode_url,
  690. success: function (res) {
  691. that.posterImage.qcode = res
  692. that.posterLoading++
  693. if (that.posterLoading === 4) {
  694. that.createCtx()
  695. }
  696. },
  697. fail: function (res) {
  698. var url = 'v1/update/poster/' + that.data.productId
  699. var params = {
  700. type: 'project'
  701. }
  702. var success = function (res2) {
  703. wx.getImageInfo({
  704. src: res2.data.qrcode_url,
  705. success: function (res2) {
  706. that.posterImage.qcode = res2
  707. that.posterLoading++
  708. if (that.posterLoading === 4) {
  709. that.createCtx()
  710. }
  711. },
  712. fail: function (res2) {
  713. that.qcodeError = true
  714. if (that.data.posterPopup) {
  715. that.setData({
  716. posterPopup: false
  717. })
  718. wx.showToast({
  719. title: '海报生成失败,请稍后重试',
  720. icon: 'none',
  721. duration: 2000
  722. })
  723. wx.hideLoading()
  724. }
  725. }
  726. })
  727. wx.getImageInfo({
  728. src: res2.data.wx_head,
  729. success: function (res2) {
  730. that.posterImage.head = res2
  731. that.posterLoading++
  732. if (that.posterLoading === 4) {
  733. that.createCtx()
  734. }
  735. }
  736. })
  737. }
  738. _request.$put(url, params, success)
  739. // that.qcodeError = true
  740. // if (that.data.posterPopup) {
  741. // that.setData({
  742. // posterPopup: false
  743. // })
  744. // wx.showToast({
  745. // title: '海报生成失败,请稍后重试',
  746. // icon: 'none',
  747. // duration: 2000
  748. // })
  749. // wx.hideLoading()
  750. // }
  751. }
  752. })
  753. wx.getImageInfo({
  754. src: res.data.wx_head,
  755. success: function (res) {
  756. that.posterImage.head = res
  757. that.posterLoading++
  758. if (that.posterLoading === 4) {
  759. that.createCtx()
  760. }
  761. }
  762. })
  763. }
  764. }
  765. _request.$get(url, params, success)
  766. },
  767. createPoster () {
  768. let that = this;
  769. if(this.data.info && this.data.info.wx_user.id && this.data.info.wx_user.id > 0 && this.data.info.user.id > 0){
  770. that.projectImageLoading()
  771. if (!this.qcodeError) {
  772. if (!this.canvasLoading) {
  773. wx.showLoading({
  774. mask: true,
  775. title: ''
  776. })
  777. }
  778. this.setData({
  779. posterPopup: true
  780. })
  781. } else {
  782. wx.showToast({
  783. title: '海报生成失败,请稍后重试',
  784. icon: 'none',
  785. duration: 2000
  786. })
  787. }
  788. }else{
  789. wx.showToast({
  790. title: '请先完成授权登录',
  791. icon: 'none',
  792. duration: 2000
  793. })
  794. setTimeout(function(){
  795. wx.reLaunch({
  796. url: '/pages/user/all/all'
  797. })
  798. },1000)
  799. }
  800. },
  801. posterClose () {
  802. this.setData({
  803. posterPopup: false
  804. })
  805. },
  806. createCtx () {
  807. var that = this
  808. ctx = wx.createCanvasContext('myCanvas')
  809. ctx.drawImage(this.posterImage.bg.path, 0, 0, this.dpi(this.posterImage.bg.width), this.dpi(this.posterImage.bg.height))
  810. ctx.drawImage(this.posterImage.qcode.path, this.dpi(501), this.dpi(1140), this.dpi(180), this.dpi(180))
  811. ctx.save()
  812. ctx.translate(this.dpi(44),this.dpi(46))
  813. ctx.save()
  814. ctx.arc(this.dpi(60), this.dpi(59), this.dpi(40), 0, Math.PI * 2, false)
  815. ctx.lineWidth = 1
  816. ctx.strokeStyle = '#d4d4d4'
  817. ctx.stroke()
  818. ctx.clip()
  819. ctx.drawImage(this.posterImage.head.path, this.dpi(21), this.dpi(20), this.dpi(78), this.dpi(78))
  820. ctx.restore()
  821. ctx.save()
  822. ctx.textBaseline = 'middle'
  823. ctx.font = this.dpi(24) + 'px Arial'
  824. ctx.fillStyle = '#eab86a'
  825. ctx.fillText('源处全球源产地的优质产品!', this.dpi(136), this.dpi(59))
  826. ctx.restore()
  827. ctx.drawImage(this.posterImage.project.path, this.dpi(20), this.dpi(140), this.dpi(622), this.dpi(622))
  828. ctx.beginPath()
  829. ctx.moveTo(this.dpi(0), this.dpi(119))
  830. ctx.lineTo(this.dpi(662), this.dpi(119))
  831. ctx.lineWidth = 1
  832. ctx.strokeStyle = '#eab86a'
  833. ctx.stroke()
  834. ctx.closePath()
  835. ctx.save()
  836. ctx.translate(this.dpi(20),this.dpi(784))
  837. ctx.textBaseline = 'middle'
  838. ctx.font = this.dpi(28) + 'px Arial'
  839. ctx.fillStyle = '#bbbbbb'
  840. ctx.fillText('购买单价', this.dpi(46), this.dpi(50))
  841. ctx.fillStyle = '#eab86a'
  842. ctx.setTextAlign('right')
  843. ctx.font = 'bold ' + this.dpi(54) + 'px Arial'
  844. ctx.fillText(util.formatMoney(this.data.project.price / 100, '¥', 2), this.dpi(584), this.dpi(50))
  845. ctx.setTextAlign('left')
  846. ctx.font = this.dpi(32) + 'px Arial'
  847. ctx.fillStyle = '#2b2b2b'
  848. this.textAutoLine(this.data.project.name, this.dpi(30), this.dpi(150), this.dpi(40))
  849. ctx.restore()
  850. ctx.restore()
  851. ctx.draw(true, function callback () {
  852. that.createImage()
  853. })
  854. },
  855. createImage () {
  856. var that = this
  857. wx.canvasToTempFilePath({
  858. destWidth: 750,
  859. destHeight: 1334,
  860. canvasId: 'myCanvas',
  861. fileType: 'jpg',
  862. success: function (res) {
  863. that.setData({
  864. posterImage: res.tempFilePath
  865. })
  866. that.canvasLoading = true
  867. wx.hideLoading()
  868. }
  869. })
  870. },
  871. saveImage () {
  872. var that = this
  873. wx.showLoading({
  874. mask: true,
  875. title: ''
  876. })
  877. wx.saveImageToPhotosAlbum({
  878. filePath: this.data.posterImage,
  879. success (res) {
  880. wx.showToast({
  881. title: '已保存相册',
  882. icon: 'success',
  883. duration: 2000
  884. })
  885. },
  886. fail (res) {
  887. wx.getSetting({
  888. success (res) {
  889. if (!res.authSetting['scope.writePhotosAlbum']) {
  890. that.setData({
  891. popup: true
  892. })
  893. }
  894. }
  895. })
  896. wx.hideLoading()
  897. }
  898. })
  899. },
  900. setting () {
  901. this.setData({
  902. popup: false
  903. })
  904. },
  905. roundRect (x, y, w, h, r, color) {
  906. ctx.beginPath()
  907. ctx.moveTo(x+r, y)
  908. ctx.arcTo(x+w, y, x+w, y+h, r)
  909. ctx.arcTo(x+w, y+h, x, y+h, r)
  910. ctx.arcTo(x, y+h, x, y, r)
  911. ctx.arcTo(x, y, x+w, y, r)
  912. ctx.closePath()
  913. ctx.fillStyle = color
  914. ctx.fill()
  915. },
  916. textAutoLine (str, initX, initY, lineHeight) {
  917. let lineWidth = 0
  918. let textWidth = this.dpi(580)
  919. let lastSubStrIndex= 0
  920. for (let i = 0; i < str.length; i++) {
  921. lineWidth += ctx.measureText(str[i]).width
  922. if (lineWidth > textWidth - initX) {
  923. ctx.fillText(str.substring(lastSubStrIndex, i), initX, initY)
  924. initY += lineHeight
  925. lineWidth = 0
  926. lastSubStrIndex = i
  927. }
  928. if (i === str.length - 1) {
  929. ctx.fillText(str.substring(lastSubStrIndex, i + 1), initX, initY)
  930. }
  931. }
  932. },
  933. stopPageScroll () {
  934. return
  935. },
  936. starttime () {
  937. var that = this
  938. that.setData({
  939. timer: setInterval(function () {
  940. // var date = new Date();
  941. // var now = date.getTime();
  942. // var endDate = new Date("2019-01-03 23:14:53");//设置截止时间
  943. // var end = that.data.clock * 1000;//设置截止时间
  944. // var end = endDate.getTime();
  945. // var leftTime = end - now; //时间差
  946. var t = Date.parse(new Date())
  947. t = t / 1000;
  948. var leftTime = that.data.clock - t
  949. var d, h, m, s, ms;
  950. if (leftTime >= 0) {
  951. // day = parseInt(ctime / 86400)
  952. h = parseInt(leftTime / 3600)
  953. m = parseInt(leftTime / 60 ) - parseInt(leftTime / 3600) * 60
  954. s = parseInt(leftTime) - parseInt(leftTime / 60 ) * 60
  955. // d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
  956. // h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
  957. // m = Math.floor(leftTime / 1000 / 60 % 60);
  958. // s = Math.floor(leftTime / 1000 % 60);
  959. // ms = Math.floor(leftTime % 1000);
  960. // ms = ms < 100 ? "0" + ms : ms
  961. s = s < 10 ? "0" + s : s
  962. m = m < 10 ? "0" + m : m
  963. h = h < 10 ? "0" + h : h
  964. that.setData({
  965. hour: h,
  966. min: m,
  967. second: s,
  968. // msecond: ms,
  969. leftTime: leftTime
  970. })
  971. }
  972. if (leftTime < 0) {
  973. clearInterval(that.data.timer);
  974. that.setData({
  975. leftTime: 0,
  976. hour: '00',
  977. min: '00',
  978. second: '00',
  979. // msecond: '00'
  980. })
  981. }
  982. },100),
  983. });
  984. },
  985. checkSize(event){
  986. var type = event.currentTarget.dataset.type;
  987. var id = event.currentTarget.dataset.id;
  988. var list = event.currentTarget.dataset.list;
  989. var tname = event.currentTarget.dataset.tname;
  990. var that = this;
  991. var tkey = type=='color_list'?'cname':'sname';
  992. var reproduct = this.data.productSize;
  993. // console.log('reproduct',reproduct)
  994. for(var i in reproduct[type]['attr_values']){
  995. // console.log('reproduct[type][i].is_select',reproduct[type]['attr_values'][i].is_select)
  996. reproduct[type]['attr_values'][i].is_select = false;
  997. if(reproduct[type]['attr_values'][i].id == id) reproduct[type]['attr_values'][i].is_select = true;
  998. }
  999. // console.log('reproduct',reproduct)
  1000. that.setData({
  1001. productSize :reproduct,
  1002. [type]:id,
  1003. [tkey]:tname
  1004. })
  1005. // console.log('that.data[type]',that.data[type])
  1006. let cflag = true;
  1007. for(let i in that.data.checkbox){
  1008. if(that.data[that.data.checkbox[i]] == 0) cflag = false;
  1009. }
  1010. if(cflag){
  1011. that.getProductDetail();
  1012. }
  1013. },
  1014. back:function(){
  1015. wx.navigateBack({})
  1016. },
  1017. evaluateLvS(star){
  1018. // console.log('star',star);
  1019. var that = this;
  1020. var lvList = that.data.lvList;
  1021. let lvlist2 = [];
  1022. lvList.forEach((item,index) => {
  1023. // console.log('index',index);
  1024. if(index <= star){
  1025. if(index % 2 === 0){
  1026. lvList[index] = that.data.lvListActive1;
  1027. }else{
  1028. lvList[index] = that.data.lvListActive3;
  1029. }
  1030. }else{
  1031. if(index % 2 === 0){
  1032. lvList[index] = that.data.lvListActive2;
  1033. }else{
  1034. lvList[index] = that.data.lvListActive4;
  1035. }
  1036.     }
  1037. lvlist2.push(lvList[index]);
  1038.  })
  1039. return lvlist2;
  1040. },
  1041. // 监听滚动条坐标
  1042. onPageScroll: function (e) {
  1043. //console.log(e)
  1044. var that = this
  1045. var scrollTop = e.scrollTop
  1046. var backTopValue = scrollTop > 500 ? true : false
  1047. that.setData({
  1048. backTopValue: backTopValue
  1049. })
  1050. },
  1051. toTop:function(){
  1052. wx.pageScrollTo({
  1053. scrollTop: 0
  1054. })
  1055. },
  1056. sharetips(){
  1057. this.setData({
  1058. showsharetips:!this.data.showsharetips
  1059. })
  1060. },
  1061. getqcode: function () {
  1062. var that = this
  1063. var url = 'v1/customer_service/qrcode'
  1064. var params = {}
  1065. var success = function (res) {
  1066. that.setData({
  1067. kfqr: res.data
  1068. })
  1069. }
  1070. _request.$get(url, params, success)
  1071. },
  1072. tiggerQR:function(){
  1073. this.setData({
  1074. showqr: !this.data.showqr
  1075. })
  1076. },
  1077. catchtapQR:function(){
  1078. console.log('catchtapQR');
  1079. }
  1080. })