index.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. import { getOrderDetail, orderAgain, orderTake, orderDel } from '../../api/order.js'
  2. import { openOrderRefundSubscribe } from '../../utils/SubscribeMessage.js'
  3. import { getUserInfo } from '../../api/user.js'
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. parameter: {
  11. navbar: '1',
  12. return: '1',
  13. title: '订单详情',
  14. color: true,
  15. class: '0'
  16. // 'class': '2' 顶部为灰色
  17. },
  18. order_id: '',
  19. evaluate: 0,
  20. cartInfo: [], //购物车产品
  21. orderInfo: {
  22. system_store: {}
  23. }, //订单详情
  24. system_store: {},
  25. isGoodsReturn: false, //是否为退款订单
  26. status: {}, //订单底部按钮状态
  27. isClose: false,
  28. payMode: [
  29. {
  30. name: '微信支付',
  31. icon: 'icon-weixinzhifu',
  32. value: 'weixin',
  33. title: '微信快捷支付'
  34. },
  35. {
  36. name: '余额支付',
  37. icon: 'icon-yuezhifu',
  38. value: 'yue',
  39. title: '可用余额:',
  40. number: 0
  41. }
  42. ],
  43. pay_close: false,
  44. pay_order_id: '',
  45. totalPrice: '0',
  46. generalActive: false,
  47. generalContent: {
  48. promoterNum: '',
  49. title: ''
  50. }
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad: function (options) {
  56. if (options.order_id)
  57. this.setData({
  58. order_id: options.order_id
  59. })
  60. if (options.isReturen) {
  61. this.setData({
  62. 'parameter.class': '2',
  63. isGoodsReturn: true
  64. })
  65. this.selectComponent('#navbar').setClass()
  66. }
  67. },
  68. openSubcribe: function (e) {
  69. let page = e.currentTarget.dataset.url
  70. wx.showLoading({
  71. title: '正在加载'
  72. })
  73. openOrderRefundSubscribe()
  74. .then(res => {
  75. wx.hideLoading()
  76. wx.navigateTo({
  77. url: page
  78. })
  79. })
  80. .catch(() => {
  81. wx.hideLoading()
  82. })
  83. },
  84. /**
  85. * 事件回调
  86. */
  87. onChangeFun: function (e) {
  88. let opt = e.detail
  89. let action = opt.action || null
  90. let value = opt.value != undefined ? opt.value : null
  91. action && this[action] && this[action](value)
  92. },
  93. /**
  94. * 拨打电话
  95. */
  96. makePhone: function () {
  97. wx.makePhoneCall({
  98. phoneNumber: this.data.system_store.phone
  99. })
  100. },
  101. /**
  102. * 打开地图
  103. */
  104. showMaoLocation: function () {
  105. if (!this.data.system_store.latitude || !this.data.system_store.longitude)
  106. return app.Tips({
  107. title: '缺少经纬度信息无法查看地图!'
  108. })
  109. wx.openLocation({
  110. latitude: parseFloat(this.data.system_store.latitude),
  111. longitude: parseFloat(this.data.system_store.longitude),
  112. scale: 8,
  113. name: this.data.system_store.name,
  114. address: this.data.system_store.address + this.data.system_store.detailed_address,
  115. success: function () {}
  116. })
  117. },
  118. /**
  119. * 关闭支付组件
  120. */
  121. pay_close: function () {
  122. this.setData({
  123. pay_close: false
  124. })
  125. },
  126. /**
  127. * 打开支付组件
  128. */
  129. pay_open: function () {
  130. this.setData({
  131. pay_close: true,
  132. pay_order_id: this.data.orderInfo.order_id,
  133. totalPrice: this.data.orderInfo.pay_price
  134. })
  135. },
  136. /**
  137. * 支付成功回调
  138. */
  139. pay_complete: function () {
  140. this.setData({
  141. pay_close: false,
  142. pay_order_id: ''
  143. })
  144. this.getOrderInfo()
  145. },
  146. /**
  147. * 支付失败回调
  148. */
  149. pay_fail: function () {
  150. this.setData({
  151. pay_close: false,
  152. pay_order_id: ''
  153. })
  154. },
  155. /**
  156. * 登录授权回调
  157. */
  158. onLoadFun: function () {
  159. this.getOrderInfo()
  160. this.getUserInfo()
  161. },
  162. /**
  163. * 获取用户信息
  164. */
  165. getUserInfo: function () {
  166. let that = this
  167. getUserInfo().then(res => {
  168. that.data.payMode[1].number = res.data.now_money
  169. that.setData({
  170. payMode: that.data.payMode
  171. })
  172. that.setUnread(res.data.notice)
  173. // app.globalData.unread = res.data.notice
  174. })
  175. },
  176. /**
  177. * 获取订单详细信息
  178. */
  179. getOrderInfo: function () {
  180. var that = this
  181. wx.showLoading({
  182. title: '正在加载中'
  183. })
  184. getOrderDetail(this.data.order_id)
  185. .then(res => {
  186. let _type = res.data._status._type
  187. wx.hideLoading()
  188. that.setData({
  189. orderInfo: res.data,
  190. cartInfo: res.data.cartInfo,
  191. evaluate: _type == 3 ? 3 : 0,
  192. system_store: res.data.system_store
  193. })
  194. if (this.data.orderInfo.refund_status != 0) {
  195. this.setData({
  196. 'parameter.class': '2',
  197. isGoodsReturn: true
  198. })
  199. this.selectComponent('#navbar').setClass()
  200. }
  201. that.getOrderStatus()
  202. })
  203. .catch(err => {
  204. wx.hideLoading()
  205. app.Tips(
  206. {
  207. title: err
  208. },
  209. '/pages/order_list/index'
  210. )
  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)
  289. .then(res => {
  290. wx.hideLoading()
  291. const generalContent = 'generalContent.promoterNum'
  292. const title = 'generalContent.title'
  293. if (res.data.gain_integral != '0.00' && res.data.gain_coupon != '0.00') {
  294. that.setData({
  295. generalActive: true,
  296. [generalContent]: `恭喜您获得${res.data.gain_coupon}元优惠券以及${res.data.gain_integral}积分,购买商品时可抵现哦~`,
  297. [title]: '恭喜您获得优惠礼包'
  298. })
  299. return
  300. } else if (res.data.gain_integral != '0.00') {
  301. that.setData({
  302. generalActive: true,
  303. [generalContent]: `恭喜您获得${res.data.gain_integral}积分,购买商品时可抵现哦~`,
  304. [title]: '赠送积分'
  305. })
  306. return
  307. } else if (res.data.gain_coupon != '0.00') {
  308. that.setData({
  309. generalActive: true,
  310. [generalContent]: `恭喜您获得${res.data.gain_coupon}元优惠券,购买商品时可抵现哦~`,
  311. [title]: '恭喜您获得优惠券'
  312. })
  313. return
  314. } else {
  315. return app.Tips(
  316. {
  317. title: '操作成功',
  318. icon: 'success'
  319. },
  320. function () {
  321. that.getOrderInfo()
  322. }
  323. )
  324. }
  325. })
  326. .catch(err => {
  327. return app.Tips({
  328. title: err
  329. })
  330. })
  331. }
  332. }
  333. })
  334. },
  335. generalWindow: function () {
  336. this.setData({
  337. generalActive: false
  338. })
  339. this.getOrderInfo()
  340. },
  341. /**
  342. * 删除订单
  343. */
  344. delOrder: function () {
  345. var that = this
  346. orderDel(this.data.order_id)
  347. .then(res => {
  348. return app.Tips(
  349. {
  350. title: '删除成功',
  351. icon: 'success'
  352. },
  353. {
  354. tab: 3,
  355. url: 1
  356. }
  357. )
  358. })
  359. .catch(err => {
  360. return app.Tips({
  361. title: err
  362. })
  363. })
  364. },
  365. /**
  366. * 生命周期函数--监听页面显示
  367. */
  368. onShow: function () {
  369. if (app.globalData.isLog && this.data.isClose) {
  370. this.getOrderInfo()
  371. }
  372. },
  373. /**
  374. * 生命周期函数--监听页面隐藏
  375. */
  376. onHide: function () {
  377. this.setData({
  378. isClose: true
  379. })
  380. }
  381. })