<template>
  <div ref="workerLogin">
    <a-modal
      :getContainer="
        (triggerNode) => {
          return $refs.workerLogin
        }
      "
      title="解锁"
      :visible="loginVisible"
      :destroyOnClose="true"
      :confirm-loading="confirmLoading"
      @ok="loginevent"
      @cancel="handleCancel"
    >
      <p style="margin-top: 30px; margin-bottom: 25px; padding-right: 60px">
        <a-form class="plg-login" :form="loginform" @submit.prevent="loginevent">
          <a-form-item label="用户名" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
            <div class="input-wrapper">
              <a-input
                class="input"
                size="large"
                type="text"
                autocomplete="false"
                placeholder="请输入用户名"
                v-decorator="[
                  'workercode',
                  { rules: [{ required: true, message: '请输入用户名' }], validateTrigger: 'change' },
                ]"
              >
              </a-input>
            </div>
          </a-form-item>
          <a-form-item label="密码" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
            <div class="input-wrapper">
              <a-input
                class="input"
                size="large"
                type="password"
                autocomplete="false"
                placeholder="请输入密码"
                v-decorator="[
                  'workpassword',
                  { rules: [{ required: true, message: '请输入密码' }], validateTrigger: 'change' },
                ]"
              >
              </a-input>
            </div>
          </a-form-item>
          <a-form-item label="解锁原因" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
            <div class="input-wrapper">
              <a-textarea
                class="input"
                size="large"
                autocomplete="false"
                placeholder="请输入解锁原因"
                v-decorator="[
                  'unlockReason',
                  { rules: [{ required: true, message: '请输入解锁原因' }], validateTrigger: 'change' },
                ]"
              >
              </a-textarea>
            </div>
          </a-form-item>
        </a-form>
      </p>
    </a-modal>
  </div>
</template>

<script>
import { mapState, mapActions, mapGetters } from 'vuex'
export default {
  name: 'workerLogin',
  components: {},
  props: {
    loginVisible: {
      type: Boolean,
      default: false,
    },
    isSupervisedData: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 },
      },
      confirmLoading: false,
      loginform: this.$form.createForm(this),
      refsss: null,
    }
  },
  created() {},
  mounted() {},
  computed: {
    ...mapState({
      chekUser: (state) => state.outBound.checkPerson,
      stationCode: (state) => state.outBound.stationCode,
      businesstype: (state) => state.outBound.businesstype,
      worktype: (state) => state.outBound.worktype,
      warehouseId: (state) => state.outBound.warehouseId,
    }),
    ...mapGetters({
      warehouse: 'warehouse',
    }),
  },
  watch: {},
  methods: {
    ...mapActions(['CheckLoginIn']),
    loginevent() {
        // this.$emit('loginResult', false, {})
        // return
      this.loginform.validateFields((err, values) => {
        if (!err) {
          values.warehouseId = this.isSupervisedData.warehouseId
          values.specialWorkType = this.isSupervisedData.specialWorkType
          // values.stationCode = this.stationCode
          // values.warehouseId = this.warehouseId
          console.log('登录前登录工号：', values)
          this.confirmLoading = true
          this.CheckLoginIn(values)
            .then((res) => {
              this.$message.success('操作成功')
              console.log('登录成功返回数据', res)
              this.confirmLoading = false
              this.$emit('loginResult', false, res)
              this.loginform.resetFields()
            })
            .catch((error) => {
              console.log(error)
              this.$message.error('解锁失败')
              this.confirmLoading = false
            })
        }
      })
    },
    handleCancel() {
      // console.log('取消')
      this.loginVisible = false
      this.$emit('handleCancel', false)
    },
  },
}
</script>

<style></style>
