mineGiftList.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. // orderList.js
  2. var app = getApp()
  3. var MD5Util = require('../../utils/md5.js');
  4. var navList = [
  5. { id: 1, navName: "送出的礼物" },
  6. { id: 2, navName: "礼物盒" }
  7. ];
  8. Page({
  9. data: {
  10. navList: navList,
  11. goosdList: [],
  12. goosdListnew: [],
  13. goodsList: [],
  14. goodsListPage: [],//整体数据分页数据
  15. pageLen: 0,
  16. isSelect: 0,
  17. orderState: 0, //状态
  18. total: [],
  19. modalCont: '',
  20. orderState: 0,
  21. order_number: '', //订单编号
  22. tabState: 0,
  23. previewUrl: [],
  24. previewUrlEach: '',
  25. previewUrlBoxEach: '',
  26. previewHidden: 'hidden',
  27. id: '',
  28. result: [],
  29. end_time: '',
  30. clock: '',
  31. tomorrow_timetamp: '',
  32. showQrfhMode: false,
  33. order_id: '',
  34. order_check_sta: '',
  35. showSendFriendMsg: false,//送朋友弹窗
  36. goodsId : 0, //送朋友-当前商品在列表中的id
  37. showBtn: false, //是否显示右侧返回首页按钮
  38. isSelectNew : 0, //默认,
  39. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  40. callbackcount: 10, //返回数据的个数
  41. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  42. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  43. },
  44. onLoad: function (options) {
  45. var that = this;
  46. var host = getApp().globalData.servsers;
  47. var un_id = getApp().globalData.un_id;
  48. var id;
  49. if (options.isSelectNew == undefined) {
  50. id = that.data.isSelect;
  51. } else {
  52. id = options.isSelectNew;
  53. that.setData({
  54. isSelect: options.isSelectNew,
  55. showBtn: true
  56. })
  57. }
  58. wx.showLoading({
  59. title: '加载中,请稍候',
  60. icon: 'loading',
  61. mask: true,
  62. success: function () {
  63. }
  64. })
  65. //console.log(getApp().globalData.userInfo.nickName);
  66. //un_id = 'oovpNwvQGE0uUqpsQrbiVigaEFM0';
  67. },
  68. onShow: function (options) {
  69. var that = this;
  70. var pages = getCurrentPages();
  71. var currPage = pages[pages.length - 1]; //当前页面
  72. var prevPage = pages[pages.length - 2]; //上一个页面
  73. var that = this;
  74. var host = getApp().globalData.servsers;
  75. var un_id = getApp().globalData.un_id;
  76. var id = that.data.isSelect;
  77. that.setData({
  78. goosdList: [],
  79. goosdListnew : [],
  80. goodsListPage: [],//整体数据分页数据
  81. pageLen: 0,
  82. modalCont: '',
  83. order_number: '', //订单编号
  84. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  85. callbackcount: 10, //返回数据的个数
  86. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  87. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  88. })
  89. if (un_id != undefined && un_id != '' && un_id != null){
  90. if (id == 0) {
  91. //送出的礼物
  92. that.sendGiftData();
  93. } else {
  94. //收到的礼物
  95. that.receiveGiftData();
  96. }
  97. }
  98. },
  99. tabNav: function (options) {
  100. var that = this
  101. var id = options.currentTarget.dataset.id;
  102. var host = getApp().globalData.servsers;
  103. var un_id = getApp().globalData.un_id;
  104. that.setData({
  105. isSelect: id,
  106. goosdListnew: [],
  107. goodsList: [],
  108. goodsListPage: [],
  109. pageLen: 0,
  110. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  111. callbackcount: 10, //返回数据的个数
  112. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  113. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  114. })
  115. wx.showLoading({
  116. title: '加载中,请稍候',
  117. icon: 'loading',
  118. mask: true,
  119. success: function () {
  120. }
  121. })
  122. if (un_id != undefined && un_id != '' && un_id != null){
  123. if (id == 0) {
  124. //送出的礼物
  125. that.sendGiftData();
  126. } else {
  127. //收到的礼物
  128. that.receiveGiftData();
  129. }
  130. }
  131. },
  132. //送出的礼物
  133. sendGiftData:function(e){
  134. var that = this;
  135. var host = getApp().globalData.servsers;
  136. var un_id = getApp().globalData.un_id;
  137. //un_id = 'oovpNwlZEABfbvN5Fkku7rntNIXc';
  138. wx.request({
  139. url: host + "giftapi/findUserGiftListSend",
  140. data: {
  141. userId: un_id
  142. },
  143. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  144. header: {
  145. 'Accept': 'application/json'
  146. },
  147. success: function (res) {
  148. console.log("flag");
  149. console.log(res);
  150. if (res.data.flag || res.flag) {
  151. var dataLen = res.data.userGiftList.length;
  152. if (dataLen > 0) {
  153. //分页
  154. var goodsListPage = that.data.goodsListPage;
  155. var chunk = 10; //每10个分一组
  156. for (var i = 0, j = dataLen; i < j; i += chunk) {
  157. goodsListPage.push(res.data.userGiftList.slice(i, i + chunk));
  158. }
  159. console.log(goodsListPage[0]);
  160. console.log(goodsListPage.length);
  161. that.setData({
  162. goodsListPage: goodsListPage,
  163. pageLen: goodsListPage.length,
  164. goosdListnew: goodsListPage[0],
  165. showQrfhMode: false,
  166. order_number: '',
  167. searchPageNum: 0, //第一次加载,设置1
  168. searchSongList: [], //放置返回数据的数组,设为空
  169. isFromSearch: true, //第一次加载,设置true
  170. searchLoading: true, //把"上拉加载"的变量设为true,显示
  171. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  172. });
  173. if (goodsListPage[0].length < 10) {
  174. that.setData({
  175. searchLoading: false, //把"上拉加载"的变量设为true,显示
  176. })
  177. }
  178. }
  179. }
  180. //console.log(res.data.userGiftList);
  181. wx.hideLoading();
  182. if (res == null || res.data == null) {
  183. console.error('网络请求失败');
  184. return;
  185. }
  186. }
  187. })
  188. },
  189. //礼物盒
  190. receiveGiftData:function(e){
  191. var that = this;
  192. var host = getApp().globalData.servsers;
  193. var un_id = getApp().globalData.un_id;
  194. wx.request({
  195. url: host + "giftapi/findUserGiftList",
  196. data: {
  197. userId: un_id
  198. },
  199. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  200. header: {
  201. 'Accept': 'application/json'
  202. },
  203. success: function (res) {
  204. console.log("收礼物:");
  205. console.log(res);
  206. if (res.data.flag || res.flag) {
  207. var dataLen = res.data.userGiftList.length;
  208. if (dataLen > 0) {
  209. //分页
  210. var goodsListPage = that.data.goodsListPage;
  211. var chunk = 10; //每10个分一组
  212. for (var i = 0, j = dataLen; i < j; i += chunk) {
  213. goodsListPage.push(res.data.userGiftList.slice(i, i + chunk));
  214. }
  215. console.log(goodsListPage[0]);
  216. console.log(goodsListPage.length);
  217. that.setData({
  218. goodsListPage: goodsListPage,
  219. pageLen: goodsListPage.length,
  220. goosdListnew: goodsListPage[0],
  221. showQrfhMode: false,
  222. order_number: '',
  223. searchPageNum: 0, //第一次加载,设置1
  224. searchSongList: [], //放置返回数据的数组,设为空
  225. isFromSearch: true, //第一次加载,设置true
  226. searchLoading: true, //把"上拉加载"的变量设为true,显示
  227. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  228. });
  229. console.log(that.data.goosdListnew);
  230. if (goodsListPage[0].length < 10) {
  231. that.setData({
  232. searchLoading: false, //把"上拉加载"的变量设为true,显示
  233. })
  234. }
  235. }
  236. }
  237. wx.hideLoading();
  238. if (res == null || res.data == null) {
  239. console.error('网络请求失败');
  240. return;
  241. }
  242. }
  243. })
  244. },
  245. //加载更多
  246. fetchSearchList: function () {
  247. var that = this;
  248. var searchPageNum = that.data.searchPageNum;
  249. console.log("searchPageNum:" + searchPageNum);
  250. var goosdListnew = that.data.goosdListnew;
  251. var goodsListPage = that.data.goodsListPage;
  252. var pageLen = that.data.pageLen;
  253. if (searchPageNum < pageLen) {
  254. let dataList = [];
  255. var newData = goodsListPage[searchPageNum];
  256. that.data.isFromSearch ? dataList = newData : dataList = that.data.goosdListnew.concat(newData);
  257. that.setData({
  258. goosdListnew: dataList, //获取数据数组
  259. searchLoading: true //把"上拉加载"的变量设为false,显示
  260. });
  261. } else {
  262. that.setData({
  263. searchLoadingComplete: true, //把“没有数据”设为true,显示
  264. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  265. })
  266. }
  267. },
  268. //滚动到底部触发事件
  269. searchScrollLower: function () {
  270. var that = this;
  271. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  272. that.setData({
  273. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  274. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  275. });
  276. that.fetchSearchList();
  277. }
  278. },
  279. // sendBtn: function (e) {//送朋友 - 提示弹窗
  280. // var that = this;
  281. // var id = e.currentTarget.dataset.id;//i
  282. // that.setData({
  283. // goodsId: id,
  284. // showSendFriendMsg: true
  285. // })
  286. // },
  287. sureSendFriend: function (e) {//送朋友 - 确定
  288. var that = this;
  289. var un_id = getApp().globalData.un_id;
  290. var formId = e.detail;
  291. console.log("mineGiftList - formId1:" + formId.formId);
  292. var id = e.currentTarget.dataset.id;
  293. that.setData({
  294. goodsId: id,
  295. })
  296. var id = that.data.goodsId;
  297. console.log(that.data.goosdListnew[id]);
  298. var order_number = that.data.order_number;
  299. var imgSrc = that.data.goosdListnew[id].affList[0].logo;
  300. var goosdListnew = that.data.goosdListnew[id];
  301. var newCarts = JSON.stringify(that.data.goosdListnew[id]);
  302. newCarts = newCarts.replace(/&/g, "zss");
  303. setTimeout(function () {
  304. wx.navigateTo({
  305. url: '/pages/shareGift/shareGift?src=' + imgSrc + "&id=" + that.data.goosdListnew[id].affList[0].com_id + '&order_number=' + that.data.goosdListnew[id].order.order_number + '&order_userid=' + un_id + "&goodsNme=" + that.data.goosdListnew[id].affList[0].com_name + "&goodsNum=" + that.data.goosdListnew[id].affList[0].com_num + "&goodsList=" + newCarts + "&flag=0" + '&order_number_send=' + that.data.goosdListnew[id].orderNumberGift + "&formId=" + formId.formId,
  306. success: function (res) {
  307. that.receiveGiftData();
  308. }
  309. })
  310. }, 500)
  311. },
  312. cancelSendFriend: function (e) {//送朋友 - 取消
  313. var that = this;
  314. that.setData({
  315. goodsId: '',
  316. showSendFriendMsg: false
  317. })
  318. },
  319. //查看礼物详情
  320. giftInfor:function(e){
  321. var that = this;
  322. var order_num_o = e.currentTarget.dataset.onum;//原始单
  323. var orderNumber = e.currentTarget.dataset.nnum;//拆分单
  324. var orderNumberGift = e.currentTarget.dataset.snum;//分享单号
  325. var un_id = getApp().globalData.un_id;
  326. var listId = e.currentTarget.dataset.id;
  327. var order_userid = that.data.goosdListnew[listId].order.order_userid;//unionid
  328. var infor = JSON.stringify(that.data.goosdListnew[listId]);
  329. console.log(infor);
  330. var newCarts = infor.replace(/&/g, "zss");
  331. //newCarts = newCarts.replace(/?/g, "口");
  332. newCarts = infor.replace(/\?/g, " ");
  333. // newCarts = newCarts.replace(/[\x{1F600}-\x{1F64F}]/g, '');
  334. // newCarts = newCarts.replace(/[\x{1F300}-\x{1F5FF}]/g, '');
  335. // newCarts = newCarts.replace(/[\x{1F680}-\x{1F6FF}]/g, '');
  336. // newCarts = newCarts.replace(/[\x{2600}-\x{26FF}]/g, '');
  337. // newCarts = newCarts.replace(/[\x{2700}-\x{27BF}]/g, '');
  338. //newCarts = infor.replace(array('"', '\''), '');
  339. var sta = 0;
  340. wx.navigateTo({
  341. url: '/pages/eachGiftInfor/eachGiftInfor?from_user_id=' + un_id + '&order_num_o=' + order_num_o + '&orderNumber=' + orderNumber + '&orderNumberGift=' + orderNumberGift + '&sta=' + sta + '&listId=' + listId + '&infor=' + newCarts + '&order_userid=' + order_userid,
  342. })
  343. },
  344. giftSendInfor:function(e){
  345. var that = this;
  346. var un_id = getApp().globalData.un_id;
  347. var order_num_o = e.currentTarget.dataset.onum;//原始单
  348. var orderNumber = e.currentTarget.dataset.nnum;//拆分单
  349. var orderNumberGift = e.currentTarget.dataset.snum;//分享单号
  350. var listId = e.currentTarget.dataset.id;
  351. var order_userid = that.data.goosdListnew[listId].order.order_userid;//unionid
  352. var infor = JSON.stringify(that.data.goosdListnew[listId]);
  353. var newCarts = infor.replace(/&/g, "zss");
  354. var sta = 1;
  355. wx.navigateTo({
  356. url: '/pages/eachGiftInfor/eachGiftInfor?from_user_id=' + un_id + '&order_num_o=' + order_num_o + '&orderNumber=' + orderNumber + '&orderNumberGift=' + orderNumberGift + '&sta=' + sta + '&listId=' + listId + '&infor=' + newCarts + '&order_userid=' + order_userid,
  357. })
  358. },
  359. preview: function (e) {//定制预览
  360. var that = this;
  361. var id = e.currentTarget.dataset.id;
  362. var index = e.currentTarget.dataset.index;
  363. var img = that.data.goosdListnew[id].list_order_aff_data[index].img1;
  364. if (img) {
  365. wx.previewImage({
  366. urls: [that.data.goosdListnew[id].list_order_aff_data[index].img2, that.data.goosdListnew[id].list_order_aff_data[index].img1]
  367. })
  368. } else {
  369. wx.previewImage({
  370. urls: [that.data.goosdListnew[id].list_order_aff_data[index].img2]
  371. })
  372. }
  373. },
  374. cancelPreview: function (e) {//取消定制预览
  375. var that = this;
  376. that.setData({
  377. previewHidden: 'hidden'
  378. })
  379. },
  380. preview: function (e) {//定制预览
  381. var that = this;
  382. var id = e.currentTarget.dataset.id;
  383. var index = e.currentTarget.dataset.index;
  384. var img = that.data.goosdListnew[id].list_order_aff_data[index].img1;
  385. if (img) {
  386. wx.previewImage({
  387. urls: [that.data.goosdListnew[id].list_order_aff_data[index].img2, that.data.goosdListnew[id].list_order_aff_data[index].img1]
  388. })
  389. } else {
  390. wx.previewImage({
  391. urls: [that.data.goosdListnew[id].list_order_aff_data[index].img2]
  392. })
  393. }
  394. },
  395. //返回首页
  396. backIndex:function(e){
  397. wx.switchTab({
  398. url: '/pages/index/index',
  399. })
  400. }
  401. })
  402. var that;
  403. var Util = require('../../utils/util.js');