project-detail.js 25 KB

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