order-detail.js 15 KB

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