<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户编号" prop="usercode">
        <el-input
            v-model="queryParams.usercode"
            placeholder="请输入用户编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称" prop="nickname">
        <el-input
            v-model="queryParams.nickname"
            placeholder="请输入昵称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input
            v-model="queryParams.mobile"
            placeholder="请输入手机号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['xq:userInfo:edit']"
        >修改</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userInfoList" @selection-change="handleSelectionChange">
      <el-table-column label="用户编号" align="center" prop="usercode" />
      <el-table-column label="昵称" align="center" prop="nickname" show-overflow-tooltip/>
      <el-table-column label="手机号" align="center" prop="mobile" width="100"/>
      <el-table-column label="个人信息" align="center" >
        <el-table-column label="头像" align="center" prop="avatar" >
          <template v-slot="scope">
            <image-avatar :src="scope.row.avatar"/>
          </template>
        </el-table-column>
        <el-table-column label="性别" align="center" prop="gender" >
          <template v-slot="scope">
            <cai-dict-tag :options="genderList" :value="scope.row.gender" />
          </template>
        </el-table-column>
        <el-table-column label="年龄" align="center" prop="age" />
        <el-table-column label="生日" align="center" prop="birthday" show-overflow-tooltip/>
        <el-table-column label="身高" align="center" prop="height" />
        <el-table-column label="体重" align="center" prop="weight" />
        <el-table-column label="体型" align="center" prop="somatotype" >
          <template v-slot="scope">
            <cai-dict-tag :options="userSomatotypeList" :value="scope.row.somatotype" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="生肖" align="center" prop="zodiac" >
          <template v-slot="scope">
            <cai-dict-tag :options="userZodiacList" :value="scope.row.zodiac" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="星座" align="center" prop="sign" >
          <template v-slot="scope">
            <cai-dict-tag :options="userSignList" :value="scope.row.sign" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="居住地" align="center" prop="residenceName" />
        <el-table-column label="户籍地" align="center" prop="addressName" />
        <el-table-column label="居住城市" align="center" prop="residenceCityName" />
        <el-table-column label="学历" align="center" prop="education" >
          <template v-slot="scope">
            <cai-dict-tag :options="userEducationList" :value="scope.row.education" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="婚况" align="center" prop="marriage" >
          <template v-slot="scope">
            <cai-dict-tag :options="userMarriageList" :value="scope.row.marriage" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="职业" align="center" prop="profession" />
        <el-table-column label="年收入" align="center" prop="annualIncome" >
          <template v-slot="scope">
            <cai-dict-tag :options="userAnnualIncomeList" :value="scope.row.annualIncome" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="公司性质" align="center" prop="companyNature" >
          <template v-slot="scope">
            <cai-dict-tag :options="userCompanyNatureList" :value="scope.row.companyNature" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="为谁征婚" align="center" prop="forPersonals" show-overflow-tooltip>
          <template v-slot="scope">
            <cai-dict-tag :options="userForPersonalsList" :value="scope.row.forPersonals" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="自我描述" align="center" prop="remark" show-overflow-tooltip />
        <el-table-column label="住房情况" align="center" prop="housingStatus" >
          <template v-slot="scope">
            <cai-dict-tag :options="userHousingStatusList" :value="scope.row.housingStatus" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="购车情况" align="center" prop="carStatus" >
          <template v-slot="scope">
            <cai-dict-tag :options="userCarStatusList" :value="scope.row.carStatus" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="是否吸烟" align="center" prop="smokeStatus" show-overflow-tooltip>
          <template v-slot="scope">
            <cai-dict-tag :options="userSmokeStatusList" :value="scope.row.smokeStatus" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="是否喝酒" align="center" prop="drinkStatus" >
          <template v-slot="scope">
            <cai-dict-tag :options="userDrinkStatusList" :value="scope.row.drinkStatus" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="民族" align="center" prop="nation" />
        <el-table-column label="有没有小孩" align="center" prop="childStatus" >
          <template v-slot="scope">
            <cai-dict-tag :options="userChildStatusList" :value="scope.row.childStatus" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="家庭背景" align="center" prop="familyBackground" >
          <template v-slot="scope">
            <cai-dict-tag :options="userFamilyBackgroundList" :value="scope.row.familyBackground" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="家中排行" align="center" prop="familyRanking" >
          <template v-slot="scope">
            <cai-dict-tag :options="userFamilyRankingList" :value="scope.row.familyRanking" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="是否接受异地恋" align="center" prop="loveAtDistance" >
          <template v-slot="scope">
            <cai-dict-tag :options="userLoveAtDistanceList" :value="scope.row.loveAtDistance" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="何时结婚" align="center" prop="whenMarriage" >
          <template v-slot="scope">
            <cai-dict-tag :options="userWhenMarriageList" :value="scope.row.whenMarriage" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="是否要小孩" align="center" prop="wantChild" >
          <template v-slot="scope">
            <cai-dict-tag :options="userWantChildList" :value="scope.row.wantChild" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="愿与对方父母同住" align="center" prop="liveAtParent" >
          <template v-slot="scope">
            <cai-dict-tag :options="userLiveAtParentList" :value="scope.row.liveAtParent" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="交友目的" align="center" prop="findTag" >
          <template v-slot="scope">
            <cai-dict-tag :options="userFindTagList" :value="scope.row.findTag" empty-value="-"/>
          </template>
        </el-table-column>
        <el-table-column label="毕业院校" align="center" prop="graduateSchool" />
        <el-table-column label="兴趣爱好" align="center" prop="hobbys" />
      </el-table-column>
      <el-table-column label="择偶条件" align="center" >
        <el-table-column label="年龄" align="center" prop="filterAge" >
          <template v-slot="scope">
            <span v-if="!scope.row.filterAge">不限</span>
            <span v-if="scope.row.filterAge">{{scope.row.filterAge}}</span>
          </template>
        </el-table-column>
        <el-table-column label="身高" align="center" prop="filterHeight" >
          <template v-slot="scope">
            <span v-if="!scope.row.filterHeight">不限</span>
            <span v-if="scope.row.filterHeight">{{scope.row.filterHeight}}</span>
          </template>
        </el-table-column>
        <el-table-column label="体型" align="center" prop="filterSomatotype" >
          <template v-slot="scope">
            <cai-dict-tag :options="userSomatotypeList" :value="scope.row.filterSomatotype" empty-value="不限" split-value="&"/>
          </template>
        </el-table-column>
        <el-table-column label="婚况" align="center" prop="filterMarriage" >
          <template v-slot="scope">
            <cai-dict-tag :options="userMarriageList" :value="scope.row.filterMarriage" empty-value="不限" split-value="&"/>
          </template>
        </el-table-column>
        <el-table-column label="学历" align="center" prop="filterEducation" >
          <template v-slot="scope">
            <cai-dict-tag :options="userEducationList" :value="scope.row.filterEducation" empty-value="不限" />
          </template>
        </el-table-column>
