index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. import {
  2. getOrderDetail,
  3. orderAgain,
  4. orderTake,
  5. orderDel
  6. } from '../../api/order.js';
  7. import {
  8. openOrderRefundSubscribe
  9. } from '../../utils/SubscribeMessage.js';
  10. import {
  11. getUserInfo
  12. } from '../../api/user.js';
  13. const app = getApp();
  14. Page({
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. parameter: {
  20. 'navbar': '1',
  21. 'return': '1',
  22. 'title': '订单详情',
  23. 'color': true,
  24. 'class': '0'
  25. // 'class': '2' 顶部为灰色
  26. },
  27. order_id: '',
  28. evaluate: 0,
  29. cartInfo: [], //购物车产品
  30. orderInfo: {
  31. system_store: {}
  32. }, //订单详情
  33. system_store: {},
  34. isGoodsReturn: false, //是否为退款订单
  35. status: {}, //订单底部按钮状态
  36. isClose: false,
  37. payMode: [{
  38. name: "微信支付",
  39. icon: "icon-weixinzhifu",
  40. value: 'weixin',
  41. title: '微信快捷支付'
  42. },
  43. {
  44. name: "余额支付",
  45. icon: "icon-yuezhifu",
  46. value: 'yue',
  47. title: '可用余额:',
  48. number: 0
  49. },
  50. ],
  51. pay_close: false,
  52. pay_order_id: '',
  53. totalPrice: '0',
  54. generalActive: false,
  55. generalContent: {
  56. promoterNum: '',
  57. title: ''
  58. }
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad: function (options) {
  64. if (options.order_id) this.setData({
  65. order_id: options.order_id
  66. });
  67. if (options.isReturen) {
  68. this.setData({
  69. 'parameter.class': '2',
  70. isGoodsReturn: true
  71. });
  72. this.selectComponent('#navbar').setClass();
  73. }
  74. },
  75. openSubcribe: function (e) {
  76. let page = e.currentTarget.dataset.url;
  77. wx.showLoading({
  78. title: '正在加载',
  79. })
  80. openOrderRefundSubscribe().then(res => {
  81. wx.hideLoading();
  82. wx.navigateTo({
  83. url: page,
  84. });
  85. }).catch(() => {
  86. wx.hideLoading();
  87. });
  88. },
  89. /**
  90. * 事件回调
  91. */
  92. onChangeFun: function (e) {
  93. let opt = e.detail;
  94. let action = opt.action || null;
  95. let value = opt.value != undefined ? opt.value : null;
  96. (action && this[action]) && this[action](value);
  97. },
  98. /**
  99. * 拨打电话
  100. */
  101. makePhone: function () {
  102. wx.makePhoneCall({
  103. phoneNumber: this.data.system_store.phone
  104. })
  105. },
  106. /**
  107. * 打开地图
  108. */
  109. showMaoLocation: function () {
  110. if (!this.data.system_store.latitude || !this.data.system_store.longitude) return app.Tips({
  111. title: '缺少经纬度信息无法查看地图!'
  112. });
  113. wx.openLocation({
  114. latitude: parseFloat(this.data.system_store.latitude),
  115. longitude: parseFloat(this.data.system_store.longitude),
  116. scale: 8,
  117. name: this.data.system_store.name,
  118. address: this.data.system_store.address + this.data.system_store.detailed_address,
  119. success: function () {
  120. },
  121. });
  122. },
  123. /**
  124. * 关闭支付组件
  125. */
  126. pay_close: function () {
  127. this.setData({
  128. pay_close: false
  129. });
  130. },
  131. /**
  132. * 打开支付组件
  133. */
  134. pay_open: function () {
  135. this.setData({
  136. pay_close: true,
  137. pay_order_id: this.data.orderInfo.order_id,
  138. totalPrice: this.data.orderInfo.pay_price
  139. });
  140. },
  141. /**
  142. * 支付成功回调
  143. */
  144. pay_complete: function () {
  145. this.setData({
  146. pay_close: false,
  147. pay_order_id: ''
  148. });
  149. this.getOrderInfo();
  150. },
  151. /**
  152. * 支付失败回调
  153. */
  154. pay_fail: function () {
  155. this.setData({
  156. pay_close: false,
  157. pay_order_id: ''
  158. });
  159. },
  160. /**
  161. * 登录授权回调
  162. */
  163. onLoadFun: function () {
  164. this.getOrderInfo();
  165. this.getUserInfo();
  166. },
  167. /**
  168. * 获取用户信息
  169. */
  170. getUserInfo: function () {
  171. let that = this;
  172. getUserInfo().then(res => {
  173. that.data.payMode[1].number = res.data.now_money;
  174. that.setData({
  175. payMode: that.data.payMode
  176. });
  177. that.setUnread(res.data.notice)
  178. // app.globalData.unread = res.data.notice
  179. })
  180. },
  181. /**
  182. * 获取订单详细信息
  183. */
  184. getOrderInfo: function () {
  185. var that = this;
  186. wx.showLoading({
  187. title: "正在加载中"
  188. });
  189. getOrderDetail(this.data.order_id).then(res => {
  190. let _type = res.data._status._type;
  191. wx.hideLoading();
  192. that.setData({
  193. orderInfo: res.data,
  194. cartInfo: res.data.cartInfo,
  195. evaluate: _type == 3 ? 3 : 0,
  196. system_store: res.data.system_store,
  197. });
  198. if (this.data.orderInfo.refund_status != 0) {
  199. this.setData({
  200. 'parameter.class': '2',
  201. isGoodsReturn: true
  202. });
  203. this.selectComponent('#navbar').setClass();
  204. }
  205. that.getOrderStatus();
  206. }).catch(err => {
  207. wx.hideLoading();
  208. app.Tips({
  209. title: err
  210. }, '/pages/order_list/index');
  211. });
  212. },
  213. /**
  214. * 剪切订单号
  215. */
  216. copy: function () {
  217. var that = this;
  218. wx.setClipboardData({
  219. data: this.data.orderInfo.order_id
  220. });
  221. },
  222. /**
  223. * 打电话
  224. */
  225. goTel: function () {
  226. wx.makePhoneCall({
  227. phoneNumber: this.data.orderInfo.delivery_id
  228. })
  229. },
  230. /**
  231. * 设置底部按钮
  232. */
  233. getOrderStatus: function () {
  234. var orderInfo = this.data.orderInfo || {},
  235. _status = orderInfo._status || {
  236. _type: 0
  237. },
  238. status = {};
  239. var type = parseInt(_status._type),
  240. combination_id = orderInfo.combination_id || 0,
  241. delivery_type = orderInfo.delivery_type,
  242. seckill_id = orderInfo.seckill_id ? parseInt(orderInfo.seckill_id) : 0,
  243. bargain_id = orderInfo.bargain_id ? parseInt(orderInfo.bargain_id) : 0,
  244. combination_id = orderInfo.combination_id ? parseInt(orderInfo.combination_id) : 0;
  245. status = {
  246. type: type == 9 ? -9 : type,
  247. class_status: 0
  248. };
  249. if (type == 1 && combination_id > 0) status.class_status = 1; //查看拼团
  250. if (type == 2 && delivery_type == 'express') status.class_status = 2; //查看物流
  251. if (type == 2) status.class_status = 3; //确认收货
  252. if (type == 4 || type == 0) status.class_status = 4; //删除订单
  253. if (!seckill_id && !bargain_id && !combination_id && (type == 3 || type == 4)) status.class_status = 5; //再次购买
  254. this.setData({
  255. status: status
  256. });
  257. },
  258. /**
  259. * 去拼团详情
  260. */
  261. goJoinPink: function () {
  262. wx.navigateTo({
  263. url: '/pages/activity/goods_combination_status/index?id=' + this.data.orderInfo.pink_id,
  264. });
  265. },
  266. /**
  267. * 再此购买
  268. */
  269. goOrderConfirm: function () {
  270. var that = this;
  271. orderAgain(that.data.orderInfo.order_id).then(res => {
  272. return wx.navigateTo({
  273. url: '/pages/order_confirm/index?cartId=' + res.data.cateId
  274. });
  275. });
  276. },
  277. confirmOrder: function () {
  278. var that = this;
  279. wx.showModal({
  280. title: '确认收货',
  281. content: '为保障权益,请收到货确认无误后,再确认收货',
  282. success: function (res) {
  283. if (res.confirm) {
  284. wx.showLoading({
  285. mask: true,
  286. title: '加载中',
  287. })
  288. orderTake(that.data.order_id).then(res => {
  289. wx.hideLoading();
  290. const generalContent = "generalContent.promoterNum";
  291. const title = "generalContent.title";
  292. if (res.data.gain_integral != "0.00" && res.data.gain_coupon != "0.00") {
  293. that.setData({
  294. generalActive: true,
  295. [generalContent]: `恭喜您获得${res.data.gain_coupon}元优惠券以及${res.data.gain_integral}积分,购买商品时可抵现哦~`,
  296. [title]: '恭喜您获得优惠礼包'
  297. });
  298. return;
  299. } else if (res.data.gain_integral != "0.00") {
  300. that.setData({
  301. generalActive: true,
  302. [generalContent]: `恭喜您获得${res.data.gain_integral}积分,购买商品时可抵现哦~`,
  303. [title]: '赠送积分'
  304. });
  305. return;
  306. } else if (res.data.gain_coupon != "0.00") {
  307. that.setData({
  308. generalActive: true,
  309. [generalContent]: `恭喜您获得${res.data.gain_coupon}元优惠券,购买商品时可抵现哦~`,
  310. [title]: '恭喜您获得优惠券'
  311. });
  312. return;
  313. } else {
  314. return app.Tips({
  315. title: '操作成功',
  316. icon: 'success'
  317. }, function () {
  318. that.getOrderInfo();
  319. });
  320. }
  321. }).catch(err => {
  322. return app.Tips({
  323. title: err
  324. });
  325. })
  326. }
  327. }
  328. })
  329. },
  330. generalWindow: function () {
  331. this.setData({
  332. generalActive: false
  333. });
  334. this.getOrderInfo();
  335. },
  336. /**
  337. * 删除订单
  338. */
  339. delOrder: function () {
  340. var that = this;
  341. orderDel(this.data.order_id).then(res => {
  342. return app.Tips({
  343. title: '删除成功',
  344. icon: 'success'
  345. }, {
  346. tab: 3,
  347. url: 1
  348. });
  349. }).catch(err => {
  350. return app.Tips({
  351. title: err
  352. });
  353. });
  354. },
  355. /**
  356. * 生命周期函数--监听页面显示
  357. */
  358. onShow: function () {
  359. if (app.globalData.isLog && this.data.isClose) {
  360. this.getOrderInfo();
  361. }
  362. },
  363. /**
  364. * 生命周期函数--监听页面隐藏
  365. */
  366. onHide: function () {
  367. this.setData({
  368. isClose: true
  369. });
  370. },
  371. })