<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="8">
            <el-form-item :label="'创建日期'">
              <el-date-picker
                @change="checkTime1"
                v-model="queryParams.times1"
                type="daterange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </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
            @click="goAdd(1)"
            size="mini"
            style="background: #48b2fd"
            class="addBtn"
            >{{ '添加' }}</el-button
          >
          <!--
            <el-button
              size="mini"
              style="background: #ffad41; color: #fff; border: none"
              class="addBtn"
              >{{'导出'}}</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="sort" label="排序">
          </el-table-column>
          <el-table-column align="center" prop="cover" label="图片">
            <template slot-scope="scope">
              <img
                style="width: 44px; height: 44px; border-radius: 8px"
                :src="scope.row.cover"
                alt=""
              />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="content" label="商品介绍">
          </el-table-column>
          <el-table-column align="center" prop="creationTime" :label="'创建日期'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
            width="150px"
          >
            <template slot-scope="scope">
              <el-button
                class="button-s"
                type="text"
                style="color: #4391fd; padding: 8px 4px; margin-left: 0px"
                size="small"
                @click="gofind(3, scope.row)"
              >
                查看
              </el-button>
              <el-button
                class="button-s"
                type="text"
                style="color: #f3a900; padding: 8px 4px; margin-left: 0px"
                size="small"
                @click="gofind(2, scope.row)"
              >
                修改
              </el-button>
              <el-button
                class="button-s"
                type="text"
                style="color: #c73030; padding: 8px 4px; margin-left: 0px"
                size="small"
                @click="deleteRow(scope.row)"
              >
                删除
              </el-button>
              <!-- <el-button
                  class="button-s"
                  type="text"
                  style="color: #4391FD;padding: 8px 4px;margin-left:0px;"
                  size="small"
                >
                  上移
                </el-button>
                <el-button
                  class="button-s"
                  type="text"
                  style="color: #4391FD;padding: 8px 4px;margin-left:0px;"
                  size="small"
                >
                  下移
                </el-button>
                <el-button
                  class="button-s"
                  type="text"
                  style="color: #37BF46;padding: 8px 4px;margin-left:0px;"
                  size="small"
                >
                置顶
                </el-button> -->
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as equ from "@/api/equipment.js";
export default {
  name: "EquipmentBanner",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "equipmentBanner",
      topList: [
        {
          name: "商品配置",
          path: "equipmentBanner",
        },
      ],
      tableData: [],
      loading:false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        type:2
      },
      total: 0,
      multipleSelection: [],
    };
  },
  created() {
    this.getSearch();
  },
  methods: {
    deleteRow(row) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        equ.deletBannerRow(row.pkId).then((res) => {
          this.$message({
            message:res.msg,
            type:"warning"
          })
          this.getSearch();
        });
      });
    },
    goAdd(index) {
      this.$router.push({
        path: "addEquProduct",
        query: {
          ifAdd: index,
        },
      });
    },
    gofind(index, row) {
      equ.getBannerRowDetail({ pkId: row.pkId }).then((res) => {
        if (res.code == 200) {
          this.$router.push({
            path: "addEquProduct",
            query: {
              ifAdd: index,
              dataForm: JSON.stringify(res.data),
            },
          });
        }
      });
    },
    checkTime1(val) {
      this.queryParams.startCreateTime = val[0];
      this.queryParams.endCreateTime = val[1];
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        type: 2,
      };
      this.getSearch();
    },
    getSearch() {
      this.loading = true
      equ.getAppletConfigList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false
      });
    },
  },
};
</script>

          <style lang="scss" scoped>
::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>

