project-detail.js 26 KB

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