<template>
  <!-- 添加或修改项目信息对话框 -->
  <el-drawer v-model="visible" size="80%" direction="rtl" :close-on-press-escape="false">
    <div class="page-container form-container">
      <div class="form-btns-container">
        <span class="title-label"><el-icon>
            <Document />
          </el-icon>
          周转详情</span>
        <el-button type="primary" icon="Check" style="margin-right: 10px" @click="handleSave">保 存
        </el-button>
        <el-button icon="Close" @click="handleCancel">取 消
        </el-button>
      </div>
      <!-- 主表 -->
      <el-form ref="dayworkItemRef" class="master-container" :model="form" :rules="rules" :show-message="true">
        <el-row :gutter="20">
          <el-col :span="7">
            <el-form-item label="开始时间：" prop="startTime" label-width="94px">
              <el-date-picker v-model="form.startTime" :disabled="!editStatus" type="datetime"
                value-format="YYYY-MM-DD HH:mm:ss " :clearable="false" :editable="false" placeholder="请选择开始时间"
                @change="handleTotalTime" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="工序名称：" prop="processId" label-width="90px">
              <el-select-v2 v-model="form.processId" clearable :disabled="true" :options="processList"
                placeholder="请选择工序" style="width: 220px" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产状态：" prop="status" align="center" label-width="94px">
              <el-select v-model="form.status" placeholder="请选择生产状态" :disabled="true" style="width: 220px"
                @change="handleChangeStatus">
                <el-option v-for="dict in dynamicOptions" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="7">
            <el-form-item label="结束时间：" prop="endTime" label-width="94px">
              <el-date-picker v-model="form.endTime" disabled type="datetime" value-format="YYYY-MM-DD HH:mm:ss "
                :editable="false" :clearable="false" placeholder="请选择结束时间" @change="handleTotalTime" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="操作者:" prop="nickName" label-width="82px">
              <el-input v-model.trim="form.nickName" placeholder="请输入操作者" readonly :clearable="true"
                style="width: 220px; margin-left: 8px">
                <template #append>
                  <el-button icon="Search" @click="handleSelectUserSingle" />
                </template></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="投产量：" prop="prodNum" label-width="94px">
              <el-input-number v-model.trim="form.prodNum" :precision="0" controls-position="right"
                style="width: 220px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="7">
            <el-form-item label="总工时：" prop="workingHoursTime" label-width="94px">
              <el-input v-model.trim="workingHoursTime" :disabled="true" style="width: 220px; margin-left: 0px" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="合格数：" prop="qualifiedNum" label-width="90px" style="padding-right: 0px">
              <el-input-number v-model.trim="form.qualifiedNum" :disabled="!editStatus" :precision="0"
                controls-position="right" style="width: 220px" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="设备：" prop="equipmentDetailId" label-width="82px">
              <el-select-v2 v-model="form.equipmentDetailId" :disabled="true" :options="equipmentList"
                placeholder="请选择设备" style="width: 220px">
              </el-select-v2>
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="周转类型：" label-width="94px" prop="turnoverType">
              <el-select v-model="form.turnoverType" :disabled="!editStatus || !isLatest || form.outsourceDetailId != 0"
                placeholder="请选择周转类型" style="width: 220px;" @change="turnoverTypeChangeHandler">
                <el-option v-for="dict in daywork_turnover_type" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7" v-if="form.outsourceDetailId != '0'">
            <el-form-item label="周转工段：" label-width="94px" prop="deptId">
              <div>{{ form.deptName }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="7" v-else-if="form.turnoverType != '3'">
            <el-form-item label="周转工段：" label-width="94px" prop="deptId">
              <el-select v-model="form.deptId" :disabled="!editStatus || !isLatest" placeholder="请选择周转工段"
                style="width: 220px;" @change="deptChangeHandler">
                <el-option v-for="dict in deptList" :key="dict.detpId" :label="dict.deptName" :value="dict.deptId" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9" v-if="form.outsourceDetailId != '0'">
            <el-form-item label="周转区：" label-width="94px" prop="deptId">
              <div>{{ form.place }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="9" v-else-if="form.turnoverType == '1'">
            <el-form-item label="周转区：" label-width="90px" prop="placeId" required>
              <el-select v-model="placeIds" :disabled="!editStatus || !isLatest" collapse-tags multiple
                placeholder="请选择周转区" style="width: 220px;" @change="turnoverChangeHandler">
                <el-option v-for="dict in turnoverList" :key="dict.id" :label="dict.code" :value="dict.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9" v-else-if="form.isWx == 0">
            <el-form-item label="周转区：" label-width="90px" prop="turnoverId" required>
              <el-select v-model="form.turnoverId" :disabled="!editStatus || !isLatest" placeholder="请选择周转区"
                style="width: 220px;" @change="workshopTurnoverChangeHandler">
                <el-option v-for="dict in workShopTurnoverList" :key="dict.id" :label="dict.code" :value="dict.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 搜索人员弹窗 -->
      <dialog-person ref="dialogPersonRef" :single-selected="handleGetUser" />
    </div>
  </el-drawer>
</template>
<script setup>
import {
  getProcessList,
  getDayworkItemRejectList,
  getDayworkItemOriginalRejectList,
  updateDayworkItemInfoForTurnover,
  getEquipmentInfo,
  getIsFirstOrder,
  getAllWorkShop
} from "@/api/business/daywork.js";
import { ref } from "vue";
import dialogPerson from "./person.vue"
import useUserStore from '@/store/modules/user'

const { proxy } = getCurrentInstance();
const emit = defineEmits(["handleSaveSuccess"]);
/** 字典 */
const { daywork_status_edit } = proxy.useDict("daywork_status_edit");
const { daywork_status_first } = proxy.useDict("daywork_status_first");
const { daywork_status_second } = proxy.useDict("daywork_status_second");
const { waste_causes } = proxy.useDict("waste_causes");
const { daywork_turnover_type } = proxy.useDict("daywork_turnover_type")
const detailInfo = ref({});
const loading = ref(false);
const processList = ref([]);
const lotId = ref(null);
const equipmentList = ref([]);
const isLatest = ref(false)
const visible = ref(false);
const isFirst = ref(true); //是否为首序
const editStatus = ref(false);
const currentDept = ref(false);
const rejectAmount = ref(0);
const dynamicOptions = ref([]);
const turnoverList = ref([])
const placeIds = ref([])
const workShopTurnoverList = ref([])
const deptList = ref([])
const workingHoursTime = ref("");
let allDepts = []
let checkDepts = []
let allWorkshop = []
const maxQuailifiedNum = ref(0);
const detailsRow = {
  id: null,
  rejectNum: "",
  reason: "",
};
// const validateprodNum = (rule, value, callback) => {
//   if (value <= 0) {
//     callback(new Error("投产量应大于0"));
//   } else {
//     callback();
//   }
// };
const validateWorkingHours = (rule, value, callback) => {
  if (form.value.workHoursTimestamp < 0) {
    callback(new Error("结束时间应晚于开始时间"));
  } else {
    callback();
  }
};
const validateQualifiedNum = (rule, value, callback) => {
  const max = maxQuailifiedNum.value;
  if (value < 0) {
    callback(new Error("合格数量应大于/等于0"));
  } else {
    callback();
  }

  // else if (
  //   value > max &&
  //   detailInfo.value.firstProcessId != form.value.processId
  // ) {
  //   callback(new Error("合格数量不应大于投产量的103%,即" + max));
  // }
};
const validateEndTime = (rule, value, callback) => {
  // if (form.value.status > 1) {
  //   if (form.value.endTime == null) {
  //     callback(new Error("结束时间不能为空"));
  //   } else {
  //     callback();
  //   }
  // } else {
  //   if (form.value.endTime != null) {
  //     callback(new Error("该状态结束时间应为空"));
  //   } else {
  //     callback();
  //   }
  // }
  callback()
};
const validateStartTime = (rule, value, callback) => {
  if (form.value.status > 1) {
    if (form.value.startTime == null) {
      callback(new Error("开始时间不能为空"));
    } else {
      callback();
    }
  } else {
    callback();
  }
};
const validatePlace = (rule, value, callback) => {
  if (form.value.turnoverType == '1') {
    if (form.value.placeId == null || form.value.placeId == '') {
      callback(new Error("周转区不能为空"));
    }
  }
  callback()
}
const validateTurnover = (rule, value, callback) => {
  if (form.value.turnoverType != '1') {
    if (form.value.turnoverId == null || form.value.turnoverId == '') {
      callback(new Error("周转区不能为空"));
    }
  }
  callback()

}

const getWorkShopInfo = (params) => {
  getAllWorkShop(params).then(res => {
    // 获取所有的工段和车间信息
    allDepts = res.data.depts
    allWorkshop = res.data.workshops
    checkDepts = res.data.allDepts
    // checkWorkshop = res.data.allWorkshop
    setTurnoverList()
  })
}
const setTurnoverList = () => {
  // console.log(form.value, placeIds)
  const fromDept = checkDepts.some(e => e.deptId == form.value.fromDeptId) ? checkDepts.filter(e => e.deptId == form.value.fromDeptId)[0] : null
  form.value.workshopId = fromDept != null ? fromDept.workshopId : null
  if (form.value.isWx == '1') {
    form.value.turnoverArea = '外协周转区'
  }
  // console.log(form.value.deptId, allDepts.filter(e => e.deptId == form.value.deptId))
  const targetDept = checkDepts.some(e => e.deptId == form.value.deptId) ? checkDepts.filter(e => e.deptId == form.value.deptId)[0] : null

  const fromWorkshop = allWorkshop.some(e => e.id == form.value.workshopId) ? allWorkshop.filter(e => e.id == form.value.workshopId)[0] : null
  // 根据form信息放置周转区等数据
  if (form.value.turnoverType == '1') {
    // 车间内周转 周转工段为同车间工段
    // 转移位置为 目标工段的位置
    // console.log(targetDept)
    deptList.value = allDepts.filter(e => e.workshopId == form.value.workshopId).map(e => ({ ...e }))
    turnoverList.value = targetDept == null || !deptList.value.some(e => e.deptId == targetDept.deptId) ? [{ id: form.value.placeId, code: form.value.place }] : targetDept.turnovers
    form.value.turnoverArea = '车间内周转看place字段'
  } else if (form.value.turnoverType == '2') {
    // console.log()
    // 车间外周转 转移为转出位置从车间获取
    // console.log(form.value.turnoverId, fromDept, form.value.deptId)
    // console.log(fromWorkshop)
    workShopTurnoverList.value = fromWorkshop == null ? [{ id: form.value.turnoverId, code: form.value.turnoverArea }] : fromWorkshop.turnovers
    deptList.value = allDepts.filter(t => t.workshopId != form.value.workshopId).map(e => ({ ...e }))
  } else if (form.value.turnoverType == '3') {
    // console.log('turnoverType 3')
    form.value.deptId = '114'
    form.value.deptName = '外协'
    workShopTurnoverList.value = fromWorkshop == null ? [{ id: form.value.turnoverId, code: form.value.turnoverArea }] : fromWorkshop.turnovers
  }
  if (deptList.value.length == 0) {
    deptList.value.push({ deptId: form.value.deptId, deptName: form.value.deptName })
  }
}
const data = reactive({
  form: {
    groupRejectList: [],
    nickName: "",
    processId: "",
    processAlias: "",
    prodNum: 0,
    qualifiedNum: 0,
    rejectNum: 0,
    startTime: "",
    endTime: "",
    workingHours: 0,
    status: "",
    workHoursTimestamp: 0,
  },
  rules: {
    // prodNum: [
    //   { required: true, message: "投产量不能为空", trigger: "blur" },
    //   { validator: validateprodNum, trigger: "blur" },
    // ],
    turnoverType: [{ trigger: "change", required: true, message: '周转类型不能为空' }],
    deptId: [{ trigger: "change", required: true, message: '周转工段不能为空' }],
    placeId: [{ trigger: "change", validator: validatePlace }],
    turnoverId: [{ trigger: "change", validator: validateTurnover }],
    startTime: [{ validator: validateStartTime, trigger: "blur" }],
    endTime: [{ validator: validateEndTime, trigger: "blur" }],
    workingHoursTime: [{ validator: validateWorkingHours, trigger: "change" }],
    qualifiedNum: [
      { required: true, message: "合格数量不能为空", trigger: "blur" },
      { validator: validateQualifiedNum, trigger: "blur" },
    ],
  },
});

const { form, rules } = toRefs(data);

/***********************  方法区  ****************************/
/** 打开抽屉 */
const open = (row) => {
  reset();
  loading.value = true;
  if (row.id) {
    //查询是否为首序
    getIsFirstOrder(row.dayworkId).then((res) => {
      isFirst.value = res.data.isFirstOrder;
    });
    lotId.value = row.lotId;
    //页面操作是编辑还是删除
    // console.log("row", row);
    detailInfo.value = proxy.deepClone(row);
    // console.log(detailInfo.value);
    //是否是当前工序
    currentDept.value = row.currentDept;
    form.value.id = row.id;
    form.value.startTime = row.startTime;
    form.value.endTime = row.endTime;
    workingHoursTime.value = row.workingHours;
    form.value.nickName = row.nickName;
    form.value.productDescription = row.productDescription;
    form.value.lotCode = row.lotCode;
    form.value.technologyVersion = row.technologyVersion
    form.value.productionPlanNo = row.productionPlanNo;
    form.value.status = row.status;
    editStatus.value = row.status < 2 ? false : true
    form.value.processId = row.processId;
    form.value.productionPlanDetailId = row.productionPlanDetailId;
    form.value.turnoverType = row.turnoverType
    form.value.fromDeptId = row.fromDeptId
    form.value.fromDeptName = row.fromDeptName
    form.value.turnoverArea = row.turnoverArea
    form.value.turnoverId = row.turnoverId
    form.value.placeId = row.placeId
    placeIds.value = form.value.placeId == '' ? [] : form.value.placeId.split('、')
    form.value.place = row.place
    form.value.deptId = row.deptId
    form.value.deptName = row.deptName
    form.value.isInnerTurnover = row.isInnerTurnover
    form.value.outsourceDetailId = row.outsourceDetailId
    if (form.value.status == 0 || form.value.status == 1) {
      dynamicOptions.value = daywork_status_first.value;
    } else if (form.value.status == 2 || form.value.status == 3) {
      dynamicOptions.value = daywork_status_edit.value;
    } else {
      dynamicOptions.value = daywork_status_second.value;
    }
    form.value.qualifiedNum = row.qualifiedNum;
    form.value.isWx = row.isWx
    //合格数最大能修改数值
    maxQuailifiedNum.value = row.maxQuailifiedNum;
    form.value.workHoursTimestamp = 0;
    form.value.prodNum = row.prodNum;
    isLatest.value = row.isLatest
    // technologicalProcessId: row.technologicalProcessId
    getProcessList({
      technologicalProcessId: row.technologicalProcessId,
      isAmend: row.isAmend,
      isWasteRecycling: row.isWasteRecycling,
      lotId: row.lotId,
    }).then((res) => {
      processList.value = res.data;
      for (let i = 0; i < processList.value.length; i++) {
        if (processList.value[i].label === row.processAlias.trim()) {
          form.value.processId = processList.value[i].value;
        }
      }
    });
    getDayworkItemOriginalRejectList({ dayworkItemId: detailInfo.value.id }).then(
      (response) => {
        if (response.code == 200) {
          for (let i = 0; i < response.data.length; i++) {
            response.data[i].rejectNum = parseInt(response.data[i].rejectNum);
          }
          form.value.groupRejectList = response.data;
        }
      }
    );
    //查询能够选择的设备信息
    // let productionPlanDetailId = parseInt(row.productionPlanDetailId);
    // getEquipmentInfo({
    //   commonCode: row.userName,
    //   productionPlanDetailId: productionPlanDetailId,
    //   dayworkItemId: row.id,
    //   deptId: row.deptId,
    // }).then((equipmentRef) => {
    //   if (equipmentRef.code == 200) {
    //     if (equipmentRef.rows.length > 0) {
    //       equipmentList.value = equipmentRef.rows;
    //       for (let i = 0; i < equipmentList.value.length; i++) {
    //         if (row.equipmentDetailCode == equipmentList.value[i].label) {
    //           form.value.equipmentDetailId = equipmentList.value[i].value;
    //         }
    //       }
    //     } else {
    //       equipmentList.value = [];
    //     }
    //   }
    // });
    loading.value = false;
    visible.value = true;
    // console.log(useUserStore().user)
    getWorkShopInfo({
      isAmend: row.isAmend, isWasteRecycling: row.isWasteRecycling, lotId: row.lotId,
      tenantId: useUserStore().user.tenantId == '0' ? null : useUserStore().user.tenantId, productionPlanDetailId: row.productionPlanDetailId,
      processStepNumber: row.processStepNumber
    })
    // console.log(row)
  }
};
//操作者人员带回
function handleGetUser(selection) {
  form.value.nickName = selection.nickName;
  form.value.userId = selection.userId;
  form.value.userName = selection.userName;
}
function handleSelectUserSingle() {
  proxy.$refs.dialogPersonRef.open()
}
/**
 * 对话框关闭 事件
 */
function close() {
  reset();
  visible.value = false;
}

/** 表单重置 */
function reset() {
  form.value = {
    groupRejectList: [],
    nickName: "",
    processId: null,
    processAlias: "",
    prodNum: 0,
    qualifiedNum: 0,
    rejectNum: 0,
    startTime: "",
    endTime: "",
    workingHours: 0,
  };
  proxy.resetForm("dayworkItemRef");
}

/** 提交按钮 */
const handleSave = () => {
  //* 历史数据fromDetpId 为0的情况下不让修改。
  if (form.value.fromDeptId == '0') {
    proxy.$modal.msgError('历史数据，不能修改')
    return
  }
  proxy.$refs["dayworkItemRef"].validate((valid) => {
    if (valid) {
      rejectAmount.value = 0;
      var reasonList = [];
      var flag = true;

      form.value.workingHours = form.value.workHoursTimestamp;
      if (flag) {
        if (form.value.groupRejectList.length > 0) {
          form.value.groupRejectList.forEach(item => {
            item.deptId = detailInfo.value.deptId
            item.processId = detailInfo.value.processId
          });
        }
        form.value.dayworkId = detailInfo.value.dayworkId;
        if (form.value.turnoverType == '1') {
          form.value.turnoverArea = '车间内周转看place字段'
        }
        //同工序的所有合格数

        const max = maxQuailifiedNum.value;
        let sunm = form.value.qualifiedNum
        let num = sunm - form.value.prodNum; //多出来的数量
        let percent = (sunm / form.value.prodNum) * 100; //合格率
        percent = Math.ceil(percent * 100) / 100; //只入不舍
        //判断是否超过投产量
        if (sunm > form.value.prodNum) {
          //判断是否为首序
          if (isFirst.value) {
            // 弹出确认对话框
            proxy.$modal
              .confirm(
                "合格数为投产量" +
                percent +
                "%,超出投产量" +
                num +
                "。 是否继续保存！"
              )
              .then(function () {
                updateDayworkItem();
              })
              .then(() => {
                return;
              })
              .catch(() => {
                return;
              });
          } else {
            if (form.value.qualifiedNum <= max) {
              updateDayworkItem();
            } else {
              proxy.$modal.msgError(
                "合格数不能超过投产量的103%,最大合格数为" + max
              );
            }
          }
        } else {
          updateDayworkItem();
        }
      }
    }
  });
};

//页面提交方法
function updateDayworkItem() {
  // console.log(form.value)
  updateDayworkItemInfoForTurnover(form.value).then((res) => {
    if (res.code == 200) {
      proxy.$modal.msgSuccess("保存成功！");
      visible.value = false;
      emit("handleSaveSuccess");
    } else {
      proxy.$modal.msgError("保存失败！");
    }
  });
}

//删除废弃信息
function handleDeleteReject(row) {
  form.value.groupRejectList.splice(form.value.groupRejectList.indexOf(row), 1);
}

//添加废弃信息
function handleAddReject() {
  const newDetail = JSON.parse(JSON.stringify(detailsRow));
  newDetail.rejectNum = 0;
  newDetail.dayworkId = detailInfo.value.dayworkId;
  newDetail.dayworkItemId = detailInfo.value.id;
  newDetail.lotId = detailInfo.value.lotId;
  form.value.groupRejectList.push(newDetail);
}

//计算总工时
function handleTotalTime() {
  if (form.value.endTime == null) {
    workingHoursTime.value = "0小时0分钟0秒";
    form.value.workHoursTimestamp = 0;
  } else {
    form.value.workHoursTimestamp =
      new Date(form.value.endTime) - new Date(form.value.startTime);
    let seconds = Math.floor((form.value.workHoursTimestamp / 1000) % 60);
    let minutes = Math.floor(
      (form.value.workHoursTimestamp / (1000 * 60)) % 60
    );
    let hours = Math.floor(form.value.workHoursTimestamp / (1000 * 60 * 60));
    let time = `${hours}小时${minutes}分钟${seconds}秒`;
    workingHoursTime.value = time;
  }
}

//当生产状态为未开始、生产中时，结束时间为空，合格数为0，废弃信息为空
function handleChangeStatus() {
  if (form.value.status == 1) {
    form.value.endTime = null;
    workingHoursTime.value = "0小时0分钟0秒";
    form.value.workingHours = 0;
    form.value.groupRejectList = [];
    form.value.qualifiedNum = 0;
  }
  if (form.value.status == 0) {
    form.value.endTime = null;
    form.value.startTime = null;
    workingHoursTime.value = "0小时0分钟0秒";
    form.value.workingHours = 0;
    form.value.groupRejectList = [];
    form.value.qualifiedNum = 0;
    form.value.equipmentDetailId = null;
    form.value.equipmentDetailCode = null;
  }
}
function turnoverTypeChangeHandler() {
  // 获取对应的工段
  if (form.value.fromDeptId == '0') {
    // 假设是旧数据，不判断工段是哪个车间的随便填写
  } else {
    // 有旧工段则根据之前工段是哪个车间的而进行车间内车间外周转
    setTurnoverList()
    // 判断当前周转deptId是否在列表中假设不在则删除
    if (form.value.turnoverType != '3' && !deptList.value.some(e => e.deptId == form.value.deptId)) {
      // console.log('不存在对应deptid')
      form.value.deptId = null
      form.value.deptName = null
    }
    if (form.value.turnoverType == '1') {
      form.value.turnoverId = ''
      form.value.turnoverArea = ''
    } else {
      form.value.placeId = ''
      form.value.place = ''
      placeIds.value = []
      turnoverList.value = []
    }
  }
  if (form.value.turnoverType == '3') {
    // 设置周转工段为外协工段 
    form.deptId = '114'
    form.deptName = '外协'
  }
}

function deptChangeHandler() {
  // 工段变化获取工段对应周转区
  const deptId = form.value.deptId
  const currentDept = checkDepts.find(e => e.deptId == deptId)
  // console.log(currentDept)
  form.value.deptName = currentDept.deptName
  setTurnoverList()
  // if (form.value.turnoverType == 1) {
  //   form.value.turnoverId = ''
  //   form.value.turnoverArea = ''
  // } else {
  //   form.value.placeId = ''
  //   form.value.place = ''
  //   placeIds.value = []
  // }
  form.value.turnoverId = ''
  form.value.turnoverArea = ''
  form.value.placeId = ''
  form.value.place = ''
  placeIds.value = []

}

function workshopTurnoverChangeHandler() {
  // 区间外周转周转区变更
  const turnovers = workShopTurnoverList.value.filter(t => t.id == form.value.turnoverId)
  form.value.turnoverArea = turnovers.map(e => e.code).join("、")
}

function turnoverChangeHandler() {
  // 区间内周转周转区变更
  const places = turnoverList.value.filter(t => placeIds.value.some(e => e == t.id))
  form.value.placeId = places.map(e => e.id).join('、')
  form.value.place = places.map(e => e.code).join('、')
}

/** 取消按钮 */
const handleCancel = () => {
  visible.value = false;
  reset();
};

/** 暴露给父组件的方法 */
defineExpose({
  open,
});
</script>
<style scoped>
.el-select-v2__placeholder {
  display: flex !important;
}
</style>
