<template>
  <view class="wrap">
    <view style="height: 100px; background: #2f4dae"></view>
    <view class="content-wrap">
      <view class="title">
        <view class="title-label">{{$t('订单号')}}</view>
        <view>{{ detail.orderNo }}</view>
      </view>
      <view class="info-wrap">
        <view class="info-item" v-for="(item, index) in detail.orderItemVOList" :key="index">
          <view class="info-header">
            <view class="header-title">{{$t('序号')}}: {{ index + 1 }}</view>
          </view>
          <view class="info-content">
            <view>
              <view>
                <view class="label">{{$t('品名')}}: </view>
                <view class="content">{{ item.prodTitleZh }}</view>
              </view>
              <view>
                <view class="label">{{$t('状态')}}: </view>
                <view class="content">
                  <dict-tag v-if="item.warehouseInInfoVO && item.warehouseInInfoVO.diffType" :type="DICT_TYPE.ORDER_WAREHOUSE_IN_STATUS" :value="item.warehouseInInfoVO.diffType" class="red" :class="{green: item.warehouseInInfoVO.diffType === 4}"/>
                  <span v-else>{{ $t('未入仓') }}</span>
                  <span class="red" v-if="item.warehouseInInfoVO && item.warehouseInInfoVO.cartonsNumDiff">{{ item.warehouseInInfoVO.cartonsNumDiff }}{{$t('箱')}}</span>
                </view>
              </view>
            </view>
            <template v-if="!item.isWarehouseInAdd">
              <view>
                <view>
                  <view class="label">{{$t('品牌')}}: </view>
                  <view class="content">{{ [$t('无牌'), $t('有牌'), $t('中性')][item.brandType] }}</view>
                </view>
                <view>
                  <view class="label">{{$t('箱数')}}: </view>
                  <view class="content">{{ item.num }}{{$t('箱')}}</view>
                </view>
              </view>
              <view>
                <view>
                  <view class="label">{{$t('体积')}}: </view>
                  <view class="content">{{ item.volume }}m³</view>
                </view>
                <view>
                  <view class="label">{{$t('重量')}}: </view>
                  <view class="content">{{ item.weight }}Kg</view>
                </view>
              </view>
              <view>
                <view>
                  <view class="label">{{$t('数量')}}（{{$t('个')}}）: </view>
                  <view class="content">{{ item.quantity }}</view>
                </view>
              </view>
            </template>
            <template v-else>
              <view>{{$t('非填单货物')}}</view>
            </template>
          </view>
          <uni-card class="info-card" v-if="item.warehouseInInfoVO">
            <view class="info-content">
              <view>
                <view>
                  <view class="label">{{$t('品名')}}: </view>
                  <view class="content">{{ item.prodTitleZh }}</view>
                </view>
                <view>
                  <view class="label">{{$t('箱数')}}: </view>
                  <view class="content" @click="showWarehouseLogs(item)" style="color: #007aff;">{{ item.warehouseInInfoVO.cartonsNum }}{{$t('箱')}}</view>
                </view>
              </view>
              <view>
                <view>
                  <view class="label">{{$t('品牌')}}: </view>
