<template>
  <basic-container>
    <avue-crud :data="data" :option="option" :page.sync="page" @on-load="onLoad" @row-del="rowDel" @row-save="rowSave"
      @row-update="rowUpdate" @search-change="searchChange" @refresh-change="refreshChange">
    </avue-crud>
  </basic-container>
</template>

<script>
import { customerList, jdmoduleDelete, jdmoduleSave, jdmoduleUpdate } from "@/api/system/configurationLedger";

export default {
  name: "configurationLedger",
  data() {
    return {
      data: [],
      form: {},
      page: {
        size: 10,
        current: 1
      },
      option: {
        index: true,
        searchMenuPosition: "right",
        searchMenuSpan: 12,
        align: 'center',
        menuAlign: 'center',
        column: [
          {
            label: "所属企业",
            prop: "tenantId",
            type: "tree",
            dicUrl: "/api/blade-system/tenant/select",
            props: {
              label: "tenantName",
              value: "tenantId"
            },
            search: true,
            rules: [{
              required: true,
              message: " ",
              trigger: "click"
            }]
          }, {
            label: '账户名称',
            prop: 'accountName',
            search: true
          }, {
            label: '客户ID',
            prop: 'clientId'
          }, {
            label: '客户密钥',
            prop: 'clientSecret'
          }, {
            label: '客户帐号',
            prop: 'username'
          }, {
            label: '帐号密码',
            prop: 'password'
          }, {
            label: '是否启用',
            prop: 'isEnable',
            type:'switch',
            formatter: (val, value, label) => {
              if (value) {
                return '是'
              } else {
                return '否'
              }
            }
          }
        ]
      }
    }
  },
  methods: {
    //列表查询
    onLoad(page, params) {
      customerList({ ...params, size: page.size, current: page.current }).then(res => {
        this.data = res.data.data.records
        this.page.total = res.data.data.total
      })
    },
    //刷新按钮触发
    refreshChange() {
      this.onLoad(this.page);
    },
    //表单搜索按钮触发
    searchChange(params, done) {
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done()
    },
    //新增
    rowSave(row, done, loading) {
      jdmoduleSave(row).then(() => {
        this.$message.success('新增成功');
        this.onLoad(this.page);
        loading()
        done()
      })
    },
    //编辑
    rowUpdate(row, index, done, loading) {
      jdmoduleUpdate(row).then(() => {
        this.$message.success('修改成功');
        this.onLoad(this.page);
        loading()
        done()
      })
    },
    //删除
    rowDel(row, index, done) {
      jdmoduleDelete(row.id).then(() => {
        this.$message.success('删除成功');
        done()
      })
    }
  }
}
</script>

<style scoped>
</style>
