<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
      <base-table
        :table-props="tableProps"
        :page="listQuery.page"
        :limit="listQuery.limit"
        :table-data="tableData"
      >
        <method-btn
          v-if="tableBtn.length"
          slot="handleBtn"
          :width="150"
          label="操作"
          :method-list="tableBtn"
          @clickBtn="handleClick"
        />
      </base-table>
      <pagination
        :limit.sync="listQuery.limit"
        :page.sync="listQuery.page"
        :total="listQuery.total"
        @pagination="getDataList"
      />
      <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @successSubmit="getDataList"
    ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import AddOrUpdate from "./components/productList-add";
import inspectionStage from "./inspectionStage"
import basicPage from "@/mixins/basic-page";
import basicFilter from "@/filters/basic-filter";

const tableProps = [
  {
    prop: "name",
    label: "名称",
  },
  {
    prop: "code",
    label: "编码",
  },
  {
    prop: "specifications",
    label: "规格",
  },
  {
    prop: "drawing",
    label: "图纸",
  },
  {
    prop: "productType",
    label: "产品类型",
  },
  {
    prop: "remark",
    label: "备注",
  },
  {
    prop: "descs",
    label: "描述",
  },
  {
    prop: "inspectionStandard",
    label: "检验标准",
  },
  {
    prop: "inspectionStage",
    label: "检验阶段",
    subcomponent: inspectionStage
  },
  {
    prop: "status",
    label: "状态",
    filter: basicFilter("status"),
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
  {
    type: "change",
    btnName: "改变状态",
  },
];

export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/basic/product/page",
        deleteURL: "/basic/product/delete",
        statusUrl: "/basic/product/status",
        exportUrl: "/basic/product/export",
      },
      tableProps,
      tableBtn,
      tableData: [],
      formConfig: [
        {
          type: "input",
          label: "名称",
          placeholder: "请输入名称",
          param: "name",
        },
        {
          type: "input",
          label: "编码",
          placeholder: "请输入编码",
          param: "code",
        },
        {
          type: "select",
          label: "产品类型",
          selectOptions: [
          ],
          param: "product_type_id",
          defaultSelect: "",
        },
        {
          type: "select",
          label: "检验阶段",
          selectOptions: [
            { id: 1, name: "进货检验" },
            { id: 2, name: "过程检验" },
            { id: 3, name: "成品检验" },
            { id: 4, name: "出货检验" },
          ],
          param: "inspection_stage",
          defaultSelect: "",
        },
        {
          type: "button",
          btnName: "查询",
          name: "search",
          color: "primary",
        },
        {
          type: "button",
          btnName: "新增",
          name: "add",
          color: "primary",
          plain: true,
        },
        {
          type: "button",
          btnName: "导出",
          name: "export",
          color: "primary",
          plain: true,
        },
      ],
    };
  },
  components: {
    AddOrUpdate,
  },
  created() {
    this.getArr();
  },
  methods: {
    //search-bar点击
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          this.listQuery.name = val.name;
          this.listQuery.code = val.code;
          this.listQuery.product_type_id = val.product_type_id;
          this.listQuery.inspection_stage = val.inspection_stage;
          this.listQuery.page = 1;
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle()
          break;
        case "export":
          this.exportHandle('产品列表')
          break;
        default:
          console.log(val)
       }
    },
    getArr() {
      this.$http
        .get("/basic/productType/page", {
          params: {
            page: 1,
            limit: 500,
          },
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            this.formConfig[2].selectOptions = [];
            return this.$message.error(res.msg);
          }
          this.formConfig[2].selectOptions = res.data.list;
        })
        .catch(() => {});
    },
  },
};
</script>