<!--                  <view class="content">{{ [$t('无牌'), $t('有牌'), $t('中性')][item.brandType] }}</view>-->
<!--                  <view class="content">{{ item.brand ? brandRang.find(v => item.brand == v.id) ? brandRang.find(v => item.brand == v.id).titleZh : $t('无') : $t('无') }}</view>-->
                  <view class="content">{{ item.brandName }}</view>
                </view>
                <view>
                  <view class="label">{{$t('重量')}}: </view>
                  <view class="content">{{ item.warehouseInInfoVO.weight }}Kg</view>
                </view>
              </view>
              <view>
                <view>
                  <view class="label">{{$t('体积')}}: </view>
                  <view class="content">{{ item.warehouseInInfoVO.volume }}m³</view>
                </view>
                <view>
                <view class="label">{{$t('数量')}}（{{$t('个')}}）: </view>
                <view class="content" @click="showWarehouseLogs(item)" style="color: #007aff;">{{ item.warehouseInInfoVO.quantityAll }}</view>
              </view>
              </view>
              <view>
                <view>
                  <view class="label">{{$t('尺寸')}}: </view>
                  <view class="content" v-if="orderItemList">
                    {{
                      orderItemList.find(v => v.orderItemId === item.orderItemId)
                      && orderItemList.find(v => v.orderItemId === item.orderItemId).orderWarehouseInBackItemDoList[0]
                      && orderItemList.find(v => v.orderItemId === item.orderItemId).orderWarehouseInBackItemDoList[0].boxGauge
                    }}
                  </view>
                </view>
				<view>
				  <view class="label">{{$t('储位')}}: </view>
				  <view class="content" v-if="item.warehouseInInfoVO && item.warehouseInInfoVO.orderLocationMergeVOSet">
				    {{item.warehouseInInfoVO.orderLocationMergeVOSet.map(item => `${item.areaName||''}${item.locationName || ''}`).join(",")}}
				  </view>
          <text class="btn" @click="showWarehouseLogs(item)">修改</text>
				</view>

              </view>
            </view>
          </uni-card>
        </view>
      </view>
    </view>
    <view class="info-form-wrap">
      <view class="cu-form-group">
        <view class="title">{{$t('下单统计')}}</view>
        <view class="content">{{ parseInt(statistics.orderSum) }}{{$t('箱')}} {{ statistics.orderV }}m³ {{ statistics.orderW }}Kg {{$t('数量')}}({{$t('个')}}): {{ parseInt(statistics.orderQ) }}</view>
      </view>
      <view class="cu-form-group">
        <view class="title">{{$t('入仓统计')}}</view>
        <view class="content">{{ parseInt(statistics.leviteSum) }}{{$t('箱')}} {{ statistics.leviteV }}m³ {{ statistics.leviteW }}Kg {{$t('数量')}}({{$t('个')}}): {{ parseInt(statistics.leviteQ) }}</view>
      </view>

	  <view class="cu-form-group">
		  <view class="title">{{$t('储位')}}</view>
		  <!-- 退场入仓的时候从这里点进去选择储位,正常入仓和入仓修改这里只能查看，不能点开选择 -->
		  <view v-if="target=='warehouseAdjustment'" class="content" @tap="toLocation" style="flex:1;justify-content: flex-end;">
			  {{ getLocationName(orderLocationCreateReqVOList) }}
			  <uni-icons type="right" size="16"></uni-icons>
		  </view>
		  <view v-else class="content">
			  {{ getLocationName(orderLocationCreateReqVOList) }}
		  </view>
	  </view>
      <view class="cu-form-group">
        <view class="title">{{$t('收货人员')}}</view>
        <view class="content">{{ detail.consigneeVO ? detail.consigneeVO.name : '' }}</view>
      </view>
      <view class="cu-form-group" v-if="target == 'warehouseAdjustment'">
        <view class="title">入仓日期</view>
        <view class="content">
          <uni-datetime-picker ref="datetime" type="date" :clear-icon="false" v-model="arrivalDate" :border="false" />
          <uni-icons type="right" size="15"></uni-icons>
        </view>
      </view>
      <view class="cu-form-group" v-if="detail.parentOrderId">
        <view class="title">{{$t('标签箱号')}}</view>
      </view>
      <view class="xianghao" v-if="detail.parentOrderId">
        <view v-for="(item, index) in labelList" :key="index">
          <uni-easyinput v-model="item.start" :placeholder="$t('输入箱数')" :clearable="false"></uni-easyinput>
          <text>-</text>
          <uni-easyinput v-model="item.end" :placeholder="$t('输入箱数')" :clearable="false"></uni-easyinput>
          <view class="icon-wrap">
            <uni-icons type="plus" size="30" color="#007aff" @tap="plus"></uni-icons>
            <uni-icons v-if="index !== 0" type="minus" size="30" color="#e64340" @tap="minus(index)"></uni-icons>
          </view>
        </view>
      </view>
      <view class="cu-form-group" v-if="texuList.length">
        <view class="title">{{$t('特殊需求')}}</view>
      </view>
      <view class="texu">
        <view v-for="(item, index) in texuList" :key="index">
          <text>{{ $l(item, 'label') }}</text>
          <template>
            <text v-if="target !== 'warehousing'">{{ item.receivableMoney || 0 }}</text>
            <uni-easyinput v-model.number="item.receivableMoney" type="number" placeholder="" v-else />
          </template>
          <template>
            <text v-if="target !== 'warehousing'">
              {{ item.receivableMoneyCurrency ? currencyData[item.receivableMoneyCurrency].name : "" }}
            </text>
            <uni-data-select v-else v-model="item.receivableMoneyCurrency" :localdata="currenvyList"
                             :placeholder="$t('请选择')"></uni-data-select>
          </template>
        </view>
      </view>
      <view class="cu-form-group">
        <view class="title">{{$t('入仓影像')}}</view>
      </view>
      <view class="img-wrap">
        <uni-grid :column="4" :highlight="true" :show-border="false">
          <uni-grid-item v-for="(item, index) in imageList" :index="index" :key="index">
            <view class="grid-item-box" style="height: 100%;position: relative;">
				<!-- 'http://jd.static.jdshangmen.com/2022/09/30/6336cda9e4b08379ba0b0093.png' -->
