refund.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. reasonData: [],
  6. current: 1,
  7. imgPath: util.config.imgPath,
  8. datas: {},
  9. reason: '',
  10. showtext: false,
  11. mask: false,
  12. refundBack: '',
  13. refundpwd: '',
  14. orderid: '',
  15. status: '',
  16. groupId: '',
  17. reasonList: [],
  18. reasonIndex: 0,
  19. default: "请选择 >",
  20. // 控制sku
  21. showSku: false,
  22. refundShow: false,
  23. oid: "",
  24. orderInfo: {},
  25. codeShow: false,
  26. query: {
  27. orderid: '',
  28. otype: 0,
  29. presellStatus: 0
  30. },
  31. showGoodsRecom: false,
  32. index: 0,
  33. changeMeal_oid: "",
  34. type: 0,
  35. // 支付宝户号绑定内容
  36. AlipayNum: "",
  37. // 支付宝账号绑定内容
  38. accountNum: "",
  39. // 银行卡户名
  40. carName: "",
  41. // 银行名称
  42. bankName: "",
  43. // 银行卡号
  44. BankcardNo: "",
  45. // 银行开户行
  46. Bankofdeposit: "",
  47. password:''
  48. },
  49. isOK() {
  50. this.setData({
  51. codeShow: false
  52. })
  53. },
  54. // 二维码弹框
  55. showCode() {
  56. console.log("执行");
  57. this.setData({
  58. showSku: false,
  59. codeShow: true
  60. })
  61. },
  62. // 换场次中点击退款条例
  63. showFund() {
  64. this.setData({
  65. showSku: false,
  66. refundShow: true,
  67. type: this.data.orderInfo.refundRule
  68. })
  69. },
  70. changedeposit(e) {
  71. this.setData({
  72. Bankofdeposit: e.detail.value
  73. })
  74. },
  75. ChangeBankcardNo(e) {
  76. this.setData({
  77. BankcardNo: e.detail.value
  78. })
  79. },
  80. closeRefund() {
  81. this.setData({
  82. refundShow: false
  83. })
  84. },
  85. changeName(e) {
  86. this.setData({
  87. bankName: e.detail.value
  88. })
  89. },
  90. changebankName(e) {
  91. this.setData({
  92. carName: e.detail.value
  93. })
  94. },
  95. changeaccount(e) {
  96. this.setData({
  97. accountNum: e.detail.value
  98. })
  99. },
  100. changeAlipay(e) {
  101. // console.log(e.detail.value);
  102. this.setData({
  103. AlipayNum: e.detail.value
  104. })
  105. },
  106. showProp() {
  107. // if(this.data.orderInfo.refundRule==1){
  108. // this.data.type=this.data.orderInfo.refundRule
  109. // }
  110. // console.log(this.data.orderInfo);
  111. console.log(this.data.orderInfo.refundRule);
  112. this.setData({
  113. refundShow: true,
  114. type: this.data.orderInfo.refundRule
  115. // type:3
  116. })
  117. },
  118. // 关闭弹框
  119. closeSku() {
  120. this.setData({
  121. showSku: false,
  122. changeMeal_oid: ''
  123. });
  124. },
  125. // 点击换场次
  126. confirmChange(e) {
  127. console.log(this.data.orderInfo);
  128. let that = this,
  129. data = {};
  130. data.newAlipayId = e.detail ? e.detail : '';
  131. data.oid = that.data.changeMeal_oid;
  132. console.log(data);
  133. util.ajax({
  134. func: "v2/order/getRefundPriceByOid",
  135. data: {
  136. oid: that.data.info.subOrders[that.data.index].oid,
  137. }
  138. }, function (res) {
  139. data.priceInfo = that.data.orderInfo
  140. data.password = that.data.password
  141. console.log(data);
  142. if (res.code == 0) {
  143. util.ajax({
  144. func: "v2/order/change/audit",
  145. data,
  146. method: 'POST',
  147. load: false
  148. }, function (res) {
  149. if (res.code == 0) {
  150. util.showTips('已发起申请,请耐心等待宝大大审核~');
  151. that.setData({
  152. showSku: false,
  153. changeMeal_oid: ''
  154. })
  155. that.getData1();
  156. } else {
  157. console.log(data);
  158. util.showTips(res.reason);
  159. }
  160. })
  161. } else if (res.code == -10) {
  162. util.showTips('不满足更换场次要求,请联系宝大大处理');
  163. } else {
  164. console.log(data);
  165. util.showTips(res.reason);
  166. }
  167. })
  168. },
  169. // 退款换场次
  170. changeMeals(e) {
  171. console.log(this.data.info.subOrders[this.data.index]);
  172. let status = this.data.info.subOrders[this.data.index].changeStatus,
  173. oid = this.data.info.subOrders[this.data.index].oid;
  174. if (status == 1) {
  175. util.showTips('已提交申请,请耐心等待宝大大审核~');
  176. return false;
  177. } else {
  178. let that = this
  179. this.OrderInfo(oid)
  180. this.setData({
  181. showSku: true,
  182. changeMeal_oid: oid
  183. });
  184. console.log(this.data.changeMeal_oid);
  185. }
  186. },
  187. // 获取换场次信息
  188. getData1(val) {
  189. let that = this;
  190. let data = {};
  191. if (!util.isEmpty(that.data.orderid)) {
  192. data.orderid = that.data.orderid;
  193. }
  194. if (!util.isEmpty((val || that.data.presellStatus))) {
  195. data.presellStatus = val || that.data.presellStatus
  196. }
  197. if (!util.isEmpty(that.data.otype)) {
  198. data.otype = that.data.otype
  199. }
  200. console.log(data);
  201. util.ajax({
  202. func: "v2/order/detail",
  203. data,
  204. load: false
  205. }, function (res) {
  206. console.log(res);
  207. if (res.code == 0) {
  208. let datas = res.data;
  209. datas.timeContrast = util.timeContrast(datas.stopBuy);
  210. if (!util.isEmpty(datas.mailAddress)) {
  211. var info = datas.mailAddress.split(" ");
  212. datas.mail = {};
  213. datas.mail.name = info[0] || "";
  214. datas.mail.postMobile = info[1] || "";
  215. datas.mail.province = info[2] || "";
  216. datas.mail.address = datas.mail.province.replace("/", "") + info[3];
  217. }
  218. if (datas.comment) {
  219. datas.comment.tag = datas.comment.content.match(/#([^#]+)#/g) ? datas.comment.content.match(/#([^#]+)#/g).join("") : '';
  220. datas.comment.content = datas.comment.content.replace(/#([^#]+)#/g, "").replace(/<br\/>/g, '\n');
  221. if (datas.comment.additionalComment.content) {
  222. datas.comment.additionalComment.content = datas.comment.additionalComment.content.replace(/<br\/>/g, '\n')
  223. }
  224. }
  225. that.nps();
  226. if (datas.saleTime && datas.presellPaymentDeadline) {
  227. datas.startTime = util.formatDate(util.formatUnixtimestamp(datas.saleTime), 'MM月dd日 hh:mm', false);
  228. datas.endTime = util.formatDate(util.formatUnixtimestamp(datas.presellPaymentDeadline), 'MM月dd日 hh:mm', false);
  229. }
  230. let num = 0,
  231. length = (datas.groupinfo.discount && !util.isEmpty(datas.groupinfo.discount.users)) ? datas.groupinfo.discount.users.length : 0;
  232. if (length > 0) {
  233. datas.groupinfo.discount.users.forEach(el => {
  234. num = el.status == 4 ? num++ : num;
  235. if (el.status == 4) {
  236. num++;
  237. }
  238. that.setData({
  239. iconView: num == 0 ? false : true
  240. });
  241. });
  242. }
  243. that.setData({
  244. info: datas
  245. });
  246. // console.log(that.data.info.subOrders[that.data.index].changeStatus);
  247. that.getGoodsRecommend()
  248. if (datas.groupinfo.gstatus == 0 && datas.groupinfo.discount && datas.groupinfo.discount.status == 0 && datas.groupinfo.discount.deadline > 0) {
  249. that.data.info.groupinfo.discount.deadline = that.data.info.groupinfo.discount.deadline - new Date().getTime();
  250. that.updateTime();
  251. }
  252. } else
  253. util.showTips(res.reason);
  254. });
  255. },
  256. // 默认评价弹窗
  257. nps() {
  258. let that = this,
  259. newDate = util.getNowFormatDate('yyyy-MM-dd hh:mm:ss');
  260. let npsData = wx.getStorageSync("nps") || {
  261. num: 0,
  262. oldDate: newDate,
  263. timesSec: newDate
  264. };
  265. if (((npsData.num < util.config.npsNum) && util.datedifference(newDate, npsData.timesSec, true) > 3600) || util.isObjEmpty(npsData)) {
  266. util.ajax({
  267. func: "v2/order/reviews/one",
  268. load: false
  269. }, function (res) {
  270. if (res.code == 0 && !util.isObjEmpty(res.data)) {
  271. that.setData({
  272. npsOptons: res.data,
  273. npsStatus: true
  274. });
  275. npsData.num += 1;
  276. npsData.timesSec = newDate;
  277. wx.setStorageSync("nps", npsData)
  278. }
  279. })
  280. }
  281. },
  282. getGoodsRecommend() {
  283. let that = this;
  284. util.getGoodsRecommend(this.data.info.aid).then(res => {
  285. that.setData({
  286. showGoodsRecom: res
  287. })
  288. })
  289. },
  290. // 获取订单信息
  291. OrderInfo(oid) {
  292. console.log(this.data.oid);
  293. let that = this
  294. util.ajax({
  295. func: "v2/order/getRefundPriceByOid",
  296. data: {
  297. "oid": that.data.oid
  298. }
  299. }, function (res) {
  300. console.log(res);
  301. if (res.code == 0) {
  302. that.setData({
  303. orderInfo: res.data,
  304. changeMeal_oid: oid
  305. })
  306. } else if (res.code == -10) {
  307. util.showTips('不满足更换场次要求,请联系宝大大处理');
  308. that.setData({
  309. showSku: false,
  310. changeMeal_oid: oid
  311. });
  312. } else {
  313. util.showTips(res.reason)
  314. }
  315. })
  316. },
  317. onLoad(options) {
  318. console.log(options);
  319. this.setData({
  320. index: options.index,
  321. oid: options.oid,
  322. refundpwd: options.refundpwd,
  323. orderid: options.orderid,
  324. status: options.refundStatus,
  325. groupId: options.groupid || '',
  326. password:options.refundpwd
  327. });
  328. if (options.atype != "1") {
  329. this.OrderInfo()
  330. } else {
  331. this.setData({
  332. atype: options.atype
  333. })
  334. }
  335. let reasonData = [],
  336. current = 1;
  337. if (this.data.status == 15) {
  338. current = 4;
  339. }
  340. this.setData({
  341. current
  342. })
  343. this.getData();
  344. },
  345. onShow() {
  346. if (this.data.atype != "1") {
  347. this.OrderInfo()
  348. this.getData1()
  349. }
  350. },
  351. // 切换退款原因
  352. changeReason(e) {
  353. console.log(e.detail.value);
  354. console.log(this.data.reasonData[e.detail.value].type == 0);
  355. if (this.data.reasonData[e.detail.value].type == 0) {
  356. this.setData({
  357. showtext: true
  358. })
  359. } else {
  360. this.setData({
  361. showtext: false
  362. })
  363. }
  364. this.data.reasonIndex = e.detail.value
  365. this.setData({
  366. reasonIndex: this.data.reasonIndex,
  367. default: this.data.reasonList[this.data.reasonIndex]
  368. });
  369. },
  370. getData() {
  371. let that = this;
  372. let current = 0
  373. util.ajax({
  374. func: "v2/order/detail",
  375. data: {
  376. "orderid": that.data.orderid,
  377. "otype": 0,
  378. "password": that.data.refundpwd || "",
  379. }
  380. }, function (res) {
  381. if (res.code == 0) {
  382. let reasonData = [];
  383. if (res.data.atype == '1') { //电商
  384. reasonData = [{
  385. type: 5,
  386. txt: '不喜欢/不想要'
  387. },
  388. {
  389. type: 6,
  390. txt: '质量问题'
  391. },
  392. {
  393. type: 0,
  394. txt: '其他原因'
  395. }
  396. ];
  397. } else {
  398. if (that.data.status == 15) {
  399. reasonData = [{
  400. type: 4,
  401. txt: '候补退款'
  402. }], current = 4;
  403. } else {
  404. reasonData = [{
  405. type: 1,
  406. txt: '行程有变'
  407. },
  408. {
  409. type: 2,
  410. txt: '买多了/买错了'
  411. },
  412. {
  413. type: 3,
  414. txt: '孩子突发身体原因'
  415. },
  416. {
  417. type: 0,
  418. txt: '其他原因'
  419. }
  420. ];
  421. }
  422. }
  423. reasonData.forEach(item => {
  424. console.log(item);
  425. that.data.reasonList.push(item.txt)
  426. })
  427. if (reasonData.length == 1) {
  428. that.data.default = "候补退款"
  429. }
  430. that.setData({
  431. default: that.data.default,
  432. datas: res.data,
  433. reasonData,
  434. current: reasonData[0].type,
  435. reasonList: that.data.reasonList
  436. });
  437. }
  438. })
  439. },
  440. backBtn() {
  441. wx.redirectTo({
  442. url: '/pages/order/index/order?otype=2'
  443. })
  444. },
  445. confirm(e) {
  446. console.log(e);
  447. this.setData({
  448. reason: e.detail.value
  449. });
  450. },
  451. bindreason(e) {
  452. console.log(e);
  453. this.setData({
  454. current: e.currentTarget.dataset.type
  455. });
  456. },
  457. img() {
  458. this.data.datas.logo = '/images/noimg.png';
  459. this.setData({
  460. datas: this.data.datas
  461. });
  462. },
  463. refundRequest() {
  464. let that = this,
  465. reason = this.data.reason,
  466. current = this.data.current;
  467. console.log(current);
  468. let type = 0
  469. if (this.data.default == "行程有变") {
  470. type = 1
  471. } else if (this.data.default == "买多了/买错了") {
  472. type = 2
  473. } else if (this.data.default == "孩子突发身体原因") {
  474. type = 3
  475. } else if (this.data.default == "其他原因") {
  476. type = 0
  477. } else if (this.data.default == "候补退款") {
  478. type = 4
  479. } else if (this.data.default == "质量问题") {
  480. type = 6
  481. } else if (this.data.default == "不喜欢/不想要") {
  482. type = 5
  483. }
  484. if (this.data.default == "请选择 >" || type == -1) {
  485. util.showTips("请选择退款原因")
  486. return false
  487. }
  488. if (this.data.showtext == true && util.isEmpty(reason)) {
  489. util.showTips("请填写退款原因")
  490. return false
  491. }
  492. if (current == 0 && reason == '') {
  493. util.showTips('请输入退款原因。');
  494. return false;
  495. }
  496. if (this.data.dayBeforeStart <= 0) {
  497. util.showTips("活动已开始,无法提交退款申请")
  498. wx.navigateBack({
  499. delta: 1,
  500. })
  501. return
  502. }
  503. if (this.data.current == 1 && this.data.orderInfo.overdue == 1) {
  504. if (util.isEmpty(this.data.AlipayNum)) {
  505. util.showTips("支付宝户号不能为空")
  506. return
  507. }
  508. if (util.isEmpty(this.data.accountNum)) {
  509. util.showTips("支付宝账号不能为空")
  510. return
  511. }
  512. } else if (this.data.current == 2 && this.data.orderInfo.overdue == 1) {
  513. if (util.isEmpty(this.data.carName)) {
  514. util.showTips("卡户名不能为空")
  515. return
  516. }
  517. if (util.isEmpty(this.data.bankName)) {
  518. util.showTips("银行名称不能为空")
  519. return
  520. }
  521. if (util.isEmpty(this.data.BankcardNo)) {
  522. util.showTips("银行卡号不能为空")
  523. return
  524. }
  525. if (util.isEmpty(this.data.Bankofdeposit)) {
  526. util.showTips("开户行不能为空")
  527. return
  528. }
  529. }
  530. let desc = ""
  531. if (this.data.current == 1) {
  532. desc = "支付宝"
  533. } else if (this.data.current == 2) {
  534. desc = "银行卡"
  535. }
  536. console.log(that.data.orderInfo);
  537. util.ajax({
  538. func: "order/commit_refund",
  539. data: {
  540. "reasonType": type,
  541. "reason": reason,
  542. "orderid": that.data.orderid,
  543. "password": that.data.refundpwd || "",
  544. "type": '0',
  545. "priceInfo": that.data.orderInfo,
  546. "receiveAccount": that.data.orderInfo.overdue == 0 ? '' : (that.data.current == 1 ? "支付宝" + " " + that.data.AlipayNum + " " + that.data.accountNum : "银行卡" + " " + that.data.carName + " " + that.data.bankName + " " + that.data.BankcardNo + " " + that.data.Bankofdeposit)
  547. },
  548. method: "POST"
  549. }, function (res) {
  550. console.log(res);
  551. if (res.code == 0) {
  552. wx.setStorageSync('_REFUND_', 'REFUND');
  553. that.setData({
  554. refundBack: res.reason,
  555. mask: true
  556. })
  557. } else if (res.code == -10) {
  558. wx.showModal({
  559. title: "提示",
  560. content: res.reason,
  561. success(res) {
  562. if (res.confirm) {
  563. wx.navigateBack({
  564. delta: 1,
  565. })
  566. } else if (res.cancel) {
  567. console.log('用户点击取消')
  568. }
  569. }
  570. });
  571. } else if (res.code == -11) {
  572. wx.showModal({
  573. title: "提示",
  574. content: res.reason,
  575. showCancel: false,
  576. success: function (res) {
  577. if (res.confirm) {
  578. that.onLoad({
  579. index: that.data.index,
  580. oid: that.data.oid,
  581. refundpwd: that.data.refundpwd,
  582. orderid: that.data.orderid,
  583. status: that.data.refundStatus,
  584. groupId: that.data.groupid || ''
  585. })
  586. // that.onReady()
  587. }
  588. }
  589. });
  590. } else {
  591. wx.showModal({
  592. title: "提示",
  593. content: res.reason,
  594. showCancel: false,
  595. success: function (res) {
  596. if (res.confirm) {
  597. wx.navigateBack({
  598. delta: 1,
  599. })
  600. }
  601. }
  602. });
  603. }
  604. });
  605. },
  606. onReady() {
  607. }
  608. })