project-detail.js 26 KB

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