project-detail-noshare.js 23 KB

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