<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 v-for="(item, index) in detail.orderItemVOList" :key="index">
          <view class="info-header">
            <view class="header-title">{{$t('序号')}}: {{ index + 1 }}</view>
            <view v-show="canWarehousing" class="header-status"  @tap="showAddPopup('1', index)">{{$t('入仓')}}</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">{{ item.prodTitleEn }}</view>
              </view>
            </view>
            <template>
              <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)[isChinese ? 'titleZh' : 'titleEn'] : '无' : '无' }}</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>
                  <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 :class="{red: item.itemStatus === 3}" v-else>{{ item.itemStatus === 3 ? ($t('少了') + item.num + $t('箱')) : $t('待入仓') }}</span>
                    <span class="red" v-if="item.warehouseInInfoVO && item.warehouseInInfoVO.cartonsNumDiff">{{ item.warehouseInInfoVO.cartonsNumDiff }}{{$t('箱')}}</span>
                  </view>
                </view>
              </view>
              <view>
                <view>
                  <view class="label">{{$t('商品特性')}}: </view>
                  <!--23-09-25要求：没有入仓就是填单，入仓后就是如此特性-->
                  <view class="content">{{ getProductNamesByIds(item.warehouseInInfo ? item.warehouseInProdAttrIds : item.prodAttrIds) }}</view>
                </view>
              </view>
            </template>
