<template>
  <el-dialog :visible.sync="visible"
             title="用户详情"
             :close-on-click-modal="false"
             :close-on-press-escape="false">
    <el-form :model="dataForm"
             :rules="dataRule"
             ref="dataForm"
             @keyup.enter.native="dataFormSubmitHandle()"
             :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
      <el-form-item label="真实姓名"
                    prop="realName" v-if="dataForm.realName">
        <span>{{dataForm.realName}}</span>
      </el-form-item>
      <el-form-item label="手机号"
                    prop="mobile" v-if="dataForm.mobile">
        <span>{{dataForm.mobile}}</span>
      </el-form-item>
      <el-form-item label="身份证号"
                    prop="identityNo" v-if="dataForm.identityNo">
        <span>{{dataForm.identityNo}}</span>
      </el-form-item>
      <el-form-item label="居民住址"
                    prop="address" v-if="dataForm.address">
        <span>{{dataForm.address}}</span>
      </el-form-item>
      <el-form-item label="是否党员" v-if="false"
                    prop="partyFlag">
        <span v-if="dataForm.partyFlag === '0'">否</span>
        <span v-if="dataForm.partyFlag === '1'">是</span>
      </el-form-item>
      <!-- <el-form-item label="干部下沉">
        <el-select v-model="dataForm.cadreFlag"
                   clearable
                   placeholder="请选择">
          <el-option v-for="item in cadreOptions"
                     :key="item.cadreFlag"
                     :label="item.cadreTitle"
                     :value="item.cadreFlag">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="通过审核"
                    prop="state" v-if="dataForm.state==='3'||dataForm.state==='2'">
        <span v-if="dataForm.state === '3'">是</span>
        <span v-if="dataForm.state === '2'">否</span>
      </el-form-item>
      <el-form-item v-if="dataForm.state === '2' && dataForm.remark"
                    label="审核备注"
                    prop="remark">
        <span>{{dataForm.remark}}</span>
      </el-form-item>
      <el-form-item label="扫码网格">
        <el-table :data="userGridList"
                  style="width: 100%">
          <!-- <el-table-column prop="street"
                           label="街道">
          </el-table-column>
          <el-table-column prop="community"
                           label="社区">
          </el-table-column>
          <el-table-column prop="grid"
                           label="网格">
          </el-table-column> -->
          <el-table-column prop="id"
                           label="主键" v-if="false">
          </el-table-column>
          <el-table-column prop="allDeptNames"
                           label="街道-社区-网格">
          </el-table-column>
          <el-table-column prop="grid"
                           label="网格名称" v-if="false">
          </el-table-column>
          <el-table-column prop="leaderFlag"
                           label="是否为网格长"
                           :formatter="showLeaderFlagFormatter">
          </el-table-column>
        </el-table>
      </el-form-item>
      <!-- <el-form-item label="用户标签"
                    prop="tagIds">
        <el-checkbox-group v-model="dataForm.tagIds">
          <el-checkbox v-for="item in tagOptions"
                       :key="item.tagName"
                       :label="item.id">{{item.tagName}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item> -->
    </el-form>
    <template slot="footer">
      <el-button @click="visible = false"
                 type="primary">{{ $t('confirm') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        id: '',
        partyFlag: '',
        cadreFlag: '',
        state: '',
        tagIds: [],
        remark: ''
      },
      partyFlagOptions: [{ id: '0', name: '不是' }, { id: '1', name: '是' }],
      cadreOptions: [{ cadreFlag: '1', cadreTitle: '是' }, { cadreFlag: '0', cadreTitle: '否' }],
      tagOptions: [],
      userGridList: []
    }
  },
  computed: {
    dataRule () {
      return {
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.getInfo()
          this.queryUserGridList()
        }
      })
      this.getTagOptions()
    },
    getTagOptions () {
      this.$http.get(`/app-user/usertag/list`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.tagOptions = res.data
      }).catch(() => { })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/app-user/user/${this.dataForm.id}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
        this.dataForm.tagIds = []
      }).catch(() => { })
    },
    // 获取用户网格列表
    queryUserGridList () {
      this.$http.get(`/app-user/usergrid/listUserGrid/${this.dataForm.id}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.userGridList = res.data
      }).catch(() => { })
    },
    showLeaderFlagFormatter (row, column, cellValue, index) {
      console.log(cellValue)
      if (cellValue === '1') {
        return '是'
      } else {
        return '否'
      }
    }
  }
}
</script>
