project-detail.js 26 KB

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