<template>
  <div class="page">
    <topBar v-if="topList.length > 0" :top-list="topList" :moren="moren" />
    <div class="thetopbox">
      <el-form ref="form" :model="queryParams" label-width="auto">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item :label="$t('商品编号')">
              <el-input v-model="queryParams.waresCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('商品名称')">
              <el-input v-model="queryParams.waresName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button class="my_search" @click="research">
                {{ '搜索' }}</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="small"
            class="addBtn"
            v-hasButtons="['WaresBonusAdd']"
            @click="addRules"
            >{{ '添加' }}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="730px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="expand">
            <template slot-scope="scope">
              <el-table :data="scope.row.bdWaresBonusItemsList">
                <!-- <el-table-column align="center" prop="" label="" width="90" /> -->
                <el-table-column align="center" prop="" label="" width="40" />
                <el-table-column align="center" prop="" label="" />
                <el-table-column align="center" prop="" label="" />
                <el-table-column
                  align="center"
                  prop="assAchieve"
                  label="分配EV"
                />
                <el-table-column align="center" prop="algebra" label="代数" />
                <el-table-column align="center" prop="" label="" width="150" />
              </el-table>
            </template>
          </el-table-column>
          <!-- <el-table-column type="selection" width="55" /> -->
          <el-table-column align="center" prop="waresCode" label="商品编号" />
          <el-table-column align="center" prop="waresName" label="商品姓名" />
          <el-table-column
            align="center"
            prop="orderAssAchieve"
            label="分配总EV"
          />
          <el-table-column
            align="center"
            prop="totalAlgebra"
            label="分配代数"
          />
          <!-- <el-table-column label="分配EV" align="center" prop="specsName">
            <template slot-scope="scope">
              <el-table
                :data="scope.row.bdWaresBonusItemsList"
                class="inlineTable"
              >
                <el-table-column align="center" prop="assAchieve">
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column label="代数" align="center" prop="specsName">
            <template slot-scope="scope">
              <el-table
                :data="scope.row.bdWaresBonusItemsList"
                class="inlineTable"
              >
                <el-table-column align="center" prop="algebra">
                </el-table-column>
              </el-table>
            </template>
          </el-table-column> -->
          <el-table-column align="center" :label="'操作'" width="150">
            <template slot-scope="scope">
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #ffad41"
                v-hasButtons="['WaresBonusEdit']"
                @click.native.prevent="updateShow(scope.row)"
              >
                {{ '修改' }}
              </el-button>
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #c73030"
                v-hasButtons="['WaresBonusDel']"
                @click.native.prevent="delRole(scope.row)"
              >
                {{ '删除' }}
              </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="research"
    />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as api from "@/api/specialBusiness.js";
