<template>
  <div class="maxContent">
    <!-- 搜索功能  -->
    <div>
      <!-- <div class="SoInput" v-show="searchSo">
        <el-form :model="SoInfoData">
          <el-form-item label="任务编号:">
            <el-input v-model="SoInfoData.questNum" placeholder="任务编号" />
          </el-form-item>
          <el-form-item label="货物编号:">
            <el-input v-model="SoInfoData.b" placeholder="货物编号" />
          </el-form-item>
          <el-form-item label="物流车次:">
            <el-input v-model="SoInfoData.c" placeholder="物流车次" />
          </el-form-item>
        </el-form>

        <div class="SoBtn">
          <el-button icon="el-icon-delete" @click="searchReset()">清 空</el-button>
          <el-button type="primary" icon="el-icon-search" @click="searchChange">搜 索</el-button>
        </div>
      </div> -->
      <!-- 查询按钮 -->
      <!-- 头部右侧按钮模块 -->

      <div class="avue-crud__right">
        <div>
          <el-button type="primary" @click="InventoryTask"
            ><el-icon>
              <Plus />
            </el-icon>
            创建盘点任务</el-button
          >
        </div>
        <div>
          <el-button icon="el-icon-refresh" @click="Refresh" circle></el-button>
          <el-button icon="el-icon-search" @click="searchSo = !searchSo" circle></el-button>
        </div>
      </div>
      <!-- 表格开始 -->
      <el-table
        v-loading="loading"
        element-loading-text="数据正在更新中..."
        :data="ElData"
        row-key="name"
        border
        height="600"
        style="width: 100%"
        ref="tableRef"
        @select-all="selectAll"
        @select="selectChange"
      >
        <el-table-column type="selection" width="55" fixed />
        <el-table-column type="index" fixed width="50" height="100" label="#" align="center" />
        <!-- 
            Type ===1 普通文本
            Type ===2 图片显示
            Type ===3 操作功能
            label:    标题
            width:    宽度
            prop:     数据字段
           -->

        <el-table-column
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :fixed="item.fixed"
          align="center"
          v-for="(item, index) in menuData"
          :key="item.label"
        >
          <el-table-column
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :fixed="item.fixed"
            align="center"
          >
            <template #header>
              <el-input
                @change="InInputSo($event,item)"
                clearable
                v-if="item.type == 5"
                v-model="item.values"
                :placeholder="`请输入${item.label}`"
              />
            </template>

            <template #default="props">
              <img :src="props.row[item.prop]" class="el-Img" v-if="item.type === 2" />

              <div :class="ElBtnClass" v-if="item.type == 3">
                <el-button
             
                  @click="ViewEvent(props.row)"
                  >已盘点明细</el-button
                >
              
                <el-button
            
                  @click="DetailsNotCounted(props.row)"
                  >未盘点明细</el-button
                >
                <el-button
     
                  @click="Discard(props.row)"
                  >废弃</el-button
                >
                <el-button
          
                  @click="extension(props.row)"
                  >延期</el-button
                >
                <el-button
          
                  @click="comparativeData(props.row)"
                  >对比数据</el-button
                >
              </div>
              <div v-if="item.type == 5 && item.prop == 'questNum'">
                {{
                props.row[item.prop] ? props.row[item.prop] : '/'
              }}
                <span class="el-exDc" @click="ExportDC(props.row)">导出</span>
                
              </div>
              <span v-if="item.type == 7">{{
                props.row[item.prop] == 1 ? '全部' : props.row[item.prop] == 2 ? '全仓' : '/'
              }}</span>
              <span v-if="item.type == 8">{{
                props.row[item.prop] == 0
                  ? '创建全部'
                  : props.row[item.prop] == 1
                  ? '开始'
                  : props.row[item.prop] == 2
                  ? '暂停'
                  : props.row[item.prop] == 3
                  ? '结束'
                  : '/'
              }}</span>
              <span v-if="item.type == 1">{{
                props.row[item.prop] ? props.row[item.prop] : '/'
              }}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
    <!-- 表格翻页功能 -->
    <div class="demo-pagination-block TCdemo-pagination-block">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="pageList"
        :disabled="disabled"
        :background="background"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="PageSizeChange"
        @current-change="SizeChange"
      />
    </div>
    <!-- 弹窗详情 -->

    <el-dialog  v-model="PopupDetails" :title="!InventoryState?'盘点数据':'未盘点数据'" width="80%" :before-close="handleClose" :fullscreen="fullScreen">
      <div style="margin-bottom: 10px">
        <div style="display: flex">
          <!-- v-if="TcMInventoryStatus" -->
          <div>
            <!-- v-if="!NotCounted" -->
            <el-button type="primary" @click="BatchdeletePackages">删 除</el-button>
            <el-button type="primary" @click="TcAddData" v-if="Statusjudgment">新 增</el-button>
            <el-button type="primary" @click="InventoryModification">提交修改</el-button>
            <el-button type="primary" @click="ModifyingStatus">修改状态</el-button>
          </div>
          <div style="margin-left: 10px">
            <!-- v-if="NotCounted" -->
            <el-button type="primary" @click="NotInventoried">盘点</el-button>
          </div>

          <div class="fullScreen" @click="BtnfullScreen"> 
            <el-icon><FullScreen /></el-icon>
          </div>

        </div>
      </div>
      <!-- 表格开始 -->
      <el-table
        v-loading="TcPdloading"
        element-loading-text="数据正在更新中..."
        :data="TcPD"
        row-key="name"
        border
        :height="eightyPercentHeight + 'px'"
        style="width: 100%"
        @select-all="TcselectAll"
        @select="TcselectChange"
      >
        <el-table-column type="selection" width="55" fixed />
        <el-table-column type="index" fixed width="50" height="100" label="#" align="center" />

        <!-- 
            Type ===1 普通文本
            Type ===2 图片显示
            Type ===3 操作功能
            label:    标题
            width:    宽度
            prop:     数据字段
           -->

        <el-table-column
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :fixed="item.fixed"
          align="center"
          v-for="(item, index) in InventoryDetails"
          :key="item.label"
        >
          <el-table-column
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :fixed="item.fixed"
            align="center"
          >
            <template #header>
              <el-input
                @change="InputSo(item)"
                clearable
                v-if="item.type == 5 || item.prop == 'categoryName' ||  item.prop == 'materialCode'"
                v-model="item.values"
                :placeholder="`请输入${item.label}`"
              />

              <el-select
                v-model="TcFrom[item.prop]"
                class="m-2"
                placeholder="请选择"
                size="large"
                v-if="item.type == 6"
                @change="TcChenge($event, item)"
                :clearable="true"
              >
                <el-option
                  v-for="item in item.checkarr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </template>
            <template #default="props">
           <span v-if="item.type == 6 && item.prop == 'questStatus'">
                {{
                  props.row[item.prop] == 0
                    ? '待盘点'
                    : props.row[item.prop] == 1
                    ? '已盘'
                    : props.row[item.prop] == 2
                    ? '未盘点'
                    : props.row[item.prop] == 3
                    ? '已排除'
                    : '/'
                }}
              </span>

              <span v-if="item.type == 6 && item.prop === 'questTarget'">
                {{
                  props.row[item.prop] == 1
                    ? '定制品'
                    : props.row[item.prop] == 2
                    ? '零担'
                    : props.row[item.prop] == 3
                    ? '库存品'
                    : '/'
                }}</span
              >

             <span v-if="item.type == 10 && item.prop !='materialCode'">
                <el-input
                  clearable
                  :disabled="props.row.Checkbox"
                  v-model="props.row[item.prop]"
                  :placeholder="`请输入${item.label}`"
                />
              </span>

             <span v-if="item.type==10 && item.prop == 'materialCode'">
            <!-- 下拉搜索 -->
            <el-select v-if="props.row.wLinputState" v-model="props.row.Input" filterable placeholder="请输入物料编码" >
            <el-option
             v-for="item in Wloptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
           />
               </el-select>
                <el-input v-else 
                  @change='wLcheng(props.row,props.row)'
                  clearable
                  :disabled="props.row.Checkbox"
                  v-model="props.row.Input"
                  :placeholder="`请输入${item.label}`"
                />

              </span>
              <div :class="ElBtnClass" v-if="item.type == 3 && !NotCounted">
                <el-button
                  :link="ElButtonS[2].link"
                  :class="ElButtonS[2].class"
                  :auto-insert-space="ElButtonS[2].space"
                  :size="ElButtonS[2].size"
                  :icon="ElButtonS[2].icon"
                  @click="InventoryEditing(props.row)"
                  >编辑</el-button
                >
              </div>

              <span v-if="item.type == 4">{{
                props.row[item.prop] ? props.row[item.prop] : '/'
              }}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
      <template #footer>
        <!-- 表格翻页功能 -->
        <div class="demo-pagination-blockPD demo-pagination-block TCdemo-pagination-block">
          <el-pagination
            v-model:current-page="TccurrentPage"
            v-model:page-size="TcpageSize"
            :page-sizes="pageList"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="Tctotal"
            @size-change="TcPageSizeChange"
            @current-change="TcSizeChange"
          />
        </div>
        <span class="dialog-footer">
          <el-button @click="PopupDetails = false">取消</el-button>
          <el-button type="primary">确定</el-button>
        </span>
      </template>

      <!-- 弹窗里面的详情 -->

      <!-- 状态选择 -->
      <el-dialog
        v-model="InventoryStatus"
        title="状态选择"
        width="70%"
        style="display: flex; flex-direction: column"
      >
        <!-- 定制品单选框 -->
        <el-radio-group
          v-model="WrapBarEditing.radio"
          class="tcradiogroup"
          v-if="!TcStateSwitching"
        >
          <template v-for="(item, index) in radioList" :key="item.label">
            <div class="Tcstate">
              <el-radio @change="TcReac" :label="item.label">{{ item.txt }} </el-radio>
              <el-input-number
                v-model="counting[item.input]"
                :disabled="item.disabled"
                placeholder="数量"
                :min="0"
              />
            </div>
          </template>
        </el-radio-group>

        <!-- 多选框 -->
        <el-checkbox-group v-model="readList" @change="Tcmultiple" v-else>
          <template v-for="(item, index) in radioList" :key="item.label">
            <div class="Tcstate TcstateS">
              <el-checkbox :label="item.txt" @change="Tclist(index + 1)" /><el-input-number
                v-model="counting[item.input]"
                :disabled="item.disabled"
                placeholder="数量"
                :min="0"
              />
            </div>
          </template>
        </el-checkbox-group>

        <span class="Tcstdialog-footer">
          <el-button @click="InventoryStatus = false">取消</el-button>
          <el-button type="primary" @click="StatusDetermination">确定</el-button>
        </span>
      </el-dialog>

      <el-dialog
        v-model="PopupEditing"
        title="信息编辑"
        width="60%"
        @close="closeInformationediting"
      >
        <el-form :model="WrapBarEditing" label-position="right" label-width="100px">
          <el-form-item label="包条:">
            <el-input v-model="WrapBarEditing.orderPackageCode" disabled placeholder="包条" />
          </el-form-item>
          <el-form-item label="订单自编号:">
            <el-input v-model="WrapBarEditing.orderCode" placeholder="请输入订单自编号" />
          </el-form-item>

          <el-form-item label="异常状态:">
            <!-- 定制品单选框 -->
            <el-radio-group
              v-model="WrapBarEditing.radio"
              class="tcradiogroup"
              v-if="!TcStateSwitching"
            >
              <template v-for="(item, index) in radioList" :key="item.label">
                <div class="Tcstate">
                  <el-radio @change="TcReac" :label="item.label">{{ item.txt }} </el-radio>
                  <el-input-number
                    v-model="counting[item.input]"
                    :disabled="item.disabled"
                    placeholder="数量"
                    :min="0"
                  />
                </div>
              </template>
            </el-radio-group>

            <!-- 多选框 -->
            <el-checkbox-group v-model="readList" @change="Tcmultiple" v-else>
              <template v-for="(item, index) in radioList" :key="item.label">
                <div class="Tcstate TcstateS">
                  <el-checkbox :label="item.txt" @change="Tclist(index + 1)" /><el-input-number
                    v-model="counting[item.input]"
                    :disabled="item.disabled"
                    placeholder="数量"
                    :min="0"
                  />
                </div>
              </template>
            </el-checkbox-group>
          </el-form-item>

       

          <el-form-item label="新的货位">
            <el-select-v2
            v-model="WrapBarEditing.groundingPositionCode"
            style="width:240px"
            filterable
            remote
            :remote-method="remoteMethod"
            clearable
            :options="optionss"
            placeholder="请输入货位"
          />
          </el-form-item>
        </el-form>

        <template #footer>
          <span class="dialog-footer">
            <el-button @click="PopupEditing = false">取消</el-button>
            <el-button type="primary" @click="InformationEditing">提交</el-button>
          </span>
        </template>
      </el-dialog>

      <!-- 新增弹窗 -->
      <el-dialog
        v-model="TcDataaddition"
        title="新增"
        width="70%"
        style="display: flex; flex-direction: column"
      >
        <el-form
          :model="Fromnewlyadded"
          label-position="right"
          label-width="100px"
          style="margin-top: 40px"
        >
          <el-form-item label="SKU:">
            <el-input v-model="Fromnewlyadded.sku" placeholder="请输入SKU" />
          </el-form-item>
          <el-form-item label="货物名称:">
            <el-input v-model="Fromnewlyadded.name" placeholder="请输入货物名称" />
          </el-form-item>
          <el-form-item label="货物单位:">
            <el-select v-model="Fromnewlyadded.logpmUnit" class="m-2" placeholder="选择货物单位">
              <el-option
                v-for="item in classification"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="规格:">
            <el-input v-model="Fromnewlyadded.specification" placeholder="请输入规格" />
          </el-form-item>
          <el-form-item label="物料编码:">
            <el-input v-model="Fromnewlyadded.packingSpecification" placeholder="请输入物料编码" />
          </el-form-item>

          <el-form-item label="产品编码:">
            <el-input v-model="Fromnewlyadded.productCode" placeholder="请输入产品编码" />
          </el-form-item>
          <el-form-item label="包装数量:">
            <el-input v-model="Fromnewlyadded.packageNum" placeholder="请输入包装数量" />
          </el-form-item>
        </el-form>

        <span class="Tcstdialog-footer">
          <el-button @click="TcDataaddition = false">取消</el-button>
          <el-button type="primary" @click="TcDataadditionsubmit">确定</el-button>
        </span>
      </el-dialog>
    </el-dialog>
    <!-- 创建盘点弹窗 -->
    <el-dialog
      v-model="InventoryPopup"
      title="创建盘点任务"
      width="30%"
    >
      <el-form :model="formInventory" label-width="120px">
        <el-form-item label="商场名称">
          <el-select
            multiple
            v-model="formInventory.scname"
            class="m-2"
            placeholder="请选择商场"
            size="large"
            @change="formInventoryChange"
          >
            <el-option
              v-for="item in formInventory.select"
              :key="item.id"
              :label="item.clientName"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="品牌">
          <el-input v-model="formInventory.brandName" disabled placeholder="品牌名称" />
        </el-form-item>

        <el-form-item label="盘点时间">
          <el-date-picker
            v-model="formInventory.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="盘点开始时间"
            format="YYYY-MM-DD HH:mm:ss"
            date-format="YYYY/MM/DD ddd"
            value-format="YYYY/MM/DD HH:mm:ss"
            end-placeholder="盘点结束时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">  
          <el-button @click="InventoryPopup = false">取消</el-button>
          <el-button type="primary" @click="InventorySubmit"> 提交 </el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 延期弹窗 -->
    <el-dialog v-model="dialogTabData" title="选择延期时间">
      <el-date-picker
        v-model="TcData"
        type="date"
        placeholder="请选择延期时间"
        value-format="YYYY-MM-DD HH:mm:ss"
      />
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogTabData = false">取消</el-button>
          <el-button type="primary" @click="InventoryDate"> 提交 </el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 对比信息弹窗 -->
    <el-dialog v-model="dialogcontrast" title="对比信息" width="70%">
      <div class="dbExPo">
        <el-button type="primary" @click="MXexport">导出</el-button>
      </div>
      <!-- 表格开始 -->
      <el-table
        v-loading="contrastloading"
        element-loading-text="数据正在更新中..."
        :data="contrastData"
        row-key="name"
        border
        height="600"
        style="width:100%"
        @select-all="contrastselectAll"
        @select="contrastselectChange"
      >
        <el-table-column type="selection" width="55" fixed />
        <el-table-column type="index" fixed width="50" height="100" label="#" align="center" />
        <!-- 
            Type ===1 普通文本
            Type ===2 图片显示
            Type ===3 操作功能
            label:    标题
            width:    宽度
            prop:     数据字段
           -->
        <el-table-column
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :fixed="item.fixed"
          align="center"
          v-for="(item, index) in contrast"
          :key="item.label"
        >
          <el-table-column
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :fixed="item.fixed"
            align="center"
          >
            <template #header>
              <!-- <el-input
                @change="InputSo(item)"
                clearable
                v-if="item.type == 4"
                v-model="item.values"
                :placeholder="`请输入${item.label}`"
              /> -->
            </template>

            <template #default="props">
              <div :class="ElBtnClass" v-if="item.type == 3">
                <!-- 按钮 -->
              </div>
              <span v-if="item.type == 4">{{
                props.row[item.prop] != null ? props.row[item.prop] : '/'
              }}</span>
              <span v-if="item.type == 6">{{
                props.row[item.prop] == null ? 0 : props.row[item.prop]
              }}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 数据对比结束 -->
  </div>
