<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-news__messageboradreply}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="所属机构" label-width="90px">
          <el-cascader
              v-model="ids"
              :options="options"
              :props="{ checkStrictly: true }"
              clearable
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="状态" label-width="90px">
          <el-select v-model="dataForm.boradType" placeholder="留言状态" style="width:250px;">
            <el-option v-for="item in boradType" :key="item.value" :label="item.typeName" :value="item.value" >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button  type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column label="序号" header-align="center" align="center" width="50px">
          <template slot-scope="scope">
            {{scope.$index+1}}
          </template>
        </el-table-column>
        <el-table-column prop="createdTime" label="创建时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="community" label="社区" header-align="center" align="center"></el-table-column>
        <el-table-column prop="dept" label="支部" header-align="center" align="center"></el-table-column>
        <el-table-column prop="userName" label="提问人" header-align="center" align="center"></el-table-column>
        <el-table-column  label="问题描述" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button  type="text"
                       @click="childHandle(scope.row)">查看详情</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="state" label="状态" :formatter = "stateFormat" header-align="center" align="center">

        </el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="scope.row.state == '0'" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">回复</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './messageboradreply-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/events/borad/page',
        getDataListIsPage: true,
        deleteURL: '/news/messageboradreply',
        deleteIsBatch: true
      },
      dataForm: {
        boradType: '',
        deptId: ''
      },
      ids: [],
      options: [],
      boradType: [
        {
          typeName:"全部",
          value:""
        },
        {
          typeName:"待回复",
          value:"0"
        },
        {
          typeName:"回复",
          value:"1"
        }
      ],
      stateFormat (row, column) {
        if (row.state === '0') {
          return '已回复'
        } else {
          return '待回复'
        }
      }
    }
  },
  components: {
    AddOrUpdate
  },
  created: function () {
    this.getOptions()
  },
  watch: {
    ids: function (val) {
      if (val.length === 0) {
        this.dataForm.deptId = ''
      } else {
        this.dataForm.deptId = this.ids[val.length - 1]
      }
    }
  },
  methods: {
    getOptions () {
      var paa = {deptType:'party'}
      this.$http
          .post(`/sys/user/deptOptions/getByLoginUserNew`,paa)
          .then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg)
            }
            this.options = res.data.options
          })
          .catch(() => {})
    },
    addOrUpdateHandle (id, disabled) {
      this.$parent.selectComponent = 'MessageBoradReplyDetail'
      this.$router.push({ path: '/events-borad-boradReplyRoute', query: { id: id, disabled: disabled } })
    }

  }
}
</script>
