project-detail.js 27 KB

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