<template>
  <div class="finance pagePadding">
    <ex-table
      v-loading="loading"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
      :table="table"
      :data="tableData"
      :columns="columns"
      :page="pageInfo"
      :size="size"
      @page-curr-change="handlePageChange"
      @page-size-change="handleSizeChange"
      @screen-reset="
        pageInfo.curr = 1;
        searchList();
      "
      @screen-submit="
        pageInfo.curr = 1;
        searchList();
      "
    >
      <template #table-header="{}">
        <div style="width: 100%">
          <el-row :gutter="10">
            <el-col :span="24">
              <el-col :span="3" style="width: 195px; float: right">
                <el-button
                  v-if="powers.some((item) => item == '002')"
                  :size="searchSize"
                  type="primary"
                  style="float: right; margin-left: 5px"
                  @click="searchList"
                >
                  刷新
                </el-button>
                <el-button
                  v-if="powers.some((item) => item == '003')"
                  :size="searchSize"
                  type="success"
                  style="float: right; margin: 0"
                  @click="openModal('add', false)"
                >
                  添加
                </el-button>
              </el-col>
            </el-col>
          </el-row>
        </div>
      </template>
      <template #status="{ scope }">
        <el-tag
          :type="scope.row.status == '0' ? 'warning' : ''"
          :size="size"
          v-text="
            (statusOptions.find((item) => item.id == scope.row.status) || {})
              .label || '--'
          "
        ></el-tag>
      </template>
      <template #operation="{ scope }">
        <el-tooltip
          v-if="powers.some((item) => item == '007')"
           
          effect="dark"
          content="详情"
          placement="top"
        >
          <i
            class="el-icon-view tb-icon"
            @click="openModal(scope.row.companyNo, true)"
          ></i>
        </el-tooltip>
        <el-tooltip
          v-if="powers.some((item) => item == '007')"
           
          effect="dark"
          content="修改"
          placement="top"
        >
          <i
            class="el-icon-edit tb-icon"
            @click="openModal(scope.row.companyNo, false)"
          ></i>
        </el-tooltip>
        <el-tooltip
          v-if="
            powers.some((item) => item == '004') && scope.row.status === '1'
          "
           
          effect="dark"
          content="禁用"
          placement="top"
        >
          <i
            class="el-icon-video-pause tb-icon"
            @click="statusConfirm(scope.row.companyNo, scope.row.status)"
          ></i>
        </el-tooltip>
        <el-tooltip
          v-if="
            powers.some((item) => item == '004') && scope.row.status === '0'
          "
           
          effect="dark"
          content="启用"
          placement="top"
        >
          <i
            class="el-icon-video-play tb-icon"
            @click="statusConfirm(scope.row.companyNo, scope.row.status)"
          ></i>
        </el-tooltip>
      </template>
    </ex-table>
    <no-auth v-else></no-auth>
    <!-- 弹窗 新增/修改 -->
    <add-edit
      :id="modelId"
      :show-model="showModel"
      :is-detail="isDetail"
      :contector="contector"
      :name="name"
      @refresh="searchList"
      @cancel="showModel = false"
    />
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/parameter/finance";
import ExTable from "@/components/ExTableNew.vue";
import mixinPage from "@/mixins/elPaginationHandle";
import addEdit from "./addEdit";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
export default {
  name: "finance",
  components: {
    ExTable,
    addEdit,
  },
  mixins: [mixinPage, resToken],
  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "finance"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  
  data() {
    return {
      isDetail: false,
      // 状态
      statusOptions: [
        { id: "0", label: "禁用" },
        { id: "1", label: "启用" },
      ],
      pickerOptions: {
        // disabledDate是一个函数,参数是当前选中的日期值,这个函数需要返回一个Boolean值,
        disabledDate(time) {
          let date = new Date().valueOf();
          const one = 1000 * 60 * 60 * 24;
          date = parseInt(date / one) * one;
          return time.getTime() <= date;
        },
      },
      showModel: false,
      loading: false,
      modelId: 0,
      parmValue: {
        // name: "", // 账户
        // contector: "", // 姓名
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "companyNo",
          label: "信息编号",
          width: "190px",
        },
        {
          prop: "company_name",
          label: "单位名称",
        },
        {
          prop: "company_license",
          label: "纳税人识别号",
          width: "190px",
        },
        {
          prop: "bank_name",
          label: "银行名称",
        },
        {
          prop: "bankNo",
          label: "银行卡号",
        },
        {
          prop: "status",
          label: "状态",
          width: "90px",
          _slot_: "status",
        },
        // {
        //   prop: "contector",
        //   label: "联系人",
        // },

        // {
        //   prop: "mobile",
        //   label: "联系电话",
        // },
        // {
        //   prop: "company_address",
        //   label: "地址",
        // },
        {
          prop: "addtime",
          label: "创建时间",
          width: "160px",
          sortable: true,
        },
        {
          prop: "",
          label: "操作",
          width: "120px",
          fixed: "right",
          _noset_: true,
          _slot_: "operation",
        },
      ],
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    async searchList() {
      this.loading = true;
      const res = await asyncRequest.list(this.parmValue);
      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        this.pageInfo.total = Number(res.data.count);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
    openModal(id, isDetail) {
      this.showModel = true;
      this.modelId = id;
      this.isDetail = isDetail;
    },
    async statusConfirm(id, status) {
      await this.$confirm(`确定要改为${status === "1" ? "禁用" : "启用"}？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          this.loading = true;
          const model = {
            companyNo: id,
            status: status === "1" ? "0" : "1",
          };
          const res = await asyncRequest.status(model);
          if (res && res.code === 0) {
            this.loading = false;
            this.$notify.success({
              title: "状态修改成功！",
              message: "",
            });
            await this.searchList();
          } else if (res && res.code >= 100 && res.code <= 104) {
            await this.logout();
          } else {
            this.loading = false;
            this.$message.warning(res.message);
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.finance {
  background: rgba(242, 242, 242, 1);
  min-height: 100%;
  width: 100%;
  height: 100%;
  // background-color: $bg;
  overflow: hidden;

  // position: absolute;
  z-index: 2;
  background: #fff;
  .change {
    .title {
      border-width: 0px;
      width: 100%;
      height: 100px;
      // display: flex;
      font-weight: 400;
      font-style: normal;
      font-size: 22px;
      text-align: left;
      padding: 0;
      padding: 60px 0 0 100px;
      width: 100%;
      box-sizing: border-box;
    }
  }
}
</style>
