<!--
@name: 车型管理明细
@author: 张泽贤
@time: 2022-03-14
-->
<template>
  <p-card class="full-card-panel">
    <a-space slot="title" style="display: flex; align-items: center; cursor: pointer">
      <a-icon type="arrow-left" style="color: #1990ff" @click="back" />
      车型管理-{{ typeTitle }}
    </a-space>
    <div slot="extra" v-show="type !== 'view'">
      <p-button type="primary" @click="onSave">保存</p-button>
    </div>
    <p-spin :spinning="spinning">
      <p-form-model ref="ruleForm" class="plg-grid-from" :model="form" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" :rules="rules">
        <a-row>
          <a-col :span="6">
            <p-form-model-item label="车型编码" prop="code">
              <div v-if="type === 'view'">{{ form.code }}</div>
              <p-input v-model="form.code" :disabled="type !== 'add'" v-else />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="车型名称" prop="name">
              <div v-if="type === 'view'">{{ form.name }}</div>
              <p-input v-model="form.name" :disabled="type !== 'add'" v-else />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="品牌" prop="brand">
              <div v-if="type === 'view'">{{ form.brandName }}</div>
              <p-select v-model="form.brand" :options="options.VEHICLE_TYPE_BRAND" allowClear :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="类别" prop="type">
              <div v-if="type === 'view'">{{ form.typeName }}</div>
              <p-select v-model="form.type" :options="options.VEHICLE_TYPE_CATEGORY" allowClear :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <p-form-model-item label="长(m)" prop="length">
              <div v-if="type === 'view'">{{ form.length }}</div>
              <p-input-number v-model="form.length" :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="宽(m)" prop="width">
              <div v-if="type === 'view'">{{ form.width }}</div>
              <p-input-number v-model="form.width" :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="高(m)" prop="height">
              <div v-if="type === 'view'">{{ form.height }}</div>
              <p-input-number v-model="form.height" :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <p-form-model-item label="载重(kg)" prop="weight">
              <div v-if="type === 'view'">{{ form.weight }}</div>
              <p-input-number v-model="form.weight" :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="载方(m³)" prop="volume">
              <div v-if="type === 'view'">{{ form.volume }}</div>
              <p-input-number v-model="form.volume" :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
          <a-col :span="12">
            <p-form-model-item label="备注" prop="memo" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
              <div v-if="type === 'view'">{{ form.memo }}</div>
              <p-input v-model="form.memo" :disabled="type === 'view'" v-else />
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-divider orientation="left">调度控制信息</a-divider>
        <a-row>
          <a-col :span="6">
            <p-form-model-item prop="maxMileage" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最长行驶里程
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线总里程不能超过此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.maxMileage }}公里</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.maxMileage" :min="0" :precision="2" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">公里</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item prop="maxOrders" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最多运单数量
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线总运单数不能超过此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.maxOrders }}单</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.maxOrders" :min="0" :precision="0" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">单</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item prop="sites" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最多配送客户
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线最多配送客户数量不能超过此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.sites }}个</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.sites" :min="0" :precision="0" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">个</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item prop="maxLoadingPcs" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最多配载件数
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线最多配载件数不能超过此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.maxLoadingPcs }}个</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.maxLoadingPcs" :min="0" :precision="0" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">个</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <p-form-model-item prop="maxLoadingWeight" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最多配载重量
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线最多配载重量不能超过此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.maxLoadingWeight }}KG</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.maxLoadingWeight" :min="0" :precision="2" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">KG</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item prop="maxLoadingVolume" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最多配载体积
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线最多配载体积不能超过此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.maxLoadingVolume }}m³</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.maxLoadingVolume" :min="0" :precision="2" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">m³</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item prop="maxLoadingRatio" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最高配载率
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线配载率不能超过此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.maxLoadingRatio }}%</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.maxLoadingRatio" :min="0" :precision="2" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">%</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item prop="minLoadingRatio" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
              <a-space slot="label">
                最低配载率
                <a-tooltip>
                  <template slot="title">
                    <span>智能调度条件限制使用此参数，用于限制车辆排线配载率不能低于此参数</span>
                  </template>
                  <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                </a-tooltip>
              </a-space>
              <div v-if="type === 'view'">{{ form.minLoadingRatio }}%</div>
              <a-row v-else type="flex">
                <a-col style="width: calc(100% - 25px)">
                  <p-input-number v-model="form.minLoadingRatio" :min="0" :precision="2" :disabled="type === 'view'" />
                </a-col>
                <a-col :flex="0">%</a-col>
              </a-row>
            </p-form-model-item>
          </a-col>
        </a-row>
        <extendedField :mextendedField_list="mextendedField_list" :type="type" :form="form"></extendedField>
      </p-form-model>
    </p-spin>
  </p-card>
  <!-- <div>
    <p-spin :spinning="spinning">
      <p-card>
        <a-space slot="title" style="display: flex; align-items: center; cursor: pointer">
          <a-icon type="arrow-left" style="color: #1990ff" @click="back" />
          车型管理-{{ typeTitle }}
        </a-space>
        <div slot="extra" v-show="type !== 'view'">
          <p-button type="primary" @click="onSave">保存</p-button>
        </div>
      </p-card>
      <p-card style="height: 100%">
        <p-form-model ref="ruleForm" class="plg-grid-from" :model="form" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" :rules="rules">
          <a-row>
            <a-col :span="6">
              <p-form-model-item label="车型编码" prop="code">
                <div v-if="type === 'view'">{{ form.code }}</div>
                <p-input v-model="form.code" :disabled="type !== 'add'" v-else />
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item label="车型名称" prop="name">
                <div v-if="type === 'view'">{{ form.name }}</div>
                <p-input v-model="form.name" :disabled="type !== 'add'" v-else />
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item label="品牌" prop="brand">
                <div v-if="type === 'view'">{{ form.brandName }}</div>
                <p-select v-model="form.brand" :options="options.VEHICLE_TYPE_BRAND" allowClear :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item label="类别" prop="type">
                <div v-if="type === 'view'">{{ form.typeName }}</div>
                <p-select v-model="form.type" :options="options.VEHICLE_TYPE_CATEGORY" allowClear :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="6">
              <p-form-model-item label="长(m)" prop="length">
                <div v-if="type === 'view'">{{ form.length }}</div>
                <p-input-number v-model="form.length" :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item label="宽(m)" prop="width">
                <div v-if="type === 'view'">{{ form.width }}</div>
                <p-input-number v-model="form.width" :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item label="高(m)" prop="height">
                <div v-if="type === 'view'">{{ form.height }}</div>
                <p-input-number v-model="form.height" :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="6">
              <p-form-model-item label="载重(kg)" prop="weight">
                <div v-if="type === 'view'">{{ form.weight }}</div>
                <p-input-number v-model="form.weight" :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item label="载方(m³)" prop="volume">
                <div v-if="type === 'view'">{{ form.volume }}</div>
                <p-input-number v-model="form.volume" :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
            <a-col :span="12">
              <p-form-model-item label="备注" prop="memo" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
                <div v-if="type === 'view'">{{ form.memo }}</div>
                <p-input v-model="form.memo" :disabled="type === 'view'" v-else />
              </p-form-model-item>
            </a-col>
          </a-row>
          <a-divider orientation="left">调度控制信息</a-divider>
          <a-row>
            <a-col :span="6">
              <p-form-model-item prop="maxMileage">
                <a-space slot="label">
                  最长行驶里程
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线总里程不能超过此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.maxMileage }}公里</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.maxMileage" :min="0" :precision="2" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">公里</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item prop="maxOrders">
                <a-space slot="label">
                  最多运单数量
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线总运单数不能超过此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.maxOrders }}单</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.maxOrders" :min="0" :precision="0" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">单</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item prop="sites">
                <a-space slot="label">
                  最多配送客户
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线最多配送客户数量不能超过此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.sites }}个</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.sites" :min="0" :precision="0" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">个</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item prop="maxLoadingPcs">
                <a-space slot="label">
                  最多配载件数
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线最多配载件数不能超过此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.maxLoadingPcs }}个</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.maxLoadingPcs" :min="0" :precision="0" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">个</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="6">
              <p-form-model-item prop="maxLoadingWeight">
                <a-space slot="label">
                  最多配载重量
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线最多配载重量不能超过此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.maxLoadingWeight }}KG</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.maxLoadingWeight" :min="0" :precision="0" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">KG</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item prop="maxLoadingVolume">
                <a-space slot="label">
                  最多配载体积
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线最多配载体积不能超过此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.maxLoadingVolume }}m³</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.maxLoadingVolume" :min="0" :precision="0" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">m³</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item prop="maxLoadingRatio">
                <a-space slot="label">
                  最高配载率
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线配载率不能超过此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.maxLoadingRatio }}%</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.maxLoadingRatio" :min="0" :precision="0" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">%</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
            <a-col :span="6">
              <p-form-model-item prop="minLoadingRatio">
                <a-space slot="label">
                  最低配载率
                  <a-tooltip>
                    <template slot="title">
                      <span>智能调度条件限制使用此参数，用于限制车辆排线配载率不能低于此参数</span>
                    </template>
                    <a-icon type="exclamation-circle" :style="{ color: '#2b80ff' }" />
                  </a-tooltip>
                </a-space>
                <div v-if="type === 'view'">{{ form.minLoadingRatio }}%</div>
                <a-row v-else type="flex">
                  <a-col style="width: calc(100% - 25px)">
                    <p-input-number  v-model="form.minLoadingRatio" :min="0" :precision="0" :disabled="type === 'view'" />
                  </a-col>
                  <a-col :flex="0">%</a-col>
                </a-row>
              </p-form-model-item>
            </a-col>
          </a-row>
          <extendedField :mextendedField_list="mextendedField_list" :type="type" :form="form"></extendedField>
        </p-form-model>
      </p-card>
    </p-spin>
  </div> -->
