project-detail.js 23 KB

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