<!--			  <image :src="iconpath" style="position: absolute;top:4px;right:4px;width:24px;height:24px;z-index:9" @tap="delimage(index)" mode="widthFix"></image>-->
              <image v-if="item.type === 'image'" :src="item.url" mode="scaleToFill" style="height: 100%" @tap="previewImage(item.url)" />
              <video v-else-if="item.type === 'video'" :id="`video_${index}`" style="width: 100%;height: 100%" :src="item.url" @play="playVideo(index)" @tap="playVideo(index)" @fullscreenchange="fullscreenchange"></video>
            </view>
          </uni-grid-item>
<!--          <uni-grid-item>-->
<!--            <view class="grid-item-box" style="height: 100%">-->
<!--              <view class="grid-item-box-add" @tap="chooseVideoImage">-->
<!--                <uni-icons type="plusempty" size="30" color="#eae8eb"></uni-icons>-->
<!--                &lt;!&ndash; <text>添加视频或图片</text> &ndash;&gt;-->
<!--              </view>-->
<!--            </view>-->
<!--          </uni-grid-item>-->
        </uni-grid>
      </view>
    </view>
    <view class="foot-btn">
      <button class="mini-btn" type="primary"  size="mini" @tap="showAddPopup">{{$t('转异')}}</button>
      <button class="mini-btn" style="color: #007aff" size="mini" @tap="save">{{$t('完成入仓')}}</button>
    </view>
    <view class="add-popup">
      <uni-popup ref="popup" background-color="#fff">
				<view class="popup-content">
          <view class="popup-title">{{ detail.orderNo }}{{$t('订单转异')}}</view>
          <view class="form-wrap">
            <view>
              <text>{{$t('异常类型')}}</text>
              <uni-data-checkbox v-model="manualExceptionType" multiple :localdata="manualExceptionTypeList" />
            </view>
            <view>
              <text>{{$t('详细信息')}}</text>
              <uni-easyinput type="textarea" autoHeight v-model="descZh" placeholder=""></uni-easyinput>
            </view>
            <view>
              <text>{{$t('附件')}}</text>
              <view class="img-wrap">
              <uni-grid :column="4" :highlight="true" :show-border="false">
                <uni-grid-item v-for="(item, index) in exceptionList" :index="index" :key="index">
				<view class="grid-item-box" style="height: 100%;position: relative;">
				 <image :src="iconpath" style="position: absolute;top:4px;right:4px;width:24px;height:24px;z-index:9" @tap="delexception(index)" mode="widthFix"></image>
                    <image :src="item.url" mode="scaleToFill" style="height: 100%" @tap="previewImage(item.url)" />
                  </view>
                </uni-grid-item>
                <uni-grid-item>
                  <view class="grid-item-box" style="height: 100%">
                    <view class="grid-item-box-add" @tap="chooseImages(false)">
                      <uni-icons type="plusempty" size="30" color="#eae8eb"></uni-icons>
                      <!-- <text>添加视频或图片</text> -->
                    </view>
                  </view>
                </uni-grid-item>
              </uni-grid>
            </view>
            </view>
          </view>
          <view class="popup-foot-btn">
            <button class="mini-btn" type="primary" size="mini" @tap="saveException">{{$t('提交')}}</button>
				    <button class="mini-btn" type="default" size="mini" @tap="cancel">{{$t('取消')}}</button>
          </view>
        </view>
			</uni-popup>
    </view>

	<!-- 查看入仓详情 -->
	<warehouse-detail locationModifiable ref="warehouseDetail" :orderId="+orderId" :orderItemId="showWarehouseInItemId" :warehouseId="warehouseId" />
  </view>