<!--        <el-table-column label="地区" align="center" prop="filterResidenceName" />-->
        <el-table-column label="年收入" align="center" prop="filterAnnualIncome" >
          <template v-slot="scope">
            <cai-dict-tag :options="userAnnualIncomeList" :value="scope.row.filterAnnualIncome" empty-value="不限" />
          </template>
        </el-table-column>
        <el-table-column label="小孩情况" align="center" prop="filterChildStatus" >
          <template v-slot="scope">
            <cai-dict-tag :options="userChildStatusList" :value="scope.row.filterChildStatus" empty-value="不限"/>
          </template>
        </el-table-column>
        <el-table-column label="住房情况" align="center" prop="filterHousingStatus" >
          <template v-slot="scope">
            <cai-dict-tag :options="userHousingStatusList" :value="scope.row.filterHousingStatus" empty-value="不限" />
          </template>
        </el-table-column>
        <el-table-column label="购车情况" align="center" prop="filterCarStatus" >
          <template v-slot="scope">
            <cai-dict-tag :options="userCarStatusList" :value="scope.row.filterCarStatus" empty-value="不限" />
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template v-slot="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleInfo(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <user-info-dialog v-if="userInfoDialogVisible" ref="userInfoDialog" />
    <update-user-info-dialog v-if="updateUserInfoDialogVisible" ref="updateUserInfoDialog" @refreshDataList="getList" />

  </div>
</template>

<script>
import { listUserInfo } from '@/api/xq/userInfo'
import {
  genderList,
  userAnnualIncomeList,
  userCarStatusList,
  userChildStatusList,
  userCompanyNatureList,
  userDrinkStatusList,
  userEducationList,
  userFamilyBackgroundList,
  userFamilyRankingList,
  userFindTagList,
  userForPersonalsList,
  userHousingStatusList,
  userLiveAtParentList,
  userLoveAtDistanceList,
  userMarriageList,
  userSignList,
  userSmokeStatusList,
  userSomatotypeList,
  userWantChildList,
  userWhenMarriageList,
  userZodiacList
} from '@/constant/statusMap'
import UserInfoDialog from '@/views/xq/user/user-info-dialog.vue'
import UpdateUserInfoDialog from '@/views/xq/userInfo/update-user-info-dialog.vue'

export default {
  name: "UserInfo",
  components: { UpdateUserInfoDialog, UserInfoDialog },
  data() {
    return {
      genderList,userCarStatusList, userChildStatusList, userCompanyNatureList, userDrinkStatusList,
      userEducationList, userFamilyBackgroundList, userFamilyRankingList, userForPersonalsList, userHousingStatusList,
      userLiveAtParentList, userLoveAtDistanceList, userSmokeStatusList,
      userSomatotypeList,userMarriageList,userAnnualIncomeList,userZodiacList,
      userWantChildList, userWhenMarriageList,userFindTagList,userSignList,
      updateUserInfoDialogVisible: false,
      userInfoDialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      userInfoList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickname: undefined,
        mobile: undefined,
        usercode: undefined,
        housingStatus: undefined,
        carStatus: undefined,
        smokeStatus: undefined,
        drinkStatus: undefined,
        nation: undefined,
        childStatus: undefined,
        familyBackground: undefined,
        familyRanking: undefined,
        loveAtDistance: undefined,
        whenMarriage: undefined,
        wantChild: undefined,
        liveAtParent: undefined,
        findTag: undefined,
        graduateSchool: undefined,
        hobbys: undefined,
        filterAge: undefined,
        filterHeight: undefined,
        filterSomatotype: undefined,
        filterMarriage: undefined,
        filterEducation: undefined,
        filterResidence: undefined,
        filterAnnualIncome: undefined,
        filterChildStatus: undefined,
        filterHousingStatus: undefined,
        filterCarStatus: undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;
      listUserInfo(this.queryParams).then(response => {
        this.userInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleInfo(row) {
      this.userInfoDialogVisible = true
      this.$nextTick(() => {
        this.$refs.userInfoDialog.init(row.userId)
      })
    },
    handleUpdate(row){
      this.updateUserInfoDialogVisible = true
      this.$nextTick(() => {
        this.$refs.updateUserInfoDialog.init(row)
      })
    }
  }
};
</script>
