index.js 8.6 KB

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