2023-12-15

<template>
<div>
<search :searchData="searchData" @search="refresh"> </search>
<mw-table
:columns="columns"
:data-source="schedulingData"
:loading="loading"
:rowKey="(record) => record.id"
hasPage
:customRow="
(record) => {
return {
onClick: (event) => {
rowClick(record);
},
};
}
"
:scroll="{ x: 'max-content' }"
:pageConfig="paginationProps"
>
<template #bodyCell="{ column }">
<template v-if="column.key == 'operate'">
<a-button type="primary">详情</a-button></template
></template
>
</mw-table>
<div v-if="schedulingDetailData.length > 0">
<div style="display: flex; justify-content: space-between">
<div>交货日期: {{ deliveryTime }}</div>
<a-button type="primary" class="mb-3" @click="showInOutCheckDrawer"
>新增排产订单</a-button
>
</div>
<mw-table
bordered
:row-selection="rowSelection"
:columns="columnsDetail"
:data-source="cloneData"
:loading="loading"
:scroll="{ x: 'max-content' }"
:pagination="pagination"
@change="handlePageChange"
:rowKey="(record) => record.index"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key == 'productName'">
<div v-for="(item, index) in record.marketProductVOs" :key="index">
<p
:class="[
'customs',
{ custom: index !== record.marketProductVOs.length - 1 },
]"
>

{{ record.marketProductVOs.length }}
</p>
</div>
</template>
<template v-if="column.key == 'specification'">
<div v-for="(item, index) in record.marketProductVOs" :key="index">
<p
:class="[
'customs',
{ custom: index !== record.marketProductVOs.length - 1 },
]"
>
{{ item.specification }}
</p>
</div>
</template>
<template v-if="column.key == 'productNo'">
<div v-for="(item, index) in record.marketProductVOs" :key="index">
<p
:class="[
'customs',
{ custom: index !== record.marketProductVOs.length - 1 },
]"
>
{{ item.productNo }}
</p>
</div>
</template>
<template v-if="column.key == 'schedulingQuantity'">
<div v-for="(item, index) in record.marketProductVOs" :key="index">
<p
:class="[
'customs',
{ custom: index !== record.marketProductVOs.length - 1 },
]"
>
{{ item.schedulingQuantity }}
</p>
</div>
</template>
<template v-if="column.key == 'unSchedulingQuantity'">
<div v-for="(item, index) in record.marketProductVOs" :key="index">
<p
:class="[
'customs',
{ custom: index !== record.marketProductVOs.length - 1 },
]"
>
{{ item.unSchedulingQuantity }}
</p>
</div>
</template>

      <template v-if="column.key == 'operate'">
        <a-button type="primary">详情</a-button></template
      ></template
    >
  </mw-table>
</div>
<new-increase-drawer
  v-model:visible="inOutCheckVisible"
  @finish="getList"
  :selectedRowKeys="pendingProductionData"
/>

</div>
</template>

