<template>
  <div>
    <basic-container v-show="show" class="page-crad">
      <avue-crud ref="crud" :option="option" :data="dataList" :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" :cell-style="cellStyle" @search-criteria-switch="searchCriteriaSwitch">
        <template slot="menuLeft">
          <el-button type="primary" size="mini" @click.stop="newAdd()">新建产品
          </el-button>
        </template>
        <template slot-scope="{ row, index }" slot="id">
          <span style="color: #409EFF;cursor: pointer" @click.stop="editOpen(row, 2)">{{ row.cname }}
          </span>
        </template>
        <template slot-scope="{ row, index }" slot="menu">
          <!-- <el-tooltip class="item" effect="dark" content="新建销售订单" placement="top">
            <i class="tradingIcon icon-add" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="删除" placement="top">
            <i class="tradingIcon icon-del" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="编辑" placement="top">
            <i class="tradingIcon icon-edit" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="收款" placement="top">
            <i class="tradingIcon icon-proceeds" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="发货" placement="top">
            <i class="tradingIcon icon-deliver" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="对账" placement="top">
            <i class="tradingIcon icon-reconciliation" />
          </el-tooltip> -->
          <!-- <el-button type="text" size="small" @click.stop="editOpen(row, 2)">
            查看
          </el-button>
          <el-button type="text" size="small" @click.stop="rowDel(row, index)">
            删除
          </el-button> -->
        </template>
      </avue-crud>
    </basic-container>
    <details-page v-if="!show" @goBack="goBack()" :detailData="detailData" />
  </div>
</template>
  
<script>
import detailsPage from "./detailsPage";
import { option } from "./js/optionList";
import { getList, getCorpsAll, pageStatistics } from "@/api/basicData/client";
export default {
  name: "index",
  data() {
    return {
      src: '',
      show: true,
      loading: false,
      search: {},
      detailData: {},
      dataList: [],
      selectionList: [],
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0,
        pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
      },
      option: {},
    };
  },
  components: {
    detailsPage
  },
  async created() {
    this.option = await this.getColumnData(this.getColumnName(217), option);
    this.option.height = window.innerHeight - 210;
    this.getAllWorkDicts()
  },
  methods: {
    getAllWorkDicts() {
      getCorpsAll().then(res => {
        this.findObject(this.option.column, "id").dicData = res.data.data;
        this.findObject(this.option.column, "ids").dicData = res.data.data;
      })
      this.$refs.crud.init();
    },
    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;";
    },
    //点击搜索按钮触发
    searchChange(params, done) {
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    refreshChange() {
      this.onLoad(this.page, this.search);
    },
    newAdd() {
      this.show = false;
    },
    onLoad(page, params = {}) {
      let data = this.deepClone(Object.assign(params, this.search));
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        data
      )
        .then(res => {
          this.dataList = res.data.data.records ? res.data.data.records : [];
          this.page.total = res.data.data.total;
        })
        .finally(() => {
          pageStatistics(data).then(res => {
            this.form = res.data.data
          })
          this.loading = false;
        });
    },
    editOpen(row, status) {
      this.detailData = {
        id: row.id,
        status: status
      };
      this.show = false;
    },
    currentChange(val) {
      this.page.currentPage = val;
    },
    sizeChange(val) {
      this.page.currentPage = 1;
      this.page.pageSize = val;
    },
    rowDel(row, index, done) {
      this.$confirm("确定删除数据?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        // remove(row.id).then(res => {
        //   if (res.data.code == 200) {
        //     this.$message({
        //       type: "success",
        //       message: "删除成功!"
        //     });
        //     this.onLoad(this.page, this.search);
        //   }
        // });
      });
    },
    async saveColumn() {
      const inSave = await this.saveColumnData(
        this.getColumnName(217),
        this.option
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud.doLayout();
        });
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crud.$refs.dialogColumn.columnBox = false;
      }
    },
    async resetColumn() {
      this.option = option;
      const inSave = await this.delColumnData(this.getColumnName(217), option);
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud.doLayout();
        });
        this.getAllWorkDicts()
        this.$message.success("重置成功");
        this.$refs.crud.$refs.dialogColumn.columnBox = false;
      }
    },
    //返回列表
    goBack() {
      this.detailData = this.$options.data().detailData;
      this.show = true;
      this.onLoad(this.page, this.search);
    },
  }
}
</script>
  
<style  lang="scss"  scoped>
.page-crad ::v-deep .basic-container__card {
  height: 94.2vh;
}

.stat-td {
  text-align: center;
  position: relative;
}

.stat-img {
  width: 95%;
  height: 100px;
}

.stat-tip {
  position: absolute;
  left: 15px;
  top: 5px;

  .money {
    color: #fff;
    font-size: 28px;
    text-align: left;
    font-weight: 600;
  }

  .title {
    color: #fff;
    font-size: 14px;
    text-align: left;
    margin-top: 5px;
    margin-bottom: 0px;
  }
}
</style>
  