<template>
  <div class="page-container column-container">
    <el-row :gutter="24" style="padding: 16px">
      <el-col :span="8">
        <div class="dashboard-total-item">
          <div><img :src="totalIcon2" /></div>
          <div class="dashboard-total-item-label">
            <span>待生产计划数</span>
            <span>5000</span>
          </div>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="dashboard-total-item">
          <div><img :src="totalIcon3" /></div>
          <div class="dashboard-total-item-label">
            <span>投产中生产计划数</span>
            <span>5000</span>
          </div>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="dashboard-total-item">
          <div><img :src="totalIcon3" /></div>
          <div class="dashboard-total-item-label">
            <span>本周完成计划数</span>
            <span>5000</span>
          </div>
        </div>
      </el-col>
    </el-row>

    <!-- 搜索区 -->
    <el-form class="list-search-container" :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="计划单号：">
        <el-input placeholder="请输入计划单号" v-model="queryParams.planningNumber" />
      </el-form-item>
      <el-form-item label="状态：">
        <el-select-v2
          v-model="queryParams.status"
          clearable
          filterable
          :options="plan_status"
          placeholder="全部状态"
          @change="handleQuery"
          style="width: 120px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="info" icon="Search" @click="handleQuery"><i class="el-icon-thumb" aria-hidden="true" />搜索</el-button>
        <el-button type="primary" icon="Switch">同步P2生产计划</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表区 -->
    <div class="el-table-container">
      <div class="el-table-inner-container">
        <el-table v-loading="loading" :data="productionPlanList" height="100%">
          <el-table-column type="index" label="行号" width="50" align="center"></el-table-column>
          <el-table-column label="计划单号" width="120" prop="planningNumber" align="center" />
          <el-table-column label="状态" width="100" prop="planStatus" align="center">
            <template #default="scope">
              <dict-tag :options="plan_status" :value="scope.row.planStatus" />
            </template>
          </el-table-column>
          <el-table-column label="产品描述" prop="productDescription" align="center" />
          <el-table-column label="调度" width="100" prop="scheduling" align="center" />
          <el-table-column label="开始时间" width="160" prop="startTime" align="center" />
          <el-table-column label="总批数" width="100" prop="totalNumber" align="center" />
          <el-table-column label="投产批次" width="100" prop="productionBatch" align="center" />
          <el-table-column label="完成批次" width="100" align="center">
            <template #default="scope">
              {{ scope.row.newNumber + '/' + scope.row.oldNumber }}
            </template>
          </el-table-column>

          <el-table-column label="操作" width="80" align="center">
            <template #default="scope">
              <el-button link type="primary" icon="View" @click="handleAdd(scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <el-pagination class="pagination-container" background layout="prev, pager, next" :total="total" />

    <!-- 表单 -->
    <!-- <productionPlan-form ref="productionPlanRef" :get-list="getList"></productionPlan-form> -->
  </div>
</template>

<script setup name="ProductionPlan">
import { getP2Plan } from '@/api/business/p2.js'
import totalIcon2 from '@/assets/images/dashboard-total-icon-2.png'
import totalIcon3 from '@/assets/images/dashboard-total-icon-3.png'
import { ref } from 'vue'
const { proxy } = getCurrentInstance()
/** 字典数组区 */
/** 查询 对象 */
const productionPlanList = ref([])
const loading = ref(true)
const total = ref(2)
const { plan_status } = proxy.useDict('plan_status')

/** 查询对象 */
const queryParams = ref({
  planningNumber: '',
  planStatus: '',
  pullP2PlanDetails: true,
  pageNum: 1,
  pageSize: 10
})

onMounted(() => {
  getList()
})

/****************************  方法区  ****************************/

/** 查询生产计划列表 */
function getList() {
  loading.value = true
  getP2Plan(queryParams.value).then((res) => {
    console.log(res)
    productionPlanList.value = res.data.dataList
    total.value = res.total
    loading.value = false
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}
</script>

<style lang="scss" scoped>
.dashboard-total-item {
  display: flex;
  align-items: center;
  font-size: 16px;
  height: 120px;
  background-color: #f2f2f2;
  border-radius: 10px;

  > div:first-child {
    display: flex;
    flex: 2;
    justify-content: center;
    align-items: center;
  }
  > div.dashboard-total-item-label {
    display: flex;
    flex: 3;
    flex-direction: column;
    justify-content: center;

    > span {
      display: block;
      width: 60%;
      text-align: center;

      &:first-child {
        font-size: 16px;
        margin-bottom: 4px;
        letter-spacing: 2px;
      }
      &:last-child {
        font-weight: bold;
        font-size: 24px;
      }
    }
  }
}
.dashboard-total-item > .dashboard-total-item-label > span:last-child {
  color: #444444;
}
.dashboard-total-item > .dashboard-total-item-label > span:last-child > span:first-child {
  margin-right: 8px;
}
.dashboard-total-item > .dashboard-total-item-label > span:last-child > span:last-child {
  color: #4367df;
}
.dashboard-total-item > .number-label {
  font-size: 40px;
  margin-left: 16px;
  font-weight: bold;
  color: #5a6ac3;
}
</style>
