order-detail.js 15 KB

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