</template>

<script>
import { uniIcons } from '@dcloudio/uni-ui';
import {
  getOrderInfo,
  adjustLastWithStatus,
  finishWarehouseIn,
  getCurrencyList,
  warehouseAdjustArrived,
  getSpecialListByOrderId,
  getOrderWarehouseIn, listByOrderId,
  updateWarehouseInLocation, geLabelByOrderId,
} from './api'
import { updateImg } from '@/api/system'
import store from '@/store/store'
import * as types from '@/store/mutations-types.js'
import { title } from 'process';
import iconpath from '../../static/images/close.png'
import {warehousePictureCreate, warehousePictureDelete, warehousePictureList} from "@/pages/transferWarehouseOut/api"
import dayjs from "dayjs"
import warehouseDetail from '../tally/warehouseDetail.vue'
export default {
  components: { uniIcons, warehouseDetail },
  data() {
    return {
      orderId: '',
      target: '', // warehouseAdjustment调仓；warehousing 入仓
      detail: {},
	  iconpath:iconpath,
      arrivalDate: '',
      imageList: [],
      videoContext: null,
      orderLocationCreateReqVOList: [],
      statistics: {},
      texuList: [],
      currenvyList: [],
      manualExceptionType: '',
      manualExceptionTypeList: [],
      descZh: '',
      exceptionList: [],
      labelList: [{start: 1, end: ''}],
	  currencyData: [],
	  orderItemList:[],
	  adjust:{},
	  showWarehouseInItemId: null, // 查询入仓详情的商品ID
    }
  },

  created() {
    // this.detail = JSON.parse(uni.getStorageSync('WarehouseWaitInDetail'))
    this.imageList = []
  },
  onLoad: function(option) {
	  uni.setNavigationBarTitle({
	  	title:this.$t('确认信息')
	  })
    if ('orderId' in option) {
      this.orderId = option.orderId;
	  getCurrencyList().then(v => {
		 this.currenvyList = v.map(item => Object.assign(item, { text: this.isChinese ? item.titleZh : item.titleEn, value: item.id }))
	  })
      getOrderInfo(this.orderId).then(data => {
        this.detail = data
        this.getStatistics()
      })
	  adjustLastWithStatus(this.orderId,0).then(data => this.adjust = data||[])
      getOrderWarehouseIn(this.orderId).then(data => this.orderItemList = data ? data.reverse() : [])
      listByOrderId({ orderId: this.orderId }).then(data => this.orderLocationCreateReqVOList = data.map(v => Object.assign({}, v, { code: v.locationName || v.areaName || '' })))
    }
    if ('target' in option) {
      this.target = option.target
    }
    const list = this.getDictDatas(this.DICT_TYPE.ORDER_SPECIAL_NEEDS)
    getSpecialListByOrderId({ orderId: this.orderId }).then(data => {
      this.texuList = data.map(v => {
        const t = list.find(item => v.advanceType === item.value)
        return { id: v.id, label: t.label , labelEn: t.labelEn, receivableMoneyCurrency: v.transCurrency, receivableMoney: v.transFee||0 }
      })
    })
    if(this.$lang.locale=='zh-Hans'){
		this.manualExceptionTypeList = this.getDictDatas(this.DICT_TYPE.MANUAL_EXCEPTION_TYPE).map(v => ({ ...v, text: v.label }))
	}else{
		this.manualExceptionTypeList = this.getDictDatas(this.DICT_TYPE.MANUAL_EXCEPTION_TYPE).map(v => ({ ...v, text: v.labelEn }))
	}

    // if ('returnLoadId' in option) {
    //   this.returnLoadId = option.returnLoadId;
    // }

    this.getWarehousePictureList()
  },
  methods: {
	// 根据入仓记录修改储位，供储位选择页面回调用
	updateWarehouseInLocation(locationList, extra = null){
		if(extra && typeof extra == 'string'){
			extra = JSON.parse(extra)
		}
		if(!extra){
			return this.$msg('参数错误')
		}
		locationList.map(item => {
			item.warehouseInId = extra.warehouseInId
			item.orderId = extra.orderId
			item.orderItemId = extra.orderItemId
		})

		updateWarehouseInLocation({
      "orderId": extra.orderId,
      "orderItemId": extra.orderItemId,
      "orderLocationUpdateReqVOList": locationList,
      "warehouseInId": extra.warehouseInId
    }).then(res => {
			// 更新之后刷新
			this.$refs.warehouseDetail.getOrderWarehouseIn();
			// 更新订单信息
			getOrderInfo(this.orderId).then(data => {
			  this.detail = data
			})
			// 更新储位显示
			listByOrderId({ orderId: this.orderId }).then(data => this.orderLocationCreateReqVOList = data.map(v => Object.assign({}, v, { code: v.locationName || v.areaName || '' })))

		})
	},
	// 显示入仓记录
	showWarehouseLogs(row) {
		this.orderId = row.orderId;
		this.showWarehouseInItemId = row.orderItemId;
		this.$refs.warehouseDetail.showDetail(row);
	},
	// 根据储位获取显示用字符串
	getLocationName(locationList){
		if(!locationList || !locationList.length) return ''
		let arr = []
		locationList.forEach(item => {
      // 接口返回的数据有areaName，但是选择储位回调的数据里只有code
			arr.push(item.areaName ? `${item.areaName}${item.locationName || ''}` : item.code)
		})
		return Array.from((new Set(arr))).join(',')
	},
    isImageFile(filename) {
      var imageExtensions = [".jpeg", ".jpg", ".png", ".gif", ".bmp", ".tiff"];
      var extension = "";
      var length = filename.length;
      for (var i = length - 1; i >= 0; i--) {
        if (filename[i] === ".") {
          extension = filename.slice(i).toLowerCase();
          break;
        }
      }

      return imageExtensions.indexOf(extension) !== -1;
    },
    getWarehousePictureList(){
      return warehousePictureList({
        bizId: this.orderId,
        type: 1
      }).then(r =>{
        this.imageList = r.map(e => {
          return {
            url: e.url,
            type: this.isImageFile(e.url) ? 'image' : 'video',
            id: e.id
          }
        })
      })
    },
    plus() {
      this.labelList = [...this.labelList, { start: '', end: '' }]
    },
    minus(index) {
      this.labelList.splice(index, 1)
      this.$set(this, 'labelList', [...this.labelList])
    },
    getStatistics(){
      let orderSum = 0
      let orderV = 0
      let orderW = 0
      let leviteSum = 0
      let leviteV = 0
      let leviteW = 0
      let orderQ = 0
      let leviteQ = 0
      this.detail?.orderItemVOList?.forEach((column, index) => {
          orderSum += column.num
          orderV += column.volume
          orderW += column.weight
          orderQ += column.quantity
          leviteSum += column.warehouseInInfoVO?column.warehouseInInfoVO.cartonsNum:0
          leviteV += column.warehouseInInfoVO?column.warehouseInInfoVO.volume:0
          leviteW += column.warehouseInInfoVO?column.warehouseInInfoVO.weight:0
          leviteQ += column.warehouseInInfoVO?column.warehouseInInfoVO.quantityAll:0
      });
      geLabelByOrderId(this.orderId).then(r => {
        if (r?.length) {
          this.labelList = r.map(e => ({start: e.start, end: e.end}))
        }
      })
      this.statistics = { orderSum: orderSum.toFixed(2), orderV: orderV.toFixed(2), orderW: orderW.toFixed(2), leviteSum: leviteSum.toFixed(2), leviteV: leviteV.toFixed(2), leviteW: leviteW.toFixed(2), orderQ: orderQ.toFixed(2), leviteQ: leviteQ.toFixed(2) };
	  this.currenvyList.forEach((v, i) => {
		  let oo = {name: v.titleZh}
		  console.log('oo', oo)
		  this.currencyData[v.id] = oo
	  })
    },
    showAddPopup() {
      this.$refs.popup.open('center')
    },
    addRow() {
      this.addForm.cardList = [...this.addForm.cardList, {}]
    },
    delRow(index) {
      this.addForm.cardList.splice(index, 1)
      this.$set(this.addForm, 'cardList', [...this.addForm.cardList])
    },
    toLocation(){
      let url = `./location?warehouseId=${this.warehouseId}&orderId=${this.orderId}&locationList=${JSON.stringify(this.orderLocationCreateReqVOList)}`
      uni.navigateTo({
        url: url
      });
    },
    chooseVideoImage() {
      uni.showActionSheet({
        title: this.$t('选择上传类型'),
        itemList: [this.$t('图片'), this.$t('视频')],
        success: res => {
          console.log(res);
          if (res.tapIndex == 0) {
            this.chooseImages(true);
          } else {
            this.chooseVideo();
          }
        }
      });
    },
    chooseImages(flag) {
      console.log(flag, '---------flag-----');
      uni.chooseImage({
        count: 9, //默认是9张
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], //从相册选择
        success: res => {
          console.log(res, 'ddddsss')
          // let imgFile = res.tempFilePaths;
          res.tempFilePaths.forEach((item, index) => {
            updateImg(item).then(data => {
              console.log(data, flag, '--------res--------');
              if (flag) {
                warehousePictureCreate({
                  "bizId": this.orderId,
                  "type": 1,
                  "url": data.data
                }).then(r => {
                  this.imageList.push({ type: 'image', url: data.data, id: r.data })
                })
              } else {
                // this.exceptionList.push({ url: data.data })
                this.$set(this.exceptionList, this.exceptionList.length, { url: data.data })
              }
            })
          })
        }
      })
    },
	delimage(index){
    warehousePictureDelete(this.imageList[index].id).then(() => {
      this.imageList.splice(index,1)
    })
	},
	delexception(index){
		this.exceptionList.splice(index,1)
	},

    //上传视频
    chooseVideo(index) {
      uni.chooseVideo({
        maxDuration: 60, //拍摄视频最长拍摄时间，单位秒。最长支持 60 秒
        count: 9,
        // camera: this.cameraList[this.cameraIndex].value, //'front'、'back'，默认'back'
        // sourceType: sourceType[this.sourceTypeIndex],
        success: res => {
          let videoFile = res.tempFilePath;
          console.log(res, 'ddddsss')
          // res.tempFilePaths.forEach((item, index) => {
          updateImg(videoFile).then(data => {
            console.log(data, '--------res--------');

            warehousePictureCreate({
              "bizId": this.orderId,
              "type": 1,
              "url": data.data
            }).then(r => {
              this.imageList.push({ type: 'video', url: data.data, id: r.data })
            })
          })
          // })
        },
        fail:(error)=>{
          uni.hideLoading();
          uni.showToast({
            title: error,
            icon: 'none'
          })
        }
      })
    },
    previewImage(url) {
      //uniapp预览轮播图
      uni.previewImage({
        current: 0, //预览图片的下标
        urls: [url] //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
      })
    },
    playVideo(index) {
      setTimeout(() => {
        this.videoContext = uni.createVideoContext(`video_${index}`)
        // this.videoContext.play()
        // this.videoContext.requestFullScreen()
      }, 500)
    },
    fullscreenchange(event) {
      // if (uni.getSystemInfoSync().platform == "ios") { return }
      if (!event.detail.fullScreen) {
        // this.videoContext.pause()
      }
    },
    cancel() {
      this.$refs.popup.close()
      this.manualExceptionType = ''
      this.descZh = ''
      this.exceptionList = []
    },
    saveException() {
		if(!this.manualExceptionType||this.manualExceptionType.length==0){
			return uni.showToast({
				title:this.$t('请选择异常类型'),
				icon:'error'
			})
		}
      const params = {
        descZh: this.descZh,
        manualExceptionType: this.manualExceptionType.join(','),
        orderId: this.orderId,
        urls: this.imageList.map(e => e.url)
      }
      if (this.exceptionList.length > 0) {
        params.exceptionUrls = this.exceptionList.map(v => v.url)
      }
      console.log(params, '--------params-----');

      const pages = getCurrentPages()
      console.log(pages, pages.length - 2, '---pages---');
	  if(this.target == 'warehouseAdjustment'){
		  params.id=this.adjust?.orderWarehouseAdjustBackVO?.id || this.detail.id
      params.arrivalDate = (this.arrivalDate ? this.arrivalDate  : dayjs().format("YYYY-MM-DD")) + ' 00:00:00'
		  warehouseAdjustArrived(params).then(data => {
		    this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('操作成功') });
		    setTimeout(() => {
		    //   uni.navigateBack({
		    //     delta: pages.length - 2
		    //   })
          uni.navigateTo({ url: '/pages/warehouseAdjustment/list' })
		    }, 500)
		  })
	  }else{
		  finishWarehouseIn(params).then(data => {
			this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('转异成功') });
			setTimeout(() => {
			  // uni.navigateBack({
				//   delta: pages.length - 2
			  // })
        uni.navigateTo({ url: '/pages/warehousingAir/list' })
			}, 100)
			// uni.showModal({
			//   title: '提示',
			//   content: '是否需要打印入仓单？',
			//   confirmText: '打印',
			//   success: (res) => {
			//     setTimeout(() => {
			//       uni.navigateBack({
			//         delta: pages.length - 2
			//       })
			//     }, 100)
			//   }
			// });
		  })
	  }
    },
    save() {
      // if (this.orderLocationCreateReqVOList.length === 0) {
      //   store.dispatch(types.SHOW_TOAST, {
			// 		msg: '请选择储位'
			// 	})
      //   return
      // }
      const params = {
        orderId: this.orderId,
      }

      if (this.orderLocationCreateReqVOList.length > 0) {
        params.orderLocationCreateReqVOList = this.orderLocationCreateReqVOList
      }

      // 标签箱号
      if (this.detail.parentOrderId) {
        const labelList = this.labelList.filter(v => v.start && v.end)
        if (labelList.length > 0) {
          params.labelList = labelList
        } else {
          this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('请填写标签箱号') });
          return
        }
      }

      console.log(params, '****params*****');
      const pages = getCurrentPages()
      console.log(pages, pages.length - 2, '---pages---');
	  if(this.target == 'warehouseAdjustment'){
		  console.log(this.adjust)
		  params.id=this.adjust?.orderWarehouseAdjustBackVO?.id
      params.arrivalDate = (this.arrivalDate ? this.arrivalDate  : dayjs().format("YYYY-MM-DD")) + ' 00:00:00'
		  warehouseAdjustArrived(params).then(data => {
		    this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('操作成功') });
		    setTimeout(() => {
		      // uni.navigateBack({
		      //   delta: pages.length - 2
		      // })
          uni.navigateTo({ url: '/pages/warehouseAdjustment/list' })
		    }, 500)
		  })
	  }else {
		  if (this.texuList.length > 0) {
			const orderSpecialNeedReceivableReqVoList = this.texuList.filter(v => v.receivableMoney && v.receivableMoneyCurrency)
			if (orderSpecialNeedReceivableReqVoList.length > 0) {
			  params.orderSpecialNeedReceivableReqVoList = orderSpecialNeedReceivableReqVoList.map(v => ({
				id: v.id,
				receivableMoneyCurrency: v.receivableMoneyCurrency,
				receivableMoney: v.receivableMoney
			  }))
			} else {
			  uni.showModal({
				title: this.$t('提示'),
				content: this.$t('有特需费用为0，请问是否继续')+'?',
				confirmText: this.$t('继续'),
				success: (res) => {
				  if (res.confirm) {
					finishWarehouseIn(params).then(data => {
					  this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('操作成功') });
					  setTimeout(() => {
						// uni.navigateBack({
						//   delta: pages.length - 2
						// })
            uni.navigateTo({ url: '/pages/warehousingAir/list' })
					  }, 500)
					})
				  }
				}
			  });
			  return
			}
		  }
		  finishWarehouseIn(params).then(data => {
			this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('操作成功') });
			setTimeout(() => {
			  // uni.navigateBack({
				// delta: pages.length - 2
			  // })
        uni.navigateTo({ url: '/pages/warehousingAir/list' })
			}, 500)
		  })
	  }
    }
  },
  computed: {
	warehouseId(){
	  let warehouseId = this.detail?.logisticsInfoDto?.startWarehouseId

	  // 如果是调仓入仓则使用调仓的目的仓ID
	  if(this.target == 'warehouseAdjustment' && this.adjust?.orderWarehouseAdjustBackVO){
		  warehouseId = this.adjust.orderWarehouseAdjustBackVO.warehouseInId
	  }
	  return warehouseId
	},
    isChinese(){
      return this.$i18n.locale.toLowerCase().indexOf('zh') > -1
    }
  }
}
</script>

