beerDetail.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // pages/beerDetail/beerDetail.js
  2. var app = getApp();
  3. const request = require("../../utils/request.js");
  4. import uCharts from '../../utils/u-charts.js';
  5. var uChartsInstance = {};
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. cWidth: 750,
  12. cHeight: 500,
  13. bannerIndex: 0,
  14. nosaleStatus: true,
  15. productId: null,
  16. beerData: {}
  17. },
  18. toCircles(event) {
  19. let name = event.currentTarget.dataset.name
  20. wx.navigateTo({
  21. url: '../beerCircles/beerCircles?productId=' + this.data.productId + '&name=' + name,
  22. })
  23. },
  24. wantDrinkFun() {
  25. let that = this;
  26. if(that.data.beerData.wantDrink) {
  27. that.setData({
  28. nosaleStatus: true
  29. })
  30. }else{
  31. request.postData(
  32. 'app/product/drink/want',
  33. {productId: that.data.beerData.productId},
  34. res => {
  35. wx.showToast({
  36. title: '已想喝+1',
  37. icon: 'none',
  38. duration: 2000
  39. })
  40. that.getProdDetailData();
  41. },
  42. res => {
  43. console.log(res)
  44. }
  45. )
  46. }
  47. },
  48. bindchange(event) {
  49. if(event.detail.source == 'touch'){
  50. this.setData({
  51. bannerIndex: event.detail.current
  52. })
  53. }else if(event.detail.source == 'autoplay'){
  54. this.setData({
  55. bannerIndex: event.detail.current
  56. })
  57. }
  58. },
  59. goStore() {
  60. wx.navigateTo({
  61. url: '../beerStore/beerStore',
  62. })
  63. },
  64. goOrder() {
  65. let url = this.data.beerData.jumpUrl;
  66. if(!url) {
  67. this.setData({
  68. nosaleStatus: false
  69. })
  70. return
  71. }
  72. let jumpType = request.getUrlKey(url, 'jumpType');
  73. if(jumpType == 'app') {
  74. let URL = decodeURIComponent(url)
  75. let jumpUrl = request.getUrlKey(URL, 'miniptogram')
  76. wx.navigateTo({
  77. url: JSON.parse(jumpUrl).path
  78. })
  79. }else if(jumpType == 'H5') {
  80. let jumpUrl = request.getUrlKey(url, 'url')
  81. wx.navigateTo({
  82. url: '../webView/webView?url='+jumpUrl
  83. })
  84. }else if(jumpType == 'miniptogram'){
  85. let appId = request.getUrlKey(url, 'appId');
  86. let path = request.getUrlKey(url, 'path')
  87. console.log(path)
  88. wx.navigateToMiniProgram({
  89. appId: appId,
  90. path: path,
  91. extraData: {},
  92. envVersion: 'release',
  93. success(res) {
  94. // 打开成功
  95. }
  96. })
  97. }
  98. },
  99. nosaleClose() {
  100. this.setData({
  101. nosaleStatus: true
  102. })
  103. },
  104. getProdDetailData() {
  105. let that = this;
  106. request.getData(
  107. 'app/product/detail',
  108. {productId: that.data.productId},
  109. res => {
  110. that.setData({
  111. beerData: res.data.data
  112. })
  113. },
  114. res => {
  115. console.log(res)
  116. }
  117. )
  118. },
  119. /**
  120. * 生命周期函数--监听页面加载
  121. */
  122. onLoad: function (options) {
  123. let that = this;
  124. that.setData({
  125. productId: options.productId
  126. })
  127. that.getProdDetailData();
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady: function () {
  133. //这里的第一个 750 对应 css .charts 的 width
  134. const cWidth = 750 / 750 * wx.getSystemInfoSync().windowWidth;
  135. //这里的 500 对应 css .charts 的 height
  136. const cHeight = 500 / 750 * wx.getSystemInfoSync().windowWidth;
  137. this.setData({ cWidth, cHeight });
  138. this.getServerData();
  139. },
  140. /**
  141. * 生命周期函数--监听页面显示
  142. */
  143. onShow: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面隐藏
  147. */
  148. onHide: function () {
  149. },
  150. /**
  151. * 生命周期函数--监听页面卸载
  152. */
  153. onUnload: function () {
  154. },
  155. /**
  156. * 页面相关事件处理函数--监听用户下拉动作
  157. */
  158. onPullDownRefresh: function () {
  159. },
  160. /**
  161. * 页面上拉触底事件的处理函数
  162. */
  163. onReachBottom: function () {
  164. },
  165. /**
  166. * 用户点击右上角分享
  167. */
  168. onShareAppMessage: function () {
  169. },
  170. getServerData() {
  171. //模拟从服务器获取数据时的延时
  172. setTimeout(() => {
  173. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  174. let res = {
  175. categories: ["原麦汁浓度","酒精度","级别","喜爱度","苦度值"],
  176. series: [
  177. {
  178. name: "当前",
  179. data: [20,40,60,80,100]
  180. },
  181. {
  182. name: "平均",
  183. data: [90,70,50,30,10]
  184. }
  185. ]
  186. };
  187. this.drawCharts('uxXiJSVkwzQtHtxxJadNKGaTRVZrgait', res);
  188. }, 500);
  189. },
  190. drawCharts(id,data){
  191. const ctx = wx.createCanvasContext(id, this);
  192. uChartsInstance[id] = new uCharts({
  193. type: "radar",
  194. context: ctx,
  195. width: this.data.cWidth,
  196. height: this.data.cHeight,
  197. categories: data.categories,
  198. series: data.series,
  199. animation: true,
  200. background: "#FFFFFF",
  201. color: ["#FFA100","#258AFB"],
  202. padding: [5,5,5,5],
  203. dataLabel: false,
  204. enableScroll: false,
  205. border: false,
  206. legend: {
  207. show: false,
  208. position: "right",
  209. lineHeight: 25
  210. },
  211. extra: {
  212. radar: {
  213. gridType: "radar",
  214. gridColor: "#EEEEEE",
  215. gridCount: 5,
  216. opacity: 0.2,
  217. max: 100,
  218. gridEval: 5,
  219. labelShow: true,
  220. border: true
  221. }
  222. }
  223. });
  224. },
  225. tap(e){
  226. uChartsInstance[e.target.id].touchLegend(e);
  227. uChartsInstance[e.target.id].showToolTip(e);
  228. }
  229. })