project-detail.js 24 KB

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