<!--            <template v-else>
              <view>{{$t('非填单货物')}}</view>
            </template> -->
          </view>
          <view v-for="(ite, ind) in getOrderLog(item)">
            <uni-card class="info-card" v-if="orderItemList.find(v => v.orderItemId === item.orderItemId)">
              <view class="info-content">
                <view>
                  <view>
                    <view class="label">{{$t('品名')}}: </view>
                    <view class="content">{{ isChinese ? item.prodTitleZh : item.prodTitleEn }}</view>
                  </view>
                  <view>
                    <view class="label">{{$t('箱数')}}: </view>
                    <view class="content">
                      <template v-if="ite.orderWarehouseInDetailsVOList && ite.orderWarehouseInDetailsVOList.length">
                        <WarehouseRecordDetail v-model="ite.orderWarehouseInDetailsVOList" text readonly :num="ite.cartonsNum" />
                      </template>
                      <template v-else>
                        {{ ite.cartonsNum }}{{$t('箱')}}
                      </template>
                    </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>
                  <view>
                    <view class="label">{{$t('重量')}}: </view>
                    <view class="content">{{ ite.weight }}Kg</view>
                  </view>
                </view>
                <view>
                  <view>
                    <view class="label">{{$t('体积')}}: </view>
                    <view class="content">{{ ite.volume }}m³</view>

                  </view>
                  <view>
                    <view class="label">{{$t('商品特性')}}: </view>
                    <!--
                    23-10-02
                    工单要求改成填单特性 https://zentao.test.jdshangmen.com/bug-view-4825.html#app=execution
                    工单要求入仓后显示特性 https://zentao.test.jdshangmen.com/bug-view-4824.html#app=execution
                    工单要求显示最新特性 https://zentao.test.jdshangmen.com/bug-view-4821.html#app=execution
                    -->
                    <view class="content">{{ getProductNamesByIds(item.warehouseInInfoVO ? item.warehouseInProdAttrIds : item.prodAttrIds) }}</view>
                  </view>
                </view>
                <view>
                  <view>
                    <view class="label">{{$t('尺寸')}}: </view>
                    <view class="content">{{ ite.boxGauge }}</view>
                  </view>
                  <view>
                    <view class="label">{{$t('数量')}}: </view>
                    <view class="content">{{ ite.quantityAll }}</view>
                  </view>
                </view>
              </view>
              <view class="card-btn" v-show="!detail.parentOrderId && canEdit">
                <view>
                  <button class="mini-btn" type="primary" size="mini"  @tap="showAddPopup('2', index, ind)">{{$t('修改')}}</button>
                  <button class="mini-btn" type="default" size="mini" @tap="deleteClick(ite)">{{$t('删除')}}</button>
                </view>
              </view>
            </uni-card>
          </view>
        </view>
        </view>
    </view>
    <view class="bottom-action">
      <button v-show="canEdit || canWarehousing" type="primary" @tap="showAddPopup('3')">{{$t('新商品入仓')}}</button>
      <button style="color: #007aff" @tap="next">{{$t('下一步')}}</button>
    </view>
    <view class="add-popup">
      <uni-popup ref="popup" background-color="#fff" :maskClick="false">
				<view class="popup-content">
          <view class="popup-title">{{title}}</view>
          <view class="add-form">
            <uni-forms ref="addForm" :modelValue="addForm" label-position="top">
              <uni-forms-item :label="$t('中文品名')" required>
                <template v-slot:label>
                  <view>
                    <text class="uni-forms-item__label"><text style="color: #dd524d">*</text>{{$t('中文品名')}}</text>
                    <button style="float: right" type="primary" size="mini" @click="addProduct">{{$t('添加新品名')}}</button>
                  </view>
                </template>
                <!-- <uni-easyinput v-model="addForm.titleZh" placeholder="中文品名" /> -->
                <select-combox
                    v-if="!detail.parentOrderId"
                    :candidates="productListZh"
                    :productListToBeDetermined="productListToBeDetermined"
                    placeholder=""
                    @getValue="getValue"
                    @input="handleInputZh"
                    v-model="addForm.prodTitleZh"
                ></select-combox>
                <text v-else>{{ addForm.prodTitleZh }}</text>
              </uni-forms-item>
              <uni-forms-item :label="$t('英文品名')" required>
                <select-combox
                    v-if="!detail.parentOrderId"
                    :candidates="productListEn"
                    :productListToBeDetermined="productListToBeDetermined"
                    placeholder=""
                    @getValue="getValueEn"
                    @input="handleInputEn"
                    v-model="addForm.prodTitleEn"
                    :is-chinese="false"
                ></select-combox>
                <text v-else>{{ addForm.prodTitleEn }}</text>
              </uni-forms-item>

              <uni-forms-item :label="$t('品牌')" required>
                <!-- <text v-if="selectListItem.orderWarehouseInBackItemDoList && selectListItem.orderWarehouseInBackItemDoList.length">{{ addForm.brand ? brandRang.find(v => v.id == addForm.brand) ? brandRang.find(v => v.id == addForm.brand).titleZh : $t('无') : $t('无') }}</text> -->
                <!-- <uni-data-select v-else v-model="addForm.brand" :localdata="brandRang" @change="brandChange"></uni-data-select> -->
				        <select-combox
                    :candidates="brandRangtitle"
                    :valuedates="brandRang"
                    placeholder=""
                    @getValue="brandChange"
                    @input="getPinPai"
                    v-model="addForm.brand"
                ></select-combox>
                <!-- <select-combox v-else :candidates="brandRangTitle" placeholder="" @getValue="getValueBrand" v-model="addForm.brand"></select-combox> -->

              </uni-forms-item>
              <uni-forms-item :label="$t('备案')" required>
                <!-- <uni-data-select v-model="addForm.brandType" :localdata="benanRang" :disabled="true"></uni-data-select> -->
                <text>{{ isBeian }}</text>
              </uni-forms-item>
              <uni-forms-item :label="$t('收费模式')" required>
                <!-- <uni-data-select v-model="addForm.feeType" :localdata="feeTypeRang" :disabled="true"></uni-data-select> -->
                <text>{{ feeType }}</text>
              </uni-forms-item>
              <uni-forms-item :label="$t('材质')">
                <uni-data-select v-model="addForm.material" :localdata="caizhiRang" :placeholder="$t('请选择')"></uni-data-select>
              </uni-forms-item>
              <uni-forms-item :label="$t('单位')" required>
                <uni-data-select v-model="addForm.unit" :localdata="danweiRange" :clear="false" @change="unitChage" :placeholder="$t('请选择')"></uni-data-select>
              </uni-forms-item>
              <uni-forms-item :label="$t('商品特性')" required>
                <uni-data-checkbox v-model="addForm.warehouseInProdAttrIds" multiple :localdata="texingLocaldata" />
              </uni-forms-item>
              <uni-forms-item :label="$t('用途')">
                <uni-data-checkbox v-model="addForm.usageIds" multiple :localdata="usageIdsList" />
              </uni-forms-item>
            </uni-forms>
          </view>
          <view class="add-row-btn" @tap="addRow"><uni-icons type="plus-filled" size="20" color="#eaeced"></uni-icons>{{$t('添加一行')}}</view>
          <uni-card class="add-popup-card" v-for="(item, index) in addForm.orderWarehouseInItemDoList" :key="index">
            <view class="card-row">
              <uni-easyinput v-model="item.cartonsNum" type="number" :placeholder="`${unitTitle}`+$t('数')" :clearable="false" @input="handleVolume(index)"/>
              <switch :checked="item.specificationType === 1" @change="switchChange(item, index)" />
              <dict-tag :type="DICT_TYPE.WAREHOUSING_SPECIFICATION_TYPE" :value="item.specificationType + ''"/>
              <uni-easyinput v-model="item.weight" type="number" :placeholder="$t('重量')" :clearable="false"/>
              <text>KG</text>
              <uni-easyinput v-model="item.quantityAll" type="number" :placeholder="$t('个数')" :clearable="false"/>
              <text>{{$t('个')}}</text>
            </view>
            <view class="card-row">
              <uni-easyinput v-model="item.c" type="number" :placeholder="$t('长')" :clearable="false" @input="handleVolume(index)"/>
              <text>*</text>
              <uni-easyinput v-model="item.k" type="number" :placeholder="$t('宽')" :clearable="false" @input="handleVolume(index)"/>
              <text>*</text>
              <uni-easyinput v-model="item.g" type="number" :placeholder="$t('高')" :clearable="false" @input="handleVolume(index)"/>
              <text>=</text>
              <uni-easyinput v-model="item.volume" type="number" placeholder="" :clearable="false" />
              <text>CBM</text>
            </view>
            <view class="card-row">
              <text>{{$t('快递单号')}}</text>
              <uni-easyinput v-model="item.expressNo" :placeholder="$t('输入快递单号')" :clearable="false" />
              <WarehouseRecordDetail v-model="item.orderWarehouseInDetailsVOList" />
            </view>
            <view class="card-row">
              <text>{{$t('入仓备注')}}</text>
              <uni-easyinput v-model="item.remark" :placeholder="$t('输入入仓备注')" :clearable="false" />
            </view>
            <view v-if="index !== 0" class="delete-btn" @tap="delRow(index)">{{$t('删除')}}</view>

            <view class="cu-form-group">
              <view class="title">{{$t('储位')}}</view>
              <view class="content" @tap="toLocation(index)" style="flex:1;justify-content: flex-end;">
                {{ item.orderLocationBackVOList && item.orderLocationBackVOList.length ? item.orderLocationBackVOList.map(v => v.code ||  v.areaName + (v.locationName || '')).join(',') : '' }}
                <uni-icons type="right" size="16"></uni-icons>
              </view>
            </view>
          </uni-card>
          <view class="cu-form-group">
            <view class="title"><span style="color: red">*</span>{{$t('入仓影像')}}</view>
          </view>
          <view class="img-wrap">
            <uni-grid :column="4" :highlight="true" :show-border="false">
              <uni-grid-item v-for="(image, index) in addForm.pictureUrls" :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="delimage(index)" mode="widthFix"></image>
                  <image v-if="image.type === 'image'" :src="image.url" mode="scaleToFill" style="height: 100%" @tap="previewImage(image.url)" />
                  <video v-else-if="image.type === 'video'" :id="`video_${index}`" style="width: 100%;height: 100%" :src="image.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(addForm.pictureUrls)">
                    <uni-icons type="plusempty" size="30" color="#eae8eb"></uni-icons>
                    <!-- <text>添加视频或图片</text> -->
                  </view>
                </view>
              </uni-grid-item>
            </uni-grid>
          </view>

          <view class="popup-foot-btn">
            <button class="mini-btn" type="primary" size="mini" @tap="saveForm">{{$t('确认')}}</button>
				    <button class="mini-btn" type="default" size="mini" @tap="maskClick">{{$t('取消')}}</button>
          </view>
        </view>
			</uni-popup>
    </view>

