<script>
import { dicts } from "./dicts";
import useColumns from "./columns";
import { queryList } from "@/api/expend/customerExpend";
export default {
  name: "customerExpend",
  dicts: dicts,
  components: {
    ElSuperUxTable: () => import("@/components/super-ux-table/index.vue"),
    ElSuperSearch: () => import("@/components/super-search/index.vue"),
    zxsddButton: () => import("./zxsdd/index.vue"),
    hgbHdkButton: () => import("./hdk-hgb/index.vue"),
    chButton: () => import("./che-hui/index.vue"),
    tjButton: () => import("./ti-jiao/index.vue"),
    editDrawer: () => import("./edit/index.vue"),
  },
  data() {
    const { TableColumns, SearchColumns } = useColumns();
    const page = this.$init.page();
    const params = this.$init.params(SearchColumns);
    return {
      page,
      params,
      TableColumns,
      SearchColumns,
      size: "mini",
      tableData: [],
      selectData: [],
      loading: false,
    };
  },
  methods: {
    // 查询
    async useQuery(params, page) {
      try {
        this.loading = true;
        let { code, rows, total } = await queryList({ ...params, ...page });
        if (code == 200) {
          this.tableData = rows;
          this.page.total = total;
        }
      } catch (error) {
      } finally {
        this.loading = false;
      }
    },
    // 查看
    useSee(row) {
      let { setVisible, fetchItem } = this.$refs.customerEdit;
      setVisible(true, "see");
      fetchItem(row);
    },
    // 编辑
    useEdit(row) {
      let { setVisible, fetchItem } = this.$refs.customerEdit;
      setVisible(true, "edit");
      fetchItem(row);
    },
    // 重置
    useReset() {
      this.page = this.$init.page();
      this.params = this.$init.params(this.SearchColumns);
    },
    // 选 择
    useSelect(prop) {
      this.selectData = prop;
    },
  },
  created() {
    this.useQuery(this.params, this.page);
  },
};
</script>

<template>
  <el-card
    v-loading="loading"
    :body-style="{
      height: '100%',
      padding: 0,
      display: 'flex',
      'flex-direction': 'column',
    }"
  >
    <el-super-search
      v-model="params"
      :size="size"
      :dict="dict"
      :columns="SearchColumns"
      @reset="useReset"
      @submit="useQuery(params, page)"
    ></el-super-search>
    <el-row class="my-4" style="text-align: right">
      <el-button-group>
        <tj-button
          :dict="dict"
          :size="size"
          type="primary"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></tj-button>
        <ch-button
          :dict="dict"
          :size="size"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></ch-button>
      </el-button-group>
      <el-button-group>
        <zxsdd-button
          :dict="dict"
          :size="size"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></zxsdd-button>
        <hgb-hdk-button
          :dict="dict"
          :size="size"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></hgb-hdk-button>
      </el-button-group>
    </el-row>
    <edit-drawer
      ref="customerEdit"
      :dict="dict"
      :size="size"
      @success="useQuery(params, page)"
    ></edit-drawer>
    <el-super-ux-table
      v-model="tableData"
      :size="size"
      :dict="dict"
      :page="page"
      :columns="TableColumns"
      index
      checkbox
      pagination
      convenitentOperation
      storage-key="CustomerExpendSuperTable"
      @row-dblclick="useSee"
      @row-select="useSelect"
      @pagination="useQuery(params, page)"
    >
      <ux-table-column fixed="right" title="操作" align="center" width="100">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status == 0"
            type="text"
            :size="size"
            @click="useEdit(scope.row)"
            >编辑</el-button
          >
        </template>
      </ux-table-column>
    </el-super-ux-table>
  </el-card>
</template>
<style scoped lang="scss">
.el-card {
  width: calc(100% - 32px);
  height: calc(100vh - 32px);
  margin: 16px;
  padding: 16px;
  border-radius: 8px;
}

.el-button-group + .el-button-group {
  margin: 0 0 0 8px;
}
</style>
