<template>
  <div class="listPage H100">
    <div class="search-container">
      <el-form :inline="true" :model="form" class="search-form" onsubmit="return false;">
        <el-form-item label="版权方名称">
          <el-input
            size="mini"
            placeholder="请输入版权方名称"
            v-model="form.name"
            @keyup.enter.native="Search"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="版权方有效期">
          <el-date-picker
            v-model="value1"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <div class="btn-group">
            <el-button size="mini" type="primary" class="btn_form_search" @click="Search">查询</el-button>
            <el-button size="mini" class="btn_form_search" @click="Reset">重置</el-button>
          </div>
        </el-form-item>
      </el-form>
      <div class="page-tip">
        <span class="page-tip-title">页面说明:</span>
        <span class="page-tips">可使用版权方、视频分类、视频名称模糊搜索对需要汇出的视频进行快速检索，选定视频后将视频汇出到指定U盘。</span>
      </div>
    </div>
    <div class="table-content">
      <div class="btn-group">
        <el-button type="primary" @click="multipleRemit()">汇出</el-button>
      </div>
      <div class="party-table">
        <el-table
          border
          style="width: 100%;height:100%"
          height="100%"
          ref="multipleTable"
          :data="tableData"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column type="index" width="120" label="序号"></el-table-column>
          <el-table-column label="视频名称" prop="name"></el-table-column>
          <el-table-column label="版权方" prop="copyrightOwnerName"></el-table-column>
          <el-table-column label="视频类别" prop="createTime"></el-table-column>
        </el-table>
      </div>
      <div class="partyt-pagination">
        <el-pagination
          small
          background
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-size="page.pageSize"
          layout="prev, pager, next, jumper"
          :total="page.total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    var checkIsNull = (rule, value, callback) => {
      if (value) {
        if (value.trim() == "") {
          callback(new Error("不允许只输入空格"));
        } else {
          callback();
        }
      }
    };
    return {
      type: true,
      value1: "",
      page: { currentPage: 1, pageSize: 10, total: 0 },
      tableData: [],
      FormVisible: false,
      FormVisible1: false,
      formLabelWidth: "100px",
      form: {
        name: ""
      },
      editform: {
        menuName: "",
        menuUrl: "",
        parentId: "",
        sort: "",
        id: ""
      },
      classForm: {
        menuName: "",
        menuUrl: "",
        parentId: "",
        sort: ""
      },
      typeList: [],
      rules: {
        sort: [
          { required: true, message: "请输入顺序值", trigger: "change" },
          { pattern: /^(\d{1,5})?$/, message: "排序值为低于5位数的纯数字" }
        ],
        menuName: [
          { required: true, message: "请输入菜单名称", trigger: "change" },
          { max: 20, message: "不能超过20个字符", trigger: "change" },
          { validator: checkIsNull, trigger: "blur" }
        ],
        menuUrl: [
          { required: true, message: "请输入菜单地址", trigger: "change" },
          { validator: checkIsNull, trigger: "blur" }
        ],
        parentId: [
          { required: true, message: "请输入父级菜单", trigger: "change" }
        ]
      },
      value: "",
      name: ""
    };
  },
  computed: {},
  mounted() {
    this.onSearch();
    // this.getPermis();
  },
  components: {},
  methods: {
    // 渲染父级权限
    getPermis() {
      let vm = this;
      vm.$https({
        method: "get",
        url: "menu/getRoleMenu?roleId=" + sessionStorage.getItem("roleId"),
        authType: this.backToken
      }).then(
        res => {
          let data = res.data;
          vm.typeList = data.map((e, i) => {
            return {
              id: e.id,
              name:
                e.menuName.indexOf("-") == -1
                  ? e.menuName
                  : e.menuName.split("-")[1]
            };
          });
        },
        error => {
          console.log(error);
        }
      );
    },
    // 获得数据接口
    getTableData(param) {
      let vm = this;
      vm.$https(
        {
          url: "videoContentCat/getPageList",
          method: "post",
          authType: this.backToken
        },
        vm.$qs.stringify(param)
        // param
      )
        .then(res => {
          let data = res.data.data;
          vm.page.pageSize = data.size;
          vm.page.total = data.total;
          vm.tableData = data.records;
        })
        .catch(function(err) {
          console.log(err);
        });
    },
    // 分页
    handleCurrentChange(val) {
      let _this = this;
      _this.page.currentPage = val;
      _this.onSearch();
    },
    onSearch() {
      let _this = this;
      let param = _this.getSearchQuery();
      _this.getTableData(param);
    },
    // 重置
    Reset(){
      // this.$refs["form"].resetFields();
      this.form = {}
      this.Search()
    },
    Search() {
      let _this = this;
      _this.page.currentPage = 1;
      let searchObj = {
        _index: 1,
        _size: _this.page.pageSize,
        name: _this.form.name
      };
      this.getTableData(searchObj);
    },
    // // 获取当前查询参数
    getSearchQuery() {
      let _this = this;
      let searchObj = {
        _index: _this.page.currentPage,
        _size: _this.page.pageSize
      };
      for (let key in _this.form) {
        if (_this.form[key]) {
          searchObj[key] = _this.form[key];
        }
      }
      return searchObj;
    },

    // 批量操作
    handleSelectionChange(selection) {
      let _this = this;
      _this.selection = selection;
    },
    getMultipleSelect() {
      let _this = this;
      let arr = [];
      let str = "";
      if (_this.selection) {
        _this.selection.forEach(function(e) {
          arr.push(e.id);
        });
        // str = arr.join(",");
        str = arr;
      } else {
        // str = "";
        str = [];
      }
      return str;
    },
    // 批量删除
    multipleRemit() {
      let _this = this;
      let str = _this.getMultipleSelect();
      //   console.log(str)
      if (str.length > 0) {
        console.log(str);
        // _this.$https({
        //     url: "menu/batchDel?menuIds=" + str,
        //     method: "post",
        //     authType: this.backToken
        //   })
        //   .then(
        //     res => {
        //       if (res.data.status == 201 || res.data.status == 200) {
        //         var reader = new FileReader();
        //         reader.readAsDataURL(blob); // 转换为base64，可以直接放入a表情href
        //         reader.onload = function(e) {
        //           var a = document.createElement("a");
        //           a.download =
        //             genUUID() + (batchno !== "" ? "_" + batchno : "") + ".zip"; //下载文件名
        //           a.href = e.target.result;
        //           $("body").append(a); // 修复firefox中无法触发click
        //           a.click();
        //           $(a).remove();
        //         };
        //       }
        //       //重新查询数据
        //       _this.onSearch();
        //     },
        //     error => {}
        //   );
      } else {
        this.$message({
          type: "info",
          message: "请至少选择一个选项！"
        });
      }

      //   if (str) {
      //     this.$confirm("此操作将删除选中菜单, 是否继续?", "提示", {
      //       confirmButtonText: "确定",
      //       cancelButtonText: "取消",
      //       type: "warning"
      //     }).then(() => {
      //       _this
      //         .$https({
      //           url: "menu/batchDel?menuIds=" + str,
      //           method: "DELETE",
      //           authType: this.backToken
      //         })
      //         .then(
      //           res => {
      //             if (res.data.status == 201 || res.data.status == 200) {
      //               this.$message({
      //                 type: "success",
      //                 message: "删除成功!"
      //               });
      //             }
      //             //重新查询数据
      //             _this.onSearch();
      //           },
      //           error => {}
      //         );
      //     });
      //   } else {
      //     this.$message({
      //       type: "info",
      //       message: "请至少选择一个选项！"
      //     });
      //   }
    }
  }
};
</script>

<style lang="less">
// @import "../../../../style/common";
// @import "../../style/list";
@import "../../../../style/dialog.less";
@import "../../../../style/table.less";
@import "../../../../style/pagination.less";
</style>
