<template>
  <a-modal
    :visible="value"
    title="新建二级销售人员"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-form
      :form="form"
    >
      <a-form-item
        label="账号"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'name',
            {
              rules: [{ required: true, message: '请输入账号' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        v-if="isMazu"
        label="真实姓名"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'real_name',
            {
              rules: [{ required: true, message: '请输入真实姓名' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        v-if="isMazu"
        label="身份证号"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'card_id',
            {
              rules: [{ required: true, message: '请输入身份证号' },
                      { pattern:/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message:'请输入正确的证件号'}

              ]

            }
          ]"
        ></a-input>
      </a-form-item>

      <a-form-item
        v-if="!isMazu"
        label="昵称"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'nick_name',
            {
              rules: [{ required: true, message: '请输入昵称' }]
            }
          ]"
        ></a-input>
      </a-form-item>

      <a-form-item
        v-if="!isMazu"
        label="密码"
        v-bind="formItemLayout"
      >
        <a-input
          type="password"
          v-decorator="[
            'password',
            {
              rules: [
                { required: true, message: '请输入密码' },
                { validator: validateToNextPassword}
              ]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        v-if="!isMazu"
        label="确认密码"
        v-bind="formItemLayout"
      >
        <a-input
          type="password"
          v-decorator="[
            'confirm',
            {
              rules: [
                { required: true, message: '请再次输入密码' },
                { validator: compareToFirstPassword}
              ]
            }
          ]"
          @blur="handleConfirmBlur"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="电话号码"
        v-bind="formItemLayout"
      >
        <a-input
          type="phone"
          v-decorator="[
            'phone',
            {
              rules: [
                { required: true, message: '请输入手机号' },
                { pattern:/^1(3|4|5|7|8|9)\d{9}$/, message:'请输入正确的手机号码'}
              ]
            }
          ]"
        ></a-input>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { addSecondSaleList } from '@/api/marketingSetting/salesUser'
import salesUserMixin from './salesUserMixin.js'

export default {
  mixins: [salesUserMixin],
  props: {
    curentId: {
      type: Number,
      default: () => 0
    }
  },
  computed: {
    isMazu () {
      return ['demo', 'YINXIANGMAZU'].includes(localStorage.mgt_project)
    }
  },
  methods: {
    handleOk (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        console.log('%c [ values ]-92', 'font-size:13px; background:pink; color:#bf2c9f;', values)
        console.log('%c [ this.curentItem ]-94', 'font-size:13px; background:pink; color:#bf2c9f;', this.curentId)
        values.parentSaleUserId = this.curentId
        if (this.isMazu) {
          values.password = '123456'
          values.nick_name = '用户'
        }
        if (!err) {
          addSecondSaleList(values).then(res => {
            this.$message.success('添加成功。')
            this.form.resetFields()
            this.$emit('input', false)
            this.$emit('update')
          })
        }
      })
    }
  },
  mounted () {
    console.log('%c [  this.isMazu ]-170', 'font-size:13px; background:pink; color:#bf2c9f;', this.isMazu)
  }
}
</script>

<style scoped>

</style>
