<template>
  <div class="main_root">
    <div class="search_header">
      <Input
        v-model="searchForm.name"
        placeholder="请输入名称、网址"
        search
        @on-search="searchList()"
        style="width: 200px"
      />
    </div>
    <div class="table_wrap">
      <Table :columns="columns" :data="searchForm.list">
        <template slot-scope="{ row }" slot="whiteName">
          <div class="name_slot">
            <div class="name_content" :title="row.whiteName">
              {{ row.whiteName }}
            </div>
            <div v-if="row.whiteType === 2" class="app_tag">公用</div>
          </div>
        </template>
        <template slot-scope="{ row }" slot="website">
          <div class="website" :title="row.website">
            {{ row.website }}
          </div>
        </template>
        <template slot-scope="{ row }" slot="actionSlot">
          <div class="action_list">
            <div @click="toView(row)">查看</div>
          </div>
        </template>
      </Table>
    </div>
    <div class="page_wrap">
      <Page
        :transfer="true"
        :total="searchForm.total"
        :current="searchForm.page"
        :page-size="searchForm.size"
        :page-size-opts="[10, 20, 40, 60]"
        @on-change="pageChange"
        @on-page-size-change="pageSizeChange"
        show-total
        show-sizer
      ></Page>
    </div>
    <!-- 查看 -->
    <Modal
      class="modal1"
      :mask-closable="false"
      v-model="viewInfo.show"
      title="查看"
    >
      <div class="view_title">
        <div>{{ viewInfo.whiteName }}</div>
        <div v-if="viewInfo.whiteType === 2" class="wltype_1">公用</div>
      </div>
      <Form :label-width="80" inline>
        <FormItem label="简介" style="margin-bottom: 0; width: 100%">
          <div
            style="
              line-height: 36px;
              word-wrap: break-word;
              word-break: break-all;
            "
          >
            {{ viewInfo.comm }}
          </div></FormItem
        >
        <FormItem label="网址" style="margin-bottom: 0; width: 100%">
          <div
            style="
              line-height: 36px;
              word-wrap: break-word;
              word-break: break-all;
            "
          >
            {{ viewInfo.website }}
          </div>
        </FormItem>
        <FormItem label="授权" style="margin-bottom: 0; width: 100%">
          <Table border :columns="columns1" :data="viewInfo.schools"> </Table>
        </FormItem>
      </Form>
      <div slot="footer" style="text-align: center">
        <Button @click="viewInfo.show = false">关闭</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import { search_list_white } from "@/api/region";
import { white_detail } from "@/api/whiteLibrary";
export default {
  data() {
    return {
      // 查看
      viewInfo: {
        show: false,
        whiteName: "",
        // 1app 2网页
        wltype: 1,
        website: "",
        versionname: "",
        comm: "",
        whiteAddress: ""
      },
      searchForm: {
        name: "",
        page: 1,
        size: 10,
        list: [],
        total: 0
      },
      columns: [
        {
          title: "序号",
          align: "center",
          width: 70,
          render: (h, params) => {
            return h(
              "span",
              params.index +
                (this.searchForm.page - 1) * this.searchForm.size +
                1
            );
          }
        },
        {
          title: "名称",
          slot: "whiteName",
          align: "center",
          width: 300
        },
        {
          title: "网址",
          slot: "website",
          align: "center"
        },
        {
          title: "操作时间",
          key: "updatetime",
          width: 190,
          align: "center"
        },
        {
          title: "操作",
          slot: "actionSlot",
          width: 100,
          align: "center"
        }
      ],
      columns1: [
        {
          title: "序号",
          align: "center",
          width: 70,
          type: "index"
        },
        {
          title: "学校名称",
          key: "schoolName",
          align: "center"
        },
        {
          title: "所属区域",
          key: "regionName",
          align: "center"
        },
        {
          title: "操作时间",
          key: "createtime",
          align: "center"
        }
      ]
    };
  },
  computed: {
    powerParams() {
      return this.$store.getters.powerParams;
    }
  },
  created() {
    this.searchList();
  },
  methods: {
    toView(row) {
      white_detail({
        rtype: this.powerParams.rtype,
        objectid: this.powerParams.objectid,
        whiteid: row.whiteid
      }).then((res) => {
        if (res.code === 0) {
          this.viewInfo = {
            show: true,
            whiteid: res.obj.whiteid,
            rversion: res.obj.rversion,
            whiteName: res.obj.whiteName,
            targetSchool: res.obj.targetSchool,
            website: res.obj.website,
            regionid: res.obj.regionid,
            whiteType: res.obj.whiteType,
            comm: res.obj.comm,
            schools: res.obj.schools
          };
        } else {
          this.$Message.error(res.msg);
        }
      });
    },
    // 搜索
    searchList() {
      this.searchForm.page = 1;
      this.getList();
    },
    // 页码改变
    pageChange(page) {
      this.searchForm.page = page;
      this.getList();
    },
    // 每页显示数量改变
    pageSizeChange(size) {
      this.searchForm.size = size;
      this.searchForm.page = 1;
      this.getList();
    },
    // 获取列表
    getList() {
      search_list_white({
        rtype: this.powerParams.rtype,
        objectid: this.powerParams.objectid,
        page: this.searchForm.page,
        size: this.searchForm.size,
        name: this.searchForm.name
      }).then((data) => {
        if (data.code === 0) {
          this.searchForm.list = data.obj.data;
          this.searchForm.total = data.obj.total;
        } else {
          this.$Message.error(data.msg);
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.search_header {
  display: flex;
  align-items: center;
  margin: 16px 16px;
}
.view_title {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  .wltype_1 {
    margin-left: 10px;
    padding: 0 10px;
    line-height: 20px;
    color: #fff;
    font-weight: normal;
    font-size: 12px;
    border-radius: 4px;
    background: #7854f6;
  }
  .wltype_2 {
    margin-left: 10px;
    padding: 0 10px;
    line-height: 20px;
    color: #fff;
    font-weight: normal;
    font-size: 12px;
    border-radius: 4px;
    background: #52c41a;
  }
}
.table_wrap {
  .website {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
.name_slot {
  display: flex;
  justify-content: center;
  align-items: center;
  .name_content {
    max-width: calc(100% - 38px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .app_tag {
    margin-left: 4px;
    width: 32px;
    text-align: center;
    color: #fff;
    line-height: 1.6;
    font-size: 12px;
    border-radius: 5px;
    background-color: #7854f6;
  }
  .web_tag {
    margin-left: 4px;
    width: 32px;
    text-align: center;
    color: #fff;
    line-height: 1.6;
    font-size: 12px;
    border-radius: 5px;
    background-color: #52c41a;
  }
}
</style>