<style lang="scss" scoped>
.red{
  color: #ff4949;
}
.green{
  color: #13ce66;
}
.wrap {
  .content-wrap {
    margin: -75px 0 0;
    // border-radius: 8px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: #fff;
    // height: calc(100vh - 69px);
    padding: 0 16px 16px;
    .title {
      display: flex;
      line-height: 48px;
      font-size: 18px;
      border-bottom: 0.5px solid #eee;
      .title-label {
        font-weight: bold;
      }
      > view + view {
        margin-left: auto;
        color: #69696b;
      }
    }
    .info-wrap {
      .info-header {
        display: flex;
        font-size: 16px;
        line-height: 40px;
        .header-title {
          font-weight: bold;
        }
        .header-status {
          margin-left: auto;
          color: #50ddae;
        }
      }
      .info-content {
        > view {
          display: flex;
          margin-bottom: 8px;
          > view {
            flex: 1;
            display: flex;
            .label {
              color: #000;
              font-weight: bold;
              white-space: nowrap;
            }
            .content {
              color: #706d71;
              padding-left: 4px;
            }
          }
        }
      }
      .info-card {
        margin: 0 !important;
        .card-btn {
          border-top: 0.5px solid #eee;
          margin-top: 4px;
          padding: 8px;
          overflow: hidden;
          padding-bottom: 0;
          > view {
            float: right;
            height: 32px;
          }
        }
      }
    }
  }
  .info-form-wrap {
    margin-top: 16px;
    padding: 0 8px;
    background: #fff;
    // .row-wrap {
    //   display: flex;
    // }
    ::v-deep .uni-date {
      width: 100px;
      text-align: right;
      .uniui-calendar {
        display: none;
      }
      .uni-date-single, .uni-date__x-input {
        padding: 0;
      }
    }
    .xianghao {
      padding: 0 10px;
      > view {
        display: flex;
        align-items: center;
        > text {
          margin: 0 24px;
        }
        .icon-wrap {
          width: 72px;
          margin-left: 24px;
          > ::v-deep .uni-icons + .uni-icons {
            margin-left: 8px;
          }
        }
      }
      > view + view {
        margin-top: 10px;
      }
    }
    .texu {
      padding: 0 16px;
      > view {
        display: flex;
        align-items: center;
        margin-bottom: 8px;
        ::v-deep .uni-easyinput {
          margin: 0 16px;
        }
        > text {
          width: 80px;
        }
      }
    }
    .img-wrap {
      ::v-deep .uni-grid-item {
        background: #fbf8fb;
      }
      .grid-item-box-add {
        height: 100%;
        display: flex;
        flex-flow: column;
        font-size: 10px;
        padding: 16px 0;
        text-align: center;
        justify-content: center;
      }
    }
  }
  video::-webkit-media-controls-play-button{
    display: none;
  }
  .add-popup {
    ::v-deep .uni-popup__wrapper {
      background: none !important;
    }
    .popup-content {
      width: 90vw;
      border-radius: 8px;
      background: #fff;
      padding: 8px;
      max-height: 80vh;
      overflow: auto;
      .popup-title {
        line-height: 48px;
        text-align: center;
        font-size: 18px;
        font-weight: bold;
      }
      .form-wrap {
        > view {
          display: flex;
          margin-bottom: 8px;
          > text {
            width: 60px;
            margin-right: 8px;
          }
        }
        .img-wrap {
          flex: 1;
          width: calc(100% - 68px);
          ::v-deep .uni-grid-item {
            background: #fbf8fb;
          }
          .grid-item-box-add {
            height: 100%;
            display: flex;
            flex-flow: column;
            font-size: 10px;
            padding: 16px 0;
            text-align: center;
            justify-content: center;
          }
        }
      }
      .popup-foot-btn {
        padding: 8px;
        margin-top: 8px;
        text-align: center;
        button {
          border: 1px solid #007aff;
        }
        > button + button {
          margin-left: 16px;
          color: #007aff;
          background: #fff;
        }
      }
    }
  }
}

.btn{
  background-color: rgb(47, 77, 174);
  color: #fff;
  border-radius: 5rpx;
  padding: 5rpx 10rpx;
  margin-left: 10px;
}
</style>
