project-detail.js 21 KB

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