<template>
  <div>
    <Row class="search-row">
      <i-col span="24" class="search-col">
        <Row class="row-style">
          <Button @click="handleEdit" type="primary">配置欢迎语</Button>
        </Row>
      </i-col>
    </Row>
    <Table :columns="columns1" :data="data" style="margin-top: 20px;" size="small">
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" @click="handleEdit(row, index)">修改</Button>
        <Button type="error" size="small" @click="handleDelete(row, index)">删除</Button>
      </template>
    </Table>
    <Page
      :total="total"
      :current="pageNum"
      :page-size="pageSize"
      show-elevator
      show-total
      placement="top"
      @on-change="handlePage"
      class="ks-page"
    ></Page>
  </div>
</template>

<script>
import data from "../../utils/PhoneRegionData";
import http from "../../services/store/IncreaseStoreManager";

import staff from "../../services/staff/staff";

export default {
  name: "IncreaseWelcomeList",
  inject: ["setMenuName"],
  data() {
    let _this = this;
    return {
      loading: true,
      // 分页
      total: 0,
      pageSize: 10,
      data: [],
      pageNum: 1,
      columns1: [
        {
          width: 60,
          align: "center",
          title: "序号",
          render(h, params) {
            console.log(params);
            let num = parseInt(params.index) + 1;
            console.log(_this.pageSize);
            if (_this.pageSize > 1) {
              num += (_this.pageNum - 1) * _this.pageSize;
            }
            return h("span", num);
          }
        },
        {
          title: "欢迎语",
          key: "scheduleVO.description",
          render(h, params) {
            return h("span", params.row.content);
          }
        },
        {
          title: "配置范围",
          key: "shop",
          render(h, params) {
            return h(
              "span",
              params.row.storeName +
                "等" +
                (params.row.storeCount || 0) +
                "家公司"
            );
          }
        },
        { title: "配置时间", key: "createTime" },
        { title: "修改时间", key: "updateTime" },
        { title: "操作", slot: "action" }
      ],
      formValidate: {}
    };
  },
  mounted() {
    this.setMenuName("门店推广", "欢迎语");
    this.handlePaginate();
  },
  methods: {
    // 分页刷新
    handlePaginate() {
      this.loading = true;
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        userId: JSON.parse(sessionStorage.getItem("loginInfo")).userId,
        categoryCode: "welcome"
      };
      http.getWelcomeList(params, res => {
        const data = res.data.results.this || {};
        this.data = data.list || [];
        this.total = data.total || 0;
        this.loading = false;
      });
    },
    //切页处理
    handlePage: function(value) {
      this.pageNum = value;
    },
    // 新增或修改
    handleEdit(row) {
      this.$router.push({
        path: "/shop/increase/welcome/edit",
        query: { id: row.id }
      });
    },
    // 删除
    handleDelete(row) {
      let _this = this;
      this.$Modal.confirm({
        title: "删除欢迎语",
        content: "您确定要删除该欢迎语?",
        onOk: () => {
          http.deleteWelcome({ id: row.scheduleId }).then(_this.handlePaginate);
        },
        onCancel: () => {}
      });
    }
  }
};
</script>

<style scoped></style>
