beerDetail.js 5.8 KB

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