order-detail.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. // pages/DetailsOfRefund/DetailsOfRefund.js
  2. var http = require('../../utils/http.js');
  3. var util = require('../../utils/util.js');
  4. var plugin = requirePlugin("logisticsPlugin")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. time: 15 * 60 * 1000,
  11. timeData: {},
  12. statusObject: {
  13. 0: '待支付',
  14. 1: '待发货',
  15. 20: '订单已接单',
  16. 30: '订单待配送',
  17. 40: '待收货',
  18. 50: '订单取消待审核',
  19. 60: '订单已取消',
  20. 70: '订单已送达',
  21. 80: '订单已完成'
  22. },
  23. shopInfo:null,
  24. totalUsableScore:0,
  25. dvyType:'',//配送方式显示文字
  26. type:'',//配送方式 1快递 3配送
  27. dvyName:'',
  28. dvyFlowId:'',
  29. orderItemDtos: [],
  30. remarks: "",
  31. actualTotal: 0,
  32. canRefund:false,
  33. shopId:0,
  34. userAddrDto: null,
  35. orderNumber: "",
  36. createTime: "",
  37. status: 0,
  38. productTotalAmount: '',
  39. transfee: '',
  40. totalNum:0,
  41. reduceAmount: '',
  42. prodid: '',
  43. orderType: 0,
  44. shopName: '', //店铺名称
  45. canRefund: false, // 能否退款
  46. canAllRefund: false, // 能否整单退款
  47. isLastProd: false, //最后一款商品
  48. irrevocable: false, //不可撤销
  49. sum: [], //本单已申请单个退款的商品数组
  50. orderScore: 0, // 整单使用积分
  51. orderNumSend:'',
  52. estimatedTime: '',
  53. estimatedTimeStr: '',
  54. sendInfo:null,//骑手信息
  55. cancelReason:null,
  56. markers:[
  57. ],
  58. polyline:[],
  59. includePoints:[],//存放点位 显示完整图标
  60. timer:null,//定时器
  61. commSts:1,//评论状态: 0 未评价 1 已评价
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad(options) {
  67. this.setData({
  68. orderNumSend:options.orderNum
  69. })
  70. this.loadOrderDetail(options.orderNum);
  71. },
  72. /**
  73. * 加载订单数据
  74. */
  75. loadOrderDetail: function(orderNum) {
  76. var ths = this;
  77. wx.showLoading();
  78. //加载订单详情
  79. var params = {
  80. url: "/p/myOrder/orderDetail",
  81. method: "GET",
  82. data: {
  83. orderNumber: orderNum
  84. },
  85. callBack: function(res) {
  86. let img=''
  87. res.orderItemDtos.forEach(e=>{
  88. img=e.pic.split(',')
  89. e.pic=img[0]
  90. })
  91. var dvyType
  92. let markers = []
  93. let includePoints = []
  94. let polyline = []
  95. if(res.dvyType == 1){
  96. ths.getShopInfo(res.shopId).then(r=>{
  97. markers = [{
  98. // 商家标记
  99. id: 1,
  100. longitude:ths.data.shopInfo.lon,
  101. latitude: ths.data.shopInfo.lat,
  102. iconPath: '../../images/icon/shopPosition.png', // 商家图标
  103. width: "140rpx",
  104. height: '176rpx',
  105. rotate: 0, // 旋转角度(可根据方向动态调整)
  106. zIndex: 99, // 层级(骑手图标在最上层)
  107. customCallout: {
  108. anchorY: 0,
  109. anchorX: 0,
  110. display: 'ALWAYS',
  111. },
  112. },
  113. {
  114. // 收货地址
  115. id: 2,
  116. longitude:res.userAddrDto.longitude,
  117. latitude: res.userAddrDto.latitude,
  118. iconPath: '../../images/icon/head04.png', // 图标
  119. width: "80rpx",
  120. height: '80rpx',
  121. rotate: 0, // 旋转角度(可根据方向动态调整)
  122. zIndex: 3, // 层级(骑手图标在最上层)
  123. }]
  124. let orderMap = wx.createMapContext('orderMap')
  125. includePoints = [
  126. {
  127. longitude:ths.data.shopInfo.lon,
  128. latitude: ths.data.shopInfo.lat,
  129. },
  130. {
  131. longitude:res.userAddrDto.longitude,
  132. latitude: res.userAddrDto.latitude,
  133. }
  134. ]
  135. orderMap.includePoints({points:includePoints,padding:[50,50,50,50]})
  136. polyline= [{
  137. points:[ {
  138. longitude:ths.data.shopInfo.lon,
  139. latitude: ths.data.shopInfo.lat,
  140. },
  141. {
  142. longitude:res.userAddrDto.longitude,
  143. latitude: res.userAddrDto.latitude,
  144. }
  145. ],
  146. color: "#006CE8", // 折线颜色(支持十六进制、rgb)
  147. width: 4, // 折线宽度(单位:px)
  148. arrowLine: true // 是否带箭头(默认 false,支持微信基础库 2.13.0+)
  149. }
  150. ]
  151. ths.setData({
  152. polyline,
  153. includePoints,
  154. markers,
  155. })
  156. })
  157. dvyType = '运费(快递)'
  158. }else if(res.dvyType == 3){
  159. dvyType = '配送费(即时配送)'
  160. }else{
  161. dvyType = '自提'
  162. }
  163. // 15分钟倒计时
  164. let time = (new Date(res.createTime).getTime() + 1000*60*15)- new Date().getTime()
  165. ths.setData({
  166. time,
  167. totalUsableScore:res.totalUsableScore,
  168. dvyType:dvyType,
  169. dvyName: res.dvyName,
  170. dvyFlowId: res.dvyFlowId,
  171. type:res.dvyType,
  172. orderNumber: orderNum,
  173. actualTotal: res.actualTotal, //实际支付总额(商品总额+运费)
  174. canRefund:res.canRefund,
  175. userAddrDto: res.userAddrDto,
  176. remarks: res.remarks,
  177. orderItemDtos: res.orderItemDtos,
  178. createTime: res.createTime,
  179. status: res.status,
  180. shopId: res.shopId,
  181. // status: res.status,//海博订单状态
  182. productTotalAmount: res.total, //所有商品总额
  183. transfee: res.transfee, //运费
  184. totalNum:res.totalNum,
  185. reduceAmount: res.reduceAmount,
  186. orderType: res.orderType,
  187. shopName: res.shopName,
  188. canRefund: res.canRefund,
  189. canAllRefund: res.canAllRefund,
  190. orderScore: res.orderScore, // 整单使用积分
  191. estimatedTime: res.estimatedTime,
  192. estimatedTimeStr: res.estimatedTimeStr,
  193. cancelReason: res.cancelReason,
  194. commSts: res.commSts,
  195. });
  196. wx.hideLoading();
  197. if(res.dvyType == 3&&res.status==40){//配送中再获取骑手位置
  198. ths.startGetposition()
  199. }
  200. }
  201. };
  202. http.request(params);
  203. },
  204. // 获取店铺详情
  205. getShopInfo: function(shopId) {
  206. return new Promise((resolve,reject)=>{
  207. var ths = this;
  208. //热门搜索
  209. var params = {
  210. url: "/shop/headInfo",
  211. method: "GET",
  212. data: {
  213. shopId: shopId
  214. },
  215. callBack: function(res) {
  216. console.log(1111,res)
  217. ths.setData({
  218. shopInfo:res
  219. })
  220. resolve()
  221. },
  222. };
  223. http.request(params);
  224. })
  225. },
  226. /**
  227. *
  228. * 开始定时查询骑手位置
  229. */
  230. startGetposition(){
  231. let timer = setInterval(() => {//1分钟查询一次
  232. this.getSenderPosition()
  233. }, 60000);
  234. this.setData({
  235. timer
  236. })
  237. },
  238. /**
  239. * 获取骑手位置
  240. */
  241. getSenderPosition: function (e) {
  242. // wx.showLoading();
  243. var ths = this;
  244. var params = {
  245. url: "/p/location/info",
  246. method: "get",
  247. data: {
  248. orderNumber:this.data.orderNumber //'1978351838923198464'
  249. },
  250. callBack: res => {
  251. // wx.hideLoading();
  252. console.log(res);
  253. if(res.code == 200&&res.data){
  254. let markers = [
  255. {
  256. // 骑手标记
  257. id: 1,
  258. longitude:res.data.longitude,
  259. latitude: res.data.latitude,
  260. iconPath: '../../images/icon/sender.png', // 骑手图标
  261. width: "140rpx",
  262. height: '176rpx',
  263. rotate: 0, // 旋转角度(可根据方向动态调整)
  264. zIndex: 3, // 层级(骑手图标在最上层)
  265. customCallout: {
  266. anchorY: 0,
  267. anchorX: 0,
  268. display: 'ALWAYS',
  269. },
  270. },
  271. {
  272. // 收货地址
  273. id: 2,
  274. longitude:ths.data.userAddrDto.longitude,
  275. latitude: ths.data.userAddrDto.latitude,
  276. iconPath: '../../images/icon/head04.png', // 图标
  277. width: "80rpx",
  278. height: '80rpx',
  279. rotate: 0, // 旋转角度(可根据方向动态调整)
  280. zIndex: 3, // 层级(骑手图标在最上层)
  281. },
  282. ]
  283. let includePoints = [
  284. {
  285. longitude:res.data.longitude,
  286. latitude: res.data.latitude,
  287. },
  288. {
  289. longitude:ths.data.userAddrDto.longitude,
  290. latitude: ths.data.userAddrDto.latitude,
  291. }
  292. ]
  293. ths.setData({
  294. includePoints,
  295. markers,
  296. sendInfo:res.data
  297. })
  298. }
  299. }
  300. };
  301. http.request(params);
  302. },
  303. clickMarker(e){
  304. console.log(e.detail.markerId);
  305. if(e.detail.markerId == 1 && this.data.type == 1&&this.data.status>1&&this.data.actualTotal>0){
  306. this.getWaybillToken()
  307. }
  308. },
  309. getWaybillToken(){
  310. wx.showLoading()
  311. var ths = this;
  312. var params = {
  313. url: "/p/myOrder/getWaybillToken",
  314. method: "get",
  315. data: {
  316. orderNumber:this.data.orderNumber //'1978351838923198464'
  317. },
  318. callBack: res => {
  319. wx.hideLoading()
  320. console.log(res);
  321. if(res.errcode == 0&&res){
  322. const waybillToken = res.waybill_token;
  323. // 在此通过调用api来查询微信快递服务详情
  324. //必须用预览才能测试这个功能,无法在工具端模拟
  325. plugin.openWaybillTracking({
  326. waybillToken: waybillToken
  327. })
  328. }
  329. }
  330. };
  331. http.request(params);
  332. },
  333. //跳转商品详情页
  334. toProdPage: function(e) {
  335. var prodid = e.currentTarget.dataset.prodid;
  336. if(this.data.orderType==3){
  337. console.log('积分商品')
  338. wx.navigateTo({
  339. url: '/pages/convertProdDet/convertProdDet?prodid=' + prodid,
  340. })
  341. }else{
  342. wx.navigateTo({
  343. url: `/pages/prod/prod?prodid=${prodid}&shopid=${this.data.shopId}`,
  344. })
  345. }
  346. },
  347. /**
  348. * 付款
  349. */
  350. onPayAgain: function (e) {
  351. wx.showLoading({
  352. mask: true
  353. });
  354. var ths = this;
  355. var orderType = this.data.orderType;
  356. var params = {
  357. url: "/p/order/pay",
  358. method: "POST",
  359. data: {
  360. orderType: orderType ? orderType : 0,
  361. payType: 1,
  362. orderNumbers: this.data.orderNumber
  363. },
  364. callBack: res => {
  365. //console.log(res);
  366. wx.hideLoading();
  367. wx.requestPayment({
  368. timeStamp: res.timeStamp,
  369. nonceStr: res.nonceStr,
  370. package: res.package,
  371. signType: res.signType,
  372. paySign: res.paySign,
  373. success: function () {
  374. ths.loadOrderDetail(ths.data.orderNumber) //请求订单详情数据
  375. // wx.navigateTo({
  376. // url: '/pages/pay-result/pay-result?sts=1&orderNumbers=' + e.currentTarget.dataset.ordernum,
  377. // })
  378. },
  379. fail: function (err) {
  380. //console.log("支付失败");
  381. }
  382. })
  383. }
  384. };
  385. http.request(params);
  386. },
  387. //删除已完成||已取消的订单
  388. delOrderList: function (e) {
  389. var ths = this
  390. wx.showModal({
  391. title: '',
  392. content: '确定要删除此订单吗?',
  393. confirmColor: "#006CE8",
  394. success(res) {
  395. if (res.confirm) {
  396. var ordernum = e.currentTarget.dataset.ordernum;
  397. wx.showLoading();
  398. var params = {
  399. url: "/p/myOrder/" + ordernum,
  400. method: "DELETE",
  401. data: {},
  402. callBack: function (res) {
  403. wx.navigateTo({
  404. url:'/pages/orderList/orderList'
  405. })
  406. wx.hideLoading();
  407. }
  408. }
  409. http.request(params);
  410. } else if (res.cancel) {
  411. console.log('用户点击取消')
  412. }
  413. }
  414. })
  415. },
  416. /**
  417. * 去评价
  418. */
  419. goWrite(e){
  420. wx.navigateTo({
  421. url: '/pages/prodComm/prodComm?orderNumber='+this.data.orderNumber,
  422. })
  423. },
  424. /**
  425. * 取消订单
  426. */
  427. onCancelOrder: function (e) {
  428. var ths = this;
  429. wx.showModal({
  430. title: '',
  431. content: '要取消此订单?',
  432. confirmColor: "#006CE8",
  433. cancelText: '否',
  434. confirmText: '是',
  435. success(res) {
  436. if (res.confirm) {
  437. wx.showLoading({
  438. mask: true
  439. });
  440. var params = {
  441. url: "/p/myOrder/cancel/" + ths.data.orderNumber,
  442. method: "PUT",
  443. data: {},
  444. callBack: function (res) {
  445. //console.log(res);
  446. ths.loadOrderDetail(ths.data.orderNumber) //请求订单详情数据
  447. wx.hideLoading();
  448. }
  449. };
  450. http.request(params);
  451. } else if (res.cancel) {
  452. //console.log('用户点击取消')
  453. }
  454. }
  455. })
  456. },
  457. /**
  458. * 确认收货
  459. */
  460. onConfirmReceive: function (e) {
  461. var ths = this;
  462. wx.showModal({
  463. title: '',
  464. content: '我已收到货?',
  465. confirmColor: "#006CE8",
  466. success(res) {
  467. if (res.confirm) {
  468. wx.showLoading({
  469. mask: true
  470. });
  471. var params = {
  472. url: "/p/myOrder/receipt/" + ths.data.orderNumber,
  473. method: "PUT",
  474. data: {},
  475. callBack: function (res) {
  476. wx.hideLoading();
  477. ths.loadOrderDetail(ths.data.orderNumber) //请求订单详情数据
  478. }
  479. };
  480. http.request(params);
  481. } else if (res.cancel) {
  482. //console.log('用户点击取消')
  483. }
  484. }
  485. })
  486. },
  487. /**
  488. * 申请退款
  489. */
  490. applyRefund: function(e) {
  491. var item = {}
  492. item.orderNumber = this.data.orderNumber;
  493. item.actualTotal = this.data.actualTotal;
  494. item.transfee = this.data.transfee;
  495. item.status = this.data.status; //订单状态
  496. item.orderItemDtos = this.data.orderItemDtos;
  497. item.totalNum = this.data.totalNum
  498. item.orderScore = this.data.orderScore, // 整单积分
  499. item.userAddrDto = this.data.userAddrDto, // 用户信息
  500. //拿到存储在本地的订单项数据
  501. wx.setStorageSync("refundItem", item);
  502. wx.redirectTo({ //通过wx.redirectTo实现跳转(关闭当前页面,跳转到应用内某个页面)
  503. url: '/pages/applyRefund/applyRefund',
  504. })
  505. },
  506. callSender(){
  507. wx.makePhoneCall({
  508. phoneNumber: this.data.sendInfo.courierPhone//仅为示例,并非真实的电话号码
  509. })
  510. },
  511. // 一键复制事件
  512. copyBtn: function(e) {
  513. let data = e.currentTarget.dataset.value
  514. wx.setClipboardData({
  515. //准备复制的数据
  516. data,
  517. success: function(res) {
  518. wx.showToast({
  519. title: '复制成功',
  520. });
  521. }
  522. })
  523. },
  524. onChange(e) {
  525. this.setData({
  526. timeData: e.detail,
  527. });
  528. },
  529. /**
  530. * 生命周期函数--监听页面初次渲染完成
  531. */
  532. onReady() {
  533. },
  534. /**
  535. * 生命周期函数--监听页面显示
  536. */
  537. onShow() {
  538. },
  539. /**
  540. * 生命周期函数--监听页面隐藏
  541. */
  542. onHide() {
  543. },
  544. /**
  545. * 生命周期函数--监听页面卸载
  546. */
  547. onUnload() {
  548. clearInterval(this.data.timer)
  549. },
  550. /**
  551. * 页面相关事件处理函数--监听用户下拉动作
  552. */
  553. onPullDownRefresh() {
  554. },
  555. /**
  556. * 页面上拉触底事件的处理函数
  557. */
  558. onReachBottom() {
  559. },
  560. /**
  561. * 用户点击右上角分享
  562. */
  563. onShareAppMessage() {
  564. }
  565. })