<!--    添加新商品-->
    <view class="add-popup">
      <uni-popup ref="product" background-color="#fff" :maskClick="false">
        <view class="popup-content">
          <view class="popup-title">{{$t('添加新商品')}}</view>

          <uni-forms ref="productForm" :modelValue="productForm" label-position="top">
            <uni-forms-item :label="$t('商品类型')" required>
              <uni-data-select v-model="productForm.typeId" :localdata="typeList" :placeholder="$t('选择商品类型')"></uni-data-select>
            </uni-forms-item>
            <uni-forms-item :label="$t('中文标题')" required>
              <uni-easyinput v-model="productForm.titleZh" placeholder="输入中文标题" :clearable="false"/>
            </uni-forms-item>
            <uni-forms-item :label="$t('英文标题')" required>
              <uni-easyinput v-model="productForm.titleEn" placeholder="输入英文标题" :clearable="false"/>
            </uni-forms-item>
            <uni-forms-item :label="$t('商品特性')">
              <uni-data-checkbox v-model="productForm.attrArray" :localdata="texingLocaldata" :placeholder="$t('选择商品特性')" multiple></uni-data-checkbox>
            </uni-forms-item>
          </uni-forms>

          <view class="popup-foot-btn">
            <button class="mini-btn" type="primary" size="mini" @tap="saveProductForm">{{$t('确认')}}</button>
            <button class="mini-btn" type="default" size="mini" @tap="maskClickAddProduct">{{$t('取消')}}</button>
          </view>
        </view>
      </uni-popup>
    </view>
  </view>
</template>

<script>
import {uniIcons} from '@dcloudio/uni-ui';
import {
  addProduct,
  getFeeTypeByCustomerProduct,
  getOrderInfo,
  getOrderWarehouseIn, getProductBrankById,
  getProductBrankPage, getProductList,
  getProductSimpleList, getProductTypeList,
  orderWarehouseIn,
  orderWarehouseInDelete,
  orderWarehouseInUpdate,
  orderWarehouseInUpdateApply,
  updateWarehouseInLocation
} from './api'
import {getProductAttrList, updateImg} from '@/api/system'
import selectCombox from '@/components/select-combox/select-combox.vue';
import * as types from '../../store/mutations-types.js';
import {DICT_TYPE, getDictData, getDictDatas} from "@/util/dict"
import store from "@/store/store";
import iconpath from "@/static/images/close.png"
import imageUpload from "@/components/image-upload/index.vue";
import {warehousePictureDelete, warehousePictureList} from "@/pages/loading/api";
import WarehouseRecordDetail from "@/components/warehouse-record-detail/index.vue";

