<template>
  <div>
    <basicLayout
        ref="list"
        :oldFormPath="{add:'HManagement/submit/list/modules'}"
        tableName="tableSubmitlist"
        idName="sat_submiteditmodelid"
        :apiId="{query:20221102093602,del:20221102094102}"
        @listData="list"
    >
    <div slot="custom" style="display:flex">
      <div class="label_center">
        <p class="search__label">状态:</p>
        <el-select
          class="inline-16"
          size="small"
          v-model="status"
          placeholder="请选择"
          @change="handleSelectChange"
          clearable
        >
          <el-option
            v-for="(item,index) in statusList"
            :label="item.label"
            :value="item.value"
            :key="index"
          ></el-option>
        </el-select>
      </div>
    </div>
      <template v-slot:tbList="scope">
        <div v-if="scope.data.column.columnname === 'status'">
            <span :style="scope.data.column.data.status === '发布' ? 'color:#52C41A' : ''">{{ scope.data.column.data.status }}</span>
        </div>
        <div v-else-if="scope.data.column.columnname === 'onceonly'">
          <span>{{ scope.data.column.data.onceonly === 1 ? '一事一报' : '一事多报' }}</span>
        </div>
        <div v-else>
          {{scope.data.column.data[[scope.data.column.columnname]]}}
        </div>
      </template>
      <template v-slot:tbOpreation="scope">
<!--        <edit :id="scope.data.data.sat_submiteditmodelid" @updateSuccess="onSuccess"></edit>-->
        <el-button class="inline-16" type="text" size="small" @click="$store.dispatch('DrawerShowChange',true),$router.push({path:'/submit_edit',query:{id:scope.data.data.sat_submiteditmodelid}})">详情</el-button>
        <el-button class="inline-16"  type="text" size="small" @click="$store.dispatch('DrawerShowChange',true),$router.push({path:'/submit_statistics',query:{id:scope.data.data.sat_submiteditmodelid}})">数据分析</el-button>

        <!--        <el-button v-if="tool.checkAuth($route.name,'data_analysis')" type="text" size="small" @click="$router.push({path:'/notice_edit',query:{id:scope.data.data.sat_noticeid}})">详情</el-button>-->
      </template>
    </basicLayout>
    <el-drawer
      title="我是标题"
      :visible.sync="drawer"
      :with-header="false"
      direction="rtl"
      size="90%"
      append-to-body
      @close="closeDrawer">
      <div class="detail__panel">
        <router-view/>
      </div>
    </el-drawer>
<!--    <list ref="list">
      <el-button slot="add" icon="el-icon-plus" type="primary" size="small" @click="$router.push({path:'/submit_add'})">新 建</el-button>
      <template v-if="tool.checkAuth($route.name,'read')" v-slot:detail="scope">
        <el-button class="inline-16" type="text" size="mini" @click="$router.push({path:'/submit_detail',query:{id:scope.data.data.sat_submiteditmodelid}})">明 细</el-button>
      </template>
      <template v-if="tool.checkAuth($route.name,'update')" v-slot:edit="scope">
        <el-button class="inline-16" style="margin-left:0 !important;" type="text" size="mini" @click="$router.push({path:'/submit_edit',query:{id:scope.data.data.sat_submiteditmodelid}})">编 辑</el-button>
      </template>
      <template v-if="tool.checkAuth($route.name,'update')" v-slot:release="scope">
        <release :data="scope.data.data" @onSuccess="onSuccess"></release>
      </template>
      <template v-if="tool.checkAuth($route.name,'update')" v-slot:data_statistics="scope">
        <el-button type="text" size="mini" class="inline-16" @click="$router.push({path:'/submit_statistics',query:{id:scope.data.data.sat_submiteditmodelid}})">数据分析</el-button>
      </template>
      
      <template v-if="tool.checkAuth($route.name,'delete')" v-slot:del="scope">
        <on-del class="inline-16" :data="scope.data.data" @onSuccess="onSuccess"></on-del>
      </template>
    </list>-->
  </div>
</template>

<script>
import {mapGetters} from 'vuex'

import list from './list/list.vue'
import onDel from './list/modules/delete.vue'
import release from './list/modules/release.vue'
import edit from './list/modules/submit_edit'

export default {
  data () {
    return {
      statusList:[
        {label:'全部',value:''},
        {label:'新建',value:'新建'},
        {label:'发布',value:'发布'},
      ],
      typeList:[
        {label:'一事一报',value:'1'},
        {label:'一事多报',value:'0'},
      ],
      status:'',
      type:'',
      drawer:false
    }
  },
  components:{
    list,
    onDel,
    release,
    edit
  },
  computed: {
    ...mapGetters({
      DrawerShow:'DrawerShow'
    })
  },
  watch: {
    $route (val) {
      if (val.path == '/submit_mag') {
        this.$refs.list.listData()
      }
    },
    DrawerShow (val) {
      val ? this.drawer = true : this.drawer = false
    }
  },
  methods:{
    closeDrawer () {
      this.$store.dispatch('DrawerShowChange',false)
      this.$router.push({path:"submit_mag"})
    },
    onSuccess () {
      this.$refs.list.listData()
    },
    handleSelectChange () {
      this.$refs.list.param.content.where.status = this.status
      this.$refs.list.listData()
    },
    typeChange () {
      this.$refs.list.param.content.where.onceonly = this.type
      this.$refs.list.listData()
    },
    async list(data) {
      let deteleList = [];
      data.forEach(v => {
        if (v.notes == '初始化数据' + JSON.parse(sessionStorage.getItem('active_account')).userid && v.title == '' && v.status == '新建') {
          deteleList.push(v.sat_submiteditmodelid)
        }
      })
      if (deteleList.length > 0) {
        let res = await this.$api.requested({
          "id":20221102094102,
          "content": {
            "sat_submiteditmodelids":deteleList
          }
        })
        this.$refs.list.listData()
      }
    }
  }
}

</script>
<style>
</style>