/*
 *@description:司机详情
 *@author: hudw
 *@date: 2022-03-15 12:07:07
*/
<template>
  <p-card class="full-card-panel" v-show="st > 0" :bordered="false">
    <a-space slot="extra" v-if="st < 3">
      <p-button type="primary" :disabled="confirmLoading" :icon="confirmLoading ? 'loading' : ''" @click="handelSave">保存
      </p-button>
      <p-button @click="back(false)">取消</p-button>
    </a-space>
    <a-space slot="title">
      <a-icon type="arrow-left" @click="back(false)" :style="{ color: '#08c' }" />基本信息
    </a-space>
    <p-grid-form ref="grid" selfUpdate formName="driverDetails" :items="items" :span="6" :labelCol="{ span: 6 }"
      :wrapperCol="{ span: 16 }"></p-grid-form>
    <a-divider />
    <children-table ref="tabs" btnSave :bind="st !== 3" :currentMainRow="currentMainRow" :st="st" />
  </p-card>
</template>
<script>

import { setDetailsForm } from './setConfig.js';
import childrenTable from '../childrenTable/index.childrenTable.vue'
import { saveMainData } from '../../js/api';
export default {
  props: {
    options: {
      type: Object,
      default: () => { return {} }
    },
    record: {
      type: Object,
    },
    formExtendedField: {
      type: Array,
    },

    st: {
      type: Number,
      default: 0
    }
  },
  components: {
    childrenTable
  },
  data() {
    return {
      activeKey: '1',

      confirmLoading: false,
      affiliationType: 1,
      items: [],
      currentMainRow: null
    };
  },
  watch: {

    st(value) {
      if (value === 0) {
        this.activeKey = 0
        this.items = []
        return
      };
      this.activeKey = 1

      if (value > 0) {
        this.currentMainRow= this.record
        this.$set(this, 'currentMainRow', this.record)
      }
      this.items = setDetailsForm(this, value);
      this.$nextTick(() => {
        this.$refs.grid.form.resetFields();
        this.record && this.$refs.grid.form.setFieldsValue(this.currentMainRow);
        this.affiliationType = +this.$refs.grid.form.getFieldValue('type');
      })
    }
  },
  mounted() {

  },
  methods: {
    handelSave() {
      this.$refs.grid.form.validateFieldsAndScroll((errors, values) => {
        if (!errors) {

          let obj = this.$refs.tabs.getTabsList();

          let _values = { ...values, ...obj }
          return saveMainData(this, _values, this.st).then((res) => {
            if (res.success) {
              if (res.data) {
                _values.id = res.data

              }
              this.currentMainRow = { ...values }
              setTimeout(() => {
                this.back(true)
              }, 1000)
            }
          });
        }
      })
    },
    back(isSave=false) {
      this.$emit('back', this.currentMainRow,isSave)
    },

  },
};
</script>
<style scope lang='less'>
.itemNote {
  .ant-input-affix-wrapper {
    width: 250%;
  }
}
</style>
