<template>
  <div class="page-container row-container">
    <section class="list-part-container" style="flex: 2">
      <!-- 搜索区域 -->
      <el-form
        class="list-search-container"
        :model="queryParams"
        ref="queryRef"
        :inline="true"
      >
        <el-form-item label="类型:" prop="pattern">
          <el-select-v2
            v-model="queryParams.pattern"
            clearable
            filterable
            :options="patternLabels"
            placeholder="类型"
            @change="handleRefreshDrawing"
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="客户名称：">
          <el-input
            placeholder="请输入客户名称"
            v-model.trim="queryParams.companyAlias"
            @keydown.enter.prevent
            clearable
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="图号：">
          <el-input
            placeholder="请输入图号"
            v-model.trim="queryParams.drawingNumber"
            @keydown.enter.prevent
            clearable
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="规格：">
          <el-input
            placeholder="请输入规格"
            v-model.trim="queryParams.specification"
            @keydown.enter.prevent
            clearable
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="产品描述：">
          <el-input
            placeholder="请输入产品描述"
            v-model.trim="queryParams.description"
            @keydown.enter.prevent
            clearable
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="工艺版本:" prop="technologyVersion">
          <el-input
            placeholder="请输入工艺版本"
            v-model.trim="queryParams.technologyVersion"
            @keydown.enter.prevent
            clearable
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="工序:" prop="processAlias">
          <el-input
            placeholder="请输入工序"
            v-model.trim="queryParams.processAlias"
            @keydown.enter.prevent
            clearable
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="info" icon="Search" @click="handleRefreshDrawing"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <div class="list-btns-container">
        <el-button
          :disabled="selections.length == 0"
          type="success"
          v-hasPermi="['business:electronicDrawings:examine']"
          @click="handleSaveBacth()"
          >批量通过
        </el-button>
        <el-button
          :disabled="selections.length == 0"
          type="danger"
          v-hasPermi="['business:electronicDrawings:examineNG']"
          @click="handleNGBacth()"
          >批量NG
        </el-button>
      </div>
      <!-- 列表区域 -->
      <div class="el-table-container">
        <div class="el-table-inner-container">
          <el-table
            ref="drawingTabel"
            v-loading="loading"
            :row-key="getRowKey"
            @selection-change="handleSelectionChange"
            :data="drawingList"
            height="100%"
          >
            <el-table-column
              type="selection"
              width="40"
              align="center"
              :reserve-selection="true"
            />
            <el-table-column
              label="行号"
              type="index"
              width="50"
              align="center"
            />
            <el-table-column label="客户" width="120" align="center">
              <template #default="scope">
                <span>{{ scope.row.product.companyAlias }}</span>
              </template>
            </el-table-column>
            <el-table-column label="图号" width="120" align="center">
              <template #default="scope">
                <span>{{ scope.row.product.drawingNumber }}</span>
              </template>
            </el-table-column>
            <el-table-column label="规格" width="250" align="center">
              <template #default="scope">
                <span>{{ scope.row.product.specification }}</span>
              </template>
            </el-table-column>
            <el-table-column label="产品描述" width="100" align="center">
              <template #default="scope">
                <span>{{ scope.row.product.description }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="工艺版本"
              prop="productVersion"
              width="100"
              align="center"
            />
            <el-table-column label="工序" prop="processAlias" align="center" />
            <el-table-column label="图纸" prop="drawingName" align="center">
            </el-table-column>
            <el-table-column label="类型" prop="pattern" align="center" />
            <el-table-column
              label="状态"
              width="80px"
              prop="status"
              align="center"
            >
              <template #default="scope">
                <dict-tag :options="drawing_status" :value="scope.row.status" />
              </template>
            </el-table-column>
            <el-table-column label="制作人" prop="producer" align="center" />
            <el-table-column label="操作" width="150" align="center">
              <template #default="scope">
                <el-button
                  link
                  type="primary"
                  @click="handlePreview(scope.row)"
                >
                  预览
                </el-button>
                <el-button
                  v-hasPermi="['business:electronicDrawings:examine']"
                  link
                  type="success"
                  @click="saveDrawingDetail(scope.row)"
                >
                  通过
                </el-button>
                <el-button
                  v-hasPermi="['business:electronicDrawings:examineNG']"
                  link
                  type="danger"
                  @click="handleNGdrawingDetail(scope.row.id)"
                >
                  NG
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getDrawingList"
      />
    </section>
  </div>
</template>
  
<script setup name="drawingAuditing">
//   import {
//     getNormalDrawing,
//     detailList,
//     delDetails,
//   } from "@/api/business/equipment";
import {
  getNormalDrawing,
  getListByName,
  saveDrawing,
  drawingNG,
  replace,
} from "@/api/business/drawing";
import { getTechnological } from "@/api/business/product";
import { getTechnologicalProcessDetails } from "@/api/business/technologicalProcessDetail";
const { proxy } = getCurrentInstance();
const webHost = import.meta.env.VITE_APP_PRODUCTION_API;
const hostIp = import.meta.env.VITE_HOST_IP;
const hostUrl = import.meta.env.VITE_HOST_URL;
const inNet = import.meta.env.VITE_HOST_INNET;
const outNet = import.meta.env.VITE_HOST_OUTNET;
/**字典数组 */
const { equipment_status } = proxy.useDict("equipment_status");
const { yes_no } = proxy.useDict("yes_no");
const drawingTabel = ref(null);
const selections = ref([]);
const total = ref(0);
const { drawing_status } = proxy.useDict("drawing_status");

const drawingList = ref([]);
const loading = ref(false);
const patternLabels = ref([
  {
    value: "新产品",
    label: "新产品",
  },
  {
    value: "替换",
    label: "替换",
  },
]);
const data = reactive({
  queryParams: {
    status: 0,
    abandoned: 0,
    pageNum: 1,
    pageSize: 10,
  },
  form: {
    pageNum: 1,
    pageSize: 10,
    technologicalProcessDetailId: null,
    groupDetailList: [],
    code: "",
    remark: "",
    type: false,
  },
});
const { form, queryParams } = toRefs(data);

/****************************************************  生命周期函数区  ****************************************************/
onMounted(() => {
  getDrawingList();
});
/****************************************************  方法区  ****************************************************/

/**删除设备明细 */
function handleNGdrawingDetail(row) {
  proxy.$modal
    .confirm("是否确认废弃图纸？")
    .then(function () {
      var itemList = [];
      itemList.push(row);
      return drawingNG(itemList);
    })
    .then(() => {
      reset();
      getDrawingList();
      open.value = false;
      proxy.$modal.msgSuccess("废弃成功");
    })
    .catch(() => {});
}

/**通过按钮 */
function saveDrawingDetail(row) {
  var itemList = [];
  itemList.push(row);
  saveDrawing(itemList).then((res) => {
    if (res.code == 200) {
      getDrawingList();
      loading.value = false;
    }
  });
}

/**预览 */
function handlePreview(row) {
  //0617预览不需要内嵌，新开一个标签页
  // hostUrl+webHost+row.url 必须时文件全路径 不能转
  // window.open(fileUrl + encodeURIComponent(Base64.encode(document.location.origin  + webHost + row.url)))
  // // window.open(fileUrl+ encodeURIComponent(Base64.encode(document.location.host +webHost+row.url)))
  // console.log('全路径：'+hostUrl+webHost+row.url)

  console.log(document.location);
  //0617预览不需要内嵌，新开一个标签页
  // hostUrl+webHost+row.url 必须时文件全路径 不能转
  var itemUrl = document.location.origin;
  var fUrl = "";
  var webUrl = "";
  console.log(hostIp, itemUrl, 215);
  console.log(document.location.origin + webHost + row.url);
  if (itemUrl.includes(hostIp)) {
    fUrl = inNet;
    // webUrl = "http://192.168.10.41"
  } else {
    fUrl = outNet;
    // webUrl = "http://36.129.132.128:401"
  }
  window.open(
    fUrl + encodeURIComponent(Base64.encode(hostUrl + webHost + row.url))
  );
}

/** 搜索按钮操作 */
function handleRefreshDrawing() {
  getDrawingList();
}
/** 获取设备档案列表 */
function getDrawingList() {
  console.log(selections.value);
  loading.value = true;
  getNormalDrawing(queryParams.value).then((res) => {
    drawingList.value = res.rows;
    loading.value = false;
    total.value = res.total;
  });
}
//刷新设备档案管理
function handleRefreshDetail() {
  getDrawingList();
}
/**
 * 列表checkbox列选择 事件
 */
function handleSelectionChange(selection) {
  selections.value = selection;
}
/**批量通过 */
function handleSaveBacth() {
  if (selections.value.length > 0) {
    saveDrawing(selections.value).then((res) => {
      if (res.code == 200) {
        proxy.$modal.msgSuccess("操作成功");
        selections.value = [];
        drawingTabel.value.clearSelection();
        getDrawingList();
      }
    });
  }
}
/**批量废弃 */
function handleNGBacth() {
  if (selections.value.length > 0) {
    drawingNG(selections.value).then((res) => {
      if (res.code == 200) {
        proxy.$modal.msgSuccess("操作成功");
        selections.value = [];
        drawingTabel.value.clearSelection();
        getDrawingList();
      }
    });
  }
}
function getRowKey(row) {
  return row.id;
}
</script>
<style scoped>
:deep(.el-tree-node__label) {
  font-size: 14px !important;
  display: inline-block;
  width: 100%;
}

:deep(.el-tree-node__content) {
  height: 40px;
  border-bottom: 1px solid #ebeef5;
  padding: 8px 0;
  line-height: 23px;
}

.move-handle {
  cursor: move;
  background-color: #eee;
}
</style>
  