</template>

<script setup>
import {
  $_getContrastInfo,
  $_getDetailInfo,
  $_updateDate,
  $_updateDetailInfo,
  $_updateQuestChildInfo,
  $_getQuestChildInfo,
  getDictList,
  getTaskQuestPage,
  postAddtaskQuest,
  $_materialList,
  $_submit,
  $_questDetailIds,
  $_exportGetContrastInfo,
  $_getList,
  $_postBatchDelete,
} from '@/api/distribution/createTask';
import { ElMessageBox } from 'element-plus'
import { ElMessage } from 'element-plus';
import { downloadXls } from '@/utils/util';
import { getDictionaryBiz } from '@/api/system/dict';
import { ref } from 'vue';
const wLinput=ref(null);//物料编码搜索框
const wLinputState=ref(false);//标记是否显示下拉框
const SoInfoData = ref({}); //搜索框参数
const searchSo = ref(false); //搜索框
const ElData = ref([]); //表格的值
const TcPD = ref([]); //弹窗盘点表格得值
const currentPage = ref(1); // 默认页码
const pageSize = ref(40); // 默认每一页几条
const dialogTabData = ref(false); //延期弹窗
const TccurrentPage = ref(1); // 默认页码
const TcpageSize = ref(50); // 默认每一页几条
const Tctotal = ref(null); //明细页码总数
const TcData = ref(null); //延期时间
const pageList = ref([50, 100, 200, 500, 1000]); // 选择每页显示多少条
const background = ref(true); // 是否开启背景颜色
const disabled = ref(false); // 是否禁止使用页码功能
const total = ref(0); //页码总数
const loading = ref(false); //表格加载Load
const PopupDetails = ref(false); //弹窗详情是否展示
const InventoryPopup = ref(false); //创建判断任务弹窗
const formInventory = ref({}); //盘点任务表单_
const TcPdloading = ref(false); //弹窗盘点数据
const PdRow = ref(null); //盘点任务选中
const TcFrom = ref({}); //弹窗搜索
const row = ref({}); //选择当前列
const Tcrow = ref(); //弹窗当前行
const WrapBarEditing = ref({}); //弹窗数据编辑
const PopupEditing = ref(false); //弹窗编辑
const ElBtnClass = ref(null);
const UncountedDetails=ref();//未盘点明细盘点必须参数
const contrastData = ref([]); //对比数据表格
const dialogcontrast = ref(false); //对比数据弹窗
const contrastloading = ref(false); //对比数据表格加载
const Inventoryrow = ref({}); //详情编辑响应式临时数据
const NotCounted = ref(false); //为盘点信息
const UncheckedRow = ref({}); //未盘点当前行存储数据
const InventoryStatus = ref(false); //盘点中的状态修改
const InventoryInput = ref(null); //用来存储盘点状态定制品选怎的第几个input
const InventoryState=ref(false);//盘带状态修改保存的数据
const TcMInventoryStatus = ref(true); //盘点弹窗按钮权限控制
const TcStatusModification = ref(false); //表示当前在修改状态
const TcStateSwitching = ref(false); //默认表示定制品状态
const TcnumStatu = ref(false); //表示零担,库存品,初始化状态
const readList = ref([]); //多选框
const TcReaJoin = ref([]); //零担库存品状态10，20，30...
const TcDataaddition = ref(false); //数据新增弹唱
const Fromnewlyadded = ref({}); //数据新增
const screenHeight = ref(0); // 屏幕高度
const eightyPercentHeight = ref(0); // 80% 高度
const Statusjudgment = ref(false); //新增按钮
const DbEx=ref(null);//对比明细导出
const fullScreen=ref(false);//是否全屏
const radioList = ref([
  { label: 0, txt: '在库', input: 'stockNum', disabled: true },
  { label: 1, txt: '破损', input: 'wornNum', disabled: true },
  { label: 2, txt: '丢失', input: 'lossNum', disabled: true },
  { label: 3, txt: '不可修复', input: 'noRepairNum', disabled: true },
  { label: 4, txt: '已配送', input: 'deliveNum', disabled: true },
  { label: 5, txt: '未入库', input: 'noReceivedNum', disabled: true },
]);
const counting = ref({});
const options = [
  {
    value: 1,
    label: '定制品',
  },
  {
    value: 2,
    label: '零担',
  },
  {
    value: 3,
    label: '库存品',
  },
];
// 新增物品分类
const classification = ref([]);
// 菜单表头
const menuData = ref([
  {
    prop: 'questNum',
    label: '盘点任务编号',
    type: 5,
    values: '',
    width: '200',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'warehouseName',
    label: '仓库名称',
    type: 4,
    values: '',
    width: '100',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'marketName',
    label: '商城名称',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'marketName',
    label: '收货单位',
    type: 4,
    values: '',
    width: '200',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'brandName',
    label: '品牌名称',
    type: 4,
    values: '',
    width: '200',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'startTime',
    label: '任务开始时间',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'endTime',
    label: '任务结束时间',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'questType',
    label: '类型',
    type: 7,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'questStatus',
    label: '状态',
    type: 8,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: '',
    label: '操作',
    type: 3,
    values: '',
    width: '430',
    checkarr: [],
    fixed: 'right',
    search: false,
    head: true,
  },
]); //表头结构

