
<template>
  <div class="templateManage app-container">
    <div class="search">
        <div>
            <el-input
            v-model="query.name"
            size="small"
            clearable
            placeholder="请输入模板名称"
            class="item-width-200 "
            ></el-input>
            <el-button
            class="ml10"
            type="primary"
            size="small"
            icon="el-icon-search"
            @click="handleSearch"
        >
            搜索
        </el-button>
        </div>
        <el-button
            type="primary"
            size="small"
            @click="handleAdd"
        >
            添加
        </el-button>
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column
        align="center"
        label="模板名称"
        prop="dataCollectName"
        show-overflow-tooltip
      >
      </el-table-column>
    
      <el-table-column
        align="center"
        label="状态"
        prop="status"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{scope.row.status == 1?"启用":"停用"}}
        </template>
      </el-table-column>
      
       <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleDetail(scope.row.id,'edit')">编辑</el-button>
          <el-button type="text" size="small" @click="handleCopy(scope.row.id)">复制</el-button>
          <el-button type="text" size="small" @click="handleOperate(scope.row.id,scope.row.status == 1?2:1)">{{scope.row.status == 1?'停用':'启用'}}</el-button>
          <el-button type="text" class="red" size="small" @click="handleOperate(scope.row.id,3)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="query.currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
  import {debounce} from '@/utils/index'
  import {dataTemplate,operate} from '@/api/activity'
  import {timeFormat} from '@/utils/index'

export default {
  name: "templateManage",
  data() {
    return {
      tableData: [],
      loading: false,
      query: {
        "name": "",
        "currentPage": 1,
        "pageSize": 10,
        shopId: 0,

      },
      title: "",
      total: 0,
    };
  },
  methods: {
    handleAdd(){
        this.$router.push({
            path:'/operationManage/templateManage/addTemplate',
            query:{
            mode:'add',
            }
        })
    },
    handleSearch(){
      this.query.currentPage = 1
      this.dataTemplate();

    },
    timeFormat(val){
      return timeFormat(val)
    },
    handleCopy(id){
        this.$router.push({
        path:'/operationManage/templateManage/addTemplate',
        query:{
          mode:'copy',
          id
        }
      })
    },
    handleDetail(id,mode){
      this.$router.push({
        path:'/operationManage/templateManage/addTemplate',
        query:{
          mode,
          id
        }
      })
    },
    handleOperate(id,type){
        let msg
        if(type == 1){
          msg = '启用'
        }else if(type == 2){
          msg = '禁用'
        }else if(type == 3){
          msg = '删除'
        }
        this.$confirm(`此操作将${msg}该活动, 是否继续?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
        }).then(() => {
          operate({id,type}).then(res=>{
            if(res.state == 'Success'){
                this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success'
                });
                this.handleSearch()
            }
          })
        })
    },
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
      this.dataTemplate()
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
       this.dataTemplate()
    },
    dataTemplate(){
      this.loading = true
      dataTemplate(this.query).then(res=>{
        this.loading = false
        if(res.state == 'Success'){
          this.tableData = res.content.records
          this.total = res.content.total
        }
      })
    }
  },
  created() {
   this.dataTemplate()
  },
};
</script>
  
<style lang="scss" >
.templateManage {

}

</style>
  