<template>
  <div>
    <el-input size="mini" v-model="msg.RealName" placeholder="根据名称搜索" :clearable="true" @clear="msg.pageIndex=1,getList()"
      @keyup.enter.native="msg.pageIndex=1,getList()" style="width:300px;">
      <el-button slot="append" @click="msg.pageIndex=1,getList()">搜索</el-button>
    </el-input>
    <el-table ref="multipleTable" :data="dataList" tooltip-effect="dark" height="450" style="width: 100%"
      @selection-change="handleSelectionChange">
      <template v-if="isSingle">
        <el-table-column width="50px" label="">
          <template slot-scope="scope">
            <el-radio v-model="scope.row.IsChecked" @change.native="getTemplateRow(scope.$index,scope.row)">&nbsp;
            </el-radio>
          </template>
        </el-table-column>
      </template>
      <template v-else>
        <el-table-column type="selection" width="50px">
        </el-table-column>
      </template>
      <el-table-column label="ID" width="60px">
        <template slot-scope="scope">{{ scope.row.Id }}</template>
      </el-table-column>
      <el-table-column prop="name" label="名称">
        <template slot-scope="scope">
          <div flex="cross:center dir:left">
            <img style="width:50px;height:50px;margin-right:10px;" :src="getIconLink(scope.row.Photo)" />
            <div>{{ scope.row.Name }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="80px">
        <template slot-scope="scope">{{ scope.row.RealName }}</template>
      </el-table-column>
      <el-table-column label="性别" width="80px">
        <template slot-scope="scope">{{ scope.row.SexStr }}</template>
      </el-table-column>
      <el-table-column label="身高" width="80px">
        <template slot-scope="scope">{{ scope.row.Height }}</template>
      </el-table-column>
      <el-table-column label="体重" width="80px">
        <template slot-scope="scope">{{ scope.row.Weight }}</template>
      </el-table-column>
      <el-table-column label="学历" width="80px">
        <template slot-scope="scope">{{ scope.row.EducationType }}</template>
      </el-table-column>
      <el-table-column label="婚姻状态" width="80px">
        <template slot-scope="scope">{{ scope.row.Marriage }}</template>
      </el-table-column>
      <el-table-column label="生日" width="100px">
        <template slot-scope="scope">{{ scope.row.Birthday }}</template>
      </el-table-column>

    </el-table>
    <el-pagination style="text-align:center" background @current-change="handleCurrentChange" :page-size="msg.pageSize"
      layout="prev, pager, next" :total="total">
    </el-pagination>
  </div>
</template>
<script>
  export default {
    props: ['ckGoods', "isSingle", "IsGetSpec","Sex"],
    data() {
      return {
        dataList: [],
        msg: {
          pageIndex: 1,
          pageSize: 15,
          Name: '', //姓名
          RealName: '', //真实姓名
          Sex:0     //1男   2女  0 不限
        },
        total: 0,
        selectRow: [],
      };
    },
    created() {
      if (this.IsGetSpec) {
        this.msg.IsGetSpec = this.IsGetSpec;
      }
    },
    methods: {
      //获取所有菜单
      getList() {
        if(this.Sex){
          this.msg.Sex = this.Sex;
        }
        this.apipost("/api/Miai/GetBaseInfoPageList", this.msg, res => {
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            var tempArray = res.data.data.pageData;
            if (tempArray && tempArray.length > 0) {
              tempArray.forEach(item => {
                item.IsChecked = false;
              });
            }
            this.dataList = JSON.parse(JSON.stringify(tempArray));
          } else {
            this.Info(res.data.message);
          }
        })
      },
      handleSelectionChange(val) {
        this.selectRow = JSON.parse(JSON.stringify(val));
      },
      getTemplateRow(index, row) {
        this.selectRow = [];
        if (this.dataList && this.dataList.length > 0) {
          this.dataList.forEach(item => {
            if (item.Id != row.Id) {
              item.IsChecked = false;
            }
          })
        }
        this.selectRow.push(JSON.parse(JSON.stringify(row)));
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      //父组件调用方法
      getChoicedGoods() {
        return this.selectRow;
      },
      //清空多选方法
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
    },
    mounted() {
      this.getList();
    }
  };

</script>
