标签搜索

响应式无刷新传值

wehg489
2025-04-06 / 0 评论 / 1 阅读 / 正在检测是否收录...
function displaySchedule() {
  const tbody = document.querySelector('#scheduleTable tbody');
  tbody.innerHTML = '';
  console.log("check1", scheduleData);

  // 按生产日期分组显示
  const productionGroups = [...new Set(scheduleData.map(item => item.productionDate))].sort((a, b) =>
    new Date(a) - new Date(b)
  );

  for (const productionDate of productionGroups) {
    // 获取该生产日期的所有排产记录
    const productions = scheduleData.filter(item => item.productionDate === productionDate);

    // 更新标题行的colspan为7(原6列+新增1列)
    const headerRow = document.createElement('tr');
    headerRow.style.backgroundColor = '#f0f0f0';
    headerRow.innerHTML = `
      <td colspan="8">
        <strong>生产日期: ${productionDate}</strong>
        ${productions.some(item => item.isLate) ? '<span class="warning"> (有超期订单)</span>' : '<span class="on-time"> (全部按时)</span>'}
      </td>
    `;
    tbody.appendChild(headerRow);

    // 添加排产记录
    for (const production of productions) {
      const order = rawData.find(item =>
        item.productId === production.productId &&
        item.deliveryDate === production.deliveryDate
      );

      if (order) {
        const row = document.createElement('tr');
        if (production.isLate) row.classList.add('warning');

        // 在原有6列后添加查询列
        row.innerHTML = `
          <td>${production.productId}</td>
          <td>${production.quantity}</td>
          <td>${production.deliveryDate}</td>
          <td>${production.dailyMax}</td>
           <td>${production.sl}</td>
          <td>${production.productionDate}</td>
          <td>${production.isLate ? '是' : '否'}</td>
          <td class="product-info">加载中...</td>
        `;

        tbody.appendChild(row);

        // 根据productId查询数据库
        fetch('get_product_info.php', {
          method: 'POST',
          headers: {'Content-Type': 'application/json'},
          body: JSON.stringify({ productId: production.productId })
        })
        .then(response => response.json())
        .then(data => {
          const infoCell = row.querySelector('.product-info');
          if (data.success) {
            // 示例显示产品名称和库存
            infoCell.innerHTML = `
              <div>内径${data.neijing} 嘴: ${data.zui} ${data.gangsi} /${data.nanyi}</div>
              
            `;
          } else {
            infoCell.textContent = '查询失败';
          }
        })
        .catch(error => {
          row.querySelector('.product-info').textContent = '服务异常';
          console.error('产品查询失败:', error);
        });
      }
    }
  }
}

0

评论 (0)

取消
歌曲封面
0:00