<template>
  <div class="app-container">
    <search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
    <base-table v-loading="dataListLoading" :table-props="tableProps" :page="listQuery.pageNo"
      :limit="listQuery.pageSize" :table-data="tableData">
      <method-btn v-if="tableBtn.length" slot="handleBtn" :width="120" label="操作" :method-list="tableBtn"
        @clickBtn="handleClick" />
    </base-table>
    <pagination :limit.sync="listQuery.pageSize" :page.sync="listQuery.pageNo" :total="listQuery.total"
      @pagination="getDataList" />
    <!-- <base-dialog
			:dialogTitle="addOrEditTitle"
			:dialogVisible="addOrUpdateVisible"
			@cancel="handleCancel"
			@confirm="handleConfirm"
			:before-close="handleCancel"
			width="30%"> -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" />
    <!-- </base-dialog> -->
  </div>
</template>

<script>
import AddOrUpdate from './add-or-updata';
import basicPage from '../../../core/mixins/basic-page';
import { parseTime } from '../../../core/mixins/code-filter';
import {
  getQualityHotMaterialPage,
  deleteQualityHotMaterial,
  getHotMaterialAllList
} from '@/api/base/qualityHotMaterial';
// import { getList, } from "@/api/base/qualityScrapType";
const tableProps = [
	{
		prop: 'createTime',
		label: '添加时间',
		filter: parseTime
  },
  {
    prop: 'supplierName',
    label: '供应商'
  },
	{
    prop: 'materialName',
    label: '原料'
	},
	{
    prop: 'sampleCode',
    label: '样品编号'
	},
	{
    prop: 'samplerName',
		label: '取样人'
  },
  {
    prop: 'appearance',
    label: '是否合格'
  },
  {
    prop: 'materialGrade',
    label: '原料等级'
  },
  {
    prop: 'checkerName',
    label: '检测人员'
  },
];

export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
        getDataListURL: getQualityHotMaterialPage,
        deleteURL: deleteQualityHotMaterial,
				// exportURL: exportFactoryExcel,
			},
			tableProps,
			tableBtn: [
        this.$auth.hasPermi(`base:quality-hot-material:update`)
					? {
							type: 'edit',
							btnName: '编辑',
					  }
          : undefined,
        this.$auth.hasPermi(`base:quality-hot-material:detail`)
          ? {
            type: 'detail',
            btnName: '详情',
          }
          : undefined,
        this.$auth.hasPermi(`base:quality-hot-material:delete`)
					? {
							type: 'delete',
							btnName: '删除',
					  }
					: undefined,
			].filter((v)=>v),
			tableData: [],
			formConfig: [
				// {
				// 	type: 'input',
        //   label: '报废原因',
        //   placeholder: '报废原因',
        //   param: 'content',
        // },
        {
          type: 'select',
          label: '原料名称',
          selectOptions: [],
          labelField: 'name',
          valueField: 'id',
          param: 'materialId',
        },
				{
					type: 'button',
					btnName: '查询',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'separate',
				},
				{
          type: this.$auth.hasPermi('base:quality-scrap-det:create') ? 'button' : '',
					btnName: '新增',
					name: 'add',
					color: 'success',
					plain: true
				},
			],
		};
	},
	components: {
		AddOrUpdate,
	},
  created() { },
  mounted () {
    this.getDict();
  },
  methods: {
    otherMethods(val) {
      if (val.type === 'detail') {
        this.addOrUpdateVisible = true;
        this.addOrEditTitle = "详情";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(val.data.id, true);
        });
      }
    },
		// 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.urlOptions.getDataListURL(this.listQuery).then(response => {
        this.tableData = response.data.list;
        this.listQuery.total = response.data.total;
        this.dataListLoading = false;
      });
    },
    async getDict() {
      // 物料列表
      const res = await getHotMaterialAllList();
      this.formConfig[0].selectOptions = res.data;
    },
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
          this.listQuery.content = val.content ? val.content : undefined;
          this.listQuery.typeId = val.typeId ? val.typeId : undefined;
					this.getDataList();
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {
						pageSize: 10,
						pageNo: 1,
						total: 1,
					};
					this.getDataList();
					break;
				case 'add':
					this.addOrEditTitle = '新增';
					this.addOrUpdateVisible = true;
					this.addOrUpdateHandle();
					break;
				case 'export':
					this.handleExport();
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
