<template>
  <div>
    <!-- 弹窗 -->
    <a-modal
      v-model="isShow"
      @cancle="isShow=false"
      :footer="null"
      :centered="true"
      title="修改手机号码">
      <a-form id="components-form-demo-validate-other" ref="form" :form="form" @submit="handleSubmit">
        <a-form-item label="手机号码" :label-col="{ span: 7 }" :wrapper-col="{ span: 12 }">
          <a-input
            id="editUserPhoneModal-mobile"
            :maxLength="11"
            v-decorator="[
              'formData.mobile',
              { initialValue: formData.mobile, rules: [{ required: true, message: '请输入手机号码!' }, { pattern: /^\d{11}$/, message: '请输入正确的手机号' }] }
            ]"
            placeholder="请输入手机号码"
            allowClear />
        </a-form-item>
        <a-form-item :wrapper-col="{ span: 12, offset: 6}" style="text-align: center;">
          <a-button type="primary" html-type="submit" id="editUserPhoneModal-submit" style="margin-right: 15px">保存</a-button>
          <a-button @click="isShow=false" style="margin-left: 15px" id="editUserPhoneModal-close">取消</a-button>
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script>
import { updateMobile } from '@/api/userInfo.js'
export default {
  name: 'EditUserPhoneModal',
  props: {
    openUserPhoneMoadl: {
      type: Boolean,
      default: false
    },
    userId: {
      type: String,
      default: ''
    }

  },
  data () {
    return {
      isShow: this.openUserPhoneMoadl,
      form: this.$form.createForm(this, { name: 'editUserPhoneModal' }),
      formData: {
        mobile: '' // 手机号码
      }
    }
  },
  methods: {
    // 点击保存;
    handleSubmit (e) {
      e.preventDefault()
      const _this = this
      this.form.validateFields((err, values) => {
        if (!err) {
          const formData = Object.assign({}, { id: this.userId }, this.formData, values.formData)
          updateMobile(formData).then(res => {
            console.log(res, 'rrrrrrrrr')
            if (res.status == 200) {
              _this.$message.success(res.message)
              // _this.$router.push({ path: `/userInfo/userManageList/list` })
              setTimeout(function () {
                _this.isShow = false
                location.reload()
              }, 300)
            }
          })
        }
      })
    }
  },
  watch: {
    openUserPhoneMoadl (newValue, oldValue) {
      this.isShow = newValue
    },
    isShow (val) {
      console.log(this.userId)
      if (!val) {
        this.$emit('close')
      } else {
   	  this.form.resetFields()
      }
    }
  }
}
</script>

<style>
</style>
