<template>
  <el-card shadow="never"
           class="aui-card--fill">
    <div class="mod-news__group}">
      <el-form :inline="true"
               :model="dataForm"
               @keyup.enter.native="getDataList()">
        <el-form-item label="网格">
          <el-input v-model="dataForm.grid"
                    placeholder="请输入网格名称"
                    clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
          <el-button @click="createPartys()"
                     type="primary">批量生成党员群</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading"
                :data="dataList"
                border
                @selection-change="dataListSelectionChangeHandle"
                style="width: 100%;">
        <el-table-column type="index"
                         width="50"
                         label="序号"></el-table-column>
        <el-table-column prop="district"
                         label="市区"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="street"
                         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="grid"
                         label="网格"
                         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 type="text"
                       size="small"
                       @click="createParty(scope.row)">生成党员群</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>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sys/dept/queryCompleteDept',
        getDataListIsPage: true
      },
      dataForm: {
        district: '',
        districtId: '',
        street: '',
        streetId: '',
        community: '',
        communityId: '',
        grid: '',
        gridId: ''
      }
    }
  },
  methods: {
    createParty (row) {
      var postForm = [{
        district: row.district,
        districtId: row.districtId,
        street: row.street,
        streetId: row.streetId,
        community: row.community,
        communityId: row.communityId,
        grid: row.grid,
        gridId: row.gridId
      }]
      this.$http['post']('/property/epdc-app/group/createPartys', postForm).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.processingOpinionsVisible = false
        this.getDataList()
        this.$message({
          message: this.$t('prompt.success'),
          type: 'success',
          duration: 500
        })
      }).catch(() => { })
    },
    createPartys () {
      var postForm = this.dataList
      this.$http['post']('/property/epdc-app/group/createPartys', postForm).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.processingOpinionsVisible = false
        this.getDataList()
        this.$message({
          message: this.$t('prompt.success'),
          type: 'success',
          duration: 500
        })
      }).catch(() => { })
    }
  }
}
</script>
