<template>
  <normalTable
    :is-select="false"
    :sequence="true"
    rowKey="w_dataparamid"
    ref="list"
    size="small"
    :param="param"
    :columns="utils.TBLayout('dataparamTable')"
  >
    <template #tb_cell="{ data }">
      <div v-if="data.column.dataIndex == 'rwtype'">
        {{
          data.record.rwtype == 0
            ? "读"
            : data.record.rwtype == 1
            ? "写"
            : "上报"
        }}
      </div>
      <div v-else>
        {{ data.record[data.column.dataIndex] }}
      </div>
    </template>
    <template #operation>
      <div style="display: flex; margin-bottom: 16px">
        <div style="margin-right: 16px">
          <span>数据类型：</span>
          <a-select
            ref="select"
            v-model:value="param.content.where.datatype"
            placeholder="选择数据类型"
            style="width: 200px"
            @change="
              param.content.pageNumber = 1;
              $refs.list.listData();
            "
            allowClear
          >
            <a-select-option
              :value="item.value"
              v-for="(item, index) in typeList"
              :key="index"
              >{{ item.value }}</a-select-option
            >
          </a-select>
        </div>
        <div style="margin-right: 16px">
          <span>读写类型：</span>
          <a-select
            ref="select"
            v-model:value="param.content.where.rwtype"
            placeholder="选择读写类型"
            style="width: 200px"
            @change="
              param.content.pageNumber = 1;
              $refs.list.listData();
            "
            allowClear
          >
            <a-select-option value="0">读</a-select-option>
            <a-select-option value="1">写</a-select-option>
            <a-select-option value="2">上报</a-select-option>
          </a-select>
        </div>

        <div>
          <a-input
            v-model:value="param.content.where.condition"
            @keyup.enter="
              param.content.pageNumber = 1;
              $refs.list.listData();
            "
            placeholder="名称/标识"
            autocomplete="off"
          ></a-input>
        </div>
      </div>
    </template>
  </normalTable>
</template>

<script setup>
import AddAttrite from "./modules/Add.vue";
import listTemp from "@/components/listTemplate/index.vue";
import normalTable from "@/template/normalTable/index.vue";
import customBtn from "@/components/customHandleBtn/index.vue";
import customBtn2 from "@/components/customHandleBtn/index.vue";
import Edit from "./modules/Edit.vue";
import { useBaseStore } from "@/stores/modules/base";
import {
  ref,
  defineProps,
  defineEmits,
  onMounted,
  provide,
  inject,
  defineExpose,
} from "vue";
import { useRouter } from "vue-router";
import Api from "@/api/api";
import utils from "@/utils/utils";
let list = ref();
let base = useBaseStore();
let router = useRouter();
let emit = defineEmits([]);
let props = defineProps(["data", "disabled", "mode"]);
let param = ref({
  id: 20230613091602,
  content: {
    ownertable: "w_device",
    ownerid: router.currentRoute.value.query.id,
    pageNumber: 1,
    pageSize: 20,
    mode: props.mode,
    where: {
      condition: "",
      datatype: undefined,
      rwtype: undefined,
    },
  },
});
let searchType = ref([{ label: "搜索", key: "condition", type: "input" }]);
let typeList = ref([]);
let optionList = ref([]);
let unitList = ref([]);

provide("optionList", optionList);
provide("typeList", typeList);
provide("unitList", unitList);

onMounted(async () => {
  let res = await base.optiontypeselect("datatype");
  typeList.value = res.data;
  let res2 = await base.optiontypeselect("optiontype");
  optionList.value = res2.data;
  let res3 = await base.optiontypeselect("dataunit");
  unitList.value = res3.data;
  console.log(typeList.value);
});
let getList = () => {
  list.value.listData();
};

defineExpose({
  param,
  getList,
});
</script>

<style scoped>
</style>
