<template>
<div class="list">
        <div class="system-table-search">
      <!-- <div class="flex-h">
        <div class="flex-item flex-h">
          <el-button size="mini" type="success" @click='addGoods'>新增</el-button>
        </div>
        <ul>
          <li>
            <el-input v-model="filterData.goodsName" placeholder="商品名称"></el-input>
          </li>

        </ul>
        <el-button
          size="mini"
          type="primary" @click="search">查询</el-button>
      </div> -->
      <div class="moreFilter"></div>
    </div>
  <el-table
    :data="list || []"
    style="width: 100%">
    <el-table-column
      prop="phone"
      label="电话号码">
    </el-table-column>
    <el-table-column
      prop="message"
      label="留言内容">
    </el-table-column>
    <el-table-column
      label="创建时间">
      <template slot-scope="scope">
          <span>{{formateDate(scope.row.createDate)}}</span>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    small
    style="margin-top:10px;"
    layout="prev, pager, next"
    :current-page.sync="pageNavi.current"
    :pageSize="pageNavi.size"
    :total="pageNavi.total || 0"
    @current-change="getList"
  >
  </el-pagination>
</div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
import dayjs from 'dayjs'

const { mapActions: mapMessageActions } = createNamespacedHelpers("message");

export default {
  name: "goods-list",
  data() {
    return {
      filterData: {
        goodsName: ""
      },
      list: [],
      pageNavi: {
        current: 1,
        size: 20,
        total: 0
      }
    };
  },
  computed: {},
  methods: {
    ...mapMessageActions(["getMessage"]),
    getList() {
      const pageNumber = this.pageNavi.current || 1;
      const pageSize = this.pageNavi.size;

      this.getMessage({
        ...this.filterData,
        pageNumber,
        pageSize
      })
        .then(res => {
          const { records, ...pageNavi } = res;

          this.list = records;
          this.pageNavi = pageNavi;
        })
        .catch(err => {
          this.$notify.error(err.msg || err.message);
        });
    },
    addGoods() {
      this.$router.push({ name: "goods.edit" });
    },
    toDetail(row) {
      this.$router.push({
        name: "goods.edit",
        params: { id: row.goodsId }
      });
    },
    changeStatus(row) {
      this.showLoadding("保存中...");
      this.changeGoodsStatus(row)
        .then(res => {
          this.hideLoadding();
          this.$notify.info("保存成功");
          this.search();
        })
        .catch(err => {
          this.hideLoadding();
          this.$notify.error(err.message);
        });
    },
    showLoadding(text) {
      this.loading = this.$loading({
        text,
        lock: true,
        spinner: "el-icon-loading",
        background: "rgba(255, 255, 255, 0.7)"
      });
    },
    hideLoadding() {
      if (this.loading) this.loading.close();
    },
    search() {
      this.pageNavi.current = 1;
      this.getList();
    },
    newPage(page) {
      this.$router.replace({ name: "goods.list", query: { page } });
    },
    formateDate(dt) {
      return !dt ? '' : dayjs(dt).format('YYYY-MM-DD HH:mm')
    },
  },
  created() {
    this.pageNavi.current = this.$route.query.page || 1;

    this.getList();
  }
};
</script>

<style lang="scss" scoped>
.list {
  .header {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  img {
      width: 100%;
      height: 100%;
    }
}
.system-table-search {
  width: calc(100% - 40px);
  margin: 20px auto 0;
}

.system-table-search li {
  margin-right: 20px;
}

.system-table-search ul {
  font-size: 0;
  white-space: nowrap;
}

.system-table-search ul > li {
  display: inline-block;
}

.flex-h {
  display: flex;
  align-items: center;
}

.flex-item {
  flex: 1;
  -webkit-flex: 1;
  position: relative;
  overflow: hidden;
}
</style>
