<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #goodsCode="{ row }">{{ row.coGoods.goodsCode }}</template>
      <template #materialGoods="{ row }">{{ row.materialGoods.materialGoods }}</template>
      <template #goodsCode-form="{ type }">
        <el-input
          placeholder="请输入物料编码"
          v-if="type == 'add'"
          v-model="form.goodsCode"
        ></el-input>
        <el-input
          placeholder="请输入物料编码"
          v-if="type == 'edit'"
          v-model="form.coGoods.goodsCode"
        ></el-input>
      </template>
      <template #materialGoods-form="{ type }">
        <el-input
          placeholder="请输入子件物料编码"
          v-if="type == 'add' || type == 'edit'"
          v-model="form.materialGoods.materialGoods"
        ></el-input>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      data: [],
      form: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        columnSort: true,
        tip: false,
        height: "auto",
        align: "center",
        calcHeight: 32,
        simplePage: false,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: true,
        viewBtn: false,
        delBtn: true,
        editBtn: true,
        editBtnText: "修改",
        editBtnIcon: " ",
        delBtnIcon: " ",
        addBtn: true,
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 200,
        dialogWidth: 600,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: true,
        gridBtn: false,
        searchShowBtn: false,
        showOverflowTooltip: true,
        searchLabelPosition: "left",
        searchLabelPosition: "left",
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: "left",
        gridBtn: false,
        searchMenuPosition: "right",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        column: [
          {
            label: "物料编号",
            prop: "goodsCode",
            span: 24,
            labelWidth: 140,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入物料编号",
                trigger: "blur",
              },
            ],
          },
          {
            label: "子件物料编号",
            prop: "materialGoods",
            span: 24,
            labelWidth: 140,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入子件物料编号",
                trigger: "blur",
              },
            ],
          },
          {
            label: "版本",
            prop: "releaseno",
            span: 24,
            labelWidth: 140,
            overflow: true,
            search: false,
            hide: true,
            rules: [
              {
                required: true,
                message: "请输入版本",
                trigger: "blur",
              },
            ],
          },
          {
            label: "数量",
            prop: "quantity",
            span: 24,
            labelWidth: 140,
            overflow: true,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入数量",
                trigger: "blur",
              },
            ],
          },
          {
            label: "单价",
            prop: "price",
            hide: true,
            span: 24,
            labelWidth: 140,
            overflow: true,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入单价",
                trigger: "blur",
              },
            ],
          },
          {
            label: "是否模架特殊物料",
            prop: "moldBaseSpecialStr",
            span: 24,
            type: "select",
            labelWidth: 140,
            overflow: true,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入是否模架特殊物料",
                trigger: "blur",
              },
            ],
            dicData: [
              { label: "是", value: 1 },
              { label: "否", value: 0 },
            ],
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    // 多选
    selectionChange(list) {
      this.selectionList = list;
    },
    onLoad() {
      this.data = [
        {
          id: 1,
          coGoods: { goodsCode: "001" },
          materialGoods: { materialGoods: "001-1" },
          releaseno: "1.0",
          quantity: 10,
          price: 20,
          moldBaseSpecialStr: 1,
        },
        {
          id: 1,
          coGoods: { goodsCode: "001" },
          materialGoods: { materialGoods: "001-1" },
          releaseno: "1.0",
          quantity: 10,
          price: 20,
          moldBaseSpecialStr: 0,
        },
      ];
      this.page.total = this.data.length;
    },
  },
};
</script>

<style></style>