</template>

<script>
import { Add, Update, View } from './api';
import extendedField from '@/blocks/extendedField';

export default {
  components: { extendedField },
  props: {
    type: '',
    editId: {
      type: String,
      default: '',
    },
    options: {
      type: Object,
      default: () => ({}),
    },
    mextendedField_list: {
      type: Array,
      default: () => [],
    },
  },
  computed: {
    typeTitle() {
      const dictionary = {
        add: '新增',
        edit: '编辑',
        view: '查看',
      };
      return dictionary[this.type] || this.type;
    },
  },
  data() {
    const LoadingRatioValidator = (rule, value, callback) => {
      if (this.form.minLoadingRatio && this.form.maxLoadingRatio && this.form.minLoadingRatio > this.form.maxLoadingRatio) {
        callback(new Error('最低配载率不能大于最高配载率'));
      } else {
        callback();
      }
    };
    return {
      spinning: false,
      form: {
        code: '',
        name: '',
        brand: '',
        brandName: '',
        type: '',
        typeName: '',
        length: '',
        width: '',
        height: '',
        maxMileage: '',
        volume: '',
        weight: '',
        memo: '',
        organizationId: '',
        organizationCode: '',
        organizationName: '',
        departmentId: '',
        departmentCode: '',
        departmentName: '',
        maxMileage: '',
        maxOrders: '',
        sites: '',
        maxLoadingPcs: '',
        maxLoadingWeight: '',
        maxLoadingVolume: '',
        maxLoadingRatio: '',
        minLoadingRatio: '',
      },
      rules: {
        code: [{ required: true, message: '车型编码不能为空', trigger: 'blur' }],
        name: [{ required: true, message: '车型名称不能为空', trigger: 'blur' }],
        type: [{ required: true, message: '类别不能为空', trigger: 'change' }],
        maxLoadingRatio: [{ validator: LoadingRatioValidator, trigger: 'change' }],
        minLoadingRatio: [{ validator: LoadingRatioValidator, trigger: 'change' }],
      },
    };
  },
  mounted() {
    if (this.editId) {
      this.spinning = true;
      View({ vehicleTypeId: this.editId })
        .then((res) => {
          if (res.success) {
            this.spinning = false;
            this.form = res.data;
          } else {
            this.$exception(res);
          }
        })
        .catch(() => {
          this.spinning = false;
        });
    }
  },
  methods: {
    back() {
      this.$emit('back');
    },
    onSave() {
      this.$refs.ruleForm.validate((valid) => {
        if (!valid) return;
        // const { contractNo, contractName } = this.form
        // const list = this.dataSource.map((item, index) => {
        //   const temp = { ...item }
        //   if (temp.seqId.includes('local')) delete temp.seqId
        //   return { ...temp, contractNo, contractName, seqNo: index + 1 }
        // })
        // let params = { ...this.form, list }
        if (this.type === 'add') return this.onAdd(this.form);
        if (this.type === 'edit') {
          let self = this;
          this.$confirm({
            title: '是否保存',
            onOk() {
              return new Promise((resolve, reject) => {
                self.spinning = true;
                Update(self.form)
                  .then((res) => {
                    self.spinning = false;
                    if (res.success) {
                      self.$message.success(res.message);
                      self.$emit('back');
                      resolve();
                    } else {
                      self.$exception(res);
                      resolve();
                    }
                  })
                  .catch(() => {
                    self.spinning = false;
                    reject();
                  });
              });
            },
          });
        }
      });
    },
    onAdd(params) {
      this.spinning = true;
      Add(params)
        .then((res) => {
          this.spinning = false;
          if (res.success) {
            this.$message.success(res.message);
            this.$emit('back');
          } else {
            this.$exception(res);
          }
        })
        .catch(() => {
          this.spinning = false;
        });
    },
    onUpdate(params) {
      this.spinning = true;
      Update(params)
        .then((res) => {
          this.spinning = false;
          if (res.success) {
            this.$message.success(res.message);
            this.$emit('back');
          } else {
            this.$exception(res);
          }
        })
        .catch(() => {
          this.spinning = false;
        });
    },
  },
};
</script>

<style lang="less" scoped>
.ant-input-number {
  width: 100%;
}
</style>