<template>
  <div>
    <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 #menu-left>
        <!-- <el-button type="danger" icon="el-icon-delete" @click="handleDelete">删 除
            </el-button> -->
        <el-button type="primary" @click="moldAddFn(null, true)">新增</el-button>
      </template>
      <template #menu-right>
        <el-button type="success" icon="el-icon-upload" @click="handleImport">导入 </el-button>
      </template>
    </avue-crud>
    <!-- 导入 -->
    <basic-import
      v-if="isShowImport"
      title="导入"
      :isShow="isShowImport"
      templateUrl="/blade-safety/wasteWaterDosingRecord/download-excel-template"
      templateName="废水加药记录模板.xlsx"
      importUrl="/blade-safety/wasteWaterDosingRecord/import-excel"
      @closeDialog="closeDialog"
    ></basic-import>
      <!-- 新增 -->
    <addEditDialogTestRecord 
    v-if="addOpen" 
    :showDialog="addOpen"
    @closeDialog="closeDialog" 
    :moldAddMore="moldAddMore" 
    @submitData="handleSubmitData">
    </addEditDialogTestRecord>
  </div>
</template>
<script>
import basicImport from '@/components/basic-import/main.vue';
import addEditDialogTestRecord from './addEditDialogTestRecord.vue';
export default {
  components: {
    basicImport,
    addEditDialogTestRecord
  },
  data() {
    return {
      addOpen: false, //新增弹窗
      moldAddMore: false,
      isShowImport: false,
      loading: false,
      selectionList: [],
      option: {
        height: 'auto',
        calcHeight: 32,
        tip: false,
        size: 'medium',
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: true,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtnText: '修改',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        viewBtnText: '详情',
        labelWidth: 120,
        menuWidth: 120,
        dialogWidth: 1040,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        index: false,
        showOverflowTooltip: true,
        searchLabelPosition: 'left',
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: 'left',
        gridBtn: false,
        searchMenuPosition: 'right',
        align: 'center',
        column: [
          {
            label: '设施',
            prop: 'device',
            sortable: true,
            filter: true,
            span: 12,
            search: true,
            searchLabelWidth: 140,
            rules: [
              {
                required: true,
                message: '请输入设施',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '化验时间',
            prop: 'dosingTime',
            search: true,
            sortable: true,
            filter: true,
            span: 12,
            type: "datetime",
            format: 'YYYY-MM-DD HH:mm:ss',
            valueFormat: 'YYYY-MM-DD HH:mm:ss',
            rules: [
              {
                required: true,
                message: '请选择化验时间',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '化验人',
            prop: 'dosingMan.userId',
            bind: 'dosingMan.userName',
            search: true,
            sortable: true,
            filter: true,
            span: 12,
            searchLabelWidth: 140,
            type: 'select',
            dicData: [
            { label: '测试', value: '测试' },
            { label: '测试1', value: '测试1' },
          ],
            rules: [
              {
                required: true,
                message: '请选择化验人',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '镍',
            prop: 'itNi',
            search: true,
            sortable: true,
            filter: true,
            span: 12,
            rules: [
              {
                required: true,
                message: '请输入报警阙值',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '铜',
            prop: 'itCu',
            search: false,
            sortable: true,
            filter: true,
            span: 12,
            rules: [
              {
                required: true,
                message: '请输入铜',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '六价铬',
            prop: 'itCr',
            search: false,
            sortable: true,
            filter: true,
            span: 12,
            rules: [
              {
                required: true,
                message: '请输入六价铬',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '氰化物',
            prop: 'itCn2',
            search: false,
            sortable: true,
            filter: true,
            span: 12,
            rules: [
              {
                required: true,
                message: '请输入氰化物',
                trigger: 'blur',
              },
            ],
          },
          {
            label: 'PH',
            prop: 'itPh',
            search: false,
            sortable: true,
            filter: true,
            span: 12,
            rules: [
              {
                required: true,
                message: '请输入PH报警点位',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '备注',
            prop: 'memo',
            search: false,
            sortable: true,
            filter: true,
            span: 12,
          },
        ],
      },
      form: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
    };
  },
  methods: {
      // 新增
        moldAddFn(row, flag) {
            this.addOpen = true
            this.moldAddMore = flag
        },
        //关闭弹窗
        closeDialog() {
            this.addOpen = false
        },
        // 处理子组件提交的数据
        handleSubmitData(data) {
          this.$message.success("数据提交成功！");
          this.addOpen = false;
        },
    // 点击导入按钮
    handleImport() {
      this.isShowImport = true
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {});
    },
    // 多选
    selectionChange(list) {
      this.selectionList = list;
    },
    onLoad() {
      this.loading = true;
      this.data = [
        {
          device: '12',
          dorType: 2,
          dosingMan: {
            accountId: null,
            card: null,
            createTime: '2023-02-08',
            curStatus: 1,
            deleted: false,
            deptName: null,
            dimissionTime: null,
            factoryId: 41,
            head: 0,
            jobName: '主任',
            keyValue: 453,
            ldapName: '00075',
            mail: null,
            mobile: null,
            pfDepartment: {
              appLink: null,
              createTime: '2023-02-08',
              deleted: false,
              deptCode: '26',
              deptId: 57,
              deptName: '外协业务中心',
              deptType: 1,
              deptTypeTitle: '厂',
              keyValue: 57,
              memo: null,
              orders: '26',
              parentDeptId: 41,
              parentPath: null,
              ucDeptId: null,
              updateTime: '2023-02-08 16:38:31',
            },
            pinyinIndex: '00075,00075',
            ucUserId: null,
            updateTime: '2023-02-08 17:25:13',
            userCode: '00075',
            userId: 453,
            userName: '测试1',
            userSex: 1,
            userSources: '测试1',
            userString: '453:A:测试1',
            userType: 'A',
          },
          dosingTime: '2023-11-22 00:00:00',
          itCn2: '3',
          itCr: '3',
          itCu: '2',
          itId: 21,
          itNi: '1',
          itPh: '10',
          keyValue: 21,
          memo: null,
        },
        {
          device: 'qq',
          dorType: 2,
          dosingMan: {
            accountId: null,
            card: null,
            createTime: '2023-04-06',
            curStatus: 1,
            deleted: false,
            deptName: null,
            dimissionTime: null,
            factoryId: 41,
            head: 0,
            jobName: '软件工程师',
            keyValue: 521,
            ldapName: null,
            mail: null,
            mobile: null,
            pfDepartment: {
              appLink: null,
              createTime: '2022-08-31',
              deleted: false,
              deptCode: '001',
              deptId: 1,
              deptName: 'MES开发部',
              deptType: 1,
              deptTypeTitle: '厂',
              keyValue: 1,
              memo: null,
              orders: '00',
              parentDeptId: null,
              parentPath: null,
              ucDeptId: null,
              updateTime: '2022-08-31 16:32:46',
            },
            pinyinIndex: '0001,0001',
            ucUserId: null,
            updateTime: '2023-04-06 16:23:38',
            userCode: '0001',
            userId: 521,
            userName: '测试',
            userSex: 1,
            userSources: '测试',
            userString: '521:A:测试',
            userType: 'A',
          },
          dosingTime: '2024-02-28 03:03:03',
          itCn2: null,
          itCr: '2',
          itCu: null,
          itId: 41,
          itNi: '1',
          itPh: null,
          keyValue: 41,
          memo: null,
        },
        {
          device: '12',
          dorType: 2,
          dosingMan: {
            accountId: null,
            card: null,
            createTime: '2023-02-08',
            curStatus: 1,
            deleted: false,
            deptName: null,
            dimissionTime: null,
            factoryId: 41,
            head: 0,
            jobName: '主任',
            keyValue: 453,
            ldapName: '00075',
            mail: null,
            mobile: null,
            pfDepartment: {
              appLink: null,
              createTime: '2023-02-08',
              deleted: false,
              deptCode: '26',
              deptId: 57,
              deptName: '外协业务中心',
              deptType: 1,
              deptTypeTitle: '厂',
              keyValue: 57,
              memo: null,
              orders: '26',
              parentDeptId: 41,
              parentPath: null,
              ucDeptId: null,
              updateTime: '2023-02-08 16:38:31',
            },
            pinyinIndex: '00075,00075',
            ucUserId: null,
            updateTime: '2023-02-08 17:25:13',
            userCode: '00075',
            userId: 453,
            userName: '测试1',
            userSex: 1,
            userSources: '测试1',
            userString: '453:A:测试1',
            userType: 'A',
          },
          dosingTime: '2023-11-24 00:00:00',
          itCn2: '9',
          itCr: '3',
          itCu: '12',
          itId: 42,
          itNi: '12',
          itPh: '8',
          keyValue: 42,
          memo: null,
        },
        {
          device: '12',
          dorType: 2,
          dosingMan: {
            accountId: null,
            card: null,
            createTime: '2023-02-08',
            curStatus: 1,
            deleted: false,
            deptName: null,
            dimissionTime: null,
            factoryId: 41,
            head: 0,
            jobName: '主任',
            keyValue: 453,
            ldapName: '00075',
            mail: null,
            mobile: null,
            pfDepartment: {
              appLink: null,
              createTime: '2023-02-08',
              deleted: false,
              deptCode: '26',
              deptId: 57,
              deptName: '外协业务中心',
              deptType: 1,
              deptTypeTitle: '厂',
              keyValue: 57,
              memo: null,
              orders: '26',
              parentDeptId: 41,
              parentPath: null,
              ucDeptId: null,
              updateTime: '2023-02-08 16:38:31',
            },
            pinyinIndex: '00075,00075',
            ucUserId: null,
            updateTime: '2023-02-08 17:25:13',
            userCode: '00075',
            userId: 453,
            userName: '测试1',
            userSex: 1,
            userSources: '测试1',
            userString: '453:A:测试1',
            userType: 'A',
          },
          dosingTime: '2024-03-24 00:00:00',
          itCn2: '9',
          itCr: '3',
          itCu: '12',
          itId: 43,
          itNi: '12',
          itPh: null,
          keyValue: 43,
          memo: null,
        },
      ];
      this.page.total = this.data.length;
      this.loading = false;
      setTimeout(() => {
        this.selectionClear();
      }, 500);
    },
  },
};
</script>
<style lang="scss" scoped></style>
