goods.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. var app = getApp(),
  2. api = getApp().api,
  3. utils = getApp().helper,
  4. videoContext = "",
  5. setIntval = null,
  6. WxParse = require("../../wxParse/wxParse.js"),
  7. userIntval = null,
  8. scrollIntval = null,
  9. is_loading = !1;
  10. Page({
  11. data: {
  12. hide: "hide",
  13. time_list: {
  14. day: 0,
  15. hour: "00",
  16. minute: "00",
  17. second: "00"
  18. },
  19. p: 1,
  20. user_index: 0,
  21. show_content: !1
  22. },
  23. onLoad: function(e) {
  24. if (getApp().page.onLoad(this, e), "undefined" == typeof my) {
  25. var t = decodeURIComponent(e.scene);
  26. if (void 0 !== t) {
  27. var a = utils.scene_decode(t);
  28. a.gid && (e.goods_id = a.gid)
  29. }
  30. } else if (null !== app.query) {
  31. var o = app.query;
  32. app.query = null, e.goods_id = o.gid
  33. }
  34. this.getGoods(e.buyNow)
  35. },
  36. getGoods: function(e) {
  37. var a = this;
  38. getApp().core.showLoading({
  39. title: "加载中"
  40. }), getApp().request({
  41. url: getApp().api.bargain.goods,
  42. data: {
  43. goods_id: e,
  44. page: 1
  45. },
  46. success: function(e) {
  47. if (0 == e.code) {
  48. var t = e.data.goods.detail;
  49. WxParse.wxParse("detail", "html", t, a), a.setData(e.data), a.setData({
  50. reset_time: a.data.goods.reset_time,
  51. time_list: a.setTimeList(e.data.goods.reset_time),
  52. p: 1,
  53. foreshow_time: a.data.goods.foreshow_time,
  54. foreshow_time_list: a.setTimeList(a.data.goods.foreshow_time)
  55. }), a.setTimeOver(), e.data.bargain_info && a.getUserTime()
  56. } else getApp().core.showModal({
  57. title: "提示",
  58. content: e.msg,
  59. showCancel: !1,
  60. success: function(e) {
  61. e.confirm && getApp().core.navigateBack({
  62. delta: -1
  63. })
  64. }
  65. })
  66. },
  67. complete: function(e) {
  68. getApp().core.hideLoading()
  69. }
  70. })
  71. },
  72. onReady: function() {
  73. app.page.onReady(this)
  74. },
  75. onShow: function() {
  76. app.page.onShow(this)
  77. },
  78. onHide: function() {
  79. app.page.onHide(this)
  80. },
  81. onUnload: function() {
  82. app.page.onUnload(this), clearInterval(setIntval), setIntval = null, clearInterval(userIntval), userIntval = null, clearInterval(scrollIntval), scrollIntval = null
  83. },
  84. play: function(e) {
  85. var t = e.target.dataset.url;
  86. this.setData({
  87. url: t,
  88. hide: "",
  89. show: !0
  90. }), (videoContext = getApp().core.createVideoContext("video")).play()
  91. },
  92. close: function(e) {
  93. if ("video" == e.target.id) return !0;
  94. this.setData({
  95. hide: "hide",
  96. show: !1
  97. }), videoContext.pause()
  98. },
  99. onGoodsImageClick: function(e) {
  100. var t = [],
  101. a = e.currentTarget.dataset.index;
  102. for (var o in this.data.goods.pic_list) t.push(this.data.goods.pic_list[o].pic_url);
  103. getApp().core.previewImage({
  104. urls: t,
  105. current: t[a]
  106. })
  107. },
  108. hide: function(e) {
  109. 0 == e.detail.current ? this.setData({
  110. img_hide: ""
  111. }) : this.setData({
  112. img_hide: "hide"
  113. })
  114. },
  115. setTimeOver: function() {
  116. var i = this;
  117. setIntval = setInterval(function() {
  118. i.data.resset_time <= 0 && clearInterval(setIntval);
  119. var e = i.data.reset_time - 1,
  120. t = i.setTimeList(e),
  121. a = i.data.foreshow_time - 1,
  122. o = i.setTimeList(a);
  123. i.setData({
  124. reset_time: e,
  125. time_list: t,
  126. foreshow_time: a,
  127. foreshow_time_list: o
  128. })
  129. }, 1e3)
  130. },
  131. orderSubmit: function() {
  132. var t = this;
  133. getApp().core.showLoading({
  134. title: "加载中"
  135. }), getApp().request({
  136. url: getApp().api.bargain.bargain_submit,
  137. method: "POST",
  138. data: {
  139. goods_id: t.data.goods.id
  140. },
  141. success: function(e) {
  142. 0 == e.code ? getApp().core.redirectTo({
  143. url: "/bargain/activity/activity?order_id=" + e.data.order_id
  144. }) : t.showToast({
  145. title: e.msg
  146. })
  147. },
  148. complete: function(e) {
  149. getApp().core.hideLoading()
  150. }
  151. })
  152. },
  153. buyNow: function() {
  154. var e = [],
  155. t = [],
  156. a = this.data.bargain_info;
  157. a && (t.push({
  158. bargain_order_id: a.order_id
  159. }), e.push({
  160. mch_id: 0,
  161. goods_list: t
  162. }), getApp().core.redirectTo({
  163. url: "/pages/new-order-submit/new-order-submit?mch_list=" + JSON.stringify(e)
  164. }))
  165. },
  166. getUserTime: function() {
  167. var t = this;
  168. userIntval = setInterval(function() {
  169. t.loadData()
  170. }, 1e3), scrollIntval = setInterval(function() {
  171. var e = t.data.user_index;
  172. 3 < t.data.bargain_info.bargain_info.length - e ? e += 3 : e = 0, t.setData({
  173. user_index: e
  174. })
  175. }, 3e3)
  176. },
  177. loadData: function() {
  178. var o = this,
  179. i = o.data.p;
  180. is_loading || (is_loading = !0, app.request({
  181. url: api.bargain.goods_user,
  182. data: {
  183. page: i + 1,
  184. goods_id: o.data.goods.id
  185. },
  186. success: function(e) {
  187. if (0 == e.code) {
  188. var t = o.data.bargain_info.bargain_info,
  189. a = e.data.bargain_info;
  190. 0 == a.bargain_info.length && (clearInterval(userIntval), userIntval = null), a.bargain_info = t.concat(a.bargain_info), o.setData({
  191. bargain_info: a,
  192. p: i + 1
  193. })
  194. } else o.showToast({
  195. title: e.msg
  196. })
  197. },
  198. complete: function() {
  199. is_loading = !1
  200. }
  201. }))
  202. },
  203. contentClose: function() {
  204. this.setData({
  205. show_content: !1
  206. })
  207. },
  208. contentOpen: function() {
  209. this.setData({
  210. show_content: !0
  211. })
  212. },
  213. onShareAppMessage: function() {
  214. getApp().page.onShareAppMessage(this);
  215. return {
  216. path: "/bargain/list/list?goods_id=" + this.data.goods.id + "&user_id=" + this.data.__user_info.id,
  217. success: function(e) {},
  218. title: this.data.goods.name,
  219. imageUrl: this.data.goods.pic_list[0].pic_url
  220. }
  221. },
  222. showShareModal: function() {
  223. this.setData({
  224. share_modal_active: "active"
  225. })
  226. },
  227. shareModalClose: function() {
  228. this.setData({
  229. share_modal_active: ""
  230. })
  231. },
  232. getGoodsQrcode: function() {
  233. var t = this;
  234. if (t.setData({
  235. qrcode_active: "active",
  236. share_modal_active: ""
  237. }), t.data.goods_qrcode) return !0;
  238. getApp().request({
  239. url: getApp().api.bargain.qrcode,
  240. data: {
  241. goods_id: t.data.goods.id
  242. },
  243. success: function(e) {
  244. 0 == e.code && t.setData({
  245. goods_qrcode: e.data.pic_url
  246. }), 1 == e.code && (t.goodsQrcodeClose(), getApp().core.showModal({
  247. title: "提示",
  248. content: e.msg,
  249. showCancel: !1,
  250. success: function(e) {
  251. e.confirm
  252. }
  253. }))
  254. }
  255. })
  256. },
  257. qrcodeClick: function(e) {
  258. var t = e.currentTarget.dataset.src;
  259. getApp().core.previewImage({
  260. urls: [t]
  261. })
  262. },
  263. qrcodeClose: function() {
  264. this.setData({
  265. qrcode_active: ""
  266. })
  267. },
  268. goodsQrcodeClose: function() {
  269. this.setData({
  270. goods_qrcode_active: "",
  271. no_scroll: !1
  272. })
  273. },
  274. saveQrcode: function() {
  275. var t = this;
  276. getApp().core.saveImageToPhotosAlbum ? (getApp().core.showLoading({
  277. title: "正在保存图片",
  278. mask: !1
  279. }), getApp().core.downloadFile({
  280. url: t.data.goods_qrcode,
  281. success: function(e) {
  282. getApp().core.showLoading({
  283. title: "正在保存图片",
  284. mask: !1
  285. }), getApp().core.saveImageToPhotosAlbum({
  286. filePath: e.tempFilePath,
  287. success: function() {
  288. getApp().core.showModal({
  289. title: "提示",
  290. content: "商品海报保存成功",
  291. showCancel: !1
  292. })
  293. },
  294. fail: function(e) {
  295. getApp().core.showModal({
  296. title: "图片保存失败",
  297. content: e.errMsg,
  298. showCancel: !1
  299. })
  300. },
  301. complete: function(e) {
  302. getApp().core.hideLoading()
  303. }
  304. })
  305. },
  306. fail: function(e) {
  307. getApp().core.showModal({
  308. title: "图片下载失败",
  309. content: e.errMsg + ";" + t.data.goods_qrcode,
  310. showCancel: !1
  311. })
  312. },
  313. complete: function(e) {
  314. getApp().core.hideLoading()
  315. }
  316. })) : getApp().core.showModal({
  317. title: "提示",
  318. content: "当前版本过低,无法使用该功能,请升级到最新版本后重试。",
  319. showCancel: !1
  320. })
  321. }
  322. });