project-comment.js 23 KB

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