order.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. var util = require('../../utils/util.js');
  2. var app = getApp();
  3. var status = require('../../utils/index.js');
  4. function count_down(that, total_micro_second) {
  5. var second = Math.floor(total_micro_second / 1000);
  6. var days = second / 3600 / 24;
  7. var daysRound = Math.floor(days);
  8. var hours = second / 3600 - (24 * daysRound);
  9. var hoursRound = Math.floor(hours);
  10. var minutes = second / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
  11. var minutesRound = Math.floor(minutes);
  12. var seconds = second - (24 * 3600 * daysRound) - (3600 * hoursRound) - (60 * minutesRound);
  13. that.setData({
  14. endtime: {
  15. days: daysRound,
  16. hours: fill_zero_prefix(hoursRound),
  17. minutes: fill_zero_prefix(minutesRound),
  18. seconds: fill_zero_prefix(seconds),
  19. show_detail: 1
  20. }
  21. });
  22. if (total_micro_second <= 0) {
  23. that.setData({
  24. changeState: 1,
  25. endtime: {
  26. days: "00",
  27. hours: "00",
  28. minutes: "00",
  29. seconds: "00",
  30. }
  31. });
  32. return;
  33. }
  34. setTimeout(function() {
  35. total_micro_second -= 1000;
  36. count_down(that, total_micro_second);
  37. }, 1000)
  38. }
  39. // 位数不足补零
  40. function fill_zero_prefix(num) {
  41. return num < 10 ? "0" + num : num
  42. }
  43. Page({
  44. data: {
  45. endtime: {
  46. days: "00",
  47. hours: "00",
  48. minutes: "00",
  49. seconds: "00",
  50. },
  51. cancelOrderVisible: false,
  52. orderSkuResps: [],
  53. tablebar: 4,
  54. navState: 0,
  55. theme_type: '',
  56. loadover: false,
  57. pingtai_deal: 0,
  58. is_show: false,
  59. order: {},
  60. common_header_backgroundimage: '',
  61. isShowModal: false,
  62. userInfo: {},
  63. groupInfo: {
  64. group_name: '社区',
  65. owner_name: '团长'
  66. }
  67. },
  68. is_show_tip: '',
  69. timeOut: function() {
  70. console.log('计时完成')
  71. },
  72. options: '',
  73. onLoad: function(options) {
  74. var that = this;
  75. that.options = options;
  76. var userInfo = wx.getStorageSync('userInfo');
  77. userInfo && (userInfo.shareNickName = userInfo.nickName.length > 3 ? userInfo.nickName.substr(0, 3) + "..." : userInfo.nickName);
  78. status.setGroupInfo().then((groupInfo) => {
  79. that.setData({
  80. groupInfo
  81. })
  82. });
  83. util.check_login() ? this.setData({
  84. needAuth: false
  85. }) : this.setData({
  86. needAuth: true
  87. });
  88. that.setData({
  89. common_header_backgroundimage: app.globalData.common_header_backgroundimage,
  90. userInfo
  91. });
  92. var token = wx.getStorageSync('token');
  93. wx.hideShareMenu();
  94. wx.showLoading();
  95. var is_show_tip = options && options.is_show || 0;
  96. let isfail = options && options.isfail || '';
  97. this.is_show_tip = is_show_tip;
  98. if (is_show_tip != undefined && is_show_tip == 1) {
  99. //todo 弹出分享
  100. } else {
  101. wx.showLoading();
  102. }
  103. if (isfail != undefined && isfail == 1) {
  104. wx.showToast({
  105. title: '支付失败',
  106. icon: 'none'
  107. })
  108. }
  109. app.util.request({
  110. 'url': 'entry/wxapp/index',
  111. 'data': {
  112. controller: 'order.order_info',
  113. token: token,
  114. id: options.id
  115. },
  116. dataType: 'json',
  117. method: 'POST',
  118. success: function(res) {
  119. wx.hideLoading();
  120. if(res.data.code==0){
  121. if (is_show_tip != undefined && is_show_tip == 1 && res.data.data.order_info.type == 'integral') {
  122. wx.showToast({
  123. title: '兑换成功'
  124. })
  125. } else if (is_show_tip != undefined && is_show_tip == 1) {
  126. if (res.data.order_pay_after_share == 1) {
  127. let share_img = res.data.data.share_img;
  128. that.setData({
  129. share_img,
  130. isShowModal: true
  131. })
  132. } else {
  133. wx.showToast({
  134. title: '支付成功'
  135. })
  136. }
  137. }
  138. if (res.data.data.order_info.order_status_id == 3) {
  139. var seconds = (res.data.data.order_info.over_buy_time - res.data.data.order_info.cur_time) * 1000;
  140. if (seconds > 0) {
  141. count_down(that, seconds);
  142. } else {
  143. res.data.data.order_info.open_auto_delete == 1 && that.setData({
  144. changeState: 1
  145. })
  146. }
  147. }
  148. that.setData({
  149. order: res.data.data,
  150. pingtai_deal: res.data.pingtai_deal,
  151. order_refund: res.data.order_refund,
  152. loadover: true,
  153. is_show: 1,
  154. hide_lding: true
  155. })
  156. that.hide_lding();
  157. } else if(res.data.code==2){
  158. that.setData({ needAuth: true })
  159. }
  160. }
  161. })
  162. },
  163. /**
  164. * 授权成功回调
  165. */
  166. authSuccess: function() {
  167. this.onLoad(this.options);
  168. },
  169. reload_data: function() {
  170. var that = this;
  171. var token = wx.getStorageSync('token');
  172. app.util.request({
  173. 'url': 'entry/wxapp/index',
  174. 'data': {
  175. controller: 'order.order_info',
  176. 'token': token,
  177. //"id": 30
  178. "id": that.data.order.order_info.order_id
  179. },
  180. dataType: 'json',
  181. method: 'POST',
  182. success: function(res) {
  183. if (res.data.data.order_info.order_status_id == 3) {
  184. var seconds = (res.data.data.order_info.over_buy_time - res.data.data.order_info.cur_time) * 1000;
  185. if (seconds > 0) {
  186. count_down(that, seconds);
  187. } else {
  188. that.setData({
  189. changeState: 1
  190. })
  191. }
  192. }
  193. that.setData({
  194. order: res.data.data,
  195. pingtai_deal: res.data.pingtai_deal,
  196. order_refund: res.data.order_refund,
  197. loadover: true,
  198. is_show: 1,
  199. hide_lding: true
  200. })
  201. }
  202. })
  203. },
  204. receivOrder: function(event) {
  205. let id = event.currentTarget.dataset.type;
  206. var token = wx.getStorageSync('token');
  207. var that = this;
  208. var that = this;
  209. wx.showModal({
  210. title: '提示',
  211. content: '确认收到',
  212. confirmColor: '#F75451',
  213. success(res) {
  214. if (res.confirm) {
  215. app.util.request({
  216. 'url': 'entry/wxapp/index',
  217. 'data': {
  218. controller: 'order.receive_order',
  219. token: token,
  220. order_id: id
  221. },
  222. dataType: 'json',
  223. success: function(res) {
  224. if (res.data.code == 0) {
  225. wx.showToast({
  226. title: '收货成功',
  227. icon: 'success',
  228. duration: 1000
  229. })
  230. that.reload_data();
  231. }
  232. }
  233. })
  234. }
  235. }
  236. })
  237. },
  238. cancelSubmit: function(e) {
  239. var that = this;
  240. var from_id = e.detail.formId;
  241. var token = wx.getStorageSync('token');
  242. app.util.request({
  243. 'url': 'entry/wxapp/user',
  244. 'data': {
  245. controller: 'user.get_member_form_id',
  246. 'token': token,
  247. "from_id": from_id
  248. },
  249. dataType: 'json',
  250. success: function(res) {}
  251. })
  252. },
  253. payNowSubmit: function(e) {
  254. var that = this;
  255. var from_id = e.detail.formId;
  256. var token = wx.getStorageSync('token');
  257. app.util.request({
  258. 'url': 'entry/wxapp/user',
  259. 'data': {
  260. controller: 'user.get_member_form_id',
  261. 'token': token,
  262. "from_id": from_id
  263. },
  264. dataType: 'json',
  265. success: function(res) {}
  266. })
  267. },
  268. callDialog: function(e) {
  269. var order_id = e.currentTarget.dataset.type;
  270. var token = wx.getStorageSync('token');
  271. var that = this;
  272. wx.showModal({
  273. title: '取消支付',
  274. content: '好不容易挑出来,确定要取消吗?',
  275. confirmColor: '#F75451',
  276. success(res) {
  277. if (res.confirm) {
  278. app.util.request({
  279. 'url': 'entry/wxapp/index',
  280. 'data': {
  281. controller: 'order.cancel_order',
  282. token: token,
  283. order_id: order_id
  284. },
  285. dataType: 'json',
  286. success: function(res) {
  287. wx.showToast({
  288. title: '取消成功',
  289. icon: 'success',
  290. complete: function() {
  291. wx.redirectTo({
  292. url: '/lionfish_comshop/pages/order/index'
  293. })
  294. }
  295. })
  296. }
  297. })
  298. }
  299. }
  300. })
  301. },
  302. callTelphone: function(e) {
  303. var phone = e.currentTarget.dataset.phone;
  304. wx.makePhoneCall({
  305. phoneNumber: phone
  306. })
  307. },
  308. applyForService: function(e) {
  309. var order_id = e.currentTarget.dataset.type;
  310. var order_goods_id = e.currentTarget.dataset.order_goods_id;
  311. console.log(order_goods_id);
  312. var that = this;
  313. var token = wx.getStorageSync('token');
  314. wx.redirectTo({
  315. url: '/lionfish_comshop/pages/order/refund?id=' + order_id + '&order_goods_id=' + order_goods_id
  316. })
  317. },
  318. payNow: function(e) {
  319. var order_id = e.currentTarget.dataset.type;
  320. var that = this;
  321. var token = wx.getStorageSync('token');
  322. app.util.request({
  323. 'url': 'entry/wxapp/index',
  324. 'data': {
  325. controller: 'car.wxpay',
  326. 'token': token,
  327. "order_id": order_id
  328. },
  329. dataType: 'json',
  330. method: 'POST',
  331. success: function(res) {
  332. if (res.data.code == 0) {
  333. wx.requestPayment({
  334. "appId": res.data.appId,
  335. "timeStamp": res.data.timeStamp,
  336. "nonceStr": res.data.nonceStr,
  337. "package": res.data.package,
  338. "signType": res.data.signType,
  339. "paySign": res.data.paySign,
  340. 'success': function(wxres) {
  341. wx.redirectTo({
  342. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&is_show=1'
  343. })
  344. },
  345. 'fail': function(res) {
  346. console.log(res);
  347. }
  348. })
  349. } else if (res.data.code == 2) {
  350. wx.showToast({
  351. title: res.data.msg,
  352. icon: 'none'
  353. })
  354. }
  355. }
  356. })
  357. },
  358. hide_lding: function() {
  359. wx.hideLoading();
  360. this.setData({
  361. is_show: true
  362. })
  363. },
  364. call_mobile: function(event) {
  365. let mobile = event.currentTarget.dataset.mobile;
  366. wx.makePhoneCall({
  367. phoneNumber: mobile
  368. })
  369. },
  370. goComment: function(event) {
  371. let id = event.currentTarget.dataset.type;
  372. let order_goods_id = event.currentTarget.dataset.order_goods_id;
  373. var goods_id = event.currentTarget.dataset.goods_id;
  374. //lionfish_comshop/pages/order / evaluate
  375. var pages_all = getCurrentPages();
  376. if (pages_all.length > 3) {
  377. wx.redirectTo({
  378. url: '/lionfish_comshop/pages/order/evaluate?id=' + id + '&goods_id=' + goods_id + '&order_goods_id=' + order_goods_id
  379. })
  380. } else {
  381. wx.navigateTo({
  382. url: '/lionfish_comshop/pages/order/evaluate?id=' + id + '&goods_id=' + goods_id + '&order_goods_id=' + order_goods_id
  383. })
  384. }
  385. },
  386. goGoods: function(event) {
  387. let id = event.currentTarget.dataset.type;
  388. var pages_all = getCurrentPages();
  389. if (pages_all.length > 3) {
  390. wx.redirectTo({
  391. url: '/Snailfish_shop/pages/goods/index?id=' + id
  392. })
  393. } else {
  394. wx.navigateTo({
  395. url: '/Snailfish_shop/pages/goods/index?id=' + id
  396. })
  397. }
  398. },
  399. orderRefund: function(event) {
  400. let order_id = event.currentTarget.dataset.type;
  401. var pages_all = getCurrentPages();
  402. if (pages_all.length > 3) {
  403. wx.redirectTo({
  404. url: '/Snailfish_shop/pages/order/refund?id=' + order_id
  405. })
  406. } else {
  407. wx.navigateTo({
  408. url: '/Snailfish_shop/pages/order/refund?id=' + order_id
  409. })
  410. }
  411. },
  412. orderRefunddetail: function(event) {
  413. let order_id = event.currentTarget.dataset.type;
  414. var pages_all = getCurrentPages();
  415. if (pages_all.length > 3) {
  416. wx.redirectTo({
  417. url: '/Snailfish_shop/pages/order/refunddetail?id=' + order_id
  418. })
  419. } else {
  420. wx.navigateTo({
  421. url: '/Snailfish_shop/pages/order/refunddetail?id=' + order_id
  422. })
  423. }
  424. },
  425. gokefu: function(event) {
  426. let id = event.currentTarget.dataset.s_id;
  427. var goods = this.data.goods;
  428. var seller_info = this.data.seller_info;
  429. var pages_all = getCurrentPages();
  430. if (pages_all.length > 3) {
  431. wx.redirectTo({
  432. url: '/pages/im/index?id=' + id
  433. })
  434. } else {
  435. wx.navigateTo({
  436. url: '/pages/im/index?id=' + id
  437. })
  438. }
  439. },
  440. goLink: function(event) {
  441. let link = event.currentTarget.dataset.link;
  442. wx.reLaunch({
  443. url: link
  444. })
  445. },
  446. goLink2: function(event) {
  447. let link = event.currentTarget.dataset.link;
  448. var pages_all = getCurrentPages();
  449. if (pages_all.length > 3) {
  450. wx.redirectTo({
  451. url: link
  452. })
  453. } else {
  454. wx.navigateTo({
  455. url: link
  456. })
  457. }
  458. },
  459. navShow: function() {
  460. this.setData({
  461. navState: 1
  462. })
  463. },
  464. navHide: function() {
  465. this.setData({
  466. navState: 0
  467. })
  468. },
  469. orderPay: function(event) {
  470. var that = this;
  471. var token = wx.getStorageSync('token');
  472. let id = event.currentTarget.dataset.type;
  473. app.util.request({
  474. 'url': 'entry/wxapp/index',
  475. 'data': {
  476. controller: 'car.wxpay',
  477. 'token': token,
  478. "order_id": id
  479. },
  480. dataType: 'json',
  481. method: 'POST',
  482. success: function(res) {
  483. var is_pin = res.data.is_pin;
  484. wx.requestPayment({
  485. appId: res.data.appId,
  486. timeStamp: res.data.timeStamp,
  487. nonceStr: res.data.nonceStr,
  488. package: res.data.package,
  489. signType: res.data.signType,
  490. paySign: res.data.paySign,
  491. success: function(wxres) {
  492. if (is_pin == 0) {
  493. wx.redirectTo({
  494. url: '/Snailfish_shop/pages/order/order?id=' + id + '&is_show=1'
  495. })
  496. } else {
  497. wx.redirectTo({
  498. url: '/Snailfish_shop/pages/share/index?id=' + id
  499. })
  500. }
  501. },
  502. 'fail': function(res) {
  503. console.log(res);
  504. }
  505. })
  506. }
  507. })
  508. },
  509. closeModal: function() {
  510. this.setData({
  511. isShowModal: false
  512. })
  513. },
  514. onShareAppMessage: function(res) {
  515. var order_id = this.data.order.order_info.order_id;
  516. let goods_share_image = this.data.order.order_goods_list[0].goods_share_image;
  517. let share_img = this.data.share_img;
  518. if (order_id && this.is_show_tip == 1) {
  519. return {
  520. title: `@${this.data.order.order_info.ziti_name}${this.data.groupInfo.owner_name},我是${this.data.userInfo.shareNickName},刚在你这里下单啦!!!`,
  521. path: "lionfish_comshop/pages/order/shareOrderInfo?order_id=" + order_id,
  522. imageUrl: share_img ? share_img : goods_share_image
  523. };
  524. }
  525. },
  526. })