export default {
  components: {WarehouseRecordDetail, uniIcons, selectCombox, imageUpload },
  data() {
    return {
      iconpath: iconpath,
      submitting: false,
      allPicture: [],
      getDictData,
      orderId: '',
      detail: {},
      addForm: {
        unit: '1',
        orderWarehouseInItemDoList: [],
        pictureUrls: [],
        usageIds: []
      },
      //类型列表
      typeList: [],
      productForm: {
        typeId: undefined,
        attrArray: [],
        titleZh: undefined,
        titleEn: undefined
      },
      productAttrList: [],
      productListZh: [],
      productListZhObj: [],
      productListEn: [],
      // 是否待确定
      productListToBeDetermined: [],
      list: [],
      brandRang: [],
      brandRangTitle: [],
      benanRang: [],
      feeTypeRang: [],
      // caizhiRang: [],
      // danweiRange: [],
      texingLocaldata: [],
      unitTitle: this.$t('箱'),
      formType: '', // 1: 新增 2: 修改 3: 新商品入仓
      selectListItem: {},
      orderItemList: [],
	  brandRangtitle:[],
	  title: this.$t('新商品入仓操作'),
	  selectBrand: 0,
	  orderItemLog:[]
    }
  },
  computed: {
    usageIdsList() {
      return getDictDatas(DICT_TYPE.WAREHOUSING_RECORD_DETAIL_USAGE).map(e => ({
        ...e,
        text: e[this.$lang.locale === 'zh-Hans' ? 'label' : 'labelEn']
      }))
    },
    include(){
      return (state, arr) => {
        return arr.indexOf(state) > -1
      }
    },
    exclude(){
      return (state, arr) => {
        return arr.indexOf(state) == -1
      }
    },
    canWarehousing(){
      return (this.include(this.detail.status, [0, 2]) || this.detail.inWarehouseState === 208)
          || (this.include(this.detail.inWarehouseState, [201,202, 202, 210, 202, 211, 202, 214, 215, 216]) && this.include(this.detail.status, [2,3,5,10,9,8]))
    },
    // 显示入仓修改
    canEdit(){
      return this.include(this.detail.inWarehouseState, [201, 202, 207, 202, 209, 210, 202, 211, 202, 214, 215, 216, 204, 205])
        && this.detail.status < 11
    },

    isEdit(){
      return this.include(this.detail.inWarehouseState, [202, 207, 202, 209, 210, 202, 211, 212, 202, 213, 214, 215, 216, 204, 205]) &&
          this.detail.status != 11 && this.exclude(this.detail.shipmentState, [314,315,317,318])
    },
    isBeian(){
      if (this.addForm.brandType !== undefined){
        return [this.$t('无备案'), this.$t('有备案'), this.$t('中性')][this.addForm.brandType]
      }
      const t = this.brandRang.find(e => e.id == this.addForm.brand) || {}
      if (t?.filing){
        return [this.$t('无备案'), this.$t('有备案'), this.$t('中性')][t.filing]
      } else {
        return ''
      }
    },
    feeType(){
      const feeType = parseInt(this.addForm.feeType)
      if (feeType >= 0 && feeType < 3) {
        return [this.$t('无牌价'), this.$t('有牌价'), this.$t('中性品牌价')][feeType]
      }
      return ''
    },
    isChinese(){
      return uni.getLocale() === 'zh-Hans'
    },
    isJiyun(){
      return this.detail.type.indexOf('1') !== -1
    },
    // 单位字典
    danweiRange(){
      return (this.$store.getters.dict_datas[this.DICT_TYPE.ECW_PACKAGING_TYPE] || []).map(v => ({ ...v, text: this.$l(v, 'label')}))
    },
    // 材质字典
    caizhiRang(){
      return (this.$store.getters.dict_datas[this.DICT_TYPE.ECW_PRODUCT_MATERIAL] || []).map(v => ({ ...v, text: this.$l(v, 'label')}))
    },
  },
  created() {
    console.log(uni.getLocale())

    getProductTypeList().then(data => {
      this.typeList = data.map(e => {
        return {
          value: e.id,
          text: this.$lang.locale === 'zh-Hans' ? e.titleZh : e.titleEn
        }
      })
    })
    getProductAttrList().then(data => {
      this.productAttrList = data
      this.texingLocaldata = data.map(v => ({ ...v, text: this.$lang.locale=='zh-Hans'?v.attrName:v.attrNameEn, value: v.id }))
    })
    this.getProductList()
    this.getPinPai()

    // this.brandRang = this.getDictDatas(this.DICT_TYPE.ECW_IS_BRAND).map(v => ({ ...v, text: v.label }))
    this.benanRang = [{ value: 0, text: this.$t('无备案') }, { value: 1, text: this.$t('有备案') }, { value: 2, text: this.$t('中性') }]
    this.feeTypeRang = [{ value: 0, text: this.$t('无牌价') }, { value: 1, text: this.$t('有牌价') }, { value: 2, text: this.$t('中性品牌价') }]
    // this.caizhiRang = this.getDictDatas(this.DICT_TYPE.ECW_PRODUCT_MATERIAL).map(v => ({ ...v, text: this.isChinese ? v.label : v.labelEn}))
    // this.danweiRange = this.getDictDatas(this.DICT_TYPE.ECW_PACKAGING_TYPE).map(v => ({ ...v, text: this.isChinese ? v.label : v.labelEn }))
  },
  onLoad: function(option) {
    if ('orderId' in option) {
      this.orderId = option.orderId;
      getOrderInfo(this.orderId).then(data => {
        this.detail = data
      })
      getOrderWarehouseIn(this.orderId).then(data => this.orderItemList = data.reverse())
    }
    // if ('returnLoadId' in option) {
    //   this.returnLoadId = option.returnLoadId;
    // }

    uni.setNavigationBarTitle({
      title: this.$t('货物信息')
    })
  },
  methods: {
    chooseVideoImage(pictureUrls) {
      uni.showActionSheet({
        title: this.$t('选择上传类型'),
        itemList: [this.$t('图片'), this.$t('视频')],
        success: res => {
          console.log(res);
          if (res.tapIndex == 0) {
            this.chooseImages(true, pictureUrls);
          } else {
            this.chooseVideo(pictureUrls);
          }
        }
      });
    },
    chooseImages(flag, pictureUrls) {
      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) {
                uni.showToast({
                  title: this.$t('影像上传成功'),
                  icon: 'success'
                })
                pictureUrls.push({ type: 'image', url: data.data })
              } else {
                // this.exceptionList.push({ url: data.data })
                this.$set(this.exceptionList, this.exceptionList.length, { url: data.data })
              }
            })
          })
        }
      })
    },

    //上传视频
    chooseVideo(pictureUrls) {
      uni.chooseVideo({
        maxDuration: 60, //拍摄视频最长拍摄时间，单位秒。最长支持 60 秒
        count: 9,
        success: res => {
          let videoFile = res.tempFilePath;
          updateImg(videoFile).then(data => {
            pictureUrls.push({ type: 'video', url: data.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()
      }
    },
    delimage(index){
      this.addForm.pictureUrls.splice(index,1)
    },
    getProductList(titleZh = ''){
      // 注意：由于接口特性，中英文均都必须使用titleZh字段搜索
      return getProductList({
        filter: false,
        pageSize: 30,
        titleZh
      }).then(data => {
        this.productListZh = data.list.map(v => v.titleZh)
        this.productListZhObj = data.list
        this.productListEn = data.list.map(v => v.titleEn)
        this.productListToBeDetermined = data.list.map(v => v.auditStatus !== 2)
      })
    },
    handleInputZh(e){
      this.getProductList(e)
    },
    handleInputEn(e){
      this.getProductList(e)
    },
    toLocation(index){
      const warehouseId = this.detail.adjustToDestWarehouseId || this.detail?.logisticsInfoDto?.startWarehouseId
      // let url = './location?warehouseId=' + warehouseId;
      let url = `./location?warehouseId=${warehouseId}&orderId=${this.orderId}&locationList=${JSON.stringify(this.addForm.orderWarehouseInItemDoList[index].orderLocationBackVOList || [])}&extra=${index}&callback=setAddFormlocation`
      uni.navigateTo({
        url: url
      });
    },
	// 选择储位回调
	setAddFormlocation(locationList, extra){
		this.$set(this.addForm.orderWarehouseInItemDoList[extra], 'orderLocationBackVOList', locationList)
	},
	  getOrderLog(item){
      return this.orderItemList.length > 0 ? this.orderItemList.find(v => v.orderItemId === item.orderItemId)?.orderWarehouseInBackItemDoList : []
		},
    switchChange(item, index){
      if (item.specificationType === 1){
        this.$set(item, 'specificationType', 2)
      }else {
        this.$set(item, 'specificationType', 1)
      }
      this.handleVolume(index)
    },
    getNeedCartonsNum(){
      let count = 0
      this.addForm.orderWarehouseInItemDoList?.forEach(e => count += (+e.cartonsNum || 0))
      return count >= this.selectListItem.num ? '' : this.selectListItem.num - count
    },
    getPinPai(title = '') {
      const params = {
        pageSize: 30
      }
      if (title) {
        params[this.$lang.locale === 'zh-Hans' ? 'titleZh' : 'titleEn'] = title
      }
      getProductBrankPage(params).then(data => {
        this.brandRangtitle = []
        this.brandRang = [
          ...data.list
        ].map(v => ({ ...v, text: v.titleZh, value: v.id + '' }))
        this.brandRang.forEach(item=>{
          if(this.$lang.locale=='zh-Hans'){
            this.brandRangtitle.push(item.titleZh)
          }else{
            this.brandRangtitle.push(item.titleEn)
          }
        })
      })
    },
    // type 1 入仓，2修改，3 新商品入仓
    async showAddPopup(type, index, x) {
      if(type == '1'){
        this.title = this.$t('入仓操作')
      } else if (type == '2') {
        this.title = this.$t('修改操作')
      }else {
        if (this.detail.parentOrderId) { // 拆单
          this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('拆单订单不能添加新商品') })
          return
        }

        this.title = this.$t('新商品入仓操作')
      }
      this.formType = type
      const t = this.orderItemList.find(v => v.orderItemId === this.detail.orderItemVOList[index]?.orderItemId) || {}
      this.selectListItem = { ...this.detail.orderItemVOList[index], ...t }
      await this.getProductList(this.detail.orderItemVOList[index]?.prodTitleZh)
      if (type === '1') {
        // 入仓特性，已入仓去入仓特性，未入仓去填单特性
        let warehouseInProdAttrIds = this.selectListItem.warehouseInInfoVO ? this.selectListItem.warehouseInProdAttrIds : this.selectListItem.prodAttrIds

        this.addForm = {
          unit: '1',
          orderWarehouseInItemDoList: [{
            cartonsNum:this.getNeedCartonsNum(),
            specificationType: 1,
            c: this.isJiyun ? 0 : '',
            k: this.isJiyun ? 0 : '',
            g: this.isJiyun ? 0 : ''
          }],
          warehouseInProdAttrIds: warehouseInProdAttrIds?.split(',').map(v => Number(v)) || [],
          pictureUrls: [],
          brandType: this.detail.orderItemVOList[index].brandType,
          prodId: this.detail.orderItemVOList[index].prodId,
          prodTitleZh: this.detail.orderItemVOList[index].prodTitleZh,
          prodTitleEn: this.detail.orderItemVOList[index].prodTitleEn,
          cartonsNum: this.detail.orderItemVOList[index].cartonsNum,
          specificationType: 1,
          usageIds: this.detail.orderItemVOList[index].usageIds?.split(',')
        }
        this.getValueEn(this.detail.orderItemVOList[index].prodTitleEn, false)
        this.addForm.pictureUrls = this.detail.orderItemVOList[index].pictureUrls?.map(e => {
          return {
            url: e,
            type: ['jpg', 'png', 'jpeg', 'heic'].includes(e.split('.')?.reverse()[0]) ? 'image' : 'video'
          }
        }) || []
      } else if (type === '2') {
        this.getFeeTypeByCustomerProduct(this.detail.orderItemVOList[index])
        this.addForm = {
          ...this.addForm, // 防止绑定失联
          // pictureUrls: this.detail.orderItemVOList[index].pictureUrls?.map(e => {return {type: 'image', url: e}}) || [],
          id: this.orderItemList.find(v => v.orderItemId === this.detail.orderItemVOList[index].orderItemId)?.orderWarehouseInBackItemDoList[x].id,
          // orderWarehouseInItemDoList: [{cartonsNum:undefined}],
          brandType: this.detail.orderItemVOList[index].brandType,
          prodTitleZh: this.detail.orderItemVOList[index].prodTitleZh,
          prodTitleEn: this.detail.orderItemVOList[index].prodTitleEn,
          prodId: this.detail.orderItemVOList[index].prodId,
          orderItemId: this.detail.orderItemVOList[index].orderItemId,
          num: this.detail.orderItemVOList[index].num,
          unit: this.detail.orderItemVOList[index].warehouseInInfoVO.unit,
          material: this.orderItemList.find(v => v.orderItemId === this.detail.orderItemVOList[index].orderItemId).material,
          warehouseInProdAttrIds: this.selectListItem.warehouseInProdAttrIds?.split(',').map(v => Number(v)) || [],
          usageIds: this.detail.orderItemVOList[index].usageIds?.split(','),
          orderWarehouseInItemDoList: [this.orderItemList.find(v => v.orderItemId === this.detail.orderItemVOList[index].orderItemId)?.orderWarehouseInBackItemDoList[x]].map(v => {
            return {
              ...v,
              specificationType: v.specificationType || 1,
              cartonsNum: v.cartonsNum,
              weight: v.weight,
              quantityAll: v.quantityAll,
              volume: v.volume,
              c: v.boxGauge.split('*')[0],
              k: v.boxGauge.split('*')[1],
              g: v.boxGauge.split('*')[2],
              id: v.id
            }
          })
        }
        this.getValueEn(this.detail.orderItemVOList[index].prodTitleEn, false)
        this.addForm.pictureUrls = this.detail.orderItemVOList[index].pictureUrls?.map(e => {
            return {
                url: e,
                type: ['jpg', 'png', 'jpeg', 'heic'].includes(e.split('.')?.reverse()[0]) ? 'image' : 'video'
            }
        })
      }
      this.selectBrand = this.selectListItem.brand
      this.addForm.brand = this.brandRang.find(v => this.selectListItem.brand == v.id)?.titleZh||undefined
      if (!this.addForm.brand && this.selectBrand) {
        // 不在当前品牌列表中
        getProductBrankById({ id: this.selectBrand }).then(r => {
          this.brandRang.push(r)
          if(this.$lang.locale === 'zh-Hans'){
            this.brandRangtitle.push(r.titleZh)
            this.addForm.brand = r.titleZh
          }else{
            this.brandRangtitle.push(r.titleEn)
            this.addForm.brand = r.titleEn
          }
        })
      }

      this.$nextTick(() => {
        this.addForm.brand && this.getFeeTypeByCustomerProduct(this.addForm)
      });
      this.addForm.material = this.selectListItem?.material || ''
      if (type === '3') {
        this.addForm.orderWarehouseInItemDoList = [{
          specificationType: 1, c: this.isJiyun ? 0 : '', k: this.isJiyun ? 0 : '', g: this.isJiyun ? 0 : ''
        }]
      }
      this.unitChage(this.addForm.unit)
      this.$refs.popup.open('center')
    },
    deleteClick(item) {
      uni.showModal({
        title: this.$t('是否删除'),
        content: this.$t('删除后不可恢复，确定是否要删除该入仓信息')+'?',
        success: (data) => {
          if (data.confirm) {
            orderWarehouseInDelete({
              "orderWarehouseInId": item.id,
            }).then(async () => {
              this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('删除成功') });
              await getOrderWarehouseIn(this.orderId).then(data => this.orderItemList = data.reverse())
              getOrderInfo(this.orderId).then(data => {
                this.detail = data
              })
            })
          }
        }
      })
    },
	getValue(e) {
		if(e){
			var sindex = 0
			this.productListZhObj.forEach((item,index)=>{
				if(item.titleZh == e){
					sindex = index
				}
			})
			// this.addForm.prodTitleZh = this.productListZhObj[sindex].titleZh
			this.$set(this.addForm,'prodTitleZh',this.productListZhObj[sindex].titleZh)
      this.$set(this.addForm,'prodTitleEn',this.productListZhObj[sindex].titleEn)
      this.$set(this.addForm,'prodId',this.productListZhObj[sindex].id)
      this.$set(this.addForm,'material',this.productListZhObj[sindex]?.materialType)
      this.$set(this.addForm,'unit',this.productListZhObj[sindex].packaging)
      this.unitChage(this.productListZhObj[sindex].packaging)
			this.$set(this.addForm,'warehouseInProdAttrIds',(this.productListZhObj[sindex].attrId || '').split(',').map(v => Number(v)))
			let num = Number(this.detail.costVO.totalNum)-Number(this.detail.sumNum)
			if(num>=0){
				this.$set(this.addForm.orderWarehouseInItemDoList,'cartonsNum',num)
			}
      this.$nextTick(() => {
        this.addForm.brand && this.getFeeTypeByCustomerProduct(this.addForm)
      });
		} else {
      this.$set(this.addForm,'prodTitleZh', undefined)
      this.$set(this.addForm,'prodTitleEn', undefined)
      this.$set(this.addForm,'prodId', undefined)
    }
	},
	getValueEn(e, updateAttr = true) {
		if(e){
			var sindex = 0
			this.productListZhObj.forEach((item,index)=>{
				if(item.titleEn == e){
					sindex = index
				}
			})
			// this.addForm.prodTitleZh = this.productListZhObj[sindex].titleZh
			this.$set(this.addForm,'prodTitleZh',this.productListZhObj[sindex]?.titleZh)
			this.$set(this.addForm,'prodTitleEn',this.productListZhObj[sindex]?.titleEn)
      this.$set(this.addForm,'material',this.productListZhObj[sindex]?.materialType)
      // this.$set(this.addForm,'unit',this.productListZhObj[sindex].packaging)
      this.unitChage(this.productListZhObj[sindex].packaging)
      if (updateAttr) {
        this.$set(this.addForm,'warehouseInProdAttrIds',(this.productListZhObj[sindex].attrId || '').split(',').map(v => Number(v)))
      }
			let num = Number(this.detail.costVO.totalNum)-Number(this.detail.sumNum)
			if(num>=0){
				this.$set(this.addForm.orderWarehouseInItemDoList,'cartonsNum',num)
			}
      this.$nextTick(() => {
        this.addForm.brand && this.getFeeTypeByCustomerProduct(this.addForm)
      });
		} else {
      this.$set(this.addForm,'prodTitleZh', undefined)
      this.$set(this.addForm,'prodTitleEn', undefined)
      this.$set(this.addForm,'prodId', undefined)
    }
	},
  getValueBrand(e, type) {
		if(e){
			var sindex = 0
			this.brandRang.forEach((item,index)=>{
				if(item.titleZh == e){
					sindex = index
				}
			})
      console.log(sindex, '+++++');
      if (sindex) {
        if (type) {
          this.$set(this.addForm,'brand',this.brandRang[sindex].id)
        } else {
          this.$set(this.addForm,'brand',this.brandRang[sindex].titleZh)
        }
        // this.$set(this.addForm,'brand',this.brandRang[sindex].id)
      } else {
        this.$set(this.addForm,'brand','')
      }
      this.$nextTick(() => {
        this.addForm.brand && this.getFeeTypeByCustomerProduct(this.addForm)
      });
		}
	},

    addRow() {
      let orderLocationBackVOList = []
      if (this.addForm.orderWarehouseInItemDoList.length > 0) {
        orderLocationBackVOList = JSON.parse(JSON.stringify(this.addForm.orderWarehouseInItemDoList[this.addForm.orderWarehouseInItemDoList.length - 1].orderLocationBackVOList || []))
      }
      this.addForm.orderWarehouseInItemDoList.push({
        cartonsNum: this.getNeedCartonsNum(),
        specificationType: 1,
        c: this.isJiyun ? 0 : '',
        k: this.isJiyun ? 0 : '',
        g: this.isJiyun ? 0 : '',
        orderLocationBackVOList,
          pictureUrls: []
      })
    },
    delRow(index) {
      this.addForm.orderWarehouseInItemDoList.splice(index, 1)
      this.$set(this.addForm, 'orderWarehouseInItemDoList', [...this.addForm.orderWarehouseInItemDoList])
    },
    unitChage(value) {
      this.unitTitle = this.danweiRange.find(v => v.value === value)?.text || this.$t('箱')
    },
    handleVolume(index) {
      this.$nextTick(() => {
        const { c, k, g, specificationType, cartonsNum } = this.addForm.orderWarehouseInItemDoList[index]
        if (c && k && g&& specificationType && cartonsNum) {
          // this.addForm.orderWarehouseInItemDoList[index].volume = ((c * k * g) / 1000000).toFixed(2)
		  const volume = (((specificationType === 1 || specificationType === '1') ? cartonsNum : 1) * (c * k * g) / 1000000).toFixed(2)
          this.$set(this.addForm.orderWarehouseInItemDoList[index], 'volume', volume === '0.00' ? '0.01' : volume)
        } else {
          this.addForm.orderWarehouseInItemDoList[index].volume = 0
        }
        this.$forceUpdate()
      })
    },
    maskClick() {
      const _this = this
      uni.showModal({
        title: '提示',
        content: '确认取消吗？',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定');
            _this.$refs.popup.close()
            _this.addForm = {
              unit: '1',
              orderWarehouseInItemDoList: [{cartonsNum:undefined}],
              pictureUrls: [],
              usageIds: [],
            }
          }
        }
      });
    },
    addProduct() {
      this.$refs.product.open('center')
    },
    maskClickAddProduct() {
      const _this = this
      uni.showModal({
        title: '提示',
        content: '确认取消吗？',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定');
            _this.$refs.product.close()
            _this.productForm = {
              typeId: undefined,
              attrArray: [],
              titleZh: undefined,
              titleEn: undefined
            }
          }
        }
      });
    },
    saveProductForm() {
      if(!this.productForm.typeId){
        return uni.showToast({
          title:this.$t('请选择商品类型'),
          icon:'error'
        })
      }
      if(!this.productForm.titleZh){
        return uni.showToast({
          title:this.$t('请输入中文标题'),
          icon:'error'
        })
      }
      if(!this.productForm.titleEn){
        return uni.showToast({
          title:this.$t('请输入英文标题'),
          icon:'error'
        })
      }
      //商品特性转字符串
      this.productForm.attrId = this.productForm.attrArray.join(',')
      // 添加的提交
      addProduct(this.productForm).then(response => {
        this.addForm.prodId = response
        this.addForm.prodTitleZh = this.productForm.titleZh
        this.addForm.prodTitleEn = this.productForm.titleEn
        this.addForm.warehouseInProdAttrIds = this.productForm.attrArray || []
        this.productListZh.push(this.productForm.titleZh)
        this.productListEn.push(this.productForm.titleEn)
        const item = {
          id: response,
          ...this.productForm,
          attrId: this.productForm.attrArray.join(',')
        }
        this.productListZhObj.push(item)
        this.productListToBeDetermined.push(true)

        this.maskClickAddProduct()
      }).catch(() => {
        this.submitting = false
      })
    },
    saveForm() {
      if (this.submitting) {
        return
      }
      if(this.addForm.warehouseInProdAttrIds.find(e => e === 4 || e === '4')){
        return uni.showToast({
          title:this.$t('订单包含不接受货物，请检查'),
          icon:'error'
        })
      }
      if(!this.addForm.prodTitleZh||!this.addForm.prodTitleEn){
      return uni.showToast({
        title:this.$t('商品名不能未空')+'!',
        icon:'error'
      })
      }
      if(!this.addForm.brand && this.addForm.brand !== 0){
          return uni.showToast({
            title:this.$t('请选择品牌'),
            icon:'error'
          })
      }
      if(!this.addForm.unit){
          return uni.showToast({
            title:this.$t('请选择单位'),
            icon:'error'
          })
      }
      if(this.addForm.warehouseInProdAttrIds.length==0){
          return uni.showToast({
            title:this.$t('请选择商品特性'),
            icon:'error'
          })
      }
      // typeof this.addForm.brand === 'string' && this.getValueBrand(this.addForm.brand, 'id')
      this.addForm.brand = this.selectBrand
      console.log(this.addForm.brand)
      let isbox = false
      let isCartonsNum = false
      let isQuantityAll = false
      let isVolume = false
      let isWeight = false
      this.addForm.orderWarehouseInItemDoList.forEach((v)=>{
        if((!v.c && v.c !== 0)||(!v.k && v.c !== 0)||(!v.g && v.c !== 0)){
          isbox = true
        }
        if(!v.cartonsNum) {
          isCartonsNum = true
        }
        if(!v.quantityAll) {
          isQuantityAll = true
        }
        if(!v.volume || v.volume === '0') {
          isVolume = true
        }
        if(!v.weight || v.weight === '0') {
          isWeight = true
        }
      })
      if(isCartonsNum){
        return uni.showToast({
          title:this.$t('请输入箱数'),
          icon:'error'
        })
      }
      if(isbox && this.detail.type.indexOf(1) === -1){
        return uni.showToast({
          title:this.$t('请输入长宽高'),
          icon:'error'
        })
      }
      if(isVolume && this.detail.type.indexOf(1) === -1){
        return uni.showToast({
          title:this.$t('请输入体积'),
          icon:'error'
        })
      }
      if (isWeight) {
        return uni.showToast({
          title:this.$t('请输入重量'),
          icon:'error'
        })
      }
      // if(isQuantityAll){
      //   return uni.showToast({
      //     title:'请输入个数',
      //     icon:'error'
      //   })
      // }
      let pictureUrls = []
      if(this.addForm.pictureUrls){
        pictureUrls = this.addForm.pictureUrls.map(e => e.url)
      }

      let orderWarehouseInItemDoList = []
      if(this.addForm.orderWarehouseInItemDoList){
        orderWarehouseInItemDoList = this.addForm.orderWarehouseInItemDoList.map(v => {
          const { c, k, g } = v
          // delete v.c
          // delete v.k
          // delete v.g
          // 提交和返回的数据字段不同，在提交前做转换
          if(!v.orderLocationCreateReqVOList && v.orderLocationBackVOList){
            v.orderLocationCreateReqVOList = v.orderLocationBackVOList
          }
          return {
            ...v,
            weight: v.weight,
            volume: v.volume,
            cartonsNum: v.cartonsNum,
            quantityAll: v.quantityAll,
            unit: this.addForm.unit,
            boxGauge: c + '*' + k + '*' + g,
            specificationType: v.specificationType
          }
        })
      }
      const params = {
        prodTitleZh: this.addForm.prodTitleZh,
        prodTitleEn: this.addForm.prodTitleEn,
        type: this.formType === '3' ? 1 : 0,
        brand: this.addForm.brand,
        brandType: this.addForm.brandType,
        feeType: this.addForm.feeType,
        material: this.addForm.material || null,
        prodAttrIds: this.addForm.prodAttrIds?.join(',') || [],
        prodId: this.addForm.prodId,
        orderId: this.orderId,
        orderNo: this.detail.orderNo,
        usageIds: this.addForm.usageIds?.join(',') || '',
        pictureUrls,
        orderWarehouseInItemDoList
      }
      if (this.formType !== '3') {
        params.orderItemId = this.selectListItem.orderItemId
      }
      if (this.formType === '3') {
        const t = this.productListZhObj.find(v => v.titleZh === this.addForm.prodTitleZh)
        params.prodId = t.id
      }
      // if (this.formType === '2') {
      //   params.orderWarehouseInUpdateItemDoList = params.orderWarehouseInItemDoList
      //   delete params.orderWarehouseInItemDoList
      // }
      this.submitting = true
      console.log(params, '------orderWarehouseIn---------')
      if (this.formType === '2') {

        // 修改入仓记录的时候需要携带全部入仓记录
        // 在显示表单的时候过滤只显示特定入仓记录，在修改的时候则获取全部入仓记录，根据ID替换修改后的记录再提交
        let orderWarehouseInUpdateItemDoList = this.orderItemList.find(item => item.orderItemId == this.addForm.orderItemId).orderWarehouseInBackItemDoList
        let updatedItemIndex = orderWarehouseInUpdateItemDoList.findIndex(item => item.id == this.addForm.orderWarehouseInItemDoList[0].id)
        orderWarehouseInUpdateItemDoList[updatedItemIndex] = params.orderWarehouseInItemDoList[0]

        orderWarehouseInUpdateApply({
          ...this.addForm,
          warehouseInProdAttrIds: this.addForm.warehouseInProdAttrIds?.join(',') || [],
          id: undefined,
          brandType: this.addForm.brandType,
          orderId: this.detail.orderId,
          orderItemId: this.addForm.orderItemId,
          orderNo: this.addForm.orderNo,
          num: this.addForm.num,
          prodId: this.addForm.prodId,
          usageIds: this.addForm.usageIds?.join(',') || '',
          "orderWarehouseInUpdateItemDoList": orderWarehouseInUpdateItemDoList,
          pictureUrls: this.addForm.pictureUrls.map(e => e.url)
        }).then(async data => {
          if(this.isEdit){
            this.$store.dispatch(types.SHOW_TOAST, { msg: data.msg || this.$t('订单已入仓，修改入仓信息需要走工作流审核，请耐心等待') });
          }else{
            this.$store.dispatch(types.SHOW_TOAST, { msg: data.msg || this.$t('修改成功') });
          }
          // 因修改接口不支持储位参数，所有修改成功后需要单独修改储位
          let locationList = []
          params.orderWarehouseInItemDoList.forEach(item => {
            locationList = locationList.concat(item.orderLocationCreateReqVOList || [])
          })
          locationList.map(item => {
            item.warehouseInId = this.addForm.id
            item.orderId = this.detail.orderId
            item.orderItemId = this.addForm.orderItemId
          })
          await updateWarehouseInLocation({
            "orderId": this.detail.orderId,
            "orderItemId": this.addForm.orderItemId,
            "orderLocationUpdateReqVOList": locationList,
            "warehouseInId": this.addForm.id
          })

          this.$refs.popup.close()
          this.addForm = {
            unit: '1',
            orderWarehouseInItemDoList: [{cartonsNum:undefined}],
            pictureUrls: [],
            usageIds: [],
          }
          await getOrderWarehouseIn(this.orderId).then(data => this.orderItemList = data.reverse())
          getOrderInfo(this.orderId).then(data => {
            this.detail = data
          })
        }).finally(() => {
          this.submitting = false
        })
        return
      }
      orderWarehouseIn({
        ...params,
        warehouseInProdAttrIds: this.addForm.warehouseInProdAttrIds?.join(',') || []
      }).then(async data => {
        this.$store.dispatch(types.SHOW_TOAST, { msg: this.$t('操作成功') });
        this.$refs.popup.close()
        this.addForm = {
          unit: '1',
          orderWarehouseInItemDoList: [{cartonsNum:undefined}],
          pictureUrls: [],
          usageIds: [],
        }
        await getOrderWarehouseIn(this.orderId).then(data => this.orderItemList = data.reverse())
        this.getPinPai()
        getOrderInfo(this.orderId).then(data => {
          this.detail = data
        })
      }).finally(() => {
        this.submitting = false
      })
    },
    async getInfo(){
      await getOrderWarehouseIn(this.orderId).then(data => this.orderItemList = data.reverse())
      getOrderInfo(this.orderId).then(data => {
        this.detail = data
      })
    },
    next() {
      // let url = './warehousing-confirm?id=' + this.id;
      // if (this.returnLoadId) {
      //   url += '&returnLoadId=' + this.returnLoadId;
      // }
      // // 待办订单
      // if(this.money.length>0){
      //   url+='&money='+JSON.stringify(this.moneyList)
      // }
      // url+='&returnGoodsId='+(this.returnGoodsId.join('|'));
      uni.navigateTo({
        url: './warehousing-confirm?orderId=' + this.orderId + '&target=warehousing'
      });
    },
    getProductNamesByIds(ids){
      const result = []
      ids?.split(',').forEach(e => {
        this.productAttrList.forEach(f => {
          if (parseInt(e) === f.id) {
            result.push(this.isChinese ? f.attrName : f.attrNameEn)
          }
        })
      })
      return result.join('、')
    },
    brandChange(e, value) {
      console.log(e, value, '-------brandChange----------')
    // let brandData = this.brandRang.find(items=>items.titleZh == e)
    this.addForm.brand = e
    this.selectBrand = value
    this.getFeeTypeByCustomerProduct(this.addForm)

    },
    getFeeTypeByCustomerProduct(item) {
      const t = this.productListZhObj.find(v => v.titleZh === this.addForm.prodTitleZh)
	  let brandData = this.brandRang.find(items=>items.titleZh == item.brand)
    console.log(t, brandData, '----brandData---');
	  if(t){
		  if(brandData){
			  getFeeTypeByCustomerProduct({
			    brandId: parseInt(brandData.id),
			    productId: this.addForm.prodId,
			    orderId: this.detail.orderId
			  }).then(data => {
			    this.$set(this.addForm, 'feeType', parseInt(data.feeType))
			    this.$set(this.addForm, 'brandType', parseInt(data.recordMode))
			  })
		  }else{
			  this.$set(this.addForm, 'feeType', 1)
			  this.$set(this.addForm, 'brandType', 1)
		  }

	  }else{
		  this.$set(this.addForm, 'feeType', undefined)
		  this.$set(this.addForm, 'brandType', undefined)
	  }

    }
  }
}
</script>

