<template>
  <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">

    <a-row :gutter="48" slot="extra">
      <a-col :md="48" :sm="48">
        <span class="table-page-search-submitButtons" style="float: right" >
          <a-button style="margin-left: 8px" type="primary" @click="save()">保存</a-button>
          <a-button style="margin-left: 8px" @click="handleCancel()">返回列表</a-button>
        </span>
      </a-col>
    </a-row>
    <a-form :form="form">

      <a-form-item v-show="false" >
        <a-input v-decorator="['id']" type="hidden"/>
        <a-input v-decorator="['sbId']" type="hidden"/>
        <a-input v-decorator="['typeId']" type="hidden"/>
      </a-form-item>
      <a-form-item v-show="false" >
        <a-input v-decorator="['unit']" type="hidden"/>
      </a-form-item>
      <a-form-item v-show="false" >
        <a-input v-decorator="['unitBz']" type="hidden"/>
      </a-form-item>
      <a-form-item v-show="false">
        <a-input v-decorator="['producerId']" />
      </a-form-item>
      <a-form-item v-show="false">
        <a-input v-decorator="['supplierId']" />
      </a-form-item>
      <title-divider title="基础信息" width="100px"></title-divider>
      <row-list :col="2">
        <row-item>
          <a-form-item
            label="类别"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-tree-select
              style="width: 100%"
              :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
              :treeData="spareTypeData"
              :treeNodeFilterProp="'title'"
              :showSearch="true"
              v-decorator="['parentTypeId', {rules: [{required: true, message: '类别不能为空'}]}]"
              placeholder="请选择"
            >
            </a-tree-select>
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="备件名称"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              v-decorator="['name', {rules: [{required: true, message: '设备名称不能为空'}]}]" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="规格型号"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              v-decorator="['ggxh']" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="生产商"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              style="width: 70%"
              disabled
              v-decorator="['producerName']" />
            <a-button style="width: 30%" type="primary" @click="handleProducerSelect">选择</a-button>
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="备件价值"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input-number
              style="width: 100%"
              :min="0"
              :step="0.01"
              :formatter="BaseTool.Amount.formatter"
              :parser="BaseTool.Amount.parser"
              v-decorator="['initialValue', {rules: [{required: true, message: '备件价值不能为空'}]}]" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="采购供应商"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              style="width: 70%"
              disabled
              v-decorator="['supplierName']" />
            <a-button style="width: 30%" type="primary" @click="handleSupplierSelect">选择</a-button>
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="备件编号"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              v-decorator="['no', {rules: [{required: false, message: '备件编码不能为空'}]}]" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="原厂编号"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              style="width: 100%"
              v-decorator="['initNo']" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="自编号"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              v-decorator="['zbh', {rules: [{required: false, message: '自编号不能为空'}]}]" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="助记码"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              v-decorator="['zjm']" />
          </a-form-item>
        </row-item>

        <row-item>
          <a-form-item
            label="备件等级"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-select v-decorator="['level', {initialValue: 1}]" placeholder="请选择">
              <a-select-option
                v-for="(label,value) in levelMap"
                :key="value"
                :label="label"
                :value="parseInt(value)">{{ label }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="计量单位"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-select
              show-search
              :value="unitName"
              :default-active-first-option="false"
              :show-arrow="true"
              :filter-option="true"
              :not-found-content="null"
              @search="handleSearch"
              @blur="handleBlur"
              @change="handleChange">
              <a-select-option
                v-for="(label,value) in unitMap"
                :key="value"
                :label="label"
                :value="label">{{ label }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </row-item>
<!--        <row-item>
          <a-form-item
            label="包装单位"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-select
              show-search
              :value="unitNameBz"
              :default-active-first-option="false"
              :show-arrow="true"
              :filter-option="true"
              :not-found-content="null"
              @search="handleSearchBz"
              @blur="handleBlurBz"
              @change="handleChangeBz">
              <a-select-option
                v-for="(label,value) in unitMap"
                :key="value"
                :label="label"
                :value="label">{{ label }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="折算系数"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              placeholder="单位折算为包装单位，如24个单位包装为一箱"
              v-decorator="['unitRate']" />
          </a-form-item>
        </row-item>-->
        <row-item>
          <a-form-item
            label="采购周期"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input suffix="天" v-decorator="['purchasePeriod']" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="使用周期"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input suffix="月" v-decorator="['usePeriod']" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="寿命周期"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input suffix="月" v-decorator="['agePeriod']" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="最高库存"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input-number
              style="width: 100%"
              :min="1"
              v-decorator="['maxStock']" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="最低库存"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input-number
              style="width: 100%"
              :min="1"
              v-decorator="['minStock']" />
          </a-form-item>
        </row-item>
        <row-item v-show="isAdd">
          <a-form-item
            label="初始库位"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-tree-select
              style="width: 100%"
              :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
              :treeData="storeTreeDate"
              :treeNodeFilterProp="'title'"
              :showSearch="true"
              v-decorator="['storeId', {rules: [{required: false, message: '仓库库位不能为空'}]}]"
              placeholder="请选择"
            >
            </a-tree-select>
          </a-form-item>
        </row-item>
        <row-item v-show="isAdd">
          <a-form-item
            label="初始库存"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input-number
              style="width: 100%"
              :min="1"
              v-decorator="['initStock']" />
          </a-form-item>
        </row-item>

        <row-item>
          <a-form-item
            label="英文名称"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              v-decorator="['englishName', {rules: [{required: false, message: '英文名称不能为空'}]}]" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="产地"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-select v-decorator="['cd']" placeholder="请选择">
              <a-select-option
                v-for="(label,value) in cdMap"
                :key="value"
                :label="label"
                :value="parseInt(value)">{{ label }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="备件图片"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-upload
              :action="uploadUrl"
              :multiple="true"
              list-type="picture"
              :file-list="this.defaultApplicationFileList"
              @change="handleApplicationFileChange"
              accept="image/*"
              :headers="headers"
            >
              <a-button> <a-icon type="upload" /> 上传图片 </a-button>
            </a-upload>
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="参数"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-textarea
              v-decorator="['params']" />
          </a-form-item>
        </row-item>
        <row-item>
          <a-form-item
            label="备注"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-textarea
              v-decorator="['remark']" />
          </a-form-item>
        </row-item>
      </row-list>
    </a-form>
    <title-divider title="设备信息" width="100px"></title-divider>
    <div class="table-operator">
      <a-button style="margin-left:8px;" type="primary" @click="handleSbSelect">
        <a-icon type="plus"/>
        添加
      </a-button>
      <a-button class="margin-left8" size="small" type="danger" @click="handleDel">
        <a-icon type="delete"/>
        删除
      </a-button>
    </div>
    <a-table
      :data-source="data"
      :columns="columns"
      bordered
      tableLayout="auto"
      :row-selection="rowSelection"
      rowKey="id">
      <span slot="action" slot-scope="record">
        <template>
          <a v-if="$auth('sb-infos-edit')" @click="handleDetailSelect(record)">修改</a>
          <a-divider type="vertical" />
          <a-popconfirm v-if="$auth('sb-infos-del')" title="是否要删除该条数据？" @confirm="handleDelOne(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </template>
      </span>
    </a-table>
    <p style="color: red">仓库数量初始化注意事项：<br/>
      1：初始化库存仅能选择一个库位入库<br/>
      2：初始化库存仅能新增，如需要修改请在仓库管理->仓库库存中修改数量<br/>
    </p>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
    </template>
    <firm-producer-select-modal ref="producerSelectModal" @selected="handleProducerSelected"/>
    <supplier-select-modal ref="supplierSelectModal" @selected="handleSupplierSelected"/>
    <store-select-modal ref="storeSelectModal" @selected="handleStoreSelected"/>
    <sb-info-select-modal :type="'checkbox'" ref="sbInfoSelectModal" @selected="handleSbSelected"/>
    <base-form-spare ref="baseModal" @selected="handleDetailSelected"/>
  </a-card>
</template>

<script>
import pick from 'lodash.pick'
import { addSparePartInfo, querySparePartInfo, updateSparePartInfo } from '@/api/sqarepartmanage/sparepartinfo'
import { querySpareType, fetchSpareTypeTree } from '@/api/sqarepartmanage/sparetype'
import { fetchSbGuigeOptions } from '@/api/sb/guige'
import FirmProducerSelectModal from '@/views/firm/producer/modules/FirmProducerSelectModal'
import SupplierSelectModal from '@/views/purchase/supplier/modules/SupplierSelectModal'
import UploadSpareFile from '@/components/Upload/UploadSpareFile'
import Vue from 'vue'
import StoreSelectModal from '@/views/store/store/modules/StoreSelectModal'
import { uploadUrl } from '@/api/upms/file'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import { fetchStoreTree } from '@/api/store/store'
import { selectSbModelListBySpareId } from '@/api/sb/modelbom'
import SbInfoSelectModal from '@/views/sb/info/modules/SbInfoSelectModal'
import BaseFormSpare from '@/views/sb/modelbom/modules/BaseFormSpare'
export default {
  name: 'BaseSparePartInfo',
  components: {
    FirmProducerSelectModal,
    SupplierSelectModal,
    UploadSpareFile,
    StoreSelectModal,
    SbInfoSelectModal,
    BaseFormSpare
  },
  data () {
    return {
      isAdd: false,
      unitName: null,
      unitNameBz: null,
      rowSelection: {
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = selectedRowKeys
          this.selectedRows = selectedRows
        }
      },
      gg: null,
      storeTreeDate: [],
      uploadUrl: uploadUrl,
      defaultApplicationFileList: [],
      applicationFileList: [], // 备件图片
      confirmLoading: false,
      modalTitle: null,
      form: this.$form.createForm(this),
      visible: false,
      // 下拉框map
      levelMap: {},
      periodTypeMap: {},
      unitMap: {},
      cdMap: {},
      ytMap: {},
      spareTypeData: [],
      spareTypeDataMiddle: [],
      spareTypeDataChild: [],
      producers: [],
      ggList: [],
      headers: {
        Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
      },
      // 表头
      columns: [
        {
          title: '型号',
          dataIndex: 'model'
        },
        {
          title: '名称',
          dataIndex: 'name'
        },
        {
          title: '新号',
          dataIndex: 'no'
        },
        {
          title: '旧号',
          dataIndex: 'zbh'
        },
        {
          title: '更换周期',
          dataIndex: 'period',
          customRender: (text, record, index) => {
            return text + this.BaseTool.Table.getMapText(this.periodTypeMap, record.periodType)
          }
        },
        {
          title: '数量',
          dataIndex: 'num'
        },
        {
          title: '操作',
          key: 'action',
          checked: true,
          align: 'center',
          // fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      data: [],
      sbId: null,
      selectedRowKeys: [],
      selectedRows: [],
      options: {
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys
        }
      }
    }
  },
  props: {
  },
  created () {
    // 下拉框map
    this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_INFO_LEVEL)
    this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
    this.cdMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PRODUCER_AREA)
    this.ytMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_USE_TYPE)
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
  },
  methods: {
    base (record, sbId) {
      this.setTree(record)
      this.visible = true
      this.sbId = sbId
      console.log('sbId: ', sbId)
      // 如果是空标识添加
      if (this.BaseTool.Object.isBlank(record)) {
        this.modalTitle = '添加'
        this.isAdd = true
        return
      }
      this.modalTitle = '编辑'
      if (this.BaseTool.Object.isBlank(record.id)) {
        this.modalTitle = '复制'
      }
      selectSbModelListBySpareId({ id: record.id }).then(res => {
        this.data = res.data
      })
      const { form: { setFieldsValue } } = this
      this.applicationFileList = record.applicationFileList
      this.defaultApplicationFileList = this.BaseTool.UPLOAD.transImg(this.applicationFileList)
      this.unitName = record.unit
      this.unitNameBz = record.unitBz
      this.gg = record.ggxh
      // 日期处理
      this.$nextTick(() => {
        setFieldsValue(Object.assign(pick(record, [
          'id',
          'no',
          'sbId',
          'initNo',
          'uniteNo',
          'nameNo',
          'ggNo',
          'name',
          'parentTypeId',
          'middleTypeId',
          'childTypeId',
          'typeId',
          'level',
          'initialValue',
          'producerId',
          'producerName',
          'supplierId',
          'supplierName',
          'unit',
          'unitBz',
          'unitRate',
          'englishName',
          'childNo',
          'parentNo',
          'parentName',
          'childName',
          'typeName',
          'middleNo',
          'middleName',
          'cd',
          'ggxh',
          // 'yt',
          'zjm',
          'zbh',
          'maxStock',
          'minStock',
          'initStock',
          'remark'
        ])))
      })
    },
    save () {
      const { form: { validateFieldsAndScroll, setFieldsValue } } = this
      this.confirmLoading = true
      console.log('sbId: ' + this.sbId)
      setFieldsValue({
        'unit': this.unitName,
        'unitBz': this.unitNameBz,
        'sbId': this.sbId
      })
      validateFieldsAndScroll((errors, values) => {
        if (errors) {
          this.confirmLoading = false
          return
        }
        values.applicationFileList = this.applicationFileList
        values.detailList = this.data
        // 日期处理
        if (this.BaseTool.String.isBlank(values.id)) {
          addSparePartInfo(values)
            .then(() => {
              this.handleCancel(values)
            }).catch(() => {
              this.confirmLoading = false
            })
        } else {
          updateSparePartInfo(values)
            .then(() => {
              this.handleCancel(values)
            }).catch(() => {
              this.confirmLoading = false
            })
        }
      })
    },
    handleProducerSelect () {
      this.$refs.producerSelectModal.base({}, { type: 3 })
    },
    handleProducerSelected (record, selectedRowKeys, selectedRow) {
      const { form: { setFieldsValue } } = this
      const [ key ] = selectedRowKeys
      const [ row ] = selectedRow
      setFieldsValue({
        'producerId': key,
        'producerName': row.name
      })
    },
    handleSupplierSelect () {
      this.$refs.supplierSelectModal.base()
    },
    handleSupplierSelected (record, selectedRowKeys, selectedRow) {
      const { form: { setFieldsValue } } = this
      const [ key ] = selectedRowKeys
      const [ row ] = selectedRow
      setFieldsValue({
        'supplierId': key,
        'supplierName': row.name
      })
    },
    handleCancel (values) {
      this.visible = false
      this.confirmLoading = false
      this.form.resetFields()
      this.unitName = null
      this.unitNameBz = null
      this.gg = null
      this.isAdd = true
      this.data = []
      if (this.BaseTool.Object.isNotBlank(values)) {
        this.$emit('ok', values)
      } else {
        this.$emit('ok')
      }
    },
    /**
     * 设置仓库、备件类别树
     */
    setTree (record = {}) {
      fetchStoreTree().then(res => {
        this.storeTreeDate = res.data
      })
      fetchSpareTypeTree().then(res => {
        this.spareTypeData = res.data
      })
      /* querySpareType({ filter: 2, parentId: record.parentTypeId }).then(res => {
        this.spareTypeDataMiddle = res.data
      })
      querySpareType({ filter: 2, parentId: record.middleTypeId }).then(res => {
        this.spareTypeDataChild = res.data
      }) */
      fetchSbGuigeOptions().then(res => {
        this.ggList = res.data
      })
    },

    checkSpareNo () {
      const { form: { getFieldValue } } = this
      const typeId = getFieldValue('typeId')
      const name = getFieldValue('name')
      // const ggxh = getFieldValue('ggxh')
      if (typeId == null) {
        this.$message.error('请先设置大小类型')
        return
      }
      querySparePartInfo({
        typeId: typeId,
        name: name,
        dataScope: {
          sortBy: 'desc',
          sortName: 'name'
        }
      }).then(res => {
        this.data = res.data
      })
    },
    /**
     * @function 任务类型文本框的值变化时的回调
     * @author ***
     * @time 2020-08-17
     **/
    handleSearch (value) {
      this.handleChange(value)
    },
    /**
     * @function 任务类型改变时的回调
     * @author ***
     * @time 2020-08-17
     **/
    handleChange (value) {
      this.unitName = (!isNaN(value) && value !== '') ? this.BaseTool.Object.getField(this.unitMap, value) : value
      if (isNaN(this.unitName) || this.unitName === '') {
        this.unitName = value
      }
    },
    /**
     * @function 修改设备关联
     * @author ***
     * @time 2020-08-17
     **/
    handleDetailSelect (record) {
      const modal = this.$refs.baseModal
      modal.base(record)
    },
    handleDetailSelected (values) {
      const newData = [...this.data]
      for (let j = 0; j < newData.length; j++) {
        if (values.sbId === newData[j].sbId) {
          newData[j].num = values.num
          newData[j].period = values.period
          newData[j].periodType = values.periodType
          break
        }
      }
      this.data = newData
    },
    /**
     * @function 添加关联设备
     * @author ***
     * @time 2020-08-17
     **/
    handleSbSelect () {
      const modal = this.$refs.sbInfoSelectModal
      modal.base()
    },
    handleSbSelected (keys, rows) {
      const { data } = this
      for (let i = 0; i < rows.length; i++) {
        var find = false
        for (let j = 0; j < data.length; j++) {
          if (rows[i].id === data[j].sbId) {
            find = true
            break
          }
        }
        if (!find) {
          const sbId = rows[i].id
          const selectData = rows[i]
          selectData.num = 1
          selectData.sbId = sbId
          selectData.id = null
          selectData.period = 1
          selectData.periodType = 1
          data.push(selectData)
        }
      }
    },
    /**
     * @function 任务类型失焦事件
     * @author ***
     * @time 2020-08-17
     **/
    handleBlur (value) {
      this.unitName = value
    },
    /**
     * @function 任务类型文本框的值变化时的回调
     * @author ***
     * @time 2020-08-17
     **/
    handleSearchBz (value) {
      this.handleChange(value)
    },
    /**
     * @function 任务类型改变时的回调
     * @author ***
     * @time 2020-08-17
     **/
    handleChangeBz (value) {
      this.unitNameBz = (!isNaN(value) && value !== '') ? this.BaseTool.Object.getField(this.unitMap, value) : value
      if (isNaN(this.unitNameBz) || this.unitNameBz === '') {
        this.unitNameBz = value
      }
    },
    /**
     * @function 任务类型失焦事件
     * @author ***
     * @time 2020-08-17
     **/
    handleBlurBz (value) {
      this.unitNameBz = value
    },
    /**
     * @function 任务类型文本框的值变化时的回调
     * @author ***
     * @time 2020-08-17
     **/
    handleSearchG (value) {
      this.handleChangeG(value)
    },
    /**
     * @function 任务类型改变时的回调
     * @author ***
     * @time 2020-08-17
     **/
    handleChangeG (value) {
      this.gg = (!isNaN(this.ggList[value]) && this.ggList[value] !== '') ? this.ggList[value].label : value
      if (isNaN(this.gg) || this.gg === '') {
        this.gg = value
      }
    },
    handleStoreSelect () {
      this.$refs.storeSelectModal.base()
    },
    handleStoreSelected (record, keys, rows) {
      const [ key ] = keys
      const [ row ] = rows
      const { form: { setFieldsValue } } = this
      // 日期处理
      this.$nextTick(() => {
        setFieldsValue(Object.assign({
          'storeId': key,
          'storeName': row.name
        }))
      })
    },
    handleDel (id) {
      const data = [...this.data]
      if (this.selectedRowKeys.length === 0) {
        this.$message.error('请至少选择一条数据')
        return
      }
      this.data = data.filter(item => !this.selectedRowKeys.includes(item.id))
    },
    handleDelOne (id) {
      const data = [...this.data]
      this.data = data.filter(item => id !== item.id)
    },
    /**
     * @function 任务类型失焦事件
     * @author ***
     * @time 2020-08-17
     **/
    handleBlurG (value) {
      this.gg = value
    },
    parentChange (val, option) {
      querySpareType({ parentId: val, filter: 2 }).then(res => {
        this.spareTypeDataMiddle = res.data
      })
      const { form: { setFieldsValue } } = this
      setFieldsValue({ parentNo: option.data.key, typeId: val, middleTypeId: null, middleNo: null, childTypeId: null, childNo: null })
    },
    middleChange (val, option) {
      querySpareType({ parentId: val, filter: 2 }).then(res => {
        this.spareTypeDataChild = res.data
      })
      const { form: { setFieldsValue } } = this
      setFieldsValue({ middleNo: option.data.key, typeId: val, childTypeId: null, childNo: null })
    },
    childChange (val, option) {
      const { form: { setFieldsValue } } = this
      setFieldsValue({ childNo: option.data.key, typeId: val, childTypeId: val })
    },
    handleApplicationFileChange (info) {
      this.defaultApplicationFileList = info.fileList
      this.applicationFileList = this.setFileList(info, 14)
    },
    setFileList (info, type) {
      const file = info.file
      const fileList = info.fileList
      if (file.status === 'done') {
        return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
      } else if (file.status === 'removed') {
        return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
      } else if (file.status === 'error') {
        this.$message.error('上传失败')
        return []
      }
    }
  }
}
</script>
