<template>
  <div style="width:100%;">
    <el-form ref="form" :model="dsCraftMold" :rules="rules" class="vd-form" label-width="80px" size="mini"
      v-if="!disabled">
      <el-row>
        <el-col :span="8">
          <!-- 级别 -->
          <el-form-item :label="'工艺级别'" prop="rank">
            <el-select v-model="dsCraftMold.rank" :placeholder="'请选择'">
              <el-option v-for="item in rankList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- 生产标识 -->
          <el-form-item :label="'生产标识'" prop="qualityGrade">
            <procedure-qua v-model="dsCraftMold.qualityGrade" :option="procedureQuaOption" multiple style="width:120px"
              @change="procedureQuaChange" />
            <el-select v-model="dsCraftMold.qualityGrade" :placeholder="'请选择'">
              <el-option v-for="item in rankList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
        </el-col>

      </el-row>

    </el-form>
    <el-tabs v-model="activeName" type="border-card">
      <!-- 试验项目 -->
      <el-tab-pane :label="'项目'" name="1">
        <!-- <trial-item ref="trialItemRef" :height="height" :order-no="orderNo" @loadTreeData="loadTreeData" />
          -->
        <avue-crud ref="crud" :option="optionTrialItem" :data="data" @row-update="rowUpdate" @row-save="rowSave"
          @row-click="handleRowClick">
          <template #menu-left="{ }">
            <el-button @click="addRow">删除选择行</el-button>
          </template>
          <template #menu-right="{ }">
            <el-cascader v-model="cascaderValue" :props="{ expandTrigger: 'hover' }" :options="cascaderOptions"
              style="width: 260px;height:30px; margin:0 12px;" class="proModel" @change="handleChange" />
            <el-button @click="importTemplate">导入模板 </el-button>
          </template>
          <template #menu="{ row, index }">
            <el-button text type="primary" :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
              @click="rowCell(row, index)">
              {{ row.$cellEdit ? '保存' : '修改' }}
            </el-button>
            <el-button v-if="row.$cellEdit" text icon="el-icon-cancel" type="primary" @click="rowCancel(row, index)">
              取消
            </el-button>
          </template>
        </avue-crud>
      </el-tab-pane>
      <!-- 尺寸量具 -->
      <el-tab-pane :label="'尺寸、量具'" name="2">
        <!-- <size-measure ref="sizeMeasureRef" :height="height" :order-no="orderNo" @loadTreeData="loadTreeData" /> -->
        <avue-crud ref="crud" :option="sizeOption" :data="data" @row-update="rowUpdate" @row-save="rowSave"
          @row-click="handleRowClick">
          <template #menu-left="{ }">
            <el-button @click="addRow">删除选择行</el-button>
          </template>
          <template #menu-right="{ }">
          </template>
          <template #menu="{ row, index }">
            <el-button text type="primary" :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
              @click="rowCell(row, index)">
              {{ row.$cellEdit ? '保存' : '修改' }}
            </el-button>
            <el-button v-if="row.$cellEdit" text icon="el-icon-cancel" type="primary" @click="rowCancel(row, index)">
              取消
            </el-button>
          </template>
        </avue-crud>
      </el-tab-pane>
      <!-- 工装对应 -->
      <el-tab-pane :label="'工装、模具表'" name="3">
        <!-- <ds-tools-info ref="dsToolsInfoRef" :height="height" /> -->
        <avue-crud ref="crud" :option="toolsOption" :data="data" @row-update="rowUpdate" @row-save="rowSave"
          @row-click="handleRowClick">
          <template #menu-left="{ }">
            <el-button @click="addRow">删除选择行</el-button>
          </template>
          <template #menu-right="{ }">
          </template>
          <template #menu="{ row, index }">
            <el-button text type="primary" :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
              @click="rowCell(row, index)">
              {{ row.$cellEdit ? '保存' : '修改' }}
            </el-button>
            <el-button v-if="row.$cellEdit" text icon="el-icon-cancel" type="primary" @click="rowCancel(row, index)">
              取消
            </el-button>
          </template>
        </avue-crud>
      </el-tab-pane>

    </el-tabs>
  </div>
</template>
<script>
// import sizeMeasure from './sizeMeasure.vue';
// import trialItem from './trialItem.vue';
// import dsToolsInfo from './dsToolsInfo.vue';

