project-detail.js 23 KB

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