<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <div class="form_all">
        <el-form ref="select" :model="select" label-width="auto">
          <el-row :gutter="40">
            <!-- 一层 -->
            <el-col :span="4">
              <el-form-item :label="'活动名称'">
                <el-input clearable v-model="select.actName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="$t('活动时间')">
                <el-date-picker
                  v-model="creationTime"
                  @change="changeTime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  type="datetimerange"
                  :range-separator="'至'"
                  :start-placeholder="'开始日期'"
                  :end-placeholder="'结束日期'"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" size="small" @click="getDataList">
                {{ '搜索' }}</el-button
              >
              <el-button size="small" class="resetBtn" @click="reset">
                {{ '重置' }}</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="main_a">
        <div class="mainbtn">
          <el-button
            size="small"
            @click="openDig"
            v-hasButtons="['TourismActAdd']"
            class="addBtn"
            >{{ '添加' }}</el-button
          >
        </div>
        <div class="maintable">
          <el-table
            :data="tableData"
            v-loading="loading"
            style="width: 100%"
            height="710px"
            :header-cell-style="{ background: '#EEEEEE' }"
            :row-class-name="tableRowClassName"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column
              align="center"
              prop="actName"
              width="150"
              :label="'活动名称'"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="actCover"
              :label="$t('活动封面')"
            >
              <template slot-scope="scope">
                <img
                  style="width: 48px; height: 48px"
                  :src="scope.row.actCover"
                  alt=""
                />
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="payMoney"
              width="120"
              :label="$t('门票金额')"
            >
            </el-table-column>

            <el-table-column align="center" prop="quantity" :label="$t('数量')" width="120">
            </el-table-column>

            <el-table-column align="center" prop="limitQuantity" :label="$t('限购数量')" width="120">
            </el-table-column>

            <el-table-column
              align="center"
              prop="actStartDate"
              width="150"
              :label="$t('活动开始时间')"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="actEndDate"
              width="150"
              :label="$t('活动结束时间')"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="disStartDate"
              width="150"
              :label="$t('活动显示开始时间')"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="disEndDate"
              width="150"
              :label="$t('活动显示结束时间')"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="time"
              :label="'操作'"
              fixed="right"
            >
              <template slot-scope="scope">
                <el-button
                  @click="toFixed(scope.row.pkId, 4)"
                  type="text"
                  style="color: #48b2fd"
                  size="small"
                >
                  {{ '查看' }}
                </el-button>
                <el-button
                  @click="toFixed(scope.row.pkId, 2)"
                  type="text"
                  v-hasButtons="['TourismActUp']"
                  style="color: #f3a900"
                  size="small"
                >
                  {{ '修改' }}
                </el-button>
                <el-button
                  @click="toFixed(scope.row.pkId, 3)"
                  type="text"
                  size="small"
                  v-hasButtons="['TourismActDel']"
                  style="color: #c8161d"
                >
                  {{ '删除' }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as api from "@/api/giftGoods.js";
export default {
  name: "Bzpz",
  components: {
    topBar,
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许';
      } else {
        return '禁止';
      }
    },
  },
  data() {
    return {
      creationTime: [],
      creationTime1: [],
      creationTime2: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      addOrEdit: "",
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading: false,
      moren: "ticketList",
      topList: [
        {
          name: "门票活动",
          path: "ticketList",
        },
      ],
      form: {
        name: "",
      },
      actStatus: [],
    };
  },
  mounted() {
    // 获取下拉
    this.getData();
    // 获取列表
    this.getDataList();
  },
  methods: {
    //重置
    reset() {
      this.select = {};
      this.creationTime = [];
      this.creationTime1 = [];
      this.creationTime2 = [];
      this.getDataList();
    },
    getData() {
      api.activityStatus().then((res) => {
        this.actStatus = res.data;
      });
    },
    changeTime(val) {
      this.select.actStartDate = val ? val[0] : "";
      this.select.actEndDate = val ? val[1] : "";
    },
    // 点击修改
    toFixed(id, index) {
      if (index == 3) {
        this.$confirm("是否确认删除该活动?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            api.delTicket(id).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.getDataList();
              }
            });
          })
          .catch(() => {});
      } else {
        this.$router.push({
          path: "AddTicket",
          query: {
            pkId: id,
            controlType: index,
          },
        });
      }
    },
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = "";
          if (this.addOrEdit == true) {
            url = classifySave;
          } else {
            url = classifyUpdate;
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.dialogVisible = false;
              // 充值数据
              this.$refs[formName].resetFields();
              // 获取列表
              this.getDataList();
            }
          });
        } else {
          return false;
        }
      });
    },
    handleClose() {
      this.dialogVisible = false;
      this.$refs["form"].clearValidate();
      this.$refs["form"].resetFields();
    },
    openDig() {
      this.$router.push({
        path: "AddTicket",
        query: {
          controlType: 1,
        },
      });
    },

    // 获取列表
    getDataList() {
      this.loading = true;
      api
        .ticketList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.loading = false;
        });
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "activity/manage/activity/export",
          Object.assign({}, { actType: 22 }, this.queryParams, this.select),
          `旅游活动${new Date().getTime()}.xlsx`
        );
      });
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>
<style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    // background: #ffffff;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    .main_a {
      background: #fff;
      border-radius: 8px;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    }
    .mainbtn {
      padding: 0;
    }
    .maintable {
      flex: 1;
    }
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
.form_all {
  padding: 0 20px;
  margin-bottom: 10px;
  background: #fff;
}
</style>