<script setup>
import {
ref,
reactive,
toRaw,
defineEmits,
onBeforeMount,
computed,
} from "vue";
import { purchaseStatusFilters } from "@/common/constant.js";
import Search from "@/components/search/index.vue";
import { schedulingOrderStatistics } from "@/api/proSchedul/waitProductionSchedul.js";
import { usePagenation } from "@/common/setup";
import newIncreaseDrawer from "../newIncreaseDrawer.vue";
import _cloneDeep from "lodash/cloneDeep";
const schedulingData = ref([{}]);
const schedulingDetailData = ref([]);
const inOutCheckVisible = ref(false);
const loading = ref(false);
const deliveryTime = ref();
const pendingProductionData = ref();
const selectedRowKeysList = ref();
const cloneData = ref();
const searchData = reactive({
fields: {
status: {
name: "采购状态",
type: "a-select",
options: purchaseStatusFilters,
placeholder: "选择状态",
width: "120px",
value: "",
},
rangeDate: {
type: "a-range-picker",
valueFormat: "YYYY-MM-DD",
value: [],
width: "240px",
},
keyword: {
type: "a-input-search",
placeholder: "输入订单编号/编码搜索",
width: "240px",
allowClear: true,
},
},
});
const columns = ref([
{
title: "交货日期",
key: "deliveryTime",
dataIndex: "deliveryTime",
},
{
title: "订单数量",
key: "marketOrderQuantity",
dataIndex: "marketOrderQuantity",
},
{
title: "已排产",
key: "schedulingQuantity",
dataIndex: "schedulingQuantity",
},
{
title: "剩余排产",
key: "unSchedulingQuantity",
dataIndex: "unSchedulingQuantity",
},
]);
const pagination = ref({
total: "",
current: 1,
pageSize: 6,
});
const columnsDetail = ref([
{
title: "订单编号",
key: "marketOrderNo",
dataIndex: "marketOrderNo",
// customCell: (value, index, column) => {
// console.log(column, "column");
// if (
// index > 0 &&
// value.marketOrderNo == cloneData.value[index - 1].marketOrderNo
// ) {
// return { rowSpan: 0 };
// } else {
// let rowSpan = 1;
// // 向后搜索相同值的行数

//     const currents =
//       (pagination.value.current - 1) * pagination.value.pageSize + 1;
//     // const page = currents + pagination.value.pageSize;
//     const endIndex = Math.min(currents + pagination.value.pageSize - 1); // 这里需要根据实际

//     // console.log(currents - 1, endIndex - 1, "dataList");
//     for (let i = currents - 1; i <= endIndex - 1; i++) {
//       if (cloneData.value[i]) {
//         console.log(
//           i,
//           "--=-=-=-=-=-",
//           value.marketOrderNo,
//           "===",
//           cloneData.value[i].marketOrderNo
//         );
//         if (value.marketOrderNo == cloneData.value[i].marketOrderNo) {
//           rowSpan++;
//           console.log("111111", cloneData.value[i].marketOrderNo);
//         } else {

//         }
//       }
//     }
//     return { rowSpan: rowSpan };
//   }
// },
customCell: (value, index, column) => {
  console.log(index, value, "============");
  // return {
  //   children: `${text}`,
  //   attrs: {
  //     rowSpan: record.marketOrderNoRowSpan,
  //   },
  // };
  return {
    rowSpan: value.marketOrderNoRowSpan,
  };
},

},
{
title: "订单名称",
key: "marketOrderName",
dataIndex: "marketOrderName",
// customCell: (value, index) => {
// if (
// index > 0 &&
// value.marketOrderName ==
// schedulingDetailData.value[index - 1].marketOrderName
// ) {
// return { rowSpan: 0 };
// } else {
// let rowSpan = 1;
// // 向后搜索相同值的行数
// for (let i = index + 1; i < schedulingDetailData.value.length; i++) {
// if (
// value.marketOrderName ==
// schedulingDetailData.value[i].marketOrderName
// ) {
// rowSpan++;
// } else {
// break;
// }
// }
// return { rowSpan: rowSpan };
// }
// },
},
{
title: "产品名称",
key: "productName",
dataIndex: "productName",
},
{
title: "产品规格",
key: "specification",
dataIndex: "specification",
},
{
title: "产品编码",
key: "productNo",
dataIndex: "productNo",
},
{
title: "已经排产数",
key: "schedulingQuantity",
dataIndex: "schedulingQuantity",
},
{
title: "剩余排产数量",
key: "unSchedulingQuantity",
dataIndex: "unSchedulingQuantity",
},
]);
// 合并单元格
const combineRow = (key) => {
// debugger;
let tableData = cloneData.value;
for (var i = 0; i < tableData.length; i++) {
const item = tableData[i];
let count = 1;
// 开始数据
const currents =
(pagination.value.current - 1) * pagination.value.pageSize + 1;
// 结束数据
const page = currents + pagination.value.pageSize;
console.log(page - 1, "page");
// 循环的数据
for (let j = i + 1; j < tableData.length; j++) {
// 如果当前数据大于开始值,小于结束值得时候,才开始走判断
if (i >= currents - 1 && i <= page - 1) {
// 如果是同一个值,往后递增
if (item[key] === tableData[j][key]) {
count++;
// 往后相同的值都设为空单元格
tableData[j][${key}RowSpan] = 0;
// 只有同值第一个才设置合并的单元格数
item[${key}RowSpan] = count;
// 所有都是为同一个值的情况
// 如果到了尾部,则循环结束
if (j === tableData.length - 1) {
return;
}
} else {
// 指针跳转到下一个,从下一排开始
i = j - 1;
count = 1;
tableData[j][${key}RowSpan] = 1;
break;
}
}
}
}

// cloneData.value = tableData;
};
const rowSelection = computed(() => {
return {
selectedRowKeys: selectedRowKeysList.value,
selectedRows: pendingProductionData.value,
onChange: (selectedRowKeys, selectedRows) => {
selectedRowKeysList.value = selectedRowKeys;
pendingProductionData.value = selectedRows;
},
};
});

const getList = async () => {
loading.value = true;
// let searchParam = {};
// //搜索信息
// for (const key in searchData.fields) {
// searchParam[key] = searchData.fields[key].value;

// let { rangeDate } = toRaw(searchParam);
// if (rangeDate && rangeDate.length > 0) {
// searchParam.planStartTime = rangeDate[0] + " 00:00:00";
// searchParam.planEndTime = rangeDate[1] + " 23:59:59";
// }
// }
let result = await schedulingOrderStatistics({
...pageParam.value,
// bizType: props.type,
});
schedulingData.value = result.data;
paginationProps.value.total = result.total;
loading.value = false;
};
const { refresh, pageParam, paginationProps } = usePagenation(getList);
function rowClick(record) {
pagination.value.current = 1;
deliveryTime.value = record.deliveryTime;
schedulingDetailData.value = _cloneDeep(record.marketOrderVOs);
cloneData.value = record.marketOrderVOs;
combineRow("marketOrderNo");
selectedRowKeysList.value = [];
pendingProductionData.value = [];
}
const showInOutCheckDrawer = () => {
inOutCheckVisible.value = true;
};
onBeforeMount(() => {
getList();
});

const handlePageChange = (page) => {
// updateDisplayData(page);
pagination.value.current = page.current;
pagination.value.total = page.total;
combineRow("marketOrderNo");
};
const updateDisplayData = (val) => {
console.log(val, "pagination.value.current");
const startIndex = (val.current - 1) * val.pageSize;
const endIndex = startIndex + val.pageSize;
console.log(startIndex, endIndex, "startIndex,endIndex");
console.log(schedulingDetailData.value, "schedulingDetailData");
cloneData.value = schedulingDetailData.value.slice(startIndex, endIndex);
console.log(cloneData, "cloneData");
};
</script>

<style lang="less" scoped>
.custom {
border-bottom: 1px solid #f0f0f0;
}
.customs {
line-height: 30px;
}
:deep(.ant-table-cell) {
padding: 16px 0px !important;
text-align: center;
}
</style>


2b4fa72034aab9eac91b13559a116dd.png

2b4fa72034aab9eac91b13559a116dd.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,817评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,329评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,354评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,498评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,600评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,829评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,979评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,722评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,189评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,519评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,654评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,329评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,940评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,762评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,993评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,382评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,543评论 2 349

推荐阅读更多精彩内容