index.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. })
  148. },
  149. /**
  150. * 获取订单详细信息
  151. *
  152. */
  153. getOrderInfo:function(){
  154. var that=this;
  155. wx.showLoading({ title: "正在加载中" });
  156. getOrderDetail(this.data.order_id).then(res=>{
  157. let _type = res.data._status._type;
  158. wx.hideLoading();
  159. that.setData({
  160. orderInfo: res.data,
  161. cartInfo: res.data.cartInfo,
  162. evaluate: _type == 3 ? 3 : 0,
  163. system_store: res.data.system_store,
  164. });
  165. if (this.data.orderInfo.refund_status != 0 ){
  166. this.setData({ 'parameter.class': '2', isGoodsReturn: true });
  167. this.selectComponent('#navbar').setClass();
  168. }
  169. that.getOrderStatus();
  170. }).catch(err=>{
  171. wx.hideLoading();
  172. app.Tips({ title: err }, '/pages/order_list/index');
  173. });
  174. },
  175. /**
  176. *
  177. * 剪切订单号
  178. */
  179. copy:function(){
  180. var that=this;
  181. wx.setClipboardData({data: this.data.orderInfo.order_id});
  182. },
  183. /**
  184. * 打电话
  185. */
  186. goTel:function(){
  187. wx.makePhoneCall({
  188. phoneNumber: this.data.orderInfo.delivery_id
  189. })
  190. },
  191. /**
  192. * 设置底部按钮
  193. *
  194. */
  195. getOrderStatus:function(){
  196. var orderInfo = this.data.orderInfo || {}, _status = orderInfo._status || { _type:0},status={};
  197. var type = parseInt(_status._type), combination_id = orderInfo.combination_id || 0, delivery_type = orderInfo.delivery_type,
  198. seckill_id = orderInfo.seckill_id ? parseInt(orderInfo.seckill_id) : 0,
  199. bargain_id=orderInfo.bargain_id ? parseInt(orderInfo.bargain_id) : 0,
  200. combination_id = orderInfo.combination_id ? parseInt(orderInfo.combination_id) : 0;
  201. status={
  202. type: type == 9 ? -9 : type,
  203. class_status:0
  204. };
  205. if (type == 1 && combination_id >0) status.class_status = 1;//查看拼团
  206. if (type == 2 && delivery_type == 'express') status.class_status = 2;//查看物流
  207. if (type == 2) status.class_status = 3;//确认收货
  208. if (type == 4 || type == 0) status.class_status = 4;//删除订单
  209. if (!seckill_id && !bargain_id && !combination_id && (type == 3 || type == 4)) status.class_status = 5;//再次购买
  210. this.setData({ status: status});
  211. },
  212. /**
  213. * 去拼团详情
  214. *
  215. */
  216. goJoinPink:function(){
  217. wx.navigateTo({
  218. url: '/pages/activity/goods_combination_status/index?id=' + this.data.orderInfo.pink_id,
  219. });
  220. },
  221. /**
  222. * 再此购买
  223. *
  224. */
  225. goOrderConfirm:function(){
  226. var that=this;
  227. orderAgain( that.data.orderInfo.order_id ).then(res=>{
  228. return wx.navigateTo({ url: '/pages/order_confirm/index?cartId=' + res.data.cateId });
  229. });
  230. },
  231. confirmOrder:function(){
  232. var that=this;
  233. wx.showModal({
  234. title: '确认收货',
  235. content: '为保障权益,请收到货确认无误后,再确认收货',
  236. success: function (res) {
  237. if (res.confirm) {
  238. wx.showLoading({
  239. mask:true,
  240. title: '加载中',
  241. })
  242. orderTake(that.data.order_id).then(res=>{
  243. wx.hideLoading();
  244. const generalContent="generalContent.promoterNum";
  245. const title="generalContent.title";
  246. if(res.data.gain_integral!="0.00" && res.data.gain_coupon!="0.00"){
  247. that.setData({
  248. generalActive: true,
  249. [generalContent]: `恭喜您获得${res.data.gain_coupon}元优惠券以及${res.data.gain_integral}积分,购买商品时可抵现哦~`,
  250. [title]: '恭喜您获得优惠礼包'
  251. });
  252. return;
  253. }else if(res.data.gain_integral!="0.00"){
  254. that.setData({
  255. generalActive: true,
  256. [generalContent]: `恭喜您获得${res.data.gain_integral}积分,购买商品时可抵现哦~`,
  257. [title]: '赠送积分'
  258. });
  259. return;
  260. }else if(res.data.gain_coupon!="0.00"){
  261. that.setData({
  262. generalActive: true,
  263. [generalContent]: `恭喜您获得${res.data.gain_coupon}元优惠券,购买商品时可抵现哦~`,
  264. [title]: '恭喜您获得优惠券'
  265. });
  266. return;
  267. }else{
  268. return app.Tips({ title: '操作成功', icon: 'success' }, function () {
  269. that.getOrderInfo();
  270. });
  271. }
  272. }).catch(err=>{
  273. return app.Tips({title:err});
  274. })
  275. }
  276. }
  277. })
  278. },
  279. generalWindow:function(){
  280. this.setData({
  281. generalActive: false
  282. });
  283. this.getOrderInfo();
  284. },
  285. /**
  286. *
  287. * 删除订单
  288. */
  289. delOrder:function(){
  290. var that=this;
  291. orderDel(this.data.order_id).then(res=>{
  292. return app.Tips({ title: '删除成功', icon: 'success' }, { tab: 3, url: 1 });
  293. }).catch(err=>{
  294. return app.Tips({title:err});
  295. });
  296. },
  297. /**
  298. * 生命周期函数--监听页面显示
  299. */
  300. onShow: function () {
  301. if (app.globalData.isLog && this.data.isClose) {
  302. this.getOrderInfo();
  303. }
  304. },
  305. /**
  306. * 生命周期函数--监听页面隐藏
  307. */
  308. onHide: function () {
  309. this.setData({ isClose: true });
  310. },
  311. })