index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. //index.js
  2. //获取应用实例
  3. var app = getApp();
  4. var coupon = [
  5. {
  6. coupon_monry : '1000',
  7. coupon_rule : '9999',
  8. coupon_name: '新年专属红包',
  9. coupon_begin_time: '2018-01-01',
  10. coupon_end_time: '2018-02-08'
  11. },
  12. {
  13. coupon_monry: '300',
  14. coupon_rule: '4999',
  15. coupon_name: '新年专属红包',
  16. coupon_begin_time: '2018-01-01',
  17. coupon_end_time: '2018-02-08'
  18. },
  19. {
  20. coupon_monry: '50',
  21. coupon_rule: '999',
  22. coupon_name: '新年专属红包',
  23. coupon_begin_time: '2018-01-01',
  24. coupon_end_time: '2018-02-08'
  25. }
  26. ];
  27. Page({
  28. data: {
  29. urlHttp: '',
  30. host : '',
  31. scrollLeft: 0,//tab标题的滚动条位置
  32. search:{
  33. placeholder:"输入搜索关键字"
  34. },
  35. navList:["推荐","中秋","改良生活","优化办公","智能科技"],
  36. firstActive: "header_nav_active",
  37. currentItem : '',
  38. flag:true,
  39. banners: [],
  40. rexiao: [],
  41. tuijian: [],
  42. tuijiannew: [],
  43. forviewFir: [],
  44. forviewSec: [],
  45. forviewtitele: '',
  46. title1: '',
  47. title2: '',
  48. title3: '',
  49. intro1: '',
  50. intro2: '',
  51. intro3: '',
  52. id1: '',
  53. id2: '',
  54. id3: '',
  55. src1: '',
  56. src2: '',
  57. src3: '',
  58. src4: '',
  59. src5: '',
  60. src6: '',
  61. price1: '',
  62. price2: '',
  63. price3: '',
  64. host: '',
  65. idTwo: '',
  66. find_name: '',
  67. find_id: '',
  68. find_logo: '',
  69. find_yuedu: '',
  70. find_shoucang: '',
  71. datatime: new Date().getTime(),
  72. city_name: '',
  73. jingpin: {// 发现精品
  74. id: 1, src: "../../images/jingxuan_banner.jpg", title: "各星座员工生日礼品如何选", liulan: 117, zan: 34
  75. },
  76. page: 1,
  77. hasMore: true,
  78. hidden : '',
  79. winHeight: "",//窗口高度
  80. coupon: coupon, //优惠劵
  81. showCoupon : false,
  82. couponSta : 0,//对于用户来说,是否是第一次显示
  83. un_id : '',
  84. showMsg : true, //显示切换模式提示
  85. showChangeModel : false, //显示切换模式确认弹窗
  86. bannerFlag : 0 //banner数量
  87. },
  88. //tab切换
  89. tagChoose: function (options) {
  90. var that = this
  91. var name = options.currentTarget.dataset.name;
  92. var des = options.currentTarget.dataset.des;
  93. var forid = options.currentTarget.dataset.forid;
  94. wx:wx.navigateTo({
  95. url: '/pages/kindSecondList/kindSecondList?classify_name=' + name + '&classify_des=' + des + '&id=' + forid
  96. })
  97. },
  98. // 滚动切换标签样式
  99. switchTab: function (e) {
  100. var that = this;
  101. var host = getApp().globalData.servsers;
  102. var current = e.detail.current;
  103. if (e.detail.current == 0){
  104. var forid = 0;
  105. }else{
  106. var forid = that.data.navList[e.detail.current - 1].id;
  107. var forname = that.data.navList[e.detail.current - 1].classify_name;
  108. var classifydes = that.data.navList[e.detail.current - 1].classify_des;
  109. }
  110. this.setData({
  111. currentItem: e.detail.current
  112. })
  113. if (forid > 0) {
  114. wx.request({
  115. url: that.data.host + "classifyapi/findAllforviewFir",
  116. data: {
  117. id: forid
  118. },
  119. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT flag: true,
  120. header: {
  121. 'Accept': 'application/json'
  122. },
  123. success: function (res) {
  124. wx.request({
  125. url: that.data.host + "commodityapi/findOneforxcx",
  126. data: {
  127. com_id: forid,
  128. },
  129. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT flag: true,
  130. header: {
  131. 'Accept': 'application/json'
  132. },
  133. success: function (res) {
  134. that.setData({
  135. tuijiannew: res.data.rows
  136. });
  137. if (res == null || res.data == null) {
  138. console.error('网络请求失败');
  139. return;
  140. }
  141. }
  142. });
  143. that.setData({
  144. forviewFir: res.data.rows,
  145. forviewtitele: res.data.rows[0].classify_des,
  146. 'firstActive': "",
  147. flag: false,
  148. });
  149. if (res == null || res.data == null) {
  150. console.error('网络请求失败');
  151. return;
  152. }
  153. }
  154. });
  155. } else {
  156. //设置当前样式
  157. that.setData({
  158. 'firstActive': "",
  159. 'currentItem':0,
  160. flag: true,
  161. })
  162. }
  163. that.checkCor();
  164. },
  165. checkCor: function () {
  166. if (this.data.currentItem > 2) {
  167. this.setData({
  168. scrollLeft: 300
  169. })
  170. } else {
  171. this.setData({
  172. scrollLeft: 0
  173. })
  174. }
  175. },
  176. onLoad: function () {
  177. var that = this;
  178. var host = getApp().globalData.servsers;
  179. var un_id = getApp().globalData.un_id;
  180. that.setData({
  181. urlHttp : host
  182. })
  183. //首页banner
  184. wx.request({
  185. url: host+"homebannerapi/homebannerall",
  186. data: {},
  187. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  188. header: {
  189. 'Accept': 'application/json'
  190. },
  191. success: function (res) {
  192. that.setData({
  193. banners: res.data.rows,
  194. host: host
  195. });
  196. console.log(res.data.rows);
  197. //判断banner位置是否为空
  198. for (var i = 0; i < res.data.rows.length;i++){
  199. var bannerFlag = that.data.bannerFlag;
  200. if (bannerFlag > 0){
  201. return false;
  202. }else{
  203. if (res.data.rows[i].banner_flag == 0) {
  204. bannerFlag++;
  205. that.setData({
  206. bannerFlag: bannerFlag
  207. })
  208. return false;
  209. }
  210. }
  211. }
  212. //console.log(that.data.banners);
  213. if (res == null || res.data == null) {
  214. console.error('网络请求失败');
  215. return;
  216. }
  217. }
  218. });
  219. //品牌定制
  220. wx.request({
  221. url: host + "brandapi/findforfirst",
  222. data: {},
  223. method: 'GET',
  224. header: {
  225. 'Accept': 'application/json'
  226. },
  227. success: function (res) {
  228. if (res.data.rows[0] == undefined) {
  229. that.setData({
  230. hidden: 'hidden'
  231. })
  232. }else{
  233. var img = res.data.rows[0].brand_logo;
  234. that.setData({
  235. title1: res.data.rows[0].brand_name,
  236. intro1: res.data.rows[0].brand_des,
  237. src1: res.data.rows[0].brand_logo,
  238. src4: res.data.rows[0].brand_logo1,
  239. price1: res.data.rows[0].price,
  240. id1: res.data.rows[0].id,
  241. });
  242. }
  243. if (res.data.rows[1] == undefined) {
  244. // that.setData({
  245. // hidden: 'hidden'
  246. // })
  247. } else {
  248. var img = res.data.rows[0].brand_logo;
  249. that.setData({
  250. title2: res.data.rows[1].brand_name,
  251. intro2: res.data.rows[1].brand_des,
  252. src2: res.data.rows[1].brand_logo,
  253. src5: res.data.rows[1].brand_logo1,
  254. price2: res.data.rows[1].price,
  255. id2: res.data.rows[1].id,
  256. });
  257. }
  258. if (res.data.rows[2] == undefined) {
  259. // that.setData({
  260. // hidden: 'hidden'
  261. // })
  262. } else {
  263. var img = res.data.rows[0].brand_logo;
  264. that.setData({
  265. title3: res.data.rows[2].brand_name,
  266. intro3: res.data.rows[2].brand_des,
  267. src3: res.data.rows[2].brand_logo,
  268. src6: res.data.rows[2].brand_logo1,
  269. price3: res.data.rows[2].price,
  270. id3: res.data.rows[2].id,
  271. });
  272. }
  273. if (res == null || res.data == null) {
  274. console.error('网络请求失败');
  275. return;
  276. }
  277. }
  278. })
  279. // 高度自适应
  280. wx.getSystemInfo({
  281. success: function (res) {
  282. var clientHeight = res.windowHeight,
  283. clientWidth = res.windowWidth,
  284. rpxR = 750 / clientWidth;
  285. var calc = clientHeight * rpxR;
  286. that.setData({
  287. winHeight: calc
  288. });
  289. }
  290. });
  291. },
  292. onReady:function(e){
  293. var that = this;
  294. var host = getApp().globalData.servsers;
  295. //判断时间,在规定时间内显示优惠劵弹窗
  296. var beiginTime = '2017/12/28';
  297. var endTime = '2018/01/08';
  298. var beginTimestamp = beiginTime.replace(/-/g, '/');
  299. beginTimestamp = Date.parse(beginTimestamp);
  300. var endTimestamp = endTime.replace(/-/g, '/');
  301. endTimestamp = Date.parse(endTimestamp);
  302. //获取当前日期
  303. var date = new Date();
  304. var Y = date.getFullYear();
  305. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  306. var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  307. var nowTime = Y + '/' + M + '/' + D;
  308. nowTime = nowTime.replace(/-/g, '/');
  309. nowTime = Date.parse(nowTime);
  310. wx.login({
  311. success: function (res) {
  312. var code = res.code;
  313. wx.getUserInfo({
  314. withCredentials: true,
  315. success: function (res) {
  316. wx.request({
  317. url: host + "userapi/insertadd",
  318. data: {
  319. user_id: code,
  320. name: res.userInfo.nickName,
  321. icon: res.userInfo.avatarUrl,
  322. iv: res.iv,
  323. encryptedData: res.encryptedData,
  324. },
  325. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  326. header: {
  327. 'Accept': 'application/json'
  328. },
  329. success: function (res) {
  330. that.setData({
  331. un_id: res.data.unionId
  332. })
  333. var un_id = res.data.unionId;
  334. if (parseInt(nowTime) >= parseInt(beginTimestamp) && parseInt(nowTime) <= parseInt(endTimestamp)) {//当前日期在优惠劵领取时间内
  335. console.log("un_id:" + un_id);
  336. if (un_id != undefined && un_id != '' && un_id != null){
  337. wx.request({//优惠活动-对于用户来说,是否应该显示
  338. url: host + "mycouponapi/getAlertFlag",
  339. data: {
  340. user_id: un_id,
  341. batch_no: 1,
  342. alert_num: 1//优惠活动对于每个用户来说,一共显示的次数
  343. },
  344. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  345. header: {
  346. 'Accept': 'application/json'
  347. },
  348. success: function (res) {
  349. if (res.data == 0) {
  350. that.setData({
  351. showCoupon: true
  352. })
  353. } else {
  354. that.setData({
  355. showCoupon: false
  356. })
  357. }
  358. if (res == null || res.data == null) {
  359. console.error('网络请求失败');
  360. return;
  361. }
  362. }
  363. });
  364. }
  365. }
  366. if (res == null || res.data == null) {
  367. console.error('网络请求失败');
  368. return;
  369. }
  370. }
  371. })
  372. }
  373. })
  374. }
  375. })
  376. },
  377. footerTap: app.footerTap,
  378. onShow:function(){
  379. var that = this;
  380. that.onLoad();
  381. },
  382. //跳转到“发现”tab页
  383. find:function(e){
  384. wx.switchTab({
  385. url : "/pages/find/index"
  386. })
  387. },
  388. //下拉刷新
  389. onPullDownRefresh: function (e) {
  390. var that = this;
  391. that.onLoad();
  392. wx.stopPullDownRefresh();
  393. },
  394. onShareAppMessage: function (res) {//页面分享
  395. var that = this;
  396. var host = getApp().globalData.servsers;
  397. if (res.from === 'button') {
  398. // 来自页面内转发按钮
  399. console.log(res.target)
  400. }
  401. return {
  402. title:'大良造-精良之选,用心造物!',
  403. path: '/pages/index/index',
  404. success: function (res) {
  405. },
  406. fail: function (res) {
  407. // 转发失败
  408. }
  409. }
  410. },
  411. //关闭优惠劵弹窗
  412. closeCoupon:function(e){
  413. var that = this;
  414. that.setData({
  415. showCoupon : false
  416. })
  417. },
  418. //关闭切换模式提示
  419. closeMsg:function(e){
  420. var that = this;
  421. that.setData({
  422. showMsg : false
  423. })
  424. },
  425. //打开切换提示
  426. openChangeModel:function(e){
  427. var that = this;
  428. that.setData({
  429. showMsg: false,
  430. showChangeModel: true
  431. })
  432. },
  433. //跳转至一键选礼
  434. goChooseGift:function(e){
  435. var that = this;
  436. that.setData({
  437. showChangeModel : false
  438. })
  439. wx.navigateTo({
  440. url: '/pages/patternMenu/patternMenu'
  441. })
  442. },
  443. //关闭切换模式确认弹窗
  444. closeChangeModel:function(e){
  445. var that = this;
  446. that.setData({
  447. showChangeModel: false
  448. })
  449. }
  450. })
  451. var banners = []
  452. // 热销新品
  453. var rexiao = []
  454. // 热销新品
  455. var pinpai = []
  456. // 人气推荐
  457. var tuijian = []
  458. var that;
  459. var Util = require('../../utils/util.js');