<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item :label="$t('操作人')" prop="memberName">
        <el-input v-model="queryParams.memberName" :placeholder="$t('请输入操作人')" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('分类')" prop="type">
        <el-select v-model="queryParams.type" :placeholder="$t('请选择分类')" clearable>
          <el-option v-for="item in getDictDatas(DICT_TYPE.SCORE_RULE_TYPE)" :label="isChinese ? item.label : item.labelEn" :value="item.value" v-if="item.value == 3 || item.value == 4" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('标题')" prop="title">
        <el-input v-model="queryParams.title" :placeholder="$t('请输入关键词查找')" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('分享ID')" prop="code">
        <el-input v-model="queryParams.code" :placeholder="$t('请输入分享ID')" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('总积分')" prop="type">
        <el-row :gutter="10" style="width: 300px">
          <el-col :span="10">
            <dict-selector v-model="queryParams.relationSymbol" clearable :type="DICT_TYPE.QUANTITATIVE_RELATION_SYMBOL" @change="handleQuery" />
          </el-col>
          <el-col :span="14">
            <el-input v-model.trim="queryParams.totalScore" :placeholder="$t('请输入数字')" clearable onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" @keyup.enter.native="handleQuery" />
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item :label="$t('操作时间')">
        <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column width="100" :label="$t('序号')" align="center" prop="id" />
      <el-table-column width="140" :label="$t('操作人')" align="center" prop="memberName" />
      <el-table-column width="120" :label="$t('分类')" align="center" :prop="isChinese ? 'typeZh' : 'typeEn'" />
      <el-table-column width="120" :label="$t('分享ID')" align="center" prop="code" />
      <el-table-column :label="$t('标题')" align="center" :prop="isChinese ? 'titleZh' : 'titleEn'" />
      <el-table-column :label="$t('操作时间')" align="center" prop="createTime"">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('点击时间')" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.triggerTime) || "--" }}</span>
        </template>
      </el-table-column>
      <el-table-column   width="180" :label="$t('ip')" align="center" prop="ipAddress" />
      <el-table-column :label="$t('积分')" align="center" prop="score" />
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.rows" @pagination="getList" />
  </div>
</template>

<script>
import { getShareRecordDetails } from "@/api/ecw/memberManagement"
export default {
  name: "EcwMembermanagementSharingdetailsIndex",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典类型列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        page: 1,
        rows: 10,
        memberName: "", //操作人
        type: "", //分类
        title: "",
        relationSymbol: "", //查询条件
        totalScore: "",
        name: null,
        status: null,
        type: null,
        category: null,
        remark: null
      }
    }
  },
  created() {
    this.getList()
  },
  computed: {
    isChinese() {
      return this.$i18n.locale === "zh_CN"
    }
  },
  methods: {
    goShareDetails(row) {
      if (row.triggerCount != "0") {
        this.$router.push({
          path: "/member/memberManagement/sharingStatisticalDetails",
          query: {
            id: row.id
          }
        })
      }
    },
    /** 查询列表 */
    getList() {
      this.loading = true
      // 处理查询参数
      let params = { ...this.queryParams }
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime")
      // 执行查询
      getShareRecordDetails(params).then((response) => {
        this.list = response.data.list
        this.total = response.data.total
        this.loading = false
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreateTime = []
      this.queryParams.relationSymbol = ""
      this.queryParams.totalScore = ""
      this.resetForm("queryForm")
      this.handleQuery()
    }
  }
}
</script>
