
<template>
  <div class="roleList app-container">
    <div class="search">
        <div>
            <el-input
            v-model="query.name"
            size="small"
            clearable
            placeholder="请输入名称"
            class="item-width-200 "
            ></el-input>
             <el-input
            v-model="query.name"
            size="small"
            clearable
            placeholder="请输入登录账号"
            class="item-width-200 ml10"
            ></el-input>
            <el-select
          v-model="query.activityType"
          size="small"
          class="item-width-200 ml10"
          placeholder="请选择角色"
          clearable
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>

        <el-date-picker
          v-model="date"
          size="small"
          value-format="timestamp"
          class="item-width-350 ml10"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
       
            <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="activityName"
        show-overflow-tooltip
      >
      </el-table-column>
      
      <el-table-column
        align="center"
        label="备注"
        prop="status"
        show-overflow-tooltip
      >
      </el-table-column>
       <el-table-column
        align="center"
        label="状态"
        prop="status"
        show-overflow-tooltip
      >
      </el-table-column>
       <el-table-column
        align="center"
        label="创建时间"
        prop="status"
        show-overflow-tooltip
      >
      </el-table-column>

       <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="text" size="small" @click="handleEdit(scope.row)">权限分配</el-button>
          <el-button type="text" size="small" @click="handleDel(scope.row.id)">删除</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>

     <el-dialog :title="title" width="550px" :visible.sync="dialogFormVisible">
        <el-form label-width="130px" :model="setQuery"
        ref="setQuery"
        :rules="rules">
            <el-form-item label="角色名称:"  prop="paperName">
                <el-input
                v-model="setQuery.paperName"
                class="item-width-300"
                ></el-input>
            </el-form-item>
            <el-form-item label="备注:"  prop="paperName">
                <el-input
                v-model="setQuery.paperName"
                class="item-width-300"
                ></el-input>
            </el-form-item>
             
            <el-form-item label="权限分配:"  prop="questionsNum">
              <el-tree
                style="margin-top: 10px;"
                :data="data"
                show-checkbox
                default-expand-all
                node-key="id"
                ref="tree"
                highlight-current
                :props="defaultProps">
              </el-tree>
            </el-form-item>
           
        </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" :loading="btnLoading" @click="save">确 定</el-button>
    </div>
    </el-dialog>

  </div>
</template>

  <script>
  import {activityList,activityDel,activityStop} from '@/api/activity'
export default {
  name: "roleList",
  data() {
    return {
        date:'',
        data: [{
          id: 1,
          label: '一级 1',
          children: [{
            id: 4,
            label: '二级 1-1',
            children: [{
              id: 9,
              label: '三级 1-1-1'
            }, {
              id: 10,
              label: '三级 1-1-2'
            }]
          }]
        }, {
          id: 2,
          label: '一级 2',
          children: [{
            id: 5,
            label: '二级 2-1'
          }, {
            id: 6,
            label: '二级 2-2'
          }]
        }, {
          id: 3,
          label: '一级 3',
          children: [{
            id: 7,
            label: '二级 3-1'
          }, {
            id: 8,
            label: '二级 3-2'
          }]
        }],
        defaultProps: {
          children: 'children',
          label: 'label'
        },
      options:[
        {
          value:1,
          label:'海报'
        },
        {
          value:2,
          label:'报名'
        },
      ],
 
      tableData: [],
      loading: false,
      btnLoading: false,
      dialogFormVisible: false,
      query: {
        "activityType":null,
        "state":'',
        "currentPage": 1,
        "pageSize": 10,
        shopId: 0,
      },
      setQuery: {
       type:1
      },
      rules:{},
      title: "",
      total: 0,
    };
  },
  watch: {
    date(val){
      if(val){
        this.query.startTime = val[0]
        this.query.endTime = val[1]
      }else{
        this.query.startTime = ''
        this.query.endTime = ''
      }
    }
  },
  methods: {
    handleEdit(row){
        this.title = "编辑"
        this.dialogFormVisible = true
     
    },
    handleAdd(){
        this.title = "添加"
        this.dialogFormVisible = true
    },
    handleSearch(){
      this.query.currentPage = 1
      this.activityList();
    },
    handleDel(id){
         this.$confirm(`此操作将删除该活动, 是否继续?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
        }).then(() => {
          activityDel({id}).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.activityList()
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.activityList()
    },
    activityList(){
    //   this.loading = true
    //   activityList(this.query).then(res=>{
    //     this.loading = false
    //     if(res.state == 'Success'){
    //       this.tableData = res.content.records
    //       this.total = res.content.total
    //     }
    //   })
    },
    save(){
        console.log(1111);
        this.$refs.setQuery.validate((v) => {
        if (v) {
        //   this.btnLoading = true
        //   addOrUpdatePaper(this.setQuery).then(res=>{
        //     this.btnLoading = false
        //     if(res.state == 'Success'){
                this.dialogFormVisible = false
        //       this.$notify({
        //           title: '成功',
        //           message: '操作成功',
        //           type: 'success'
        //         });
        //         this.query.currentPage = 1
        //         this.paperList();
        //     }
        //   })
        }
      });
    }
  },
  created() {
    this.activityList()
  },
};
</script>

<style lang="scss" >
.roleList {

}

</style>
