<template>
  <!-- 转外协 -->
  <el-dialog
    title="转外协"
    append-to-body
    :modelValue="showDialog"
    width="60%"
    @close="closeDialog"
  >
    <el-form :model="outsourceForm" :rules="outsourceRules" label-width="70px">
      <el-form-item label="备注：" prop="memo">
        <el-input
          placeholder="请输入备注"
          v-model="outsourceForm.memo"
          type="textarea"
          style="width: 40%"
        ></el-input>
      </el-form-item>
    </el-form>
    <el-table :data="outsourceData">
      <el-table-column align="center" type="selection"></el-table-column>
      <el-table-column align="center" label="工序号" prop="workPlan.processSet.code"></el-table-column>
      <el-table-column
        align="center"
        label="工序代码"
        prop="workPlan.processSet.code"
      ></el-table-column>
      <el-table-column
        align="center"
        label="工序名称"
        prop="workPlan.processSet.name"
      ></el-table-column>

      <el-table-column align="center" label="工艺能力" prop="caId">
        <template #default="scope">
          <el-select v-model="scope.row.processAbility.caId">
            <el-option
              v-for="item in craftData"
              :key="item.caId"
              :label="item.caName"
              :value="item.caId"
            ></el-option>
          </el-select>
        </template>
      </el-table-column>

      <el-table-column align="center" label="工序描述" prop="makeMemo"> </el-table-column>
      <el-table-column align="center" label="不可转外协原因" prop="reason"> </el-table-column>
    </el-table>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="turnOem">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { getListProProcess, transferBill } from '@/api/productionManagement/productionMonitoring';
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false,
    },
    itemData: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      outsourceForm: {},
      outsourceRules: {
        memo: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
      outsourceData: [],
      craftData: [
        {
          bsWorkType: null,
          caCode: 'E3240',
          caId: 25,
          caName: '化学氧化',
          keyValue: 25,
          updateTime: '2023-04-03 18:35:23',
        },
        {
          bsWorkType: null,
          caCode: 'E802',
          caId: 26,
          caName: '镀后检验',
          keyValue: 26,
          updateTime: '2023-04-11 15:31:32',
        },
        {
          bsWorkType: null,
          caCode: 'E390',
          caId: 27,
          caName: '超声波清洗',
          keyValue: 27,
          updateTime: '2023-04-11 10:19:50',
        },
        {
          bsWorkType: null,
          caCode: 'E379',
          caId: 28,
          caName: '滚镀金或振镀金',
          keyValue: 28,
          updateTime: '2023-04-11 10:20:29',
        },
        {
          bsWorkType: null,
          caCode: 'E386',
          caId: 36,
          caName: '化学镀镍',
          keyValue: 36,
          updateTime: '2023-04-11 15:31:25',
        },
      ],
    };
  },
  mounted() {
    this.getListProProcess();
  },
  methods: {
    getListProProcess() {
      let params = {
        woIds: this.itemData.map(item => item.woId),
        runType: 1, //转换类型：1-外协，2-厂内
      };
      getListProProcess(params).then(res => {
        this.outsourceData = res.data.data;
      });
    },
    closeDialog() {
      this.$emit('closeDialog');
    },
    // 确定
    turnOem() {
      if (this.outsourceData.length == 0) {
        this.$message.error('当前数据列表为空');
        return;
      }

      let query={
        workOrderRuns:this.itemData,
        workPlanRuns:this.outsourceData
      }

      transferBill(query).then(res => {
        this.$message.success('操作成功');
        this.closeDialog();
      });
    },
  },
};
</script>

<style></style>
