<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="70"
          :label="$t('handle')"
          :method-list="tableBtn"
          @clickBtn="handleClick"
        />
      </base-table>
      <pagination
        :limit.sync="listQuery.limit"
        :page.sync="listQuery.page"
        :total="listQuery.total"
        @pagination="getDataList"
      />
      <!-- 弹窗, 条件搜索-->
      <!-- <base-dialog
        :dialogTitle="searchsTitle"
        :dialogVisible="searchsVisible"
        @cancel="searchsCancel"
        @confirm="searchsConfirm"
        :before-close="searchsCancel"
      >
        <searchs ref="searchsRef" @refreshDataList="searchsSubmit"></searchs>
      </base-dialog> -->
      <!-- 弹窗, 新增 / 修改 -->
      <base-dialog
        :dialogTitle="addOrEditTitle"
        :dialogVisible="addOrUpdateVisible"
        @cancel="handleCancel"
        @confirm="handleConfirm"
        :before-close="handleCancel"
        width="80%"
      >
        <add-or-update ref="addOrUpdate" @refreshDataList="successSubmit"></add-or-update>
      </base-dialog>
    </div>
  </el-card>
</template>

<script>
import AddOrUpdate from "./components/eightDisciplineList-detail";
// import Searchs from "./components/searchs";
import processStatus from "./components/processStatus"
import basicPage from "@/mixins/basic-page";
import codeFilter from "@/filters/code-filter";
import { timeFormatter } from "@/filters/code-filter";
import i18n from "@/i18n";

const tableProps = [
  {
    prop: "title",
    label: i18n.t("code.title"),
    align: "center",
  },
  {
    prop: "productName",
    label: "产品",
    align: "center",
  },
  {
    prop: "customName",
    label: "客户",
    align: "center",
  },
  {
    prop: "occurrenceDate",
    label: i18n.t("code.occurrenceDate"),
    align: "center",
    filter: timeFormatter,
  },
  {
    prop: "D1",
    label: "D1",
    num: 1,
    align: "center",
    subcomponent: processStatus,
  },
  {
    prop: "D2",
    label: "D2",
    num: 2,
    align: "center",
    subcomponent: processStatus,
  },
  {
    prop: "D3",
    label: "D3",
    num: 3,
    align: "center",
    subcomponent: processStatus,
  },
  {
    prop: "D4",
    label: "D4",
    num: 4,
    align: "center",
    subcomponent: processStatus,
  },
  {
    prop: "D5",
    label: "D5",
    num: 5,
    align: "center",
    subcomponent: processStatus,
  },
  {
    prop: "D6",
    label: "D6",
    num: 6,
    align: "center",
    subcomponent: processStatus,
  },
  {
    prop: "D7",
    label: "D7",
    num: 7,
    align: "center",
    subcomponent: processStatus,
  },
  {
    prop: "D8",
    label: "D8",
    num: 8,
    align: "center",
    subcomponent: processStatus,
  },
];
const tableBtn = [
  {
    type: "detail",
    btnName: "详情",
  },
];

const eightDisciplineStatusArr = [
  {
    name: "D0",
    id: 0,
  },
  {
    name: "D1",
    id: 1,
  },
  {
    name: "D2",
    id: 2,
  },
  {
    name: "D3",
    id: 3,
  },
  {
    name: "D4",
    id: 4,
  },
  {
    name: "D5",
    id: 5,
  },
  {
    name: "D6",
    id: 6,
  },
  {
    name: "D7",
    id: 7,
  },
  {
    name: "D8",
    id: 8,
  },
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/code/startEightDiscipline/eight/page",
        deleteURL: "/code/startEightDiscipline",
      },
      tableProps,
      tableBtn,
      eightDisciplineStatusArr,
      tableData: [],
      optionArrUrl: ["/basic/qmsCustomer/page", "/basic/qmsProduct/page"],
      formConfig: [
        {
          type: "input",
          label: i18n.t("code.title"),
          placeholder: i18n.t("code.title"),
          param: "title",
        },
        {
          type: "select",
          label: "客户",
          selectOptions: [],
          param: "customId",
          defaultSelect: "",
          labelField: "customerName",
          filterable: true,
        },
        {
          type: "select",
          label: "产品",
          selectOptions: [],
          param: "productId",
          defaultSelect: "",
          labelField: "productName",
          filterable: true,
        },
        {
          type: "select",
          label: "步骤",
          selectOptions: eightDisciplineStatusArr,
          param: "eightDisciplineStatus",
          defaultSelect: "",
          filterable: true,
        },
        {
          type: "datePicker",
          label: "日期",
          dateType: "date",
          format: "yyyy-MM-dd",
          valueFormat: "yyyy-MM-ddTHH:mm:ss",
          placeholder: "日期",
          param: "occurrenceDate",
          width: 170,
        },
        {
          type: "button",
          btnName: "搜索",
          name: "search",
          color: "primary",
        },
      ],
    };
  },
  components: {
    AddOrUpdate,
    processStatus,
    // Searchs,
  },
  created() {
    this.getArr();
  },
  methods: {
    getArr() {
      this.optionArrUrl.forEach((item, index) => {
        this.$http
          .get(item, {
            params: {
              page: 1,
              limit: 500,
            },
          })
          .then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg);
            }
            this.formConfig[index + 1].selectOptions = res.data.list;
          })
          .catch(() => {});
      });
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http
        .post(this.urlOptions.getDataListURL, this.listQuery)
        .then(({ data: res }) => {
          this.dataListLoading = false;
          if (res.code !== 0) {
            this.tableData = [];
            this.listQuery.total = 0;
            return this.$message.error(res.msg);
          }
          this.tableData = res.data.list;
          this.listQuery.total = res.data.total;
        })
        .catch(() => {
          this.dataListLoading = false;
        });
    },
    //search-bar点击
    searchsClick() {
      this.searchsTitle = "条件搜索";
      this.searchsHandle();
    },
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          this.listQuery.page = 1;
          this.listQuery.limit = 10;
          this.listQuery.title = val.title;
          this.listQuery.eightDisciplineStatus = val.eightDisciplineStatus;
          this.listQuery.customId = val.customId;
          this.listQuery.productId = val.productId;
          this.listQuery.occurrenceDate = val.occurrenceDate;
          this.getDataList();
          break;
        default:
          console.log(val);
      }
    },
    otherMethods(val) {
      this.addOrEditTitle = "详情";
      this.addOrUpdateVisible = true;
      this.addOrUpdateHandle(val.data.id);
    },
  },
};
</script>