// 弹窗盘点
const InventoryDetails = ref([
{
    prop: 'orderCode',
    label: '订单自编号',
    type: 5,
    values: '',
    width: '230',
    checkarr: [],
    fixed: true,
    search: true,
    head: true,
  },
  {
    prop: 'orderPackageCode',
    label: '包条',
    type: 5,
    values: '',
    width: '200',
    checkarr: [],
    fixed: true,
    search: true,
    head: true,
  },

  {
    prop: 'questTarget',
    label: '品类',
    type: 6,
    values: '',
    width: '100',
    checkarr: [
      {
        value: 1,
        label: '定制品',
      },
      {
        value: 2,
        label: '零担',
      },
      {
        value: 3,
        label: '库存品',
      },
    ],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'questStatus',
    label: '盘点状态',
    type: 6,
    values: '',
    width: '100',
    checkarr: [
      {
        value: 0,
        label: '待盘点',
      },
      {
        value: 1,
        label: '已盘',
      },
      {
        value: 2,
        label: '未盘点',
      },
      {
        value: 3,
        label: '已排除',
      },
    ],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'positionCode',
    label: '货位',
    type: 5,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'materialName',
    label: '物料名称',
    type: 5,
    values: '',
    width: '260',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'trayCode',
    label: '托盘码',
    type: 5,
    values: '',
    width: '260',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'trayName',
    label: '托盘名称',
    type: 5,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'inventoryPerson',
    label: '盘点人',
    type: 5,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'inventoryDate',
    label: '盘点时间',
    type: 5,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'firsts',
    label: '一级品类',
    type: 10,
    values: '',
    width: '260',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'second',
    label: '二级品类',
    type: 10,
    values: '',
    width: '260',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'thirdProduct',
    label: '三级品类',
    type: 10,
    values: '',
    width: '260',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },

  {
    prop: 'categoryName',
    label: '产品名称',
    type: 10,
    values: '',
    width: '260',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'materialCode',
    label: '物料编码',
    type: 10,
    values: '',
    width: '260',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'brandName',
    label: '品牌',
    type: 5,
    values: '',
    width: '250',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: '',
    label: '操作',
    type: 3,
    values: '',
    width: '120',
    checkarr: [],
    fixed: 'right',
    search: false,
    head: true,
  },
]);
// 对比数据表格结构
const contrast = ref([
  {
    prop: 'orderCode',
    label: '订单自编号',
    type: 4,
    values: '',
    width: '260',
    checkarr: [],
    fixed: true,
    search: true,
    head: true,
  },
  {
    prop: 'orderPackageCode',
    label: '包条',
    type: 5,
    values: '',
    width: '260',
    checkarr: [],
    fixed: true,
    search: true,
    head: true,
  },
  {
    prop: 'trayCode',
    label: '托盘码',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'trayName',
    label: '托盘名称',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'brandName',
    label: '品牌',
    type: 4,
    values: '',
    width: '250',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'mallName',
    label: '商场名称',
    type: 4,
    values: '',
    width: '250',
    checkarr: [],
    fixed: false,
    search: true,
    head: true,
  },
  {
    prop: 'customerName',
    label: '客户名称',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'thirdProduct',
    label: '三级品',
    type: 4,
    values: '',
    width: '350',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'materialName',
    label: '物料名称',
    type: 4,
    values: '',
    width: '200',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'totalNumber',
    label: '总件数',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'handQuantity',
    label: '在库件数',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'positionCode',
    label: '货区-货架-货位',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'inventoryPerson',
    label: '盘点人',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'inventoryDate',
    label: '盘点时间',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'questNum',
    label: '盘点件数',
    type: 6,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'differenceNum',
    label: '差异数',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },

  {
    prop: 'groundingPositionCode',
    label: '新货位',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
  {
    prop: 'questStatusName',
    label: '货物状态',
    type: 4,
    values: '',
    width: '150',
    checkarr: [],
    fixed: false,
    search: false,
    head: true,
  },
]);
// 按钮配置
const ElButtonS = ref([
  // 1.link    切换按钮样式(文本模式-false ,按钮模式-tre)
  // 2.class   按钮样式名(用于切换按钮样式)
  // 3.space   是否开启按钮文子直接间距(true开启 ,false关闭)
  // 4.size    按钮尺寸默认小尺寸('large'| 'default'| 'small')
  // 5.icon    按钮图标
  // 6.table   按钮名称
  {
    link: false,
    class: 'el-btn-view',
    space: true,
    size: 'small',
    icon: 'el-icon-view',
    table: '详情',
  },
  {
    link: false,
    class: 'el-btn-view',
    space: true,
    size: 'small',
    icon: 'el-icon-view',
    table: '延期',
  },
  {
    link: false,
    class: 'el-btn-view',
    space: true,
    size: 'small',
    icon: 'el-icon-view',
    table: '编辑',
  },
  {
    link: false,
    class: 'el-btn-view',
    space: true,
    size: 'small',
    icon: 'el-icon-view',
    table: '对比数据',
  },
]);
// 页面初始化请求

const IndexPd=(val)=>{
  let Data = {
    current: currentPage.value, //页码
    size: pageSize.value, //条数
    ...val
  };
  getTaskQuestPage(Data).then(res => {
    console.log(res, '获取盘点列表');
    if (res.data.code == 200) {
      total.value = res.data.data.total;
      loading.value = false; //关闭表格加载
      res.data.data.records; //初始化盘点列表
      if (res.data.data.records) {
        res.data.data.records.forEach(items => {
          items.marketName = items.list.map(item => item.refName).join(','); //商场名称
          items.brandName = items.list.map(item => item.brandName).join(','); //品牌名称
        });
        console.log(ElData.value, 'ElData.value');
      }
      ElData.value = res.data.data.records;
    }
  });
}
// 弹窗全屏
const BtnfullScreen=()=>{
  fullScreen.value=!fullScreen.value;
}

function onLoad() {
   // 在组件挂载后获取屏幕高度
  screenHeight.value = window.innerHeight;
   // 计算80%的高度
  eightyPercentHeight.value = screenHeight.value * 0.8;
  getDictionaryBiz('logpm_unit').then(res => {
    //异常类型
    console.log(res, '字典返回值');

    if (res.data.data.length) {
      res.data.data.forEach(item => {
        classification.value.push({
          value: item.dictKey,
          label: item.dictValue,
        });
      });
    }
  });

  loading.value = true; //开启表格加载
  IndexPd()
  // let Data = {
  //   current: currentPage.value, //页码
  //   size: pageSize.value, //条数
  //   questNum: 'PDLS20231124625',
  // };
  // getTaskQuestPage(Data).then(res => {
  //   console.log(res, '获取盘点列表');
  //   if (res.data.code == 200) {
  //     total.value = res.data.data.total;
  //     loading.value = false; //关闭表格加载
  //     res.data.data.records; //初始化盘点列表
  //     if (res.data.data.records) {
  //       res.data.data.records.forEach(items => {
  //         items.marketName = items.list.map(item => item.refName).join(','); //商场名称
  //         items.brandName = items.list.map(item => item.brandName).join(','); //品牌名称
  //       });
  //       console.log(ElData.value, 'ElData.value');
  //     }
  //     ElData.value = res.data.data.records;
  //   }
  // });
}
// 调用页面初始化获取数据
onLoad();


// 首页搜索框
const InInputSo=(values,val)=>{
  console.log(values,val);
  let data={
    [val.prop]:values
  }
  console.log(data);
  IndexPd(data)
}


// 搜索框
const InputSo = val => {
  TcPdloading.value=true
  console.log(val, '搜索框接收的值');
  let data = {};
  console.log(row.value,'row.value');
  data.current = TccurrentPage.value;
  data.size = TcpageSize.value;
  // if (val.prop == 'categoryName') {
  //   //查询产品名称
  //   data.name = val.values;
  //   $_materialList(data).then(res => {
  //     console.log(res, '查询的返回值');
  //     if (res.data.data.records.length) {
  //       Tctotal.value = res.data.data.total;
  //       res.data.data.records.forEach(item => {
  //         item.Checkbox = true;
  //       });
  //       TcPdloading.value = false;
  //       console.log(res, '明细返回值');
  //       TcPD.value = res.data.data.records;
  //     } else {
  //       Statusjudgment.value = true; //显示新增按钮
  //       TcPD.value = res.data.data.records;
  //       ElMessage({
  //         message: '暂未查询到内容',
  //         type: 'warning',
  //       });
  //     }
  //   });
   
  //   return;
  // }
  // if (val.prop == 'materialCode') {
  //   //查询物料编码
  //   data.sku = val.values;
  //   $_materialList(data).then(res => {
  //     console.log(res, '查询的返回值');
  //     if (res.data.data.records.length) {
  //       Tctotal.value = res.data.data.total;
  //       res.data.data.records.forEach(item => {
  //         item.Checkbox = true;
  //       });
  //       TcPdloading.value = false;
  //       console.log(res, '明细返回值');
  //       TcPD.value = res.data.data.records;
  //     } else {
  //       Statusjudgment.value = true; //显示新增按钮
  //       TcPD.value = res.data.data.records;
  //       ElMessage({
  //         message: '暂未查询到内容',
  //         type: 'warning',
  //       });
  //     }
  //   });
  //   return;
  // }

  // if (val.prop != 'categoryName' || val.prop != 'materialCode') {
    let dataS = {
      questNum: UncountedDetails.value.questNum,
      questId: UncountedDetails.value.id,
      current: TccurrentPage.value, //页码
      size: TcpageSize.value, //条数
      [val.prop]: val.values,
    };
    console.log(dataS, '要提交的数据');
    $_getDetailInfo(dataS).then(res => {
      Tctotal.value = res.data.data.total;
      res.data.data.records.forEach(item => {
        item.Checkbox = true;
        item.wLinputState=false;
        item.Input=null
      });
      TcPdloading.value = false;
      console.log(res, '明细返回值222');
      TcPD.value = res.data.data.records;
    });
  // }
};
// 点击新增按钮
const TcAddData = () => {
  TcDataaddition.value = true; //新增弹窗显示
};
// 对比数据导出公共函数
const DbExTc=(data)=>{
  $_exportGetContrastInfo({
    id:data.id,
    questNum:data.questNum
  }).then(res=>{
    console.log(res,'导出');
    downloadXls(res.data,  `${data.questNum}对比明细.xlsx`)
  })
}
// 盘点对比导出
const ExportDC = (val) => {
  // 触发下载函数
console.log(val);
DbExTc(val)
};
// 对比数据导出
const MXexport=()=>{
  // 触发下载函数
DbExTc(DbEx.value)
}


// 新增任务按钮(搜索不到出现此按钮)
const TcDataadditionsubmit = () => {
  console.log(Fromnewlyadded.value);
  const validations = [
    { property: 'sku', message: 'SKU为空' },
    { property: 'name', message: '货物名称为空' },
    { property: 'logpmUnit', message: '货物单位为空' },
    { property: 'specification', message: '规格为空' },
    { property: 'packingSpecification', message: '物料编码为空' },
    { property: 'productCode', message: '产品编码为空' },
    { property: 'packageNum', message: '包装数量为空' },
  ];

  for (const validation of validations) {
    if (!Fromnewlyadded.value[validation.property]) {
      ElMessage({
        message: validation.message,
        type: 'warning',
      });
      return;
    }
  }
  TcDataaddition.value = false; //关闭弹窗
  $_submit({ ...Fromnewlyadded.value }).then(res => {
    console.log(res, '添加物品返回值');
    if (res.data.code == 200) {
      ElMessage({
        message: res.data.msg,
        type: 'success',
      });
    }
  });
  Statusjudgment.value = false; //点击确定之后关闭按钮
};


// 盘点任务单选
const selectChange = (select, val) => {
  console.log('触发了选择');
  console.log(select, val);
  PdRow.value = select;
};
// 表格筛选
const selectAll = val => {
  console.log(val, '触发了选择');
};
// 弹窗详情选中（全选）
const TcselectAll = (selectAll, val) => {
  Tcrow.value = selectAll;
  if (!selectAll.length) {
    TcPD.value.forEach(item => {
      item.Checkbox = !item.Checkbox;
    });
  } else {
    selectAll.forEach(item => {
      item.Checkbox = !item.Checkbox;
    });
  }
  console.log(Tcrow.value, '全选复选框');
  // 状态修改
};
// 弹窗详情单选
const TcselectChange = (selectAll, val) => {
  console.log(val, '当前选中的');
  console.log(Tcrow.value);
  val.Checkbox = !val.Checkbox; //开启修改
  Tcrow.value = selectAll;
};
// 延期
const extension = val => {
  row.value = val;
  dialogTabData.value = true;
};

// 批量删除盘点任务
const BatchDelete = () => {};


// 延期提交
const InventoryDate = () => {
  console.log(TcData.value, '延期');
  $_updateDate({
    id: row.value.id,
    startTime: row.value.startTime,
    endTime: TcData.value,
  }).then(res => {
    dialogTabData.value = false;
    if (res.data.code == 200) {
      ElMessage({
        showClose: true,
        message: res.data.msg,
        type: 'success',
      });
    }
    onLoad();
    console.log(res, '延期成功返回值');
  });
};

// 提交修改
const InventoryModification = () => {
  console.log(Tcrow.value,'Tcrow.value');
  if (!Tcrow.value) {
    ElMessage({
      showClose: true,
      message: '暂未选择信息',
      type: 'warning',
    });
    return;
  }
  let data = [];
  Tcrow.value.forEach(item => {
    data.push({
      id: item.id,
      firsts: item.firsts,
      second: item.second,
      thirdProduct: item.thirdProduct,
      categoryName: item.categoryName,
      questId: item.questId,
      questNum: row.value.questNum,
      name:item.Input,
      questStatus: 1
    });
  });
  console.log(data, '要提交的数据');
  $_updateDetailInfo(data).then(res => {
    TcViewEvent(row.value); //修改之后刷新页面
    console.log(res, '修改成功之后的返回值');
    if (res.data.code == 200) {
      ElMessage({
        showClose: true,
        message: res.data.msg,
        type: 'success',
      });
    }
  });
};
// 对比数据按钮
const comparativeData = val => {
  dialogcontrast.value = true; //显示对比数据表格
  contrastloading.value = true; //开启表格加载
  console.log(val, '对比数据当前行');
  DbEx.value=val;//存储当前行数据用于导出
  let data = {};
  data.questNum = val.questNum;
  data.questId = val.id;
  $_getContrastInfo(data).then(res => {
    console.log(res, '对比数据返回值');
    contrastData.value = res.data.data;
    contrastloading.value = false; //关闭表格加载
  });
};
// 重置搜索表单
const searchReset = () => {
  SoInfoData.value = {};
};

const TcViewEvent = (val,Inso) => {
  Statusjudgment.value = false; //关闭新增按钮
  TcPdloading.value = true;
  console.log(val, '要传递的对象');
  let data = {
    questNum: val.questNum,
    questId: val.id,
    current: TccurrentPage.value, //页码
    size: TcpageSize.value, //条数
    questStatus: 1,
    ...Inso
  };
  console.log(data, '要提交的数据');

  $_getDetailInfo(data).then(res => {
    Tctotal.value = res.data.data.total;
    res.data.data.records.forEach(item => {
      item.Checkbox = true;
      item.wLinputState=false;
      item.Input=null
    });
    TcPdloading.value = false;
    console.log(res, '明细返回值');
    TcPD.value = res.data.data.records;
  });
};
// 点击详情按钮
const ViewEvent = val => {
  InventoryDetails.value.forEach(item=>{
    item.values=null
  })
  InventoryState.value=false;//修改标题（盘点数据）
  TccurrentPage.value = 1; //重置页码
  NotCounted.value = false; //关闭未盘点
  row.value = val;
  PopupDetails.value = true;
  TcPdloading.value = true;
  console.log(val, '明细');
  if (val.questStatus != 1) {
    TcMInventoryStatus.value = false; //表示当前盘点任务不属于盘点中,关闭所有按钮权限
  } else {
    TcMInventoryStatus.value = true;
  }
  TcViewEvent(row.value);
};
// 废弃按钮
const Discard=(val)=>{
  console.log(val);
  let data=[]
  data.push(val.id)
 let ids = data.join(',')
     console.log(data);
     ElMessageBox.confirm('是否废弃该盘点任务?')
    .then(() => {
      $_postBatchDelete({ids}).then(res=>{
      console.log(res,'删除成功');
      if(res.data.code==200){
        ElMessage({
        message: '删除成功.',
        type: 'success',
       })
      }
      IndexPd()
    })
    })
    .catch(() => {
      // catch error
    })



}
// 未盘点数据请求
const NotCountedFn = (row,Inso,type=0) => {
  TcPdloading.value = true;
  $_getDetailInfo({
    questStatus: type,
    questNum: row.questNum,
    questId: row.id,
    current: TccurrentPage.value, //页码
    size: TcpageSize.value, //条数
    ...Inso
  }).then(res => {
    TcPdloading.value = false;
    console.log(res, '未盘点明细返回值');
    res.data.data.records.forEach(item => {
      item.Checkbox = true;
      item.wLinputState=false;
      item.Input=null
    });
    TcPD.value = res.data.data.records;
    Tctotal.value = res.data.data.total; //总页码
  });
};

// 未盘点明细
const DetailsNotCounted = row => {
  InventoryDetails.value.forEach(item=>{
    item.values=null
  })
  UncountedDetails.value=row;
  InventoryState.value=true;//修改弹窗标题（未盘点数据），
  TcFrom.value={};//重置搜索
  TccurrentPage.value = 1; //重置页码
  UncheckedRow.value = row; //存储当前点击行的数据
  console.log(row.value,'存储好的数据');
  NotCounted.value = true; //展开未盘点
  TcPdloading.value = true;
  PopupDetails.value = true;
  NotCountedFn(row);
  row.value = row;
  console.log(row.value,'未盘点明细存储值');
};









// 未盘点转已盘点按钮
const NotInventoried = val => {
  if (!Tcrow.value) {
    ElMessage({
      showClose: true,
      message: '暂未选择信息',
      type: 'warning',
    });
    return;
  }
  let data = [];
  console.log(UncheckedRow.value, '提交盘点了');
  Tcrow.value.forEach(item => {
    data.push({
      id: item.id,
      questStatus: (item.questStatus = 1),
      questId: item.questId,
      questNum:UncheckedRow.value.questNum,
    });
  });
  console.log(data, '未盘点处理好的值');
  $_updateDetailInfo(data).then(res => {
    console.log(res, '未盘点转为已盘点');
    if (res.data.code == 200) {
      ElMessage({
        showClose: true,
        message: res.data.msg,
        type: 'success',
      });
      NotCountedFn(UncheckedRow.value);
    }
  });
};
// 对盘点中的参数,修改状态
const ModifyingStatus = () => {
  if (!Tcrow.value) {
    ElMessage({
      showClose: true,
      message: '暂未选择信息',
      type: 'warning',
    });
    return;
  }
  counting.value = {}; //重置数据值对象
  // 修改过的参数回显
  $_getQuestChildInfo({
    questNum: row.value.questNum,
    id: Tcrow.value[0].id,
  }).then(res => {
    console.log(res, '数量回显');
    if (res.data.data.length) {
      res.data.data.forEach((item, index) => {
        counting.value[radioList.value[index].input] = item.questNum;
      });
    }
  });

  InventoryStatus.value = true; //展开状态选择
  if (Tcrow.value[0].questTarget == 1) {
    //表示当前是定制品
    TcStateSwitching.value = false;
  } else {
    TcStateSwitching.value = true; //表示当前是零担，库存品
  }
};

// 删除盘点任务包件(只能删除已盘)
const BatchdeletePackages = () => {
  const invalidQuestStatusIndex = Tcrow.value.findIndex(item => item.questStatus !== 1);
  if (invalidQuestStatusIndex !== -1) {
    // 存在状态不为1的元素
    ElMessage({
      message: '只能删除已盘',
      type: 'warning',
    });
    return;
  }

  const data = {
    questDetailIds: Tcrow.value.map(item => item.id),
    questId: Tcrow.value[0]?.questId,
    questNum: row.value.questNum,
  };
  console.log(data, '要删除处理好的数据');
  $_questDetailIds(data).then(res => {
    TcViewEvent(row.value);
    console.log(res, '删除后的返回值');
    if (res.data.code === 200) {
      ElMessage({
        message: res.data.msg,
        type: 'success',
      });
    }
  });
};

// 信息编辑弹窗关闭的时候重置保存的数据
const closeInformationediting = () => {
  Tcrow.value = null;
};
// 盘点状态选择
const TcReac = val => {
  console.log(val);
  InventoryInput.value = val; //存储当前选择的是第几个input
  if (!TcStateSwitching.value) {
    //定制品规则 可以批量操作
    radioList.value.forEach(item => {
      item.disabled = true;
      counting.value[item.input] = 0;
    });
    radioList.value[val].disabled = false;
    counting.value[radioList.value[val].input] = 1; //定制品选中的值默认为1
  } else {
    //零担,库存品规则
    if (!TcnumStatu.value) {
      radioList.value.forEach(item => {
        item.disabled = true;
        counting.value[item.input] = 0;
      });
      TcnumStatu.value = true; //表示当前零担库存品已经初始化了
    } else {
      radioList.value[val].disabled = false;
    }
  }
};
// 零担，库存品多选处理
function updateFlag(ids, contents, newFlag) {
  contents.forEach((content, index) => {
    if (ids.includes(content.txt)) {
      content.disabled = newFlag;
      counting.value[content.input] = 1;
    } else {
      content.disabled = !newFlag;
      counting.value[content.input] = 0;
    }
  });
  console.log(radioList.value);
}
// 状态多选操作
const Tcmultiple = val => {
  updateFlag(val, radioList.value, false); //吧选中的状态设为可以修改
};

// 盘点状态确认修改
const StatusDetermination = () => {
  console.log(row.value, 'row.value');
  if (!TcStateSwitching.value) {
    //为假表示当前走定制品规则
    //定制品规则
    let InputMax = counting.value[radioList.value[InventoryInput.value].input]; //存储当前输入框最大值
    if (InputMax > Tcrow.value[0].questTarget) {
      ElMessage({
        showClose: true,
        message: `总数[${InputMax}]不能超过在库数量[${Tcrow.value[0].questTarget}]`,
        type: 'warning',
      });
      return;
    }
    console.log(counting.value, '状态输入框的值');
    let start = Tcrow.value.questTarget;
    let data = [];
    const filteredData = Tcrow.value.filter(item => item.name == start); //
    filteredData.forEach(item => {
      console.log(item);
      data.push({
        stockNum: counting.value.stockNum, //在库数量
        lossNum: counting.value.lossNum, //丢失数量
        deliveNum: counting.value.deliveNum, //配送数量
        wornNum: counting.value.wornNum, //破损数量
        noRepairNum: counting.value.noRepairNum, //不可修复数量
        noReceivedNum: counting.value.noReceivedNum, //未入库数量
        questNum: row.value.questNum, //任务编号
        questId: item.questId,
        allocationId: item.allocationId, //上架后的库位id
        id: item.id,
        cargoName: Number(InventoryInput.value + 1 + '0'), //状态
      });
    });
    console.log(data, '处理好的数据');

    $_updateQuestChildInfo(data).then(res => {
      console.log(res, '盘点状态修改完成的返回值');
      if (res.data.code == 200) {
        ElMessage({
          showClose: true,
          message: res.data.msg,
          type: 'success',
        });
        InventoryStatus.value = false; //关闭状态选择
        TcViewEvent(row.value);
      }
    });
  } else {
    // 零担,库存品规则
    console.log(counting.value, 'input输入框的数据');
    console.log(Tcrow.value, 'questId');
    let data = [
      {
        stockNum: counting.value.stockNum, //在库数量
        wornNum: counting.value.wornNum, //破损数量
        lossNum: counting.value.lossNum, //丢失数量
        noRepairNum: counting.value.noRepairNum, //不可修复数量
        deliveNum: counting.value.deliveNum, //配送数量
        noReceivedNum: counting.value.noReceivedNum, //未入库数量
        questNum: row.value.questNum, //任务编号
        questId: Tcrow.value[0].questId, //零担和库存品一次只能操作第一条数据，这里暂取第一个选中的数据，后续的数据无效操作
        allocationId: Tcrow.value[0].allocationId, //上架后的库位id
        id: Tcrow.value[0].id,
        cargoName: TcReaJoin.value.join(), //状态
      },
    ];
    let sum =
      data[0].stockNum +
      data[0].wornNum +
      data[0].lossNum +
      data[0].noRepairNum +
      data[0].deliveNum +
      data[0].noReceivedNum;
    if (sum > Tcrow.value[0].stockNum) {
      ElMessage({
        showClose: true,
        message: `总数[${sum}]不能超过在库数量[${Tcrow.value[0].stockNum}]`,
        type: 'error',
      });
      return;
    }
    console.log(data, '处理好的数据');
    $_updateQuestChildInfo(data).then(res => {
      console.log(res, '盘点状态修改完成的返回值');
      if (res.data.code == 200) {
        ElMessage({
          showClose: true,
          message: res.data.msg,
          type: 'success',
        });
        InventoryStatus.value = false; //关闭状态选择
        TcViewEvent(row.value);
      }
    });
  }
};


const optionss = ref([])
const list =  ref([])
const remoteMethod = (query) => {
  if (query !== '') {
      optionss.value = list.value.filter((item) => {
        return item.label.toLowerCase().includes(query.toLowerCase())
      })
  } else {
    optionss.value = []
  }
}
// 多选数据状态处理
const Tclist = val => {
  console.log(val);
  if (val >= 1 && val <= 6 && !radioList.value[val - 1].disabled) {
    if (!TcReaJoin.value.includes(val * 10)) {
      TcReaJoin.value.push(val * 10);
    }
  } else {
    const index = TcReaJoin.value.indexOf(val * 10);
    if (index !== -1) {
      TcReaJoin.value.splice(index, 1);
    }
  }
  console.log(TcReaJoin.value, '处理好的数据');
};
// 物料编码

const Wllist =  ref([])
const WLCode = (query) => {
  if (query !== '') {
      optionss.value = Wllist.value.filter((item) => {
        return item.label.toLowerCase().includes(query.toLowerCase())
      })
  } else {
    optionss.value = []
  }
}
// 物料列表
const Wloptions = ref([])
// 物料信息搜索
const wLcheng=(val,info)=>{
  console.log(val.undefined);
  console.log(info,'信息');
  $_materialList({
    name:val.undefined
  }).then(res=>{
    console.log(res,'物料查询');
    if(!res.data.data.records.length){
        ElMessageBox.confirm('暂无数据是否新增?')
    .then(() => {
      TcDataaddition.value=true
    })
    .catch(() => {
      // catch error
    })
    }else{
      // productCode
      // wLinputState.value=true;//开启下拉选择

      info.wLinputState=true;
      // Wloptions.value 下拉选择变量
      res.data.data.records.forEach(item=>{
        Wloptions.value.push(
          {
            label:item.name,
            value:item.name 
          }
        )
      })

    }
  })
}

// 盘点详情编辑
const InventoryEditing = val => {
  $_getList({
    current: 1, //页码
    size: 10000, //条数
    warehouseId:val.warehouseId,
  }).then(res=>{
    console.log(res);
    
    if(res.data.data.records){
  list.value=   res.data.data.records.map((item) => {  
  return { value:`${item.id}`, label: `${item.qrCode}` }
})
console.log(list.value);
    }
  })


  counting.value = {}; //重置数据值对象
  WrapBarEditing.value.radio = null;
  readList.value = [];
  // 修改过的参数回显
  $_getQuestChildInfo({
    questNum: row.value.questNum,
    id: val.id,
  }).then(res => {
    console.log(res, '数量回显');
    if (res.data.data.length) {
      res.data.data.forEach((item, index) => {
        counting.value[radioList.value[index].input] = item.questNum;
      });
    }
  });

  Tcrow.value = val;
  if (val.questTarget == 1) {
    TcStateSwitching.value = false; //定制品规则
  } else {
    TcStateSwitching.value = true; //库存品，零担规则
  }
  PopupEditing.value = true;
  Inventoryrow.value = val; //存一份响应式数据
  const copiedObject = Object.assign({}, val);
  console.log(val, '盘点详情编辑');
  WrapBarEditing.value.orderPackageCode = copiedObject.orderPackageCode; //包条
  WrapBarEditing.value.orderCode = copiedObject.orderCode; //订单自编号
  WrapBarEditing.value.positionCode = copiedObject.positionCode; //货位
};
// 信息编辑弹窗提交
const InformationEditing = () => {
  TcPdloading.value = true;
  console.log(WrapBarEditing.value,'WrapBarEditing.value');
  let data = [
    {
      orderCode: WrapBarEditing.value.orderCode, //订单编号
      groundingPositionCode: WrapBarEditing.value.groundingPositionCode, //新的货位
      stockNum: counting.value.stockNum, //在库数量
      lossNum: counting.value.lossNum, //丢失数量
      deliveNum: counting.value.deliveNum, //配送数量
      wornNum: counting.value.wornNum, //破损数量
      noRepairNum: counting.value.noRepairNum, //不可修复数量
      noReceivedNum: counting.value.noReceivedNum, //未入库数量
      allocationId: Tcrow.value.allocationId, //上架后的库位id
      questId: Tcrow.value.questId,
      questNum: row.value.questNum, //任务编号
      id: Tcrow.value.id,
    },
  ];
  if(WrapBarEditing.value.groundingPositionCode){
   let val = list.value.find(obj => obj.value == WrapBarEditing.value.groundingPositionCode);
   console.log(data,'货位处理好的数据');
    data[0].groundingAllocationId=val.value;
    data[0].groundingPositionCode=val.label
  }
  if (!TcStateSwitching.value) {
    //为假表示当前走定制品规则
    let InputMax = counting.value[radioList.value[InventoryInput.value].input]; //存储当前输入框最大值
    if (InputMax > Tcrow.value.questTarget) {
      ElMessage({
        showClose: true,
        message: `总数[${InputMax}]不能超过在库数量[${Tcrow.value.questTarget}]`,
        type: 'warning',
      });
      return;
    }

    console.log(data, '处理好的数据');
  } else {
    let sum =
      data[0].stockNum +
      data[0].wornNum +
      data[0].lossNum +
      data[0].noRepairNum +
      data[0].deliveNum +
      data[0].noReceivedNum;
    if (sum > Tcrow.value.stockNum) {
      ElMessage({
        showClose: true,
        message: `总数[${sum}]不能超过在库数量[${Tcrow.value.stockNum}]`,
        type: 'error',
      });
      return;
    }
    (data[0].cargoName = TcReaJoin.value.join()), //状态 //状态
      console.log(data, '处理好的数据d');
  }
  $_updateQuestChildInfo(data).then(res => {
    console.log(res, '盘点状态修改完成的返回值');
    if (res.data.code == 200) {
      ElMessage({
        showClose: true,
        message: res.data.msg,
        type: 'success',
      });
      WrapBarEditing.value = {}; //重置提交表单
      InventoryStatus.value = false; //关闭状态选择
      TcViewEvent(row.value);
    }
  });
  PopupEditing.value = false; //关闭弹窗
  TcFrom.value = {}; //重置搜索对象
};

// 弹窗品类搜索
const TcChenge = (event, val) => {
  console.log(event, val);
  TcPdloading.value = true;
  console.log(row.value,'必须参数');
  console.log(row.value.questNum,'questNum');
  let quest=row.value.questNum
  let qstId=row.value.id
  let data = {
    current: TccurrentPage.value, //页码
    size: TcpageSize.value, //条数
    ...TcFrom.value,
    questNum:quest,
    questId:qstId,
  };

  console.log(data, '要提交的数据');

  $_getDetailInfo(data).then(res => {
    Tctotal.value = res.data.data.total;
    res.data.data.records.forEach(item => {
      item.Checkbox = true;
      item.wLinputState=false;
      item.Input=null
    });
    TcPdloading.value = false;
    console.log(res, '明细返回值');
    TcPD.value = res.data.data.records;
  });
};
// 弹窗明细，每一页多少条
const TcPageSizeChange = val => {
  console.log('每一页多少条');
  TcpageSize.value = val;
  if (NotCounted.value) {
    //表示当前是未盘点翻页
    NotCountedFn(UncheckedRow.value,TcFrom.value);
  } else {
    console.log(val);
    TcViewEvent(row.value,TcFrom.value);
  }
};

// 弹窗明细，选择了多少页
const TcSizeChange = val => {
  console.log('翻页');
  TccurrentPage.value = val;
  if (NotCounted.value) {
    //表示当前是未盘点翻页

    NotCountedFn(UncheckedRow.value,TcFrom.value);
  } else {
    console.log(val);
    TcViewEvent(row.value,TcFrom.value);
  }
};
// 弹窗翻页
const TcpageList = val => {
  console.log(val, '弹窗翻页');
};
// 条数
const SizeChange = val => {
  console.log(val, '条数');
  currentPage.value = val;
  onLoad();
};
// 翻页···························
const PageSizeChange = val => {
  console.log(val, '每页50条');
  pageSize.value = val;
  onLoad();
};
// 对比数据单选按钮
const contrastselectChange = (select, val) => {
  console.log(select, val, '对比数据1');
};
// 对比数据全选按钮
const contrastselectAll = (select, val) => {
  console.log(select, val, '对比数据2');
};

// 关闭弹窗关闭回调
const handleClose = () => {
  PopupDetails.value = false;
};
// 刷新页面按钮(初始化页面参数)
const Refresh = () => {
  onLoad(); //初始化表格数据
};

// 获取盘点列表
// 搜索盘点任务
//  const searchChange=()=>{
// console.log('触发搜索');
// $_getDetailInfo({...SoInfoData.value}).then(res=>{
//     console.log(res,'搜索框的值');
// })
//  }

// 创建盘点任务
const InventoryTask = () => {
  formInventory.value={}
  let select = [];
  InventoryPopup.value = true; //开启创建盘点任务弹窗
  getDictList().then(res => {
    console.log('创建盘点返回值', res);
    if (res.data.code == 200) {
      res.data.data.forEach(item => {
        console.log(item, '盘点任务返回值');
        select.push({
          clientName: item.clientName, // 商城名称
          id: item.id, // 商场id
          brandName: item.brandName, // 商场下品牌名
        });
      });
      formInventory.value.select = select;
      console.log(formInventory.value, '处理好的商场名称');
    }
  });
};

// 处理商场名称函数根据传入ID读取列表中的商场
function matchInfoById(idArray, infoArray) {
  const matchedInfo = [];
  idArray.forEach(id => {
    const matchedItem = infoArray.find(item => item.id === id);
    if (matchedItem) {
      matchedInfo.push(matchedItem);
    }
  });
  return matchedInfo;
}

// 商场名称选择回调
const formInventoryChange = val => {
  console.log('选择了商场名称');
  formInventory.value.id = val;
  const matchedInfo = matchInfoById(val, formInventory.value.select);
  console.log(matchedInfo, '处理好的参数');
  formInventory.value.brandName;
  let name = [];
  matchedInfo.forEach(item => {
    name.push(item.brandName);
  });
  formInventory.value.brandName = name.join(','); //处理品牌名称显示
};

// 创建盘点任务弹窗关闭回调
const InventoryPopupClose = () => {
  console.log('创建盘点任务关闭弹窗回调');
};
// 盘点提交
const InventorySubmit = () => {
  console.log(formInventory.value, '盘点选择好的参数');
  // 创建提交表单
  let SubData = {};
  SubData.list = [];
  if (!formInventory.value.scname.length && !formInventory.value.brandName) {
    //
    SubData.list = [];
    // 结束时间
    SubData.endTime = formInventory.value.time[1];
    // 开始时间
    SubData.startTime = formInventory.value.time[0];
    InventoryPopup.value = false; //关闭创建盘点任务弹窗
    loading.value = true; //开启表格加载
    console.log(SubData,'处理好的数据');
    postAddtaskQuest(SubData).then(res => {
      onLoad(); //体积之后初始化页面
      if ((res.data.code = 200)) {
        ElMessage({
          message: res.data.msg,
          type: 'success',
        });
        onLoad(); //体积之后初始化页面
      }
      console.log(res, '盘点计划提交成功');
    });
    return;
  }

  // 处理商场名称和商场ID
  const matchedInfo = matchInfoById(formInventory.value.id, formInventory.value.select);
  console.log(matchedInfo, 'matchedInfo');
  console.log(matchedInfo, 'matchedInfo提交处理数据');
  if (matchedInfo) {
    matchedInfo.forEach(item => {
      SubData.list.push({
        refId: item.id,
        refName: item.clientName,
      });
    });
  }

  // 结束时间
  SubData.endTime = formInventory.value.time[1];
  // 开始时间
  SubData.startTime = formInventory.value.time[0];
  console.log(SubData, '处理好要提交的数据');
  InventoryPopup.value = false; //关闭创建盘点任务弹窗
  // postAddtaskQuest(SubData).then(res => {
  //   console.log(res, '盘点计划提交成功');
  //   onLoad(); //体积之后初始化页面
  // });
};
</script>

<style lang="scss" scoped>
.maxContent {
  width: 100%;
  box-sizing: border-box;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.SoInput {
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
  margin-top: 10px;

  form {
    display: flex;
    flex-wrap: wrap;
    margin-top: 5px;

    :deep(.el-form-item) {
      margin-bottom: 0;
    }
  }

  .SoBtn {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.avue-crud__right {
  margin-top: 5px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
  padding: 0 10px;
}



.demo-pagination-block {
  flex: 1;
  display: flex;
  align-items: flex-end;
  margin-bottom: 8px;
  justify-content: flex-end;
  margin-right: 6px;
}

.demo-pagination-blockPD {
  justify-content: space-between;
}

:deep(.el-table-column--selection) {
  text-align: center;
}

:deep(.el-dialog__footer) {
  display: flex;
}

:deep(.el-dialog__body) {
  padding-top: 0;
}

:deep(.el-dialog) {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin-top: 0;
}

.Tcstdialog-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 80px;
 
}

.Tcstate {
  display: flex;
  margin-bottom: 20px;

  .el-radio {
    width: 54px;
  }
}

.TcstateS {
  margin: 0 2%;
  margin-bottom: 30px;

  label {
    width: 80px;
  }
}

.tcradiogroup {
  display: inline-flex;
  align-items: flex-start;
  font-size: 0;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
}

.el-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.el-input__inner {
  text-align: center;
}

.dbExPo {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.el-exDc{
  margin-left: 20px;
  color: #10d070;
  cursor: pointer;
}
:deep(.el-dialog){
  display: flex;
    flex-direction: column;
    justify-content: flex-start;
    .el-dialog__footer{
      flex: 1;
    }
    .dialog-footer{
    display: flex;
    align-items: flex-end;
  }
}
.fullScreen{
  display: flex;
    margin-left: auto;
    align-items: center;
    justify-content: center;
    i{
      width: 20px;
    height: 20px;
    svg{
      height: 100%;
    width: 100%;
    }
    }
}
:deep(.el-input__wrapper){
  height: 30px;

}
:deep(.el-input__inner){
  height: 100% !important;
}
</style>
