order-detail.js 15 KB

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