<template>
  <view class="my-data">
	  <uni-nav-bar @clickLeft="goBack()" class="nav-bar" height="110rpx" leftWidth="200rpx" leftText="个人信息"
	  	leftIcon="left" border backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
	  
    <view class="wrap-view">
      <view class="item">
        <view class="title">所属部门</view>
        <picker class="content" mode="selector" :range="deptRange" @change="deptChange" range-key="name">
          <view class="">
            {{deptGender}}
          </view>
        </picker>
       
      </view>
    </view>
    <view class="wrap-view">
      <view class="item">
        <view class="title">姓名</view>
        <view class="content">
          <input type="text" v-model="principal.mobile" maxlength="20" placeholder="请输入" />
        </view>
      </view>
      <view class="item">
        <view class="title">手机号</view>
        <view class="content">
          <input type="text" v-model="principal.mobile" maxlength="20" placeholder="请输入" />
        </view>
      </view>
	  <view class="item">
	    <view class="title">身份证号</view>
	    <view class="content">
	      <input type="text" v-model="principal.mobile" maxlength="20" placeholder="请输入" />
	    </view>
	  </view>
	  <view class="item">
	    <view class="title">人员编号</view>
	    <view class="content">
	      <input type="text" v-model="principal.mobile" maxlength="20" placeholder="请输入" />
	    </view>
	  </view>
      <view class="item">
        <view class="title">性别</view>
        <picker class="content" mode="selector" :range="genderRange" @change="genderChange" range-key="name">
          <view class="">
            {{selectedGender}}
          </view>
        </picker>
      </view>
      <view class="item">
        <view class="title">邮箱</view>
        <view class="content">
          <input type="text" v-model="principal.email" maxlength="20" placeholder="请输入" />
        </view>
      </view>
	  <view class="item" style="height: fit-content;">
	    <view class="title">证件照</view>
		<view style="flex: 3;">
			<uni-file-picker
			 v-model="principal.mobile" 
			 file-mediatype="image" 
			 mode="grid" 
			 file-extname="png,jpg"
			:limit="5" 
			ref="files" 
			:auto-upload="false" 
			@select="select" 
			/>
		</view>
	  </view>
    </view>
		 <view class="btn">
		 	 <button type="default" class="save-btn">保存</button>
		 </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {

        principal: {},
        realname: "",
        userId: "",
        mobile: "",



        selectedGender: '男',
        genderRange: [{
            id: 0,
            name: '男'
          },
          {
            id: 1,
            name: '女'
          }
        ],
		deptGender: '设计部',
		deptRange: [{
		    id: 10,
		    name: '设计部'
		  },
		  {
		    id: 11,
		    name: '生产部'
		  }
		]
      }
    },
    onShow() {
      // this.getUserInfo();
    },
    methods: {
      getUserInfo() {
        authUser().then((res) => {
          if (res.statusCode === 200) {

            const principal = res.data.principal;
            this.principal = principal;
            this.realname = principal.realname;
            this.userId = principal.userId;
            this.mobile = principal.mobile || '';





          } else {
            this.principal = {};
            this.realname = "";
            this.userId = "";
            this.mobile = "";
            uni.showToast({
              title: '获取用户信息失败',
              icon: 'none'
            })
          }
        }).catch(() => {
          this.principal = {};
          this.realname = "";
          this.userId = "";
          this.mobile = "";

          uni.showToast({
            title: '请求失败',
            icon: 'none'
          })
        })
      },
      goBack() {
        uni.navigateBack({
          delta: 1
        })
      },
      genderChange(e) {
        const idx = e.detail.value;
        this.selectedGender = this.genderRange[idx].name;
      },
	  deptChange(e) {
	    const idx = e.detail.value;
	    this.deptGender = this.deptRange[idx].name;
	  },
	  
    }
  }
</script>

<style scoped>
	
  >>>.uni-navbar__header,>>>.uni-status-bar {
    background-image: linear-gradient(254deg,
        #0ca7ee 0%,
        #005aff 100%,
        #2a8cff 100%,
        #54bdff 100%),
      linear-gradient(#e60012,
        #e60012);
  }

  .my-data {
    background-color: #f3fbff;
	padding-bottom: 227rpx;
  }

  .nav-bar>>>.uni-navbar-btn-text text {
    font-size: 32rpx !important;
  }

  .wrap-view {
    width: 720rpx;
    margin: 0 auto;
    background-color: #ffffff;
    border-radius: 10rpx;
    line-height: 94rpx;
    font-family: PingFang-SC-Medium;
    font-size: 30rpx;
  }

  .item {
    border-bottom: 1rpx solid #eeeeee;
    margin: 0rpx 32rpx;
    display: flex;
    margin-top: 20rpx;
  }

  .title {
    color: #212121;
    flex: 1;
  }

  .content {
    flex: 3;
    color: #414141;

  }

  .content input {
    height: 100%;
  }

  .save-btn {
    width: 400rpx;
    height: 80rpx;
    background-color: #2c6fd9;
    border-radius: 40rpx;
    font-size: 30rpx;
    line-height: 80rpx;
    color: #f3fbff;
    margin-top: 21rpx;
  }
</style>
