project-detail.js 27 KB

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