add-logistics.vue 16 KB

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