project-detail-noshare.js 23 KB

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