import { Message } from "element-ui";
export default {
  name: "Qxpz",
  components: {
    topBar,
  },
  data() {
    return {
      title: '添加',
      modifiedTime: [],
      modifiedTime1: [],
      forms: "",
      rules: {
        memberCode: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        expandRatio: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        coachGeneration: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        startDate: [
          { required: true, message: '请选择', trigger: "change" },
        ],
        endDate: [
          { required: true, message: '请选择', trigger: "change" },
        ],
      },
      table: {},
      ruleShow: false,
      moren: "waresBonus",
      topList: [
        {
          name: "特殊品奖金分配",
          path: "waresBonus",
        },
      ],
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      tableData: [],
      loading: false,
      total: 0,
    };
  },
  created() {
    this.research();
  },
  methods: {
    addRules() {
      this.$router.push({
        path: "WaresBonusRules",
        // query: {
        //   allData: JSON.stringify(this.tableData),
        // },
      });
    },
    updateShow(item) {
      this.$router.push({
        path: "WaresBonusRules",
        query: {
          allData: JSON.stringify(item),
          isEdit: 1,
        },
      });
    },
    delRole(item) {
      let pkId = item.pkId;
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        api.waresBonusDel(pkId).then((res) => {
          if (res.code === 200) {
            Message({
              message: res.msg,
              type: "success",
            });
            this.research();
          }
        });
      });
    },
    ruleSubmit() {
      this.$refs["forms"].validate((valid) => {
        if (!valid) {
          return false;
        } else {
          if (this.types == 1) {
            api.kValueAdd(this.table).then((res) => {
              if (res.code == 200) {
                Message({
                  message: res.msg,
                  type: "success",
                });
                this.ruleShow = false;
                this.$refs["forms"].clearValidate();
                this.$refs["forms"].resetFields();
                this.research();
              }
            });
          }
          if (this.types == 2) {
            api.kValueUp(this.table).then((res) => {
              if (res.code == 200) {
                Message({
                  message: res.msg,
                  type: "success",
                });
                this.ruleShow = false;
                this.$refs["forms"].clearValidate();
                this.$refs["forms"].resetFields();
                this.research();
              }
            });
          }
        }
      });
    },
    handleClose() {
      this.ruleShow = false;
      this.table = {};
    },
    changeTime(val) {
      this.queryParams.beginStartDate = val ? val[0] : "";
      this.queryParams.endStartDate = val ? val[1] : "";
    },
    changeTime1(val) {
      this.queryParams.beginEndDate = val ? val[0] : "";
      this.queryParams.endEndDate = val ? val[1] : "";
    },
    research() {
      this.loading = true;
      api.waresBonusQuery(this.queryParams).then((res) => {
        this.loading = false;
        this.tableData = res.rows;
        this.total = res.total;
      });
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
      };
      this.modifiedTime = [];
      this.modifiedTime1 = [];
      this.research();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .inlineTable thead {
  display: none !important;
}
::v-deep .el-upload--picture-card {
  min-width: 80px !important;
  min-height: 80px !important;
  border: 1px solid #ccc;
  border-radius: 4px;
}

::v-deep .el-select {
  width: 100%;
}

::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}

::v-deep .colors {
  padding: 5px !important;
}

::v-deep .banner .el-form-item__error {
  left: 100px;
  margin-top: 10px;
}

.avatar-uploader {
  width: 68px !important;
  height: 68px !important;
}

::v-deep .input-s .el-input {
  //width:637px;
}

.button-style {
  width: 209px;
  height: 48px;
  background: #cccccc;
  border-radius: 5px 5px 5px 5px;
  opacity: 1;
  line-height: 48px;
  padding: 0 !important;
  color: #fff;
  font-size: 18px;
}

::v-deep .el-dialog__title {
  font-weight: bold;
}

::v-deep .el-dialog__header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.button-s {
  padding: 0 2px !important;
}

::v-deep .el-button {
  padding: 10px 20px;
}

::v-deep .el-date-editor .el-range__close-icon {
  margin-top: -10px;
}

::v-deep .el-date-editor .el-range-separator {
  margin-top: -10px;
}

::v-deep .el-date-editor .el-range__icon {
  margin-top: -10px;
}

::v-deep .el-input__inner {
  //height:28px;
  //line-height: 28px;
}

::v-deep .el-form-item {
  margin-bottom: 15px;
}

::v-deep .el-form-item__label {
  color: #333;
  font-weight: inherit;
}

::v-deep .el-row {
  //margin-top: 20px;
}

::v-deep .el-date-editor {
  width: 100% !important;
}

::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}

::v-deep .el-table thead {
  color: #000000;
}

.openClose {
  margin-top: 10px;
  margin-right: 10px;
  color: #666666;
  text-align: center;
}

.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;

  .thetopbox {
    background: #ffffff;
    border-radius: 8px;
    padding-bottom: 10px;

    .searchbox {
      display: flex;
      align-items: center;

      .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: 0px 0;
      justify-content: space-between;
      align-items: center;

      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #3181e5;
          width: 68px;
          margin-bottom: 20px;
          //height: 32px;
        }
      }
    }
  }
}
</style>
