project-detail.js 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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. wx.navigateTo({
  453. url: '/packageUser/pages/user/bind/bind'
  454. })
  455. }
  456. },
  457. pay: function (e) {
  458. _handle.setFormId(e)
  459. var that = this
  460. //规格
  461. let cflag = true;
  462. for(let i in that.data.checkbox){
  463. if(that.data[that.data.checkbox[i]] == 0) cflag = false;
  464. }
  465. if(!cflag){
  466. wx.showToast({
  467. title: '请先选择商品规格~',
  468. icon: 'none',
  469. duration: 2000
  470. })
  471. return false;
  472. }
  473. var url = "v1/product/" + that.data.productId + "/order/" + that.data.count
  474. var params = {}
  475. var success = function (res) {
  476. if (res.data.order_id) {
  477. wx.navigateTo({
  478. url: '../../pay/pay?orderId=' + res.data.order_id
  479. })
  480. that.hideModal()
  481. that.setData({
  482. count: 1
  483. })
  484. }
  485. }
  486. if (that.data.count <= that.data.project.left_count) {
  487. _request.$post(url, params, success)
  488. } else {
  489. wx.showToast({
  490. title: '库存不足~',
  491. icon: 'none',
  492. duration: 2000
  493. })
  494. }
  495. },
  496. addCart:function(){
  497. var that = this;
  498. //规格
  499. let cflag = true;
  500. for(let i in that.data.checkbox){
  501. if(that.data[that.data.checkbox[i]] == 0) cflag = false;
  502. }
  503. if(!cflag){
  504. wx.showToast({
  505. title: '请先选择商品规格~',
  506. icon: 'none',
  507. duration: 2000
  508. })
  509. return false;
  510. }
  511. console.log('that.data.productId',that.data.productId)
  512. var url = "v1/cart/" + that.data.productId + "/" + that.data.count
  513. var params = {}
  514. var success = function (res) {
  515. if(res.data.result){
  516. //添加购物车后,更新本地数量
  517. var localcl = wx.getStorageSync('localCartList') ? wx.getStorageSync('localCartList') : [];
  518. if(localcl.length > 0){
  519. for(let i in localcl){
  520. if(localcl[i]['product_id'] == that.data.productId){
  521. localcl[i]['count'] = localcl[i]['count'] + that.data.count;
  522. }
  523. }
  524. //setlocalcartlist
  525. wx.setStorageSync('localCartList',localcl);
  526. }
  527. console.log('localcl',localcl);
  528. that.hideModal(2);
  529. wx.showToast({
  530. title: '添加成功,请到购物车查看~',
  531. icon: 'none',
  532. duration: 2000
  533. })
  534. }
  535. // if (res.data.order_id) {
  536. // wx.navigateTo({
  537. // url: '../../pay/pay?orderId=' + res.data.order_id
  538. // })
  539. // that.hideModal()
  540. // that.setData({
  541. // count: 1
  542. // })
  543. // }
  544. }
  545. if (that.data.count <= that.data.project.left_count) {
  546. _request.$post(url, params, success)
  547. } else {
  548. wx.showToast({
  549. title: '库存不足~',
  550. icon: 'none',
  551. duration: 2000
  552. })
  553. }
  554. },
  555. getIphoneX () {
  556. var that = this
  557. wx.getSystemInfo({
  558. success: function (res) {
  559. if (res.model.toLowerCase().indexOf('iphone x') > -1) {
  560. that.setData({
  561. value: 34
  562. })
  563. }
  564. }
  565. })
  566. },
  567. getBalanceInfo () {
  568. var that = this
  569. var url = 'v1/user/balance/info'
  570. var params = {
  571. }
  572. var success = function (res) {
  573. var result = res.data.total
  574. that.setData({
  575. balance: result
  576. })
  577. }
  578. _request.$get(url, params, success)
  579. },
  580. projectImageLoading () {
  581. console.log('do projectImageLoading');
  582. var that = this
  583. wx.getImageInfo({
  584. src: 'https://cfohow.hiwavo.com/xcx/poster6.jpg',
  585. success: function (res) {
  586. that.posterImage.bg = res
  587. that.posterLoading++
  588. if (that.posterLoading === 4) {
  589. that.createCtx()
  590. }
  591. }
  592. })
  593. if (this.data.project.pics.length > 0) {
  594. wx.getImageInfo({
  595. src: this.data.project.pics[0].img,
  596. success: function (res) {
  597. that.posterImage.project = res
  598. that.posterLoading++
  599. if (that.posterLoading === 4) {
  600. that.createCtx()
  601. }
  602. }
  603. })
  604. }
  605. var url = 'v1/poster/' + this.data.productId
  606. var params = {
  607. type: 'project'
  608. }
  609. var success = function (res) {
  610. var wxhead = res.data.wx_head;
  611. if(!wxhead){
  612. wx.getUserProfile({
  613. desc: '用户头像无法获取,请从新授权', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  614. success: function(res3) {
  615. var url = 'xcx/save_wx_user/info'
  616. console.log(JSON.stringify(res3.userInfo));
  617. var params = {
  618. userinfo: JSON.stringify(res3.userInfo)
  619. }
  620. var success = function (res4) {
  621. console.log('authorize',res4)
  622. wxhead = res4.data.head;
  623. console.log(wxhead);
  624. that.posterLoading = 0;
  625. that.projectImageLoading();
  626. }
  627. _request.$post(url, params, success)
  628. },
  629. fail: function(err){
  630. wx.showToast({
  631. title: '用户头像获取失败,生成海报失败',
  632. icon: 'none',
  633. duration: 2000
  634. })
  635. wx.hideLoading();
  636. return;
  637. }
  638. })
  639. }else{
  640. wx.getImageInfo({
  641. src: res.data.qrcode_url,
  642. success: function (res) {
  643. that.posterImage.qcode = res
  644. that.posterLoading++
  645. if (that.posterLoading === 4) {
  646. that.createCtx()
  647. }
  648. },
  649. fail: function (res) {
  650. var url = 'v1/update/poster/' + that.data.productId
  651. var params = {
  652. type: 'project'
  653. }
  654. var success = function (res2) {
  655. wx.getImageInfo({
  656. src: res2.data.qrcode_url,
  657. success: function (res2) {
  658. that.posterImage.qcode = res2
  659. that.posterLoading++
  660. if (that.posterLoading === 4) {
  661. that.createCtx()
  662. }
  663. },
  664. fail: function (res2) {
  665. that.qcodeError = true
  666. if (that.data.posterPopup) {
  667. that.setData({
  668. posterPopup: false
  669. })
  670. wx.showToast({
  671. title: '海报生成失败,请稍后重试',
  672. icon: 'none',
  673. duration: 2000
  674. })
  675. wx.hideLoading()
  676. }
  677. }
  678. })
  679. wx.getImageInfo({
  680. src: res2.data.wx_head,
  681. success: function (res2) {
  682. that.posterImage.head = res2
  683. that.posterLoading++
  684. if (that.posterLoading === 4) {
  685. that.createCtx()
  686. }
  687. }
  688. })
  689. }
  690. _request.$put(url, params, success)
  691. // that.qcodeError = true
  692. // if (that.data.posterPopup) {
  693. // that.setData({
  694. // posterPopup: false
  695. // })
  696. // wx.showToast({
  697. // title: '海报生成失败,请稍后重试',
  698. // icon: 'none',
  699. // duration: 2000
  700. // })
  701. // wx.hideLoading()
  702. // }
  703. }
  704. })
  705. wx.getImageInfo({
  706. src: res.data.wx_head,
  707. success: function (res) {
  708. that.posterImage.head = res
  709. that.posterLoading++
  710. if (that.posterLoading === 4) {
  711. that.createCtx()
  712. }
  713. }
  714. })
  715. }
  716. }
  717. _request.$get(url, params, success)
  718. },
  719. createPoster () {
  720. let that = this;
  721. if(this.data.info && this.data.info.wx_user.id && this.data.info.wx_user.id > 0 && this.data.info.user.id > 0){
  722. that.projectImageLoading()
  723. if (!this.qcodeError) {
  724. if (!this.canvasLoading) {
  725. wx.showLoading({
  726. mask: true,
  727. title: ''
  728. })
  729. }
  730. this.setData({
  731. posterPopup: true
  732. })
  733. } else {
  734. wx.showToast({
  735. title: '海报生成失败,请稍后重试',
  736. icon: 'none',
  737. duration: 2000
  738. })
  739. }
  740. }else{
  741. wx.showToast({
  742. title: '请先完成授权登录',
  743. icon: 'none',
  744. duration: 2000
  745. })
  746. setTimeout(function(){
  747. wx.reLaunch({
  748. url: '/pages/user/all/all'
  749. })
  750. },1000)
  751. }
  752. },
  753. posterClose () {
  754. this.setData({
  755. posterPopup: false
  756. })
  757. },
  758. createCtx () {
  759. var that = this
  760. ctx = wx.createCanvasContext('myCanvas')
  761. ctx.drawImage(this.posterImage.bg.path, 0, 0, this.dpi(this.posterImage.bg.width), this.dpi(this.posterImage.bg.height))
  762. ctx.drawImage(this.posterImage.qcode.path, this.dpi(501), this.dpi(1140), this.dpi(180), this.dpi(180))
  763. ctx.save()
  764. ctx.translate(this.dpi(44),this.dpi(46))
  765. ctx.save()
  766. ctx.arc(this.dpi(60), this.dpi(59), this.dpi(40), 0, Math.PI * 2, false)
  767. ctx.lineWidth = 1
  768. ctx.strokeStyle = '#d4d4d4'
  769. ctx.stroke()
  770. ctx.clip()
  771. ctx.drawImage(this.posterImage.head.path, this.dpi(21), this.dpi(20), this.dpi(78), this.dpi(78))
  772. ctx.restore()
  773. ctx.save()
  774. ctx.textBaseline = 'middle'
  775. ctx.font = this.dpi(24) + 'px Arial'
  776. ctx.fillStyle = '#eab86a'
  777. ctx.fillText('源处全球源产地的优质产品!', this.dpi(136), this.dpi(59))
  778. ctx.restore()
  779. ctx.drawImage(this.posterImage.project.path, this.dpi(20), this.dpi(140), this.dpi(622), this.dpi(622))
  780. ctx.beginPath()
  781. ctx.moveTo(this.dpi(0), this.dpi(119))
  782. ctx.lineTo(this.dpi(662), this.dpi(119))
  783. ctx.lineWidth = 1
  784. ctx.strokeStyle = '#eab86a'
  785. ctx.stroke()
  786. ctx.closePath()
  787. ctx.save()
  788. ctx.translate(this.dpi(20),this.dpi(784))
  789. ctx.textBaseline = 'middle'
  790. ctx.font = this.dpi(28) + 'px Arial'
  791. ctx.fillStyle = '#bbbbbb'
  792. ctx.fillText('购买单价', this.dpi(46), this.dpi(50))
  793. ctx.fillStyle = '#eab86a'
  794. ctx.setTextAlign('right')
  795. ctx.font = 'bold ' + this.dpi(54) + 'px Arial'
  796. ctx.fillText(util.formatMoney(this.data.project.price / 100, '¥', 2), this.dpi(584), this.dpi(50))
  797. ctx.setTextAlign('left')
  798. ctx.font = this.dpi(32) + 'px Arial'
  799. ctx.fillStyle = '#2b2b2b'
  800. this.textAutoLine(this.data.project.name, this.dpi(30), this.dpi(150), this.dpi(40))
  801. ctx.restore()
  802. ctx.restore()
  803. ctx.draw(true, function callback () {
  804. that.createImage()
  805. })
  806. },
  807. createImage () {
  808. var that = this
  809. wx.canvasToTempFilePath({
  810. destWidth: 750,
  811. destHeight: 1334,
  812. canvasId: 'myCanvas',
  813. fileType: 'jpg',
  814. success: function (res) {
  815. that.setData({
  816. posterImage: res.tempFilePath
  817. })
  818. that.canvasLoading = true
  819. wx.hideLoading()
  820. }
  821. })
  822. },
  823. saveImage () {
  824. var that = this
  825. wx.showLoading({
  826. mask: true,
  827. title: ''
  828. })
  829. wx.saveImageToPhotosAlbum({
  830. filePath: this.data.posterImage,
  831. success (res) {
  832. wx.showToast({
  833. title: '已保存相册',
  834. icon: 'success',
  835. duration: 2000
  836. })
  837. },
  838. fail (res) {
  839. wx.getSetting({
  840. success (res) {
  841. if (!res.authSetting['scope.writePhotosAlbum']) {
  842. that.setData({
  843. popup: true
  844. })
  845. }
  846. }
  847. })
  848. wx.hideLoading()
  849. }
  850. })
  851. },
  852. setting () {
  853. this.setData({
  854. popup: false
  855. })
  856. },
  857. roundRect (x, y, w, h, r, color) {
  858. ctx.beginPath()
  859. ctx.moveTo(x+r, y)
  860. ctx.arcTo(x+w, y, x+w, y+h, r)
  861. ctx.arcTo(x+w, y+h, x, y+h, r)
  862. ctx.arcTo(x, y+h, x, y, r)
  863. ctx.arcTo(x, y, x+w, y, r)
  864. ctx.closePath()
  865. ctx.fillStyle = color
  866. ctx.fill()
  867. },
  868. textAutoLine (str, initX, initY, lineHeight) {
  869. let lineWidth = 0
  870. let textWidth = this.dpi(580)
  871. let lastSubStrIndex= 0
  872. for (let i = 0; i < str.length; i++) {
  873. lineWidth += ctx.measureText(str[i]).width
  874. if (lineWidth > textWidth - initX) {
  875. ctx.fillText(str.substring(lastSubStrIndex, i), initX, initY)
  876. initY += lineHeight
  877. lineWidth = 0
  878. lastSubStrIndex = i
  879. }
  880. if (i === str.length - 1) {
  881. ctx.fillText(str.substring(lastSubStrIndex, i + 1), initX, initY)
  882. }
  883. }
  884. },
  885. stopPageScroll () {
  886. return
  887. },
  888. starttime () {
  889. var that = this
  890. that.setData({
  891. timer: setInterval(function () {
  892. // var date = new Date();
  893. // var now = date.getTime();
  894. // var endDate = new Date("2019-01-03 23:14:53");//设置截止时间
  895. // var end = that.data.clock * 1000;//设置截止时间
  896. // var end = endDate.getTime();
  897. // var leftTime = end - now; //时间差
  898. var t = Date.parse(new Date())
  899. t = t / 1000;
  900. var leftTime = that.data.clock - t
  901. var d, h, m, s, ms;
  902. if (leftTime >= 0) {
  903. // day = parseInt(ctime / 86400)
  904. h = parseInt(leftTime / 3600)
  905. m = parseInt(leftTime / 60 ) - parseInt(leftTime / 3600) * 60
  906. s = parseInt(leftTime) - parseInt(leftTime / 60 ) * 60
  907. // d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
  908. // h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
  909. // m = Math.floor(leftTime / 1000 / 60 % 60);
  910. // s = Math.floor(leftTime / 1000 % 60);
  911. // ms = Math.floor(leftTime % 1000);
  912. // ms = ms < 100 ? "0" + ms : ms
  913. s = s < 10 ? "0" + s : s
  914. m = m < 10 ? "0" + m : m
  915. h = h < 10 ? "0" + h : h
  916. that.setData({
  917. hour: h,
  918. min: m,
  919. second: s,
  920. // msecond: ms,
  921. leftTime: leftTime
  922. })
  923. }
  924. if (leftTime < 0) {
  925. clearInterval(that.data.timer);
  926. that.setData({
  927. leftTime: 0,
  928. hour: '00',
  929. min: '00',
  930. second: '00',
  931. // msecond: '00'
  932. })
  933. }
  934. },100),
  935. });
  936. },
  937. checkSize(event){
  938. var type = event.currentTarget.dataset.type;
  939. var id = event.currentTarget.dataset.id;
  940. var list = event.currentTarget.dataset.list;
  941. var tname = event.currentTarget.dataset.tname;
  942. var that = this;
  943. var tkey = type=='color_list'?'cname':'sname';
  944. var reproduct = this.data.productSize;
  945. // console.log('reproduct',reproduct)
  946. for(var i in reproduct[type]['attr_values']){
  947. // console.log('reproduct[type][i].is_select',reproduct[type]['attr_values'][i].is_select)
  948. reproduct[type]['attr_values'][i].is_select = false;
  949. if(reproduct[type]['attr_values'][i].id == id) reproduct[type]['attr_values'][i].is_select = true;
  950. }
  951. // console.log('reproduct',reproduct)
  952. that.setData({
  953. productSize :reproduct,
  954. [type]:id,
  955. [tkey]:tname
  956. })
  957. // console.log('that.data[type]',that.data[type])
  958. let cflag = true;
  959. for(let i in that.data.checkbox){
  960. if(that.data[that.data.checkbox[i]] == 0) cflag = false;
  961. }
  962. if(cflag){
  963. that.getProductDetail();
  964. }
  965. },
  966. back:function(){
  967. wx.navigateBack({})
  968. },
  969. evaluateLvS(star){
  970. // console.log('star',star);
  971. var that = this;
  972. var lvList = that.data.lvList;
  973. let lvlist2 = [];
  974. lvList.forEach((item,index) => {
  975. // console.log('index',index);
  976. if(index <= star){
  977. if(index % 2 === 0){
  978. lvList[index] = that.data.lvListActive1;
  979. }else{
  980. lvList[index] = that.data.lvListActive3;
  981. }
  982. }else{
  983. if(index % 2 === 0){
  984. lvList[index] = that.data.lvListActive2;
  985. }else{
  986. lvList[index] = that.data.lvListActive4;
  987. }
  988.     }
  989. lvlist2.push(lvList[index]);
  990.  })
  991. return lvlist2;
  992. },
  993. // 监听滚动条坐标
  994. onPageScroll: function (e) {
  995. //console.log(e)
  996. var that = this
  997. var scrollTop = e.scrollTop
  998. var backTopValue = scrollTop > 500 ? true : false
  999. that.setData({
  1000. backTopValue: backTopValue
  1001. })
  1002. },
  1003. toTop:function(){
  1004. wx.pageScrollTo({
  1005. scrollTop: 0
  1006. })
  1007. },
  1008. sharetips(){
  1009. this.setData({
  1010. showsharetips:!this.data.showsharetips
  1011. })
  1012. },
  1013. getqcode: function () {
  1014. var that = this
  1015. var url = 'v1/customer_service/qrcode'
  1016. var params = {}
  1017. var success = function (res) {
  1018. that.setData({
  1019. kfqr: res.data
  1020. })
  1021. }
  1022. _request.$get(url, params, success)
  1023. },
  1024. tiggerQR:function(){
  1025. this.setData({
  1026. showqr: !this.data.showqr
  1027. })
  1028. },
  1029. catchtapQR:function(){
  1030. console.log('catchtapQR');
  1031. }
  1032. })