<!--
 * @Author: zhp
 * @Date: 2023-01-11 09:24:58
 * @LastEditTime: 2023-07-17 16:27:53
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <SearchBar :formConfigs="formConfig" ref="ruleForm" @headBtnClick="buttonClick">
        <!-- <el-badge :value="2" class="item">
          <el-button type="primary" size="small" @click="conditionSearch">条件搜索</el-button>
        </el-badge> -->
      </SearchBar>
      <base-table :table-props="tableProps" :page="listQuery.page" :limit="listQuery.limit" :table-data="tableData">
        <method-btn v-if="tableBtn.length" slot="handleBtn" :width="100" label="操作" :method-list="tableBtn"
          @clickBtn="handleClick" />
      </base-table>
      <pagination :limit.sync="listQuery.limit" :page.sync="listQuery.page" :total="listQuery.total"
        @pagination="getDataList" />
      <!-- 弹窗, 新增 / 修改 -->
      <base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="addOrUpdateVisible" @cancel="handleCancel"
        @confirm="handleConfirm" :before-close="handleCancel">
        <approvalProcessConfiguration-add ref="addOrUpdate" @refreshDataList="successSubmit">
        </approvalProcessConfiguration-add>
        <!-- <el-row slot="footer" type="flex" justify="end"> </el-row> -->
      </base-dialog>
      <base-dialog :dialogTitle="searchOrEditTitle" :dialogVisible="searchOrUpdateVisible" @cancel="handleSearchCancel"
        @confirm="handleSearchConfirm" :before-close="handleSearchCancel">
        <approvalProcessConfiguration-search ref="searchOrUpdate" @successSubmit="conditionSearchSubmit">
        </approvalProcessConfiguration-search>
        <el-row slot="footer" type="flex" justify="end">
          <el-col :span="12">
            <el-button size="small" type="primary" plain class="btnTextStyle" @click="handleSearchCancel">
              {{ $t("close") }}
            </el-button>
            <el-button size="small" class="btnTextStyle" type="primary" plain @click="handleSearchReset">{{
              $t("reset")
              }}</el-button>
            <el-button type="primary" size="small" class="btnTextStyle" @click="handleSearchConfirm">
              {{ $t("search") }}
            </el-button>
          </el-col>
        </el-row>
      </base-dialog>
    </div>
  </el-card>
</template>

<script>
import basicPage from "@/mixins/basic-page"
import approvalProcessConfigurationAdd from "./components/approvalProcessConfiguration-add"
import nonconform from '@/filters/nonconform'

// import AddOrUpdate from './params-add-or-update'
import approvalProcessConfigurationSearch from "./components/approvalProcessConfigurationSearch"
// import available from "./components/available.vue"
import basicSearch from "@/mixins/basic-search"
import i18n from "@/i18n"
const tableProps = [
  {
    prop: 'inspectionTypeId',
    label: i18n.t("disqualification.inspectionTypeId"),
    align: 'center',
    filter: nonconform('inspectionType'),
  },
  {
    prop: 'productName',
    label: i18n.t("disqualification.productName"),
    align: 'center'
  },
  {
    prop: 'disposalMethod',
    label: i18n.t("disqualification.disposalMethod"),
    align: 'center'
  },
  {
    prop: 'approvalProcessName',
    label: i18n.t("disqualification.approvalProcessName"),
    align: 'center'
  }
]
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
];
export default {
  mixins: [basicPage, basicSearch],
  components: {
    approvalProcessConfigurationSearch,
    approvalProcessConfigurationAdd
  },
  data() {
    return {
      urlOptions: {
        getDataListURL: "/nonconform/qmsApprovalProcessConfiguration/page",
        deleteURL: "/nonconform/qmsApprovalProcessConfiguration",
        getProductURL: '/basic/qmsProduct/page'
      },
      tableProps,
      tableBtn,
      searchOrEditTitle: '',
      searchOrUpdateVisible: false,
      formConfig: [
        {
          type: 'select',
          label: i18n.t('disqualification.inspectionTypeId'),
          placeholder: i18n.t('disqualification.inspectionTypeId'),
          param: 'inspectionTypeId',
          selectOptions: [
            {
              id: '0',
              name: '监控'
            },
            {
              id: '1',
              name: '电芯来料检验'
            },
            {
              id: '2',
              name: 'IQC抽检'
            },
            {
              id: '3',
              name: 'IQC抽检2'
            },
            {
              id: '4',
              name: '原料抽检'
            },
            {
              id: '5',
              name: '进货外观检验'
            },
            {
              id: '6',
              name: '库内原料检验'
            },
            {
              id: '7',
              name: '来料检验'
            },
            {
              id: '8',
              name: '胶片'
            },
            {
              id: '9',
              name: '抽检'
            },
            {
              id: '10',
              name: '巡检'
            },
            {
              id: '11',
              name: '首检'
            },
            {
              id: '12',
              name: '末检'
            },
            {
              id: '13',
              name: '实时监测'
            },
            {
              id: 14,
              name: 'FQC抽检'
            },
            {
              id: 15,
              name: 'OQC抽检'
            },
          ],
          clearable: true,
          filterable: true
        },
        {
          type: 'select',
          label: i18n.t('disqualification.productName'),
          placeholder: i18n.t('disqualification.productName'),
          param: 'productId',
          selectOptions: [],
          clearable: true,
          filterable: true
        },
        {
          type: "button",
          btnName: "新增",
          name: "add",
          color: 'success',
          plain: true
        },
        {
          type: "button",
          btnName: "搜索",
          name: "search",
          color: "primary",
        }
      ],
    };
  },
  // components: {
  //   AddOrUpdate,
  // },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$http
        .get(this.urlOptions.getProductURL, {
          params: this.listQuery,
        })
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res.data)
            this.formConfig[1].selectOptions = res.data.list.map((item) => {
              return {
                id: item.id,
                name: item.productName
              }
            })
          }
        })
        .catch(() => {
        })
    },
    //search-bar点击
    handleProductCancel() {
      this.productOrUpdateVisible = false;
      this.productOrEditTitle = "";
    },
    // handleSearchCancel() {
    //   this.searchOrEditTitle = "";
    //   this.searchOrUpdateVisible = false;
    // },
    conditionSearch() {
      this.searchOrEditTitle = "搜索";
      this.searchOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.searchOrUpdate.init();
      });
    },
    conditionSearchSubmit(dataForm) {
      this.listQuery.inspectionTypeId = dataForm.inspectionTypeId
      this.listQuery.productId = dataForm.productId
      this.listQuery.page = 1;
      this.getDataList();
      this.searchOrUpdateVisible = false;
      // console.log(11111);
      // this.conditionSearchSubmit();
    },
    handleClick(val) {
      console.log(val);
      if (val.type === "delete") {
        this.$confirm(`确定对[名称=${val.data.failureTypeName}]进行删除操作?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.$http.delete(this.urlOptions.deleteURL, { data: [val.data.id] }).then(({ data }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.getDataList();
                  },
                });
              } else {
                this.$message.error(data.msg);
              }
            });
          })
          .catch(() => { });
      } else if (val.type === 'edit') {
        this.addOrEditTitle = this.$t('edit')
        this.addOrUpdateVisible = true;
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(val.data.id);
        });
      }
    },
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          // this.listQuery.paramCode = val.paramCode;
          this.listQuery.page = 1;
          this.listQuery.inspectionTypeId = val.inspectionTypeId ? val.inspectionTypeId : null
          this.listQuery.productId = val.productId ? val.productId :null
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle()
          break;
        default:
          console.log(val)
      }
    },
  }
};
</script>
