<!-- 币别及汇率 -->
<template>
  <div>
    <basic-container v-show="isShow" class="page-crad">
      <avue-crud
        ref="crud"
        :option="option"
        :data="dataList"
        :before-open="beforeOpen"
        id="out-table"
        :header-cell-class-name="headerClassName"
        :page.sync="page"
        :search.sync="search"
        @search-change="searchChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        @on-load="onLoad"
        :table-loading="loading"
        @saveColumn="saveColumn"
        @resetColumn="resetColumn"
        @selection-change="selectionChange"
        :cell-style="cellStyle"
        @search-criteria-switch="searchCriteriaSwitch"
      >
        <template slot-scope="{ row }" slot="updateUser">
          <span>{{ row.updateUserName }}</span>
        </template>
        <template slot-scope="{ row, index }" slot="menu">
          <el-button type="text" size="small" @click.stop="editOpen(row, 1)">
            查看
          </el-button>
          <!-- <el-button type="text" size="small" @click.stop="editOpen(row, 1)">
            编辑
          </el-button> -->
          <el-button
            type="text"
            size="small"
            @click.stop="rowDel(row, index)"
            :disabled="row.status > 0"
          >
            删除
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
    <detailPage
      v-if="!isShow"
      ref="detail"
      @goBack="goBack"
      @copyOrder="copyOrder"
      :detailData="detailData"
    ></detailPage>
  </div>
</template>

<script>
import detailPage from "./detailsPage";
import { getRateList, deleteDetails } from "@/api/iosBasicData/rateManagement";

export default {
  name: "index",
  components: {
    detailPage
  },
  data() {
    return {
      selectionList: [],
      form: {},
      dataList: [],
      loading: false,
      isShow: true,
      detailData: {},
      search: {},
      page: {
        pageSize: 10,
        currentPage: 1
      },
      option: {
        searchShow: true,
        searchMenuSpan: 6,
        align: "center",
        border: true,
        index: true,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 120,
        tip: false,
        selection: true,
        searchIcon: true,
          searchIndex: 3,
          calcHeight: 30,
        addBtnText: "新单",
        stripe: true,
        column: [
          {
            label: "代码",
            prop: "code",
            overHidden: true,
            search: true
          },
          {
            label: "国际三字码",
            prop: "unCode",
            overHidden: true,
            search: true
          },
          {
            label: "中文名称",
            prop: "cnName",
            overHidden: true,
            search: true
          },
          {
            label: "英文名称",
            prop: "enName",
            overHidden: true,
            search: true
          },
          {
            label: "货币符号",
            prop: "symbol",
            overHidden: true
          },
          {
            label: "是否本币",
            prop: "isLocal",
              dicData:[{
                label:'非本币',
                value:0
              },{
                label:'本币',
                value:1
              }],
            overHidden: true
          },
          {
            label: "对本币汇率",
            prop: "exrate",
            overHidden: true
          },
          {
            label: "国家代码",
            prop: "cntyCode",
            overHidden: true
          },
          {
            label: "国家名称",
            prop: "cntyName",
            overHidden: true
          },
          {
            label: "状态",
            prop: "status",
              type: "select",
              dicData:[{
                label:'启用',
                value:0
              },{
                label:'停用',
                value:1
              }],
              value: 0,
            overHidden: true
          }
        ]
      }
    };
  },
  created() {
    this.option.height = window.innerHeight - 210;
  },
  activated() {
    if (this.$route.query.check) {
      this.isShow = true;
      setTimeout(() => {
        this.editOpen({ id: this.$route.query.check.billId }, 1);
      }, 100);
    }
  },
  methods: {
    searchCriteriaSwitch(type) {
      if (type) {
        this.option.height = this.option.height - 46;
      } else {
        this.option.height = this.option.height + 46;
      }
      this.$refs.crud.getTableHeight();
    },
    cellStyle() {
      return "padding:0;height:40px;";
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    //点击搜索按钮触发
    searchChange(params, done) {
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    refreshChange() {
      this.onLoad(this.page, this.search);
    },
    currentChange(val) {
      this.page.currentPage = val;
    },
    sizeChange(val) {
      this.page.currentPage = 1;
      this.page.pageSize = val;
    },
    onLoad(page, params = {}) {
      this.loading = true;
      let queryParams = {
        ...params,
        ...this.search,
        size: page.pageSize,
        current: page.currentPage
      };
      getRateList(queryParams)
        .then(res => {
          this.dataList = res.data.data.records ? res.data.data.records : [];
          this.page.total = res.data.data.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //新增跳转页面
    beforeOpen() {
      this.isShow = false;
    },
    editOpen(row, status) {
      this.detailData = {
        id: row.id,
        status: status
      };
      this.isShow = false;
    },
    rowDel(row, index, done) {
      this.$confirm("确定删除数据?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        deleteDetails(row.id).then(res => {
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.onLoad(this.page, this.search);
          }
        });
      });
    },
    goBack() {
      if (this.$route.query.check) {
        this.$router.$avueRouter.closeTag(this.$route.fullPath);
        this.$router.push({
          path: "/salaryManagement/primarySchool/index"
        });
      }
      this.detailData = this.$options.data().detailData;
      this.onLoad(this.page, this.search);
      this.isShow = true;
    },
        // 更改表格颜色
        headerClassName(tab){
            //颜色间隔
            let back = ""
            if (tab.columnIndex >= 0 && tab.column.level === 1) {
                if (tab.columnIndex % 2 === 0) {
                    back = "back-one"
                } else if (tab.columnIndex % 2 === 1) {
                    back = "back-two"
                }
            }
            return back;
        },
  }
};
</script>

<style lang="scss" scoped>
.page-crad ::v-deep .basic-container__card {
  height: 94.2vh;
}
::v-deep#out-table .back-one {
        background: #ecf5ff !important;
    }
    ::v-deep#out-table .back-two {
        background: #ecf5ff !important;
    }
/deep/ .el-col-md-8 {
  width: 24.33333%;
}
</style>