<style lang="scss" scoped>
.red{
  color: #ff4949;
}
.green{
  color: #13ce66;
}
.wrap {
  padding-bottom: 120px;
  .content-wrap {
    margin: -75px 0 0;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: #fff;
    min-height: calc(100vh - 69px - 120px);
    padding: 0 16px 8px;
    .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: 10px 0px 0px !important;
        .card-btn {
          border-top: 0.5px solid #eee;
          margin-top: 4px;
          padding: 8px;
          overflow: hidden;
          padding-bottom: 0;
          > view {
            float: right;
            height: 32px;
          }
          .mini-btn {
            border-radius: 20px;
            border: 1px solid #007aff;
          }
          .mini-btn + .mini-btn {
            color: #007aff;
            margin-left: 24px;
          }
        }
      }
    }
  }
  .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;
      }
      .add-form {
        ::v-deep .uni-forms-item__label {
          font-weight: bold;
        }
      }
      .add-row-btn {
        border: 0.5px solid #eee;
        text-align: center;
        line-height: 30px;
        border-radius: 5px;
        ::v-deep .uni-icons {
          vertical-align: bottom;
          margin-right: 8px;
        }
      }
      .add-popup-card {
        margin: 16px 0 0 0 !important;
        .card-row {
          display: flex;
          align-items: center;
          margin-bottom: 12px;
          > text {
            padding: 0 6px;
          }
        }
        .delete-btn {
          width: 72px;
          line-height: 30px;
          border: 0.5px solid #007aff;
          text-align: center;
          border-radius: 15px;
          color: #007aff;
          margin-left: auto;
        }
      }
      .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;
        }
      }
    }
  }
}
.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;
  }
}
</style>