export default {
  name: 'ProcessIndex',
  components: {
    // sizeMeasure, 
    // trialItem, 
    // dsToolsInfo 
  },
  props: {
    height: {
      type: Number,
      default: 600
    },
    orderNo: {
      type: String,
      default: ''
    },
    dialogType: {
      type: String,
      default: '',
    }
  },
  data() {
    return {
      disabled: false,
      activeName: '1',
      keyId: null,
      fid: null,
      clickRow: {},
      dsCraftMold: {
        qualityGrade: [],
        quGrText: [],
        dsPart: { partId: this.partId },
        priority: 3,
        craftNo: 'C000000',
        rank: 2
      },
      option: {
        submitBtn: false,
        emptyBtn: false,
        addBtn: false,
        editBtn: false,
        addRowBtn: true,
        addRowBtnText: '插入一行',
        cellBtn: false,
        cancelBtn: false,
        menu: false,
        selection: true,
        tip: false,
        menuAlign: 'left',
        column: [
          {
            label: '工序号',
            prop: 'processNo',
            span: 23,
            cell: true,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '工序',
            prop: 'bsProcedureSet.ppsId',
            bind: 'bsProcedureSet.ppsId',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '工序代码',
            prop: 'bsProcedureSet.ppsCode',
            bind: "bsProcedureSet.ppsCode",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '工艺能力',
            prop: 'bsCraftAbility.caId',
            bind: "bsCraftAbility.caId",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '工时定额',
            prop: 'hourQuota',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '工序描述',
            prop: 'memo',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '主工序',
            prop: 'cruxProcess',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },


        ]
      },
      optionTrialItem: {
        submitBtn: false,
        emptyBtn: false,
        addBtn: false,
        editBtn: false,
        addRowBtn: true,
        addRowBtnText: '插入一行',
        cellBtn: false,
        cancelBtn: false,
        menu: false,
        selection: true,
        tip: false,
        menuAlign: 'left',
        searchLabelPosition:'left',
searchLabelPosition:'left',
 searchGutter:24,
  searchSpan:6,
menuAlign: 'left',
gridBtn:false,
searchMenuPosition:'right',
        column: [
          {
            label: '工序号',
            prop: 'processNo',
            span: 23,
            cell: true,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '检验项目',
            prop: 'bsProcedureSet.ppsId',
            bind: 'bsProcedureSet.ppsId',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '检验标准',
            prop: 'bsProcedureSet.ppsCode',
            bind: "bsProcedureSet.ppsCode",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '工时定额(分钟)',
            prop: 'bsCraftAbility.caId',
            bind: "bsCraftAbility.caId",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '准备公式(分钟)',
            prop: 'hourQuota',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '测试夹具号',
            prop: 'memo',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
        ]
      },
      sizeOption: {
        submitBtn: false,
        emptyBtn: false,
        addBtn: false,
        editBtn: false,
        addRowBtn: true,
        addRowBtnText: '插入一行',
        cellBtn: false,
        cancelBtn: false,
        menu: false,
        selection: true,
        tip: false,
        menuAlign: 'left',
        searchLabelPosition:'left',
searchLabelPosition:'left',
 searchGutter:24,
  searchSpan:6,
menuAlign: 'left',
gridBtn:false,
searchMenuPosition:'right',
        column: [
          {
            label: '工序号',
            prop: 'processNo',
            span: 23,
            cell: true,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '镀前镀后',
            prop: 'bsProcedureSet.ppsId',
            bind: 'bsProcedureSet.ppsId',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '量具',
            prop: 'bsProcedureSet.ppsCode',
            bind: "bsProcedureSet.ppsCode",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '量具尺寸',
            prop: 'bsCraftAbility.caId',
            bind: "bsCraftAbility.caId",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '图纸尺寸',
            prop: 'hourQuota',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
        ]
      },
      toolsOption: {
        submitBtn: false,
        emptyBtn: false,
        addBtn: false,
        editBtn: false,
        addRowBtn: true,
        addRowBtnText: '插入一行',
        cellBtn: false,
        cancelBtn: false,
        menu: false,
        selection: true,
        tip: false,
        searchLabelPosition:'left',
searchLabelPosition:'left',
 searchGutter:24,
  searchSpan:6,
menuAlign: 'left',
gridBtn:false,
searchMenuPosition:'right',
        column: [
          {
            label: '工序号',
            prop: 'processNo',
            span: 23,
            cell: true,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '对应工装',
            prop: 'bsProcedureSet.ppsId',
            bind: 'bsProcedureSet.ppsId',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          }, {
            label: '工装名称',
            prop: 'bsProcedureSet.ppsCode',
            bind: "bsProcedureSet.ppsCode",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '是否印字',
            prop: 'bsCraftAbility.caId',
            bind: "bsCraftAbility.caId",
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '印字版编号',
            prop: 'hourQuota',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '测试夹具号',
            prop: 'memo',
            cell: true,
            span: 23,
            rules: [
              {
                required: true,
                message: '请输入密码',
                trigger: 'blur'
              }
            ]
          },

        ]
      }
    };
  },
  watch: {
    activeName: function () {
      this.loadDetail();
    }
  },
  mounted() {
    console.log(9999, this.dialogType)
    this.disabled = this.dialogType == 'view' ? true : false
  },
  methods: {
    loadData(keyId, level = 1, fid = null) {
      this.keyId = keyId;
      this.fid = fid;
      this.loadDetail(level);
    },
    loadDetail(level = 1) {
      if (this.activeName === '1') {
        this.$refs.trialItemRef.loadData(this.keyId, this.fid, level);
      } else if (this.activeName === '2') {
        this.$refs.sizeMeasureRef.loadData(this.keyId);
      } else if (this.activeName === '3') {
        this.$refs.dsToolsInfoRef.loadData(this.keyId);
        // } else if (this.activeName === '4') {
        //   this.$refs.dsGlassInfoRef.loadData(this.keyId);
      }
    },
    loadTreeData(pid) {
      this.$emit('loadTreeData', pid);
    }
  }
};
</script>
