<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item class="dizhi" label="设备码" prop="">
              <el-input v-model="queryParams.barCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button class="my_search" @click="getSearch">
                {{ '搜索' }}</el-button
              >
              <el-button class="my_reset" @click="reChongzhi">
                {{ '重置' }}</el-button
              >
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            size="mini"
            style="background: #c8161d; color: #fff; border: none"
            class="addBtn"
            :disabled="canbind"
            @click="unbindCode"
            >解绑</el-button
          >
          <el-button
            size="mini"
            style="background: #ffad41; color: #fff; border: none"
            class="addBtn"
            @click="handleExport"
            >{{'导出'}}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          ref="multipleTable"
          :data="tableData"
          v-loading="loading"
          height="720px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>

          <el-table-column align="center" prop="storeName" label="门店名称">
          </el-table-column>
          <el-table-column align="center" prop="barCode" label="设备码">
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />
    <el-dialog
      title=""
      :visible.sync="unbindShow"
      :close-on-click-modal="false"
      width="25%"
      center
      :before-close="handleClose"
    >
      <div style="text-align: center">
        <div>
          <img
            src="@/assets/images/gth.png"
            style="width: 83px; height: 74px"
            alt=""
          />
        </div>
        <div
          style="
            font-size: 24px;
            color: #333333;
            font-weight: 500;
            margin-top: 20px;
          "
        >
          确定要解绑此设备吗？
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sureBind">{{
          '确认'
        }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as equ from "@/api/equipment.js";
export default {
  name: "DevicesDetail",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "devicesDetail",
      topList: [
        {
          name: "查看详情",
          path: "devicesDetail",
        },
      ],
      tableData: [],
      loading:false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      multipleSelection: [],
      canbind: true,
      unbindShow: false,
    };
  },
  created() {
    this.queryParams.pkMakerSpace = this.$route.query.pkMakerSpace;
    this.queryParams.barCode = this.$route.query.barCode;
    this.getSearch();
  },
  methods: {
    sureBind() {
      const theList = [];
      this.multipleSelection.forEach((ele) => {
        theList.push(ele.barCode);
      });
      equ.unbindEquipment({ barCodeList: theList }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: res.msg,
            type: "success",
          });
          this.unbindShow = false;
          this.$router.push({
            path: "devices",
          });
        }
      });
    },
    handleClose() {
      this.unbindShow = false;
    },
    unbindCode() {
      this.unbindShow = true;
    },
    checkTime1(val) {
      this.queryParams.startDate = val[0];
      this.queryParams.endDate = val[1];
    },
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/system/manage/bd-machine-maker-space/export-detail",
          Object.assign({}, this.queryParams),
          `设备列表详情${new Date().getTime()}.xlsx`
        );
      });
    },
    handleSelectionChange(val) {
      if (val.length > 0) {
        this.canbind = false;
      } else {
        this.canbind = true;
      }
      this.multipleSelection = val;
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
      };
      this.getSearch();
    },
    getSearch() {
      this.loading = true
      equ.getMakerSpaceDetailList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false
      });
    },
  },
};
</script>

  <style lang="scss" scoped>
::v-deep .el-dialog__header {
  border: none;
}
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #48b2fd;
        }
        .thebtn2 {
          color: #ffffff;
          background: #ffad41;
        }
      }
    }
  }
}
</style>
