<template>
    <div>
      <el-table
        v-loading="loading"
        :data="itemList"
      >
        <!-- <el-table-column type="selection" width="55" align="center"/> -->
        <el-table-column label="工序名称" width="120" prop="processName"/>
        <el-table-column label="工作中心" width="120" prop="workstationName"/>
        <el-table-column label="标准工时" width="100" prop="stdWorkingTime"/>
        <el-table-column label="工时单位" width="80" prop="stdWorkingTimeUom"/>
        <el-table-column label="工序总量" width="80" prop="quantity"/>
        <el-table-column label="工作单元" width="180" prop="workunitId">
          <template slot-scope="scope">
            <el-select v-model="scope.row.workunitId" placeholder="请选择" @focus="handleFous(scope.row)">
              <el-option
                v-for="(item,index) in scope.row.taskList"
                :key="index"
                :label="item.workunitName"
                :value="item.workunitId">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="计划开始时间" width="220" prop="scheduleStartTime">
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.scheduleStartTime"
              type="datetime"
              style="width: 100%;"
              placeholder="请选择计划开始时间"
              format ="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column label="计划结束时间" width="220" prop="scheduleEndTime">
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.scheduleEndTime"
              type="datetime"
              style="width: 100%;"
              placeholder="请选择计划结束时间"
              format ="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
          </template>
        </el-table-column>
      </el-table>
    </div>
</template>

<script>
import { getProWorkOrderProcessList } from "@/api/mes/pro/workorder";
import { gettaskWorkunitList } from '@/api/mes/pro/scheduleList'

export default {
  name: "commandList",
  components: { },
  data() {
    return {
      showFlag: false,
      // 选中数组
      ids: [],
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 物料产品表格数据
      itemList: [{}],
      loading: false,
    };
  },
  created() {

  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;
      console.log(this.$attrs.workorderId, 'attrs')
      getProWorkOrderProcessList({
        workorderId: this.$attrs.workorderId
      }).then((response) => {
        this.itemList = response.rows
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.statusArr = ["ORCHESTRATED"]
      this.handleQuery();
    },
    async handleFous(row) {
      if (row.taskList&&row.taskList.length) {
        return
      }
      const response = await gettaskWorkunitList({workstationId: row.workstationId})
      this.$set(row,'taskList',response.rows)
      console.log(row)
    },
  },
};
</script>
