project-detail.js 24 KB

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