<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="用户手机号" prop="userMobile">
        <el-input v-model="queryParams.userMobile" placeholder="请输入用户手机号" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="评价时间">
        <el-date-picker v-model="daterangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</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" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="55" label="序号" align="center">
        <template slot-scope="scope">
          <div>
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="userNickname" />
      <el-table-column label="用户手机号" align="center" prop="userMobile" />
      <el-table-column label="商品名称" prop="productTitle" align="center" />
      <el-table-column label="评分" prop="commentScore" align="center" />
      <el-table-column label="评价内容" show-overflow-tooltip align="center" prop="comment" width="400" />
      <el-table-column label="图片" align="center" prop="image">
        <template slot-scope="scope">
          <div v-if="scope.row.commentImages&&scope.row.commentImages.length>0">
            <el-image v-for="(v,i) in scope.row.commentImages" :key="i" :initial-index="i" style="width: 50px; height: 50px;margin:0 5px;" :src="v" :preview-src-list="scope.row.commentImages "></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="评价时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.commentTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { shopOrderCommentPage, shopOrderCommentDel } from "@/api/pointsMall.js";
import { getToken } from "@/utils/auth";
import SelNotice from "@/components/SelNotice/index.vue";
import SelPointsGoods from "@/components/SelPointsGoods/index.vue";
import SelShop from "@/components/SelShop/index.vue";
export default {
  dicts: ['ad_location', 'internal_page'],
  components: {
    SelNotice,
    SelPointsGoods,
    SelShop
  },
  data () {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created () {
    this.getList();
  },
  methods: {
    handleSelectionChange () {

    },
    /** 查询测试单表列表 */
    getList () {
      this.loading = true;
      this.queryParams["startTime"] = undefined;
      this.queryParams["endTime"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["startTime"] = this.daterangeCreateTime[0];
        this.queryParams["endTime"] = this.daterangeCreateTime[1];
      }
      shopOrderCommentPage(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.commentId || this.ids;
      this.$modal.confirm('是否确认删除此评价？').then(() => {
        this.loading = true;
        return shopOrderCommentDel(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },
  }
};
</script>
<style lang="scss">
.el-drawer__body {
  padding: 0 20px !important;
}
</style>
<style lang="scss" scoped>
.flex {
  display: flex;
}
.demo-drawer__footer {
  margin-left: 120px;
}
::v-deep .el-input.is-disabled .el-input__inner {
  background-color: #fff;
  color: rgb(96, 98, 102);
}
</style>
