project-detail.js 27 KB

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