batchSel.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <!-- 批量售后 批量选择商品-->
  2. <template>
  3. <view class="batchSel">
  4. <!-- 默认商品 start -->
  5. <view class="default">
  6. <view class="batch_sel_pre">
  7. <image :src="imgUrl+'order-detail/default_sel.png'" mode="" class="sel_btn"></image>
  8. <view class="default_goods_image" @click="goApplyBatch">
  9. <image :src="defaultGoods.productImage" mode="aspectFit"></image>
  10. </view>
  11. <view class="default_goods_des">
  12. <view class="default_goods_name" @click="goApplyBatch">{{defaultGoods.goodsName}}</view>
  13. <view class="default_goods_spec" @click="goApplyBatch" v-if="defaultGoods.specValues">{{defaultGoods.specValues}}</view>
  14. <view class="default_goods_bottom">
  15. <view class="default_goods_price" v-if="defaultGoods.moneyAmount && $getPartNumber(defaultGoods.moneyAmount,'int') && $getPartNumber(defaultGoods.moneyAmount,'decimal')">
  16. <text class="unit">¥</text>
  17. <text class="price_int">{{$getPartNumber(defaultGoods.moneyAmount,'int')}}</text>
  18. <text class="price_decimal">{{$getPartNumber(defaultGoods.moneyAmount,'decimal')}}</text>
  19. </view>
  20. <view class="default_goods_num">
  21. <view class="default_goods_number">
  22. <text @click="editNum('reduce','default',defaultGoods.productNum,defaultGoods.productId,defaultGoods.currNum)">-</text>
  23. <input type="text" v-model="defaultGoods.currNum" :disabled="isEdit ? true : false" @input="editNum('edit','default',defaultGoods.productNum,defaultGoods.productId,defaultGoods.currNum,$event)" class="pre_num"/>
  24. <text @click="editNum('add','default',defaultGoods.productNum,defaultGoods.productId,defaultGoods.currNum)">+</text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 默认商品 end -->
  32. <!-- 批量选择需要售后的商品 start -->
  33. <view class="batch_sel_list" v-if="batchGoodsList.length > 0">
  34. <view class="batch_sel_pre" v-for="(item,index) in batchGoodsList" :key="index">
  35. <image :src="item.sel ? imgUrl+'order-detail/sel.png' : imgUrl+'order-detail/no_sel.png' " mode="" class="sel_btn" @click="selGoods(item.productId)"></image>
  36. <view class="default_goods_image">
  37. <image :src="item.productImage" mode="aspectFit"></image>
  38. </view>
  39. <view class="default_goods_des">
  40. <view class="default_goods_name">{{item.goodsName}}</view>
  41. <view class="default_goods_spec" v-if="item.specValues">{{item.specValues}}</view>
  42. <view class="default_goods_bottom">
  43. <view class="default_goods_price" v-if="item.moneyAmount && $getPartNumber(item.moneyAmount,'int') && $getPartNumber(item.moneyAmount,'decimal')">
  44. <text class="unit">¥</text>
  45. <text class="price_int">{{$getPartNumber(item.moneyAmount,'int')}}</text>
  46. <text class="price_decimal">{{$getPartNumber(item.moneyAmount,'decimal')}}</text>
  47. </view>
  48. <view class="default_goods_num">
  49. <view class="default_goods_number">
  50. <text @click="editNum('reduce','batch',item.productNum,item.productId,item.currNum)">-</text>
  51. <input type="text" v-model="item.currNum" :disabled="isEdit ? true : false" @input="editNum('edit','batch',item.productNum,item.productId,item.currNum,$event)" class="pre_num"/>
  52. <text @click="editNum('add','batch',item.productNum,item.productId,item.currNum)">+</text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 批量选择需要售后的商品 end -->
  60. <view class="batch_bottom">
  61. <text class="submit_btn" @click="goApplyBatch">提交</text>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. mapState
  68. } from 'vuex';
  69. import recommendGoods from "@/components/recommend-goods.vue";
  70. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  71. import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue';
  72. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
  73. let startY = 0,
  74. moveY = 0,
  75. pageAtTop = true;
  76. export default {
  77. components: {
  78. recommendGoods,
  79. uniPopup,
  80. uniPopupMessage,
  81. uniPopupDialog
  82. },
  83. data() {
  84. return {
  85. imgUrl: getApp().globalData.imgUrl,
  86. coverTransform: 'translateY(0px)',
  87. coverTransition: '0s',
  88. moving: false,
  89. orderSn:'', //订单号
  90. orderProductId:'', //商品的订单id
  91. batchList:[], //订单列表
  92. defaultGoods:{}, //默认商品
  93. batchGoodsList:[], //同订单的其他商品
  94. batchSelListAmount:0, //批量选择的退款总金额
  95. isEdit:'true', //数量是否可编辑 默认为可编辑
  96. batchGoods:[], //当前页面数据的各种信息状态
  97. }
  98. },
  99. async onLoad(option) {
  100. this.orderSn = option.orderSn;
  101. this.orderProductId = option.orderProductId;
  102. this.isEdit = option.isEdit;
  103. this.batchGoods = JSON.parse(option.batchGoods);
  104. //订单id
  105. this.initData();
  106. this.getOrderDetail();
  107. },
  108. // #ifndef MP
  109. onNavigationBarButtonTap(e) {
  110. const index = e.index;
  111. if (index === 0) {
  112. this.navTo('/pages/set/set');
  113. } else if (index === 1) {
  114. // #ifdef APP-PLUS
  115. const pages = getCurrentPages();
  116. const page = pages[pages.length - 1];
  117. const currentWebview = page.$getAppWebview();
  118. currentWebview.hideTitleNViewButtonRedDot({
  119. index
  120. });
  121. // #endif
  122. uni.navigateTo({
  123. url: '/pages/notice/notice'
  124. })
  125. }
  126. },
  127. // #endif
  128. computed: {
  129. ...mapState(['hasLogin', 'userInfo', 'userCenterData'])
  130. },
  131. methods: {
  132. initData() {
  133. },
  134. /**
  135. * 统一跳转接口,拦截未登录路由
  136. * navigator标签现在默认没有转场动画,所以用view
  137. */
  138. navTo(url) {
  139. if (!this.hasLogin) {
  140. url = '/pages/public/login';
  141. }
  142. uni.navigateTo({
  143. url
  144. })
  145. },
  146. /**
  147. * 会员卡下拉和回弹
  148. * 1.关闭bounce避免ios端下拉冲突
  149. * 2.由于touchmove事件的缺陷(以前做小程序就遇到,比如20跳到40,h5反而好很多),下拉的时候会有掉帧的感觉
  150. * transition设置0.1秒延迟,让css来过渡这段空窗期
  151. * 3.回弹效果可修改曲线值来调整效果,推荐一个好用的bezier生成工具 http://cubic-bezier.com/
  152. */
  153. coverTouchstart(e) {
  154. if (pageAtTop === false) {
  155. return;
  156. }
  157. this.coverTransition = 'transform .1s linear';
  158. startY = e.touches[0].clientY;
  159. },
  160. coverTouchmove(e) {
  161. moveY = e.touches[0].clientY;
  162. let moveDistance = moveY - startY;
  163. if (moveDistance < 0) {
  164. this.moving = false;
  165. return;
  166. }
  167. this.moving = true;
  168. if (moveDistance >= 80 && moveDistance < 100) {
  169. moveDistance = 80;
  170. }
  171. if (moveDistance > 0 && moveDistance <= 80) {
  172. this.coverTransform = `translateY(${moveDistance}px)`;
  173. }
  174. },
  175. coverTouchend() {
  176. if (this.moving === false) {
  177. return;
  178. }
  179. this.moving = false;
  180. this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
  181. this.coverTransform = 'translateY(0px)';
  182. },
  183. //获取售后商品选择的商品数据
  184. getOrderDetail(){
  185. let param = {};
  186. param.url = 'v3/business/front/after/sale/apply/getOrderProductList';
  187. param.method = 'GET';
  188. param.data = {};
  189. param.data.orderSn = this.orderSn; //订单号
  190. param.data.orderProductId = this.orderProductId;
  191. this.$request(param).then(res => {
  192. if (res.state == 200) {
  193. let result = res.data;
  194. if(this.batchGoods && this.batchGoods.length > 0){
  195. this.batchList = result;
  196. this.batchList.map(item=>{
  197. this.batchGoods.map(item1=>{
  198. if(item.orderProductId == item1.orderProductId){
  199. item.currNum = item1.currNum;
  200. item.sel = item1.sel;
  201. }
  202. })
  203. })
  204. // 主商品
  205. this.defaultGoods = this.batchList[0];
  206. // 同订单的其他商品
  207. this.batchList.splice(0,1);
  208. this.batchGoodsList = this.batchList;
  209. }else{
  210. this.batchList = result;
  211. // 主商品
  212. this.defaultGoods = this.batchList[0];
  213. this.defaultGoods.currNum = this.batchList[0].productNum;
  214. this.defaultGoods.sel = true; //sel是否选中
  215. // 同订单的其他商品
  216. this.batchList.splice(0,1);
  217. this.batchGoodsList = this.batchList;
  218. this.batchGoodsList.map((item,index)=>{
  219. item.currNum = item.productNum;
  220. item.sel = false;
  221. })
  222. }
  223. } else {
  224. this.$api.msg(res.msg);
  225. }
  226. }).catch((e) => {
  227. //异常处理
  228. })
  229. },
  230. /**
  231. * 功能:商品数量的编辑
  232. * 参数:
  233. * type:加减编辑
  234. * sourseType:点击来源 :default主商品 batch:同订单的其他商品
  235. * productNum:该商品数量可编辑的最大值
  236. * productId: 货品id
  237. * currNum: 当前商品的数量值
  238. * e:事件对象 $event
  239. *
  240. * */
  241. editNum(type,sourseType,productNum,productId,currNum,e){
  242. let that = this;
  243. if(that.isEdit == 'true'){
  244. if(sourseType == 'default'){ //主商品
  245. if(type == 'add'){
  246. if(currNum < productNum){
  247. that.defaultGoods.currNum++;
  248. }else{
  249. uni.showToast({
  250. title:'不能超出最大限制',
  251. duration:500,
  252. icon:'none'
  253. })
  254. setTimeout(function(){
  255. that.defaultGoods.currNum = productNum;
  256. },700)
  257. }
  258. }else if(type == 'reduce'){
  259. if(that.defaultGoods.currNum <= 1){
  260. uni.showToast({
  261. title:'不能低于最小限制',
  262. duration:500,
  263. icon:'none'
  264. })
  265. setTimeout(function(){
  266. that.defaultGoods.currNum = 1;
  267. },700)
  268. }else{
  269. that.defaultGoods.currNum--;
  270. }
  271. }else if(type == 'edit'){
  272. that.defaultGoods.currNum = e.detail.value;
  273. if(that.defaultGoods.currNum <= 1){
  274. uni.showToast({
  275. title:'不能低于最小限制',
  276. duration:500,
  277. icon:'none'
  278. })
  279. setTimeout(function(){
  280. that.defaultGoods.currNum = 1;
  281. },700)
  282. }else if(that.defaultGoods.currNum >= productNum){
  283. uni.showToast({
  284. title:'不能超出最大限制',
  285. duration:500,
  286. icon:'none'
  287. })
  288. setTimeout(function(){
  289. that.defaultGoods.currNum = productNum;
  290. },700)
  291. }
  292. }
  293. that.$forceUpdate();
  294. }else if(sourseType == 'batch'){ //同订单的其他商品
  295. if(type == 'add'){
  296. if(currNum < productNum){
  297. that.batchGoodsList.map((item,index)=>{
  298. if(item.productId == productId){
  299. item.currNum++;
  300. }
  301. })
  302. }else{
  303. that.batchGoodsList.map((item,index)=>{
  304. if(item.productId == productId){
  305. uni.showToast({
  306. title:'不能超出最大限制',
  307. duration:500,
  308. icon:'none'
  309. })
  310. setTimeout(function(){
  311. item.currNum = productNum;
  312. },700)
  313. }
  314. })
  315. }
  316. }else if(type == 'reduce'){
  317. that.batchGoodsList.map((item,index)=>{
  318. if(item.productId == productId){
  319. if(item.currNum <= 1){
  320. uni.showToast({
  321. title:'不能低于最小限制',
  322. duration:500,
  323. icon:'none'
  324. })
  325. setTimeout(function(){
  326. item.currNum = 1;
  327. },700)
  328. }else{
  329. item.currNum--;
  330. }
  331. }
  332. })
  333. }else if(type == 'edit'){
  334. that.batchGoodsList.map((item,index)=>{
  335. if(item.productId == productId){
  336. item.currNum = e.detail.value;
  337. if(item.currNum <= 1){
  338. uni.showToast({
  339. title:'不能低于最小限制',
  340. duration:500,
  341. icon:'none'
  342. })
  343. setTimeout(function(){
  344. item.currNum = 1;
  345. },700)
  346. item.currNum = 1;
  347. }else if(item.currNum >= productNum){
  348. uni.showToast({
  349. title:'不能超出最大限制',
  350. duration:500,
  351. icon:'none'
  352. })
  353. setTimeout(function(){
  354. item.currNum = productNum;
  355. },700)
  356. }
  357. }
  358. })
  359. }
  360. that.$forceUpdate();
  361. }
  362. }else{
  363. uni.showToast({
  364. title:'不可修改',
  365. icon:'none',
  366. duration:700
  367. })
  368. }
  369. },
  370. //商品选中状态的修改
  371. selGoods(productId){
  372. let that = this;
  373. that.batchGoodsList.map((item,index)=>{
  374. if(item.productId == productId){
  375. item.sel = !item.sel;
  376. }
  377. })
  378. that.$forceUpdate(); //强制刷新
  379. },
  380. /**
  381. * 功能:不四舍不入,保留两位小数
  382. * toFixeds(num,decimal)
  383. * @param {Object} num 数字(价格)
  384. * @param {Object} decimal 保留的位数
  385. */
  386. toFixeds(num,decimal){
  387. num = num.toString();
  388. let index = num.indexOf('.');
  389. if(index != -1){
  390. num = num.substring(0,decimal + index + 1)
  391. }else{
  392. num = num.substring(0)
  393. }
  394. return parseFloat(num).toFixed(decimal)
  395. },
  396. //去申请页面
  397. goApplyBatch(){
  398. // 售后商品选择存入缓存,来实现页面切换时会显 start
  399. let batchListStorage = [];
  400. batchListStorage.push(this.defaultGoods);
  401. this.batchGoodsList.map(item=>{
  402. batchListStorage.push(item)
  403. })
  404. //改变数据结构 过滤出 货品id,选中状态,当前数量
  405. let batchGoods = [];
  406. batchListStorage.forEach(item=>{
  407. batchGoods.push({
  408. orderProductId : item.orderProductId,
  409. currNum:item.currNum,
  410. sel:item.sel
  411. })
  412. })
  413. // 售后商品选择存入缓存,来实现页面切换时会显 end
  414. let batchSelList = [];
  415. batchSelList.push(this.defaultGoods);
  416. this.batchGoodsList.map(item=>{
  417. if(item.sel){
  418. batchSelList.push(item)
  419. }
  420. })
  421. //多个商品
  422. let orderProductInfos = '';
  423. batchSelList.forEach(item=>{
  424. item.infopre = item.orderProductId + '-' + item.currNum
  425. })
  426. let Infos = [];
  427. batchSelList.forEach(item=>{
  428. Infos.push(item.infopre)
  429. })
  430. //获取计算售后退款信息 计算结果为此次最多可退金额
  431. let param = {};
  432. param.url = 'v3/business/front/after/sale/apply/countReturnMoney';
  433. param.method = 'GET';
  434. param.data = {};
  435. param.data.orderSn = this.orderSn;
  436. param.data.orderProductInfos = Infos.join(','); //退换的订单货品列表,格式为:id1-num1,id2-num2...num为空时表示此订单货品全部退换
  437. this.$request(param).then(res => {
  438. if (res.state == 200) {
  439. let result = res.data;
  440. let pages = getCurrentPages();
  441. let prevPage = pages[pages.length - 2]; //上一个页面
  442. prevPage.$vm.refundInfos = result;
  443. prevPage.$vm.tosource = '1';
  444. prevPage.$vm.batchSelList = batchSelList;
  445. prevPage.$vm.applyNum = result.number;
  446. prevPage.$vm.returnAmount = result.maxReturnMoney;
  447. prevPage.$vm.refundDetail.maxReturnMoney = result.maxReturnMoney;
  448. prevPage.$vm.batchGoods = batchGoods;
  449. uni.navigateBack({
  450. delta:1
  451. })
  452. } else {
  453. this.$api.msg(res.msg);
  454. }
  455. }).catch((e) => {
  456. //异常处理
  457. })
  458. }
  459. }
  460. }
  461. </script>
  462. <style lang="scss">
  463. page {
  464. background: $bg-color-split;
  465. }
  466. uni-page-body {
  467. display: flex;
  468. height: 100%;
  469. background: #FFFFFF;
  470. width: 750rpx;
  471. margin-left: calc((100vw - 750rpx) / 2)
  472. }
  473. .default{
  474. border-top: 20rpx solid #F5F5F5;
  475. display: flex;
  476. align-items: center;
  477. padding-top: 20rpx;
  478. box-sizing: border-box;
  479. border-bottom: 1rpx solid #F2F2F2;
  480. }
  481. .batch_sel_list{
  482. display: flex;
  483. flex-direction: column;
  484. padding-top: 20rpx;
  485. padding-bottom: 100rpx;
  486. box-sizing: border-box;
  487. background: #FFFFFF;
  488. }
  489. // 商品的公共样式 每一个商品的样式
  490. .batch_sel_pre{
  491. height: 200rpx;
  492. margin-bottom: 20rpx;
  493. padding: 0 20rpx;
  494. box-sizing: border-box;
  495. display: flex;
  496. align-items: center;
  497. .sel_btn{
  498. width: 32rpx;
  499. height: 32rpx;
  500. }
  501. .default_goods_image{
  502. width: 200rpx;
  503. height: 200rpx;
  504. background: #F3F3F3;
  505. border-radius: 14rpx;
  506. margin: 0 22rpx 0 20rpx;
  507. image{
  508. width: 200rpx;
  509. height: 200rpx;
  510. border-radius: 14rpx;
  511. }
  512. }
  513. .default_goods_des{
  514. display: flex;
  515. flex-direction: column;
  516. justify-content: space-between;
  517. height: 200rpx;
  518. .default_goods_name{
  519. font-size: 26rpx;
  520. font-family: PingFang SC;
  521. font-weight: 500;
  522. color: #343434;
  523. line-height: 39rpx;
  524. width: 435rpx;
  525. text-overflow: -o-ellipsis-lastline;
  526. overflow: hidden;
  527. text-overflow: ellipsis;
  528. display: -webkit-box;
  529. -webkit-line-clamp: 2;
  530. line-clamp: 2;
  531. -webkit-box-orient: vertical;
  532. }
  533. .default_goods_spec{
  534. font-size: 24rpx;
  535. font-family: PingFang SC;
  536. font-weight: 400;
  537. color: #9A9A9A;
  538. line-height: 24rpx;
  539. width: 435rpx;
  540. white-space: nowrap;
  541. text-overflow: ellipsis;
  542. overflow: hidden;
  543. word-break: break-all;
  544. margin: 29rpx 0 24rpx;
  545. }
  546. .default_goods_bottom{
  547. display: flex;
  548. align-items: center;
  549. justify-content: space-between;
  550. .default_goods_price{
  551. font-size: 24rpx;
  552. font-family: PingFang SC;
  553. font-weight: 500;
  554. color: #F30300;
  555. line-height: 30rpx;
  556. text:nth-child(2){
  557. font-size: 34rpx;
  558. }
  559. }
  560. .default_goods_num{
  561. display: flex;
  562. justify-content: flex-end;
  563. .default_goods_number{
  564. display: flex;
  565. align-items: center;
  566. text:nth-of-type(1){
  567. width: 51rpx;
  568. height: 50rpx;
  569. text-align: center;
  570. font-size: 24rpx;
  571. font-family: PingFang SC;
  572. font-weight: 400;
  573. color: #949494;
  574. line-height: 50rpx;
  575. border: 1rpx solid #F4F4F4;
  576. }
  577. .pre_num{
  578. font-size: 24Rpx;
  579. font-family: PingFang SC;
  580. font-weight: 500;
  581. color: #2E2E2E;
  582. width: 78rpx;
  583. height: 50rpx;
  584. line-height: 50rpx;
  585. border-top: 1rpx solid #F4F4F4;
  586. border-bottom: 1rpx solid #F4F4F4;
  587. text-align: center;
  588. }
  589. text:nth-of-type(2){
  590. width: 51rpx;
  591. height: 50rpx;
  592. text-align: center;
  593. font-size: 24rpx;
  594. font-family: PingFang SC;
  595. font-weight: 500;
  596. color: #2E2E2E;
  597. line-height: 50rpx;
  598. border: 1rpx solid #F4F4F4;
  599. }
  600. }
  601. }
  602. }
  603. }
  604. }
  605. .batch_bottom{
  606. // width: 100%;
  607. height: 100rpx;
  608. background: #FFFFFF;
  609. box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(154, 154, 154, 0.1);
  610. width: 100%;
  611. display: flex;
  612. justify-content: flex-end;
  613. align-items: center;
  614. position: fixed;
  615. bottom: 0;
  616. z-index: 10;
  617. padding-right: 20rpx;
  618. width: 750rpx;
  619. .submit_btn{
  620. width: 120rpx;
  621. height: 50rpx;
  622. background: linear-gradient(-90deg, #FC1E1C, #FF7A18);
  623. border-radius: 25rpx;
  624. font-size: 28rpx;
  625. font-family: PingFang SC;
  626. font-weight: 500;
  627. color: #FFFFFF;
  628. text-align: center;
  629. line-height: 50rpx;
  630. }
  631. }
  632. </style>