<template>
  <div>
    <el-card>
      <el-form :model="query" label-width="100px" size="mini">
        <el-row>
          <el-col :span="6">
            <el-form-item label="自助平台名称" class="query-form-item">
              <el-input v-model="query.key" style="width: 100%;" placeholder="请输入自助平台名称" clearable="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
              <el-button-group>
                <el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button>
                <el-button type="primary" icon="search" @click="search">查询</el-button>
              </el-button-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-table v-loading="loading" :data="list" border  style="width: 100%" @row-click="handleSelectionChange">
        <el-table-column label="序号" type="index" fixed></el-table-column>
        <el-table-column label="自助平台名称" prop="name" fixed></el-table-column>
        <el-table-column label="往来单位编码" prop="unitId" fixed></el-table-column>
        <el-table-column label="往来单位名称" prop="corpName" fixed></el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.native.stop="handleModifyClick(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
          v-show="total>0"
          :total="total"
          :limit.sync="query.limit"
          :page.sync="query.page"
          @pagination="handleCurrentChange"
      ></pagination>
    </el-card>


      <el-card>
        <el-table :data="delectList" border highlight-current-row style="width: 100%">
          <el-table-column label="本地单据" prop="sourceName" fixed></el-table-column>
          <el-table-column label="目标部门" prop="invName" fixed></el-table-column>
          <el-table-column label="目标仓库" prop="invSubName" fixed></el-table-column>
          <el-table-column label="目标单据类型" prop="targetName" fixed></el-table-column>
        </el-table>

        <pagination
            v-show="delectTotal>0"
            :total="delectTotal"
            :limit.sync="delectQuery.limit"
            :page.sync="delectQuery.page"
            @pagination="handleCurrentChange"
        ></pagination>
      </el-card>



      <el-dialog
          title="关联医院客户"
          :visible.sync="editLoginVisible"
          v-if="editLoginVisible"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          width="60%"
      >
        <bindPlatformModel
            :editQuery="editLogin"
            :closeDialog="closeDialog"
        ></bindPlatformModel>
      </el-dialog>

  </div>
</template>

<script>
import {
  addUnit,
  modifyUnit
} from "@/api/userManage/unitMaintain";
import {getBasicUnitMaintains, getPlatFormDelect} from "@/api/basic/basicUnitMaintain";
import {
  getPlatform,
  linkPlatform,
  getLinkPlatformList,
  unbindPlatform,
  getTargetActions,
  getTargetInv,
  getTargetSubInv,
  testUserInfo
} from "@/api/userManage/platform";
import {getBussinessType} from "../../api/basic/bussinessType";
import {isBlank} from "@/utils/strUtil";
import bindPlatformModel from "@/views/userManage/bindPlatformModel";

export default {
  data() {
    return {
      query: {
        key: "",
        coryType: null,
        page: 1,
        limit: 20
      },
      delectQuery: {
        page: 1,
        limit: 20
      },
      editLogin: {},
      loading: false,
      editLoginVisible: false,

      checked: false,
      list: [],
      delectList: [],
      total: 0,
      delectTotal:0,
      editType: 0,
    };
  },
  components: {bindPlatformModel},
  methods: {
    onReset() {
      this.$router.push({
        path: ""
      });
      this.query = {
        key: "",
        coryType: null,
        customerId: this.$store.getters.customerId,
        page: 1,
        limit: 20
      };
      this.getList();
    },
    search() {
      this.query.page = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      getLinkPlatformList(this.query).then((res) => {
        this.loading = false;
        this.list = res.data.list || [];
        this.total = res.data.total || 0;
      }).catch(() => {
        this.loading = false;
        this.list = [];
      });
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getList();
    },
    handleModifyClick(row) {
      this.editLoginVisible = true;
      this.editLogin = row;
    },
    handleAddClick() {
      this.editLoginVisible = true;
    },
    //获取详情列表
    getPlatFormDelect(platformId) {
      this.delectQuery.platformId=platformId
      getPlatFormDelect(this.delectQuery).then((res) => {
        this.delectList = res.data.list || [];
        this.delectTotal = res.data.total || 0;
      }).catch((error) => {
        this.$message.error(error.message);
      });
    },
    handleSelectionChange(row){
      this.getPlatFormDelect(row.platformId)
    }
  },
  created() {
    this.getList();
  }
};

</script>

<style>

</style>
