add-logistics.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <template>
  2. <view class="container logistics" :style="{paddingBottom :isIphoneX ? (236+68)+'rpx' : '236rpx'}" v-if="isChange">
  3. <view class="logistics-list" v-for="(item,index) in logisticsList" :key="index">
  4. <view class="item-title">
  5. <view class="title-left">物流{{index+1}}</view>
  6. <view class="title-right" v-if="(index+1) > 1" @click="deleteLogistItemFn(item,index)">
  7. <text class="iconfont icon-shanchu" ></text>删除
  8. </view>
  9. </view>
  10. <view class="item-main">
  11. <view class="item-main-cell" @click.stop="pageNavigateTo(index)">
  12. <input class="input" type="text" v-model="item.label" placeholder="物流公司" disabled="true">
  13. <text class="iconfont icon-xiayibu"></text>
  14. </view>
  15. <view class="item-main-cell">
  16. <input class="input" type="text" v-model="item.number" placeholder="物流单号">
  17. </view>
  18. <view class="item-main-cell none" @click.stop="AddScanCode(item)" >
  19. <text class="iconfont icon-icon-test" ></text><text>扫码录入</text>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="logistics-btn">
  24. <view class="btn add-btn" @click="addListFn">添加物流</view>
  25. </view>
  26. <view class="logistics-btn-fiexd" :style="{paddingBottom :isIphoneX ? '68rpx' : '34rpx'}">
  27. <view class="btn-tips" @click.stop="showShowRemarksFn">
  28. <text class="iconfont icon-xiangxiajiantou" v-if="isShowRemarks"></text>
  29. <text class="iconfont icon-xiangshangjiantou" v-else></text>
  30. 添加备注
  31. </view>
  32. <view class="logistics-remarks" :class="specClass" v-show="isShowRemarks">
  33. <view class="label">拍照备注</view>
  34. <view class="remarks-photo clearfix">
  35. <view class="photo-item" v-for="(item, index) in photoLists" :key="index">
  36. <image :src="item" mode="aspectFill" @click.stop="previewImg(index)"></image>
  37. <text class="iconfont icon-iconfontguanbi" @click.stop="deletePhotoFn(index)"></text>
  38. </view>
  39. <view class="photo-item add" @click.stop="uploadPhotoFn" v-if="photoLists.length<10 || photoLists.length == 0">
  40. <text class="iconfont icon-jiahao"></text>
  41. </view>
  42. </view>
  43. <view class="label">文字备注</view>
  44. <view class="remarks-textarea">
  45. <textarea class="textarea" v-model="info.note" value="" placeholder="文字备注,200字以内" maxlength="200" @input="conInput"/>
  46. <text class="limit-text"><text class="red">{{min}}</text>/{{max}}</text>
  47. </view>
  48. <view class="remarks-tips">请备注快递单、发货现场和货物的照片,最多10张</view>
  49. </view>
  50. <view class="btn confim-btn" @click="confirmDeliverFn">确认发货</view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { mapState,mapMutations } from 'vuex'
  56. import authorize from '@/common/config/authorize.js'
  57. import { uploadFileImage } from "@/api/utils.js"
  58. var isPreviewImg;
  59. export default{
  60. data() {
  61. return{
  62. logisticsBatchId:'',
  63. isIphoneX:this.$store.state.isIphoneX,
  64. isChange:true,
  65. isShowRemarks:false,
  66. specClass:'',
  67. photoLists:[],
  68. checkLogicsIndex:0,
  69. selectID:0,
  70. addLogisticsType:'',
  71. info:{
  72. image:'',
  73. note:'',
  74. shopOrderId:''
  75. },//备注信息
  76. record:[],//子订单商品信息
  77. logisticsList:[{
  78. label:'',
  79. number:'',
  80. value:'',
  81. }],
  82. min:0,
  83. max:200
  84. }
  85. },
  86. watch: {
  87. logisticsList: {
  88. handler: function (el) {//监听对象的变换使用 function,箭头函数容易出现this指向不正确
  89. this.logisticsList = el
  90. },
  91. deep: true
  92. }
  93. },
  94. onLoad(option) {
  95. if(option.type == 'add'){
  96. this.addLogisticsType = option.type
  97. this.info.shopOrderId = option.shopOrderId;
  98. this.record = JSON.parse(option.data)
  99. }else{
  100. let queryData = JSON.parse(option.data);
  101. this.addLogisticsType = option.type
  102. this.logisticsBatchId = queryData.logisticsBatchId
  103. this.info.shopOrderId = option.shopOrderId;
  104. this.initGetLogisticsInfo()
  105. }
  106. },
  107. methods:{
  108. ...mapMutations(['login']),
  109. initGetLogisticsInfo(){
  110. this.ShopService.GetLogisticsInfo({ logisticsBatchId : this.logisticsBatchId, shopOrderId:this.info.shopOrderId }).then(response =>{
  111. const data = response.data.logisticsBatch
  112. if(data.remarkImages!=null){
  113. this.photoLists = data.remarkImages
  114. }else{
  115. this.photoLists =[]
  116. }
  117. this.info.note = data.remark
  118. }).catch(error =>{
  119. this.$util.msg(error.msg,2000);
  120. })
  121. },
  122. AddScanCode(item){
  123. let self = this;
  124. uni.scanCode({
  125. onlyFromCamera: true,
  126. success: function (res) {
  127. item.number= res.result
  128. self.ShopService.GetExpressInformation({number:res.result}).then(response =>{
  129. item.label= response.data.label
  130. item.value= response.data.value
  131. self.selectID = response.data.id
  132. }).catch(error =>{
  133. self.$util.msg(error.msg,2000);
  134. })
  135. }
  136. });
  137. },
  138. addListFn(){//添加
  139. this.isShowRemarks = false
  140. let obj ={name:'',number:'',value:''};
  141. this.logisticsList.push(obj)
  142. },
  143. deleteLogistItemFn(item,index){
  144. this.$util.modal('提示','确认删除物流信息吗?','确定','取消',true,() =>{
  145. this.logisticsList.splice(index, 1);
  146. })
  147. },
  148. pageNavigateTo(index){//选择物流公司
  149. this.isChange = false
  150. this.checkLogicsIndex = index
  151. this.$api.navigateTo(`/supplier/pages/deliver/logistics-list?selectID=${this.selectID}`)
  152. },
  153. showShowRemarksFn(){//显示发货备注
  154. this.isShowRemarks = !this.isShowRemarks
  155. if(this.isShowRemarks){
  156. this.specClass = 'show';
  157. }else{
  158. this.specClass = 'hide';
  159. }
  160. },
  161. uploadPhotoFn(){//添加发货备注图片
  162. uploadFileImage().then(res =>{
  163. this.photoLists.push(JSON.parse(res.data).data)
  164. })
  165. },
  166. deletePhotoFn(index){//删除发货备注图片
  167. this.photoLists.splice(index, 1);
  168. },
  169. confirmDeliverFn(){//确认发货
  170. switch(this.addLogisticsType){
  171. case 'add':
  172. this.isNewAddLogisticsFn()
  173. break;
  174. case 'reple':
  175. this.isRepleAddLogisticsFn()
  176. break;
  177. }
  178. },
  179. isRepleAddLogisticsFn(){//重新添加物流信息
  180. // 校验物流公司不能为空
  181. let isLogisticsLabel = false
  182. let isLogisticsNumber = false
  183. this.logisticsList.forEach(el =>{
  184. if(el.label == ''){
  185. isLogisticsLabel = true
  186. }
  187. if(el.number == ''){
  188. isLogisticsNumber = true
  189. }
  190. })
  191. if(isLogisticsLabel){
  192. this.$util.msg('请选择物流公司',2000);
  193. return
  194. }
  195. if(isLogisticsNumber){
  196. this.$util.msg('请输入物流单号',2000);
  197. return
  198. }
  199. //统一处理物流单号
  200. let logisticsArray = []
  201. let checkRepeat = false
  202. for (const el of this.logisticsList) {
  203. // 检查缓存中是否已经存在
  204. if (logisticsArray.find(c => c.number === el.number && c.number === el.number)) {
  205. // 已经存在
  206. checkRepeat = true
  207. }else{
  208. // 不存在就说明以前没遇到过,把它记录下来
  209. let logisticsObj = {
  210. number:el.number,
  211. logisticsCompanyName:el.label,
  212. logisticsCompanyCode:el.value
  213. }
  214. logisticsArray.push(logisticsObj)
  215. }
  216. }
  217. if(checkRepeat){
  218. this.$util.msg('物流单号重复',2000);
  219. return
  220. }
  221. //统一处理备注图片
  222. this.photoLists.forEach(el =>{
  223. this.info.image += el+'##'
  224. })
  225. let params = {
  226. logistics:logisticsArray,
  227. remarkImage:this.info.image,
  228. remark:this.info.note,
  229. logisticsBatchID:this.logisticsBatchId
  230. }
  231. this.ShopService.ShopAddLogisticsInfo({params:JSON.stringify(params)}).then(response =>{
  232. this.$util.msg('添加物流成功',2000,true,'success')
  233. setTimeout(()=>{
  234. this.$api.navigateTo(`/supplier/pages/deliver/deliver-record?shopOrderId=${this.info.shopOrderId}`)
  235. },2000)
  236. }).catch(error =>{
  237. this.$util.msg(error.msg,2000);
  238. })
  239. },
  240. isNewAddLogisticsFn(){//第一次添加发货物流信息
  241. // 校验物流公司不能为空
  242. let isLogisticsLabel = false
  243. let isLogisticsNumber = false
  244. this.logisticsList.forEach(el =>{
  245. if(el.label == ''){
  246. isLogisticsLabel = true
  247. }
  248. if(el.number == ''){
  249. isLogisticsNumber = true
  250. }
  251. })
  252. if(isLogisticsLabel){
  253. this.$util.msg('请选择物流公司',2000);
  254. return
  255. }
  256. if(isLogisticsNumber){
  257. this.$util.msg('请输入物流单号',2000);
  258. return
  259. }
  260. //统一处理物流单号
  261. let logisticsArray = []
  262. let checkRepeat = false
  263. for (const el of this.logisticsList) {
  264. // 检查缓存中是否已经存在
  265. if (logisticsArray.find(c => c.number === el.number && c.number === el.number)) {
  266. // 已经存在
  267. checkRepeat = true
  268. }else{
  269. // 不存在就说明以前没遇到过,把它记录下来
  270. let logisticsObj = {
  271. number:el.number,
  272. logisticsCompanyName:el.label,
  273. logisticsCompanyCode:el.value
  274. }
  275. logisticsArray.push(logisticsObj)
  276. }
  277. }
  278. if(checkRepeat){
  279. this.$util.msg('物流单号重复',2000);
  280. return
  281. }
  282. //统一处理备注图片
  283. this.info.image = ''
  284. this.photoLists.forEach(el =>{
  285. this.info.image += el+'##'
  286. })
  287. let params = {
  288. logistics:logisticsArray,
  289. record:this.record,
  290. info:this.info
  291. }
  292. this.ShopService.ShopAddLogistics({params:JSON.stringify(params)}).then(response =>{
  293. this.$util.msg('发货成功',2000,true,'success')
  294. setTimeout(()=>{
  295. this.$api.redirectTo(`/supplier/pages/deliver/deliver-record?shopOrderId=${this.info.shopOrderId}`)
  296. },2000)
  297. }).catch(error =>{
  298. this.$util.msg(error.msg,2000);
  299. })
  300. },
  301. previewImg (index) {//顶部商品图片预览
  302. isPreviewImg = true
  303. let previewUrls = this.photoLists
  304. uni.previewImage({
  305. current: index, //图片索引
  306. urls: previewUrls, //必须是http图片,本地图片无效
  307. longPressActions:''
  308. })
  309. },
  310. conInput(e){//备注文字字数限制
  311. let value = e.detail.value;
  312. let len = parseInt(value.length);
  313. if (len > this.max) return;
  314. this.min = len;
  315. if(this.min == 200){
  316. this.$util.msg('您输入的字数已达上限',2000);
  317. }
  318. }
  319. },
  320. onShow() {
  321. //处理选择物流公司
  322. let pages = getCurrentPages();
  323. let currPage = pages[pages.length-1];
  324. if(currPage.data.select =='select'){
  325. let SelectData = uni.getStorageSync('selectLogics')
  326. this.selectID = SelectData.id
  327. let setNewLogisticsList = this.logisticsList
  328. setNewLogisticsList.forEach((el,index,arr) =>{
  329. if(index == this.checkLogicsIndex ){
  330. arr[this.checkLogicsIndex] = Object.assign({},arr[this.checkLogicsIndex],SelectData)
  331. }
  332. })
  333. this.logisticsList = setNewLogisticsList
  334. }
  335. this.isChange = true
  336. }
  337. }
  338. </script>
  339. <style lang="scss">
  340. page {
  341. height: auto;
  342. background:#F7F7F7;
  343. }
  344. @keyframes showRemarks {
  345. 0% {opacity: 0;}
  346. 20% {opacity: 0.2;}
  347. 40% {opacity: 0.4;}
  348. 60% {opacity: 0.6;}
  349. 80% {opacity: 0.8;}
  350. 100% {opacity: 1;}
  351. }
  352. @keyframes hideRemarks {
  353. 0% {opacity: 1;}
  354. 20% {opacity: 0.8;}
  355. 40% {opacity: 0.6;}
  356. 60% {opacity: 0.4;}
  357. 80% {opacity: 0.2;}
  358. 100% {opacity: 0;}
  359. }
  360. .logistics{
  361. border-top: 1px solid #EBEBEB;
  362. }
  363. .logistics-list{
  364. width: 100%;
  365. height: auto;
  366. padding: 10rpx 0;
  367. background-color: #FFFFFF;
  368. margin-bottom: 24rpx;
  369. .item-title{
  370. width: 702rpx;
  371. height: 80rpx;
  372. padding: 0 24rpx;
  373. line-height: 80rpx;
  374. text-align: left;
  375. font-size: $font-size-28;
  376. color: $text-color;
  377. border-bottom: 1px solid #EBEBEB;
  378. .title-left{
  379. float: left;
  380. }
  381. .title-right{
  382. float: right;
  383. .icon-shanchu{
  384. font-size: $font-size-30;
  385. color: #FF2A2A;
  386. }
  387. }
  388. }
  389. .item-main{
  390. width: 702rpx;
  391. padding: 0 24rpx;
  392. .item-main-cell{
  393. width: 100%;
  394. height: 80rpx;
  395. line-height: 80rpx;
  396. border-bottom: 1px solid #EBEBEB;
  397. position: relative;
  398. &.none{
  399. border-bottom: none;
  400. text-align: center;
  401. font-size: $font-size-28;
  402. color: $color-system;
  403. }
  404. .icon-xiayibu{
  405. width: 40rpx;
  406. height: 80rpx;
  407. display: block;
  408. position: absolute;
  409. right: 0;
  410. top: 0;
  411. font-size: $font-size-32;
  412. color: $text-color;
  413. text-align: center;
  414. }
  415. .icon-icon-test{
  416. color: $color-system;
  417. font-size: $font-size-28;
  418. margin-right: 10rpx;
  419. }
  420. .input{
  421. width: 100%;
  422. height: 44rpx;
  423. line-height: 44rpx;
  424. padding: 18rpx 0;
  425. font-size: $font-size-28;
  426. color: $text-color;
  427. }
  428. }
  429. }
  430. }
  431. .logistics-btn{
  432. width: 702rpx;
  433. height: 88rpx;
  434. margin: 0 auto;
  435. .btn{
  436. width: 100%;
  437. height: 100%;
  438. background-color: #FFF;
  439. border-radius: 44rpx;
  440. border: 1px solid $color-system;
  441. line-height: 88rpx;
  442. text-align: center;
  443. color: $color-system;
  444. }
  445. }
  446. .logistics-btn-fiexd{
  447. width: 702rpx;
  448. padding: 0 24rpx;
  449. height:auto;
  450. position: fixed;
  451. bottom: 0;
  452. left: 0;
  453. background-color: #FFF;
  454. border-radius: 20rpx 20rpx 0 0;
  455. box-shadow:0px 3px 10px rgba(51, 51, 51,0.5);
  456. z-index: 999;
  457. .btn-tips{
  458. height: 80rpx;
  459. line-height: 80rpx;
  460. text-align: center;
  461. font-size: $font-size-28;
  462. color: #999999;
  463. }
  464. .confim-btn{
  465. width: 702rpx;
  466. height: 88rpx;
  467. background: $btn-confirm;
  468. line-height: 88rpx;
  469. text-align: center;
  470. color: #FFF;
  471. font-size: $font-size-28;
  472. border-radius: 44rpx;
  473. }
  474. .logistics-remarks{
  475. width: 100%;
  476. height: auto;
  477. &.show {
  478. animation: showRemarks 0.2s linear both;
  479. }
  480. &.hide {
  481. animation: hideRemarks 0.2s linear both;
  482. }
  483. .label{
  484. height: 44rpx;
  485. line-height: 44rpx;
  486. font-size: $font-size-28;
  487. color: $text-color;
  488. }
  489. .remarks-photo{
  490. width: 100%;
  491. height: auto;
  492. padding: 10rpx 0;
  493. .photo-item{
  494. display: inline-block;
  495. width: 112rpx;
  496. height: 112rpx;
  497. margin: 10rpx 0;
  498. margin-right: 25rpx;
  499. border-radius: 10rpx;
  500. border:1px solid #F5F5F5;
  501. position: relative;
  502. float: left;
  503. &.add{
  504. width: 112rpx;
  505. height: 112rpx;
  506. border-color: #FFC684;
  507. text-align: center;
  508. line-height: 112rpx;
  509. margin-right: 0rpx;
  510. .icon-jiahao{
  511. font-size: $font-size-44;
  512. color:#FFC684 ;
  513. font-weight: bold;
  514. }
  515. }
  516. .icon-iconfontguanbi{
  517. width: 24rpx;
  518. height: 24rpx;
  519. border-radius: 0 10rpx 0 0;
  520. display: block;
  521. position: absolute;
  522. right: 0;
  523. top: 0;
  524. background: rgba(51, 51, 51, 0.7);
  525. text-align: center;
  526. line-height: 24rpx;
  527. color: #FFF;
  528. font-size: $font-size-22;
  529. }
  530. image{
  531. width: 112rpx;
  532. height: 112rpx;
  533. border-radius: 10rpx;
  534. }
  535. }
  536. .photo-list{
  537. width: 100%;
  538. height: 116rpx;
  539. overflow: hidden;
  540. white-space: nowrap;
  541. display: flex;
  542. align-items: flex-start;
  543. }
  544. .scoll-wrapper{
  545. display:flex;
  546. align-items: flex-start;
  547. }
  548. }
  549. .remarks-textarea{
  550. width: 652rpx;
  551. height: 124rpx;
  552. padding:10rpx 24rpx 24rpx 24rpx;
  553. margin-top: 20rpx;
  554. background-color: #F5F5F5;
  555. border-radius: 10rpx;
  556. position: relative;
  557. .textarea{
  558. width: 100%;
  559. height: 100%;
  560. line-height: 36rpx;
  561. font-size: $font-size-24;
  562. color: $text-color;
  563. z-index: 1;
  564. }
  565. .limit-text{
  566. position: absolute;
  567. right: 20rpx;
  568. bottom: 0;
  569. line-height: 44rpx;
  570. font-size: $font-size-24;
  571. color: #D0D0D0;
  572. .red{
  573. color: $color-system;
  574. }
  575. }
  576. }
  577. .remarks-tips{
  578. width: 100%;
  579. line-height: 70rpx;
  580. font-size: $font-size-24;
  581. color: #999999;
  582. }
  583. }
  584. }
  585. </style>