<template>
  <div class="app-container">
    <div v-show="viewState == 1">
      <button-bar view-title="流程抄送设置" ref="btnbar" :btndisabled="btndisabled" @btnhandle="btnHandle"/>
      <div class="main-content">
        <div class="searchcon">
          <el-button size="small" class="searchbtn" @click="clicksearchShow">{{ searchxianshitit }}</el-button>
          <div v-show="isSearchShow" class="search">
            <el-form ref="listQueryform" :inline="true" :model="listQuery" label-width="100px" class="tab-header">
              <el-form-item label="流程名称">
                <el-select v-model="listQuery.params.flowName" placeholder="请选择" filterable>
                  <el-option v-for="item in flow_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictValue"></el-option>
                </el-select>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" size="small" icon="el-icon-search" @click="handleFilter">查询</el-button>
              <el-button type="primary" size="small" icon="el-icon-refresh" @click="handleReset">重置</el-button>
            </div>
          </div>
        </div>
        <div class="listtop">
          <div class="tit">业务流程列表</div>
          <pageye v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
        <div class="">
          <el-table :key="tableKey" v-loading="listLoading" :data="list" border style="width: 100%">
            <el-table-column width="60" label="序号" type="index" :index="indexMethod" align="center"/>
            <el-table-column width="180" label="操作" align="center">
              <template slot-scope="scope">
                <el-button size="small" type="primary" @click="handleUpdate(scope.row)">设置</el-button>
                <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
            <el-table-column label="流程名称" align="center" width="400">
              <template slot-scope="scope">
                <span>{{ scope.row.flowName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="抄送角色" align="left" header-align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.roleName }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pages">
          <div class="tit"/>
          <!-- 翻页 -->
          <pagination v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
      </div>
    </div>
    <liuchengchaosongAdd v-show="viewState == 2 ||viewState == 3" ref="divadd" @doback="resetState" @reloadlist="getList" />
  </div>
</template>

<script>
import { pageList, delBySids } from '@/api/system/liuchengchaosong/liuchengchaosong'
import { selectFlowList } from '@/api/system/postManage/index'
import Pagination from '@/components/pagination'
import pageye from '@/components/pagination/pageye'
import ButtonBar from '@/components/ButtonBar'
import liuchengchaosongAdd from './liuchengchaosongAdd'

export default {
  name: 'liuchengchaosong',
  components: {
    Pagination,
    pageye,
    ButtonBar,
    liuchengchaosongAdd
  },
  data() {
    return {
      btndisabled: false,
      btnList: [
        {
          type: 'primary',
          size: 'small',
          icon: 'plus',
          btnKey: 'toAdd',
          btnLabel: '新增'
        },
        {
          type: 'info',
          size: 'small',
          icon: 'cross',
          btnKey: 'doClose',
          btnLabel: '关闭'
        }
      ],
      isSearchShow: false,
      searchxianshitit: '显示查询条件',
      viewState: 1, // 1、列表 2、添加-车辆预订 3、编辑  4、查看 5、订金-订金收取
      // 查询 -----------
      flow_list: [], // 分公司
      tableKey: 0,
      list: [],
      sids: [],
      FormLoading: false,
      listLoading: false,
      listQuery: {
        current: 1,
        size: 5,
        total: 0,
        params: {
          flowName: ''
        }
      }
    }
  },
  mounted() {
    this.$refs['btnbar'].setButtonList(this.btnList)
  },
  created() {
    // 初始化变量
    this.init()
    // 加载列表
    this.getList()
  },
  methods: {
    init() {
      selectFlowList().then((res) => {
        if (res.success) {
          this.flow_list = res.data
        }
      })
    },
    btnHandle(btnKey) {
      console.log('XXXXXXXXXXXXXXX    ' + btnKey)
      switch (btnKey) {
        case 'toAdd':
          this.toAdd()
          break
        case 'doClose':
          this.doClose()
          break
        default:
          break
      }
    },
    // 搜索条件效果
    clicksearchShow() {
      this.isSearchShow = !this.isSearchShow
      if (this.isSearchShow) {
        this.searchxianshitit = '隐藏查询条件'
      } else {
        this.searchxianshitit = '显示查询条件'
      }
    },
    // 序号
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    // 查询列表信息
    getList() {
      this.listLoading = true
      this.listQuery.params.orgSidPath = window.sessionStorage.getItem('orgSidPath')
      pageList(this.listQuery).then((response) => {
        this.listLoading = false
        if (response.success) {
          this.list = response.data.records
          this.listQuery.total = response.data.total
        } else {
          this.list = []
          this.listQuery.total = 0
        }
      })
    },
    // 查询按钮
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    // 重置
    handleReset() {
      this.listQuery = {
        current: 1,
        size: 5,
        total: 0,
        params: {
          flowName: ''
        }
      }
      this.getList()
    },
    toAdd() {
      this.viewState = 2
      this.$refs['divadd'].showAdd()
    },
    // 编辑
    handleUpdate(row) {
      this.viewState = 3
      this.$refs['divadd'].showEdit(row)
    },
    handleDelete(row) {
      const tip = '请确认是否删除'
      this.$confirm(tip, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const aa = []
        aa.push(row.sid)
        delBySids(aa).then((res) => {
          if (res.success) {
            this.$message({ showClose: true, type: 'success', message: '删除成功' })
            this.getList()
          }
        })
      })
    },
    resetState() {
      this.viewState = 1
    },
    doClose() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
</style>
