project-detail.js 25 KB

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