<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight">
        <el-col :span="24" class="one"> <span>商品评价</span> </el-col>
        <el-col :span="24" class="two">
          <search-1 :form="searchForm" @onSubmit="search" @toReset="toClose"></search-1>
        </el-col>
        <el-col :span="24" class="four">
          <data-table
            :select="true"
            :selected="selected"
            @handleSelect="handleSelect"
            :fields="fields"
            :opera="opera"
            @query="search"
            :data="list"
            :total="total"
            @edit="toEdit"
          >
          </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const _ = require('lodash');
import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
const { mapActions: selfShop } = createNamespacedHelpers('selfShop');
const { mapActions: goods } = createNamespacedHelpers('goods');
const { mapActions: dictData } = createNamespacedHelpers('dictData');
export default {
  name: 'index',
  props: {},
  components: {
    search1: () => import('./parts/search-1.vue'),
  },
  data: function () {
    const that = this;
    return {
      // 列表
      opera: [{ label: '查看评价', method: 'edit' }],
      fields: [
        { label: '商品名称', model: 'name' },
        { label: '店铺名称', model: 'shop.name' },
      ],
      list: [],
      total: 0,
      // 查询
      searchForm: {},
      // 多选值
      selected: [],
      shop: {},
    };
  },
  async created() {
    await this.searchOther();
    await this.search();
  },
  methods: {
    ...dictData({ getDict: 'query' }),
    ...selfShop(['getInfo', 'getGoods', 'goodsCreate']),
    ...goods(['delete', 'fetch', 'update', 'create']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      let condition = _.cloneDeep(this.searchForm);
      let res = await this.getGoods({ skip, limit, ...condition, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, 'list', res.data);
        this.$set(this, 'total', res.total);
      }
    },
    // 修改
    async toEdit({ data }) {
      this.$router.push({ path: '/platmanag/goodsRate/detail', query: { id: data.id } });
    },
    // 重置
    toClose() {
      this.searchForm = {};
      this.search();
    },
    // 多选
    handleSelect(data) {
      this.$set(this, `selected`, data);
    },
    async searchOther() {},
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    margin: 0 0 10px 0;

    span:nth-child(1) {
      font-size: 20px;
      font-weight: 700;
      margin-right: 10px;
    }
  }
  .two {
    margin: 0 0 10px 0;
  }
  .thr {
    margin: 0 0 10px 0;
  }
}
</style>
