project-detail.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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. console.log('do projectImageLoading');
  505. var that = this
  506. wx.getImageInfo({
  507. src: 'https://cfohow.hiwavo.com/xcx/poster6.jpg',
  508. success: function (res) {
  509. that.posterImage.bg = res
  510. that.posterLoading++
  511. if (that.posterLoading === 4) {
  512. that.createCtx()
  513. }
  514. }
  515. })
  516. if (this.data.project.pics.length > 0) {
  517. wx.getImageInfo({
  518. src: this.data.project.pics[0].img,
  519. success: function (res) {
  520. that.posterImage.project = res
  521. that.posterLoading++
  522. if (that.posterLoading === 4) {
  523. that.createCtx()
  524. }
  525. }
  526. })
  527. }
  528. var url = 'v1/poster/' + this.data.productId
  529. var params = {
  530. type: 'project'
  531. }
  532. var success = function (res) {
  533. var wxhead = res.data.wx_head;
  534. if(!wxhead){
  535. wx.getUserProfile({
  536. desc: '用户头像无法获取,请从新授权', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  537. success: function(res3) {
  538. var url = 'xcx/save_wx_user/info'
  539. console.log(JSON.stringify(res3.userInfo));
  540. var params = {
  541. userinfo: JSON.stringify(res3.userInfo)
  542. }
  543. var success = function (res4) {
  544. console.log('authorize',res4)
  545. wxhead = res4.data.head;
  546. console.log(wxhead);
  547. that.posterLoading = 0;
  548. that.projectImageLoading();
  549. }
  550. _request.$post(url, params, success)
  551. },
  552. fail: function(err){
  553. wx.showToast({
  554. title: '用户头像获取失败,生成海报失败',
  555. icon: 'none',
  556. duration: 2000
  557. })
  558. wx.hideLoading();
  559. return;
  560. }
  561. })
  562. }else{
  563. wx.getImageInfo({
  564. src: res.data.qrcode_url,
  565. success: function (res) {
  566. that.posterImage.qcode = res
  567. that.posterLoading++
  568. if (that.posterLoading === 4) {
  569. that.createCtx()
  570. }
  571. },
  572. fail: function (res) {
  573. var url = 'v1/update/poster/' + that.data.productId
  574. var params = {
  575. type: 'project'
  576. }
  577. var success = function (res2) {
  578. wx.getImageInfo({
  579. src: res2.data.qrcode_url,
  580. success: function (res2) {
  581. that.posterImage.qcode = res2
  582. that.posterLoading++
  583. if (that.posterLoading === 4) {
  584. that.createCtx()
  585. }
  586. },
  587. fail: function (res2) {
  588. that.qcodeError = true
  589. if (that.data.posterPopup) {
  590. that.setData({
  591. posterPopup: false
  592. })
  593. wx.showToast({
  594. title: '海报生成失败,请稍后重试',
  595. icon: 'none',
  596. duration: 2000
  597. })
  598. wx.hideLoading()
  599. }
  600. }
  601. })
  602. wx.getImageInfo({
  603. src: res2.data.wx_head,
  604. success: function (res2) {
  605. that.posterImage.head = res2
  606. that.posterLoading++
  607. if (that.posterLoading === 4) {
  608. that.createCtx()
  609. }
  610. }
  611. })
  612. }
  613. _request.$put(url, params, success)
  614. // that.qcodeError = true
  615. // if (that.data.posterPopup) {
  616. // that.setData({
  617. // posterPopup: false
  618. // })
  619. // wx.showToast({
  620. // title: '海报生成失败,请稍后重试',
  621. // icon: 'none',
  622. // duration: 2000
  623. // })
  624. // wx.hideLoading()
  625. // }
  626. }
  627. })
  628. wx.getImageInfo({
  629. src: res.data.wx_head,
  630. success: function (res) {
  631. that.posterImage.head = res
  632. that.posterLoading++
  633. if (that.posterLoading === 4) {
  634. that.createCtx()
  635. }
  636. }
  637. })
  638. }
  639. }
  640. _request.$get(url, params, success)
  641. },
  642. createPoster () {
  643. let that = this;
  644. if(this.data.check && this.data.check.wx_user_id && this.data.check.wx_user_id > 0 && this.data.check.user_id > 0){
  645. that.projectImageLoading()
  646. if (!this.qcodeError) {
  647. if (!this.canvasLoading) {
  648. wx.showLoading({
  649. mask: true,
  650. title: ''
  651. })
  652. }
  653. this.setData({
  654. posterPopup: true
  655. })
  656. } else {
  657. wx.showToast({
  658. title: '海报生成失败,请稍后重试',
  659. icon: 'none',
  660. duration: 2000
  661. })
  662. }
  663. }else{
  664. wx.showToast({
  665. title: '请先完成授权登录',
  666. icon: 'none',
  667. duration: 2000
  668. })
  669. }
  670. },
  671. posterClose () {
  672. this.setData({
  673. posterPopup: false
  674. })
  675. },
  676. createCtx () {
  677. var that = this
  678. ctx = wx.createCanvasContext('myCanvas')
  679. ctx.drawImage(this.posterImage.bg.path, 0, 0, this.dpi(this.posterImage.bg.width), this.dpi(this.posterImage.bg.height))
  680. ctx.drawImage(this.posterImage.qcode.path, this.dpi(501), this.dpi(1140), this.dpi(180), this.dpi(180))
  681. ctx.save()
  682. ctx.translate(this.dpi(44),this.dpi(46))
  683. ctx.save()
  684. ctx.arc(this.dpi(60), this.dpi(59), this.dpi(40), 0, Math.PI * 2, false)
  685. ctx.lineWidth = 1
  686. ctx.strokeStyle = '#d4d4d4'
  687. ctx.stroke()
  688. ctx.clip()
  689. ctx.drawImage(this.posterImage.head.path, this.dpi(21), this.dpi(20), this.dpi(78), this.dpi(78))
  690. ctx.restore()
  691. ctx.save()
  692. ctx.textBaseline = 'middle'
  693. ctx.font = this.dpi(24) + 'px Arial'
  694. ctx.fillStyle = '#eab86a'
  695. ctx.fillText('源处全球源产地的优质产品!', this.dpi(136), this.dpi(59))
  696. ctx.restore()
  697. ctx.drawImage(this.posterImage.project.path, this.dpi(20), this.dpi(140), this.dpi(622), this.dpi(622))
  698. ctx.beginPath()
  699. ctx.moveTo(this.dpi(0), this.dpi(119))
  700. ctx.lineTo(this.dpi(662), this.dpi(119))
  701. ctx.lineWidth = 1
  702. ctx.strokeStyle = '#eab86a'
  703. ctx.stroke()
  704. ctx.closePath()
  705. ctx.save()
  706. ctx.translate(this.dpi(20),this.dpi(784))
  707. ctx.textBaseline = 'middle'
  708. ctx.font = this.dpi(28) + 'px Arial'
  709. ctx.fillStyle = '#bbbbbb'
  710. ctx.fillText('购买单价', this.dpi(46), this.dpi(50))
  711. ctx.fillStyle = '#eab86a'
  712. ctx.setTextAlign('right')
  713. ctx.font = 'bold ' + this.dpi(54) + 'px Arial'
  714. ctx.fillText(util.formatMoney(this.data.project.price / 100, '¥', 2), this.dpi(584), this.dpi(50))
  715. ctx.setTextAlign('left')
  716. ctx.font = this.dpi(32) + 'px Arial'
  717. ctx.fillStyle = '#2b2b2b'
  718. this.textAutoLine(this.data.project.name, this.dpi(30), this.dpi(150), this.dpi(40))
  719. ctx.restore()
  720. ctx.restore()
  721. ctx.draw(true, function callback () {
  722. that.createImage()
  723. })
  724. },
  725. createImage () {
  726. var that = this
  727. wx.canvasToTempFilePath({
  728. destWidth: 750,
  729. destHeight: 1334,
  730. canvasId: 'myCanvas',
  731. fileType: 'jpg',
  732. success: function (res) {
  733. that.setData({
  734. posterImage: res.tempFilePath
  735. })
  736. that.canvasLoading = true
  737. wx.hideLoading()
  738. }
  739. })
  740. },
  741. saveImage () {
  742. var that = this
  743. wx.showLoading({
  744. mask: true,
  745. title: ''
  746. })
  747. wx.saveImageToPhotosAlbum({
  748. filePath: this.data.posterImage,
  749. success (res) {
  750. wx.showToast({
  751. title: '已保存相册',
  752. icon: 'success',
  753. duration: 2000
  754. })
  755. },
  756. fail (res) {
  757. wx.getSetting({
  758. success (res) {
  759. if (!res.authSetting['scope.writePhotosAlbum']) {
  760. that.setData({
  761. popup: true
  762. })
  763. }
  764. }
  765. })
  766. wx.hideLoading()
  767. }
  768. })
  769. },
  770. setting () {
  771. this.setData({
  772. popup: false
  773. })
  774. },
  775. roundRect (x, y, w, h, r, color) {
  776. ctx.beginPath()
  777. ctx.moveTo(x+r, y)
  778. ctx.arcTo(x+w, y, x+w, y+h, r)
  779. ctx.arcTo(x+w, y+h, x, y+h, r)
  780. ctx.arcTo(x, y+h, x, y, r)
  781. ctx.arcTo(x, y, x+w, y, r)
  782. ctx.closePath()
  783. ctx.fillStyle = color
  784. ctx.fill()
  785. },
  786. textAutoLine (str, initX, initY, lineHeight) {
  787. let lineWidth = 0
  788. let textWidth = this.dpi(580)
  789. let lastSubStrIndex= 0
  790. for (let i = 0; i < str.length; i++) {
  791. lineWidth += ctx.measureText(str[i]).width
  792. if (lineWidth > textWidth - initX) {
  793. ctx.fillText(str.substring(lastSubStrIndex, i), initX, initY)
  794. initY += lineHeight
  795. lineWidth = 0
  796. lastSubStrIndex = i
  797. }
  798. if (i === str.length - 1) {
  799. ctx.fillText(str.substring(lastSubStrIndex, i + 1), initX, initY)
  800. }
  801. }
  802. },
  803. stopPageScroll () {
  804. return
  805. },
  806. starttime () {
  807. var that = this
  808. that.setData({
  809. timer: setInterval(function () {
  810. // var date = new Date();
  811. // var now = date.getTime();
  812. // var endDate = new Date("2019-01-03 23:14:53");//设置截止时间
  813. // var end = that.data.clock * 1000;//设置截止时间
  814. // var end = endDate.getTime();
  815. // var leftTime = end - now; //时间差
  816. var t = Date.parse(new Date())
  817. t = t / 1000;
  818. var leftTime = that.data.clock - t
  819. var d, h, m, s, ms;
  820. if (leftTime >= 0) {
  821. // day = parseInt(ctime / 86400)
  822. h = parseInt(leftTime / 3600)
  823. m = parseInt(leftTime / 60 ) - parseInt(leftTime / 3600) * 60
  824. s = parseInt(leftTime) - parseInt(leftTime / 60 ) * 60
  825. // d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
  826. // h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
  827. // m = Math.floor(leftTime / 1000 / 60 % 60);
  828. // s = Math.floor(leftTime / 1000 % 60);
  829. // ms = Math.floor(leftTime % 1000);
  830. // ms = ms < 100 ? "0" + ms : ms
  831. s = s < 10 ? "0" + s : s
  832. m = m < 10 ? "0" + m : m
  833. h = h < 10 ? "0" + h : h
  834. that.setData({
  835. hour: h,
  836. min: m,
  837. second: s,
  838. // msecond: ms,
  839. leftTime: leftTime
  840. })
  841. }
  842. if (leftTime < 0) {
  843. clearInterval(that.data.timer);
  844. that.setData({
  845. leftTime: 0,
  846. hour: '00',
  847. min: '00',
  848. second: '00',
  849. // msecond: '00'
  850. })
  851. }
  852. },100),
  853. });
  854. },
  855. checkSize(event){
  856. var type = event.currentTarget.dataset.type;
  857. var id = event.currentTarget.dataset.id;
  858. var list = event.currentTarget.dataset.list;
  859. var tname = event.currentTarget.dataset.tname;
  860. var that = this;
  861. var tkey = type=='color_list'?'cname':'sname';
  862. var reproduct = this.data.productSize;
  863. // console.log('reproduct',reproduct)
  864. for(var i in reproduct[type]['attr_values']){
  865. // console.log('reproduct[type][i].is_select',reproduct[type]['attr_values'][i].is_select)
  866. reproduct[type]['attr_values'][i].is_select = false;
  867. if(reproduct[type]['attr_values'][i].id == id) reproduct[type]['attr_values'][i].is_select = true;
  868. }
  869. // console.log('reproduct',reproduct)
  870. that.setData({
  871. productSize :reproduct,
  872. [type]:id,
  873. [tkey]:tname
  874. })
  875. // console.log('that.data[type]',that.data[type])
  876. let cflag = true;
  877. for(let i in that.data.checkbox){
  878. if(that.data[that.data.checkbox[i]] == 0) cflag = false;
  879. }
  880. if(cflag){
  881. that.getProductDetail();
  882. }
  883. },
  884. back:function(){
  885. wx.navigateBack({})
  886. },
  887. evaluateLvS(star){
  888. // console.log('star',star);
  889. var that = this;
  890. var lvList = that.data.lvList;
  891. let lvlist2 = [];
  892. lvList.forEach((item,index) => {
  893. // console.log('index',index);
  894. if(index <= star){
  895. if(index % 2 === 0){
  896. lvList[index] = that.data.lvListActive1;
  897. }else{
  898. lvList[index] = that.data.lvListActive3;
  899. }
  900. }else{
  901. if(index % 2 === 0){
  902. lvList[index] = that.data.lvListActive2;
  903. }else{
  904. lvList[index] = that.data.lvListActive4;
  905. }
  906.     }
  907. lvlist2.push(lvList[index]);
  908.  })
  909. return lvlist2;
  910. }
  911. })