<template>
  <div class="app-container">
    <div class="tab-header webtop">
      <div>{{ viewTitle }}</div>
      <div>
        <el-button type="primary" size="small" @click="handleCreate()">保存</el-button>
        <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
      </div>
    </div>
    <div class="listconadd">
      <el-form ref="dataForm" :model="temp" label-position="right" label-width="170px" class="formadd" :rules="rules">
        <div class="title">车辆台账信息</div>
        <el-row>
          <el-col :span="24" class="tleftb">金额单位：元</el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="purchaseSystemName">
              <span slot="label">采购系统：</span>
              <el-select v-model="temp.purchaseSystemName" class="addinputw" clearable placeholder="" filterable @change="orgDeptChange">
                <el-option v-for="item in orgDept_list" :key="item.deptSid" :label="item.purchaseSystemName" :value="item.purchaseSystemName"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="carBrandName">
              <span slot="label">品牌：</span>
              <el-select v-model="temp.carBrandName" class="addinputw" clearable placeholder="" @change="carBrandChange" filterable>
                <el-option v-for="item in carBrand_list" :key="item.sid" :label="item.brandName" :value="item.brandName"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item class="configNameStyle">
              <div style="display: flex;flex-direction: row;justify-content: space-between;align-items: center">
                <div>
                  <span slot="label"><span class="icon">*</span>车型(配置简述)：</span>
                  <span>{{ temp.modelName }}</span>
                </div>
                <div>
                  <el-button type="primary" size="mini" @click="handSelect">选择</el-button>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16" class="tlineheightb">
            <el-form-item>
              <span slot="label"><span class="icon">*</span>常用配置：</span>
              <span>{{ temp.configName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">内部编码：</span>
              <span>{{ temp.insideCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="vinNo">
              <span slot="label">车架号：</span>
              <el-input v-model="temp.vinNo" maxlength="17" placeholder="车架号位数与金蝶系统一致" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">发动机号：</span>
              <el-input v-model="temp.engineNo" maxlength="125" placeholder="" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="vehMark">
              <span slot="label">车辆型号：</span>
              <el-input v-model="temp.vehMark" maxlength="17" placeholder="" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="manPurOrderTypeValue">
              <span slot="label">采购类型：</span>
              <el-select v-model="temp.manPurOrderTypeKey" class="addinputw" clearable placeholder="" @change="manPurOrderTypeChange">
                <el-option v-for="item in manPurOrderType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">排产订单编号：</span>
              <el-input v-model="temp.orderingNo" maxlength="125" placeholder="" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="supplierName">
              <span slot="label">供应商：</span>
              <el-select v-if="temp.manPurOrderTypeKey !== '001' && temp.manPurOrderTypeKey !== '004' && temp.manPurOrderTypeKey !== ''" v-model="temp.supplierName" class="addinputw" clearable placeholder="" @change="supplierChange">
                <el-option v-for="item in supplier_list" :key="item.sid" :label="item.manufacturerName" :value="item.manufacturerName"/>
              </el-select>
              <span v-else>{{ temp.supplierName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="lockedStateValue">
              <span slot="label">锁定状态：</span>
              <el-select v-model="temp.lockedState" class="addinputw" clearable placeholder="" @change="lockedStateChange">
                <el-option v-for="item in lockedState_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="vehicleStateValue">
              <span slot="label">库存状态：</span>
              <el-select v-model="temp.vehicleState" class="addinputw" clearable placeholder="" @change="vehicleStateValueChange">
                <el-option v-for="item in vehicleState_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="priceDate">
              <span slot="label">厂家入库日期：</span>
              <el-date-picker v-model="temp.priceDate" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="选择日期"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="departureDate">
              <span slot="label">物流发车日期：</span>
              <el-date-picker v-model="temp.departureDate" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="选择日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">物流到车日期：</span>
              <el-date-picker v-model="temp.arrivalDate" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="选择日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">退库日期：</span>
              <el-date-picker v-model="temp.returnDate" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="选择日期"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="locationName">
              <span slot="label">存放地点：</span>
              <el-select v-model="temp.locationName" class="addinputw" clearable placeholder="" @change="locationChange">
                <el-option v-for="item in location_list" :key="item.sid" :label="item.warehouseName" :value="item.warehouseName"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="manufSaleAccessName">
              <span slot="label">厂家回款通路：</span>
              <el-select v-model="temp.manufSaleAccessName" class="addinputw" clearable placeholder="" @change="actualPayChange">
                <el-option v-for="item in actualPay_list" :key="item.sid" :label="item.name" :value="item.name"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">厂家开票日期：</span>
              <el-date-picker v-model="temp.manDate" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="选择日期"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="contractPrice">
              <span slot="label">厂家合同价(含运费)：</span>
              <el-input v-model="temp.contractPrice" maxlength="125" placeholder="" @keyup.native="temp.contractPrice = oninput(temp.contractPrice,2)" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="costPrice">
              <span slot="label">车辆入库价(含运费)：</span>
              <el-input v-model="temp.costPrice" maxlength="125" placeholder="" @keyup.native="temp.costPrice = oninput(temp.costPrice,2)" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="freight">
              <span slot="label">运费：</span>
              <el-input v-model="temp.freight" maxlength="125" @keyup.native="temp.freight = oninput(temp.freight,2)" placeholder="" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="settlementStatusValue">
              <span slot="label">买断状态：</span>
              <el-select v-model="temp.settlementStatus" class="addinputw" clearable placeholder="" @change="settlementStatusChange">
                <el-option v-for="item in settlementStatus_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">买断备注：</span>
              <el-input v-model="temp.rebate1" maxlength="125" placeholder="" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">买断日期：</span>
              <el-date-picker v-model="temp.solidDate" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="选择日期"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">全款/贷款销售指导价：</span>
              <span>{{ temp.price }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">销售成交价：</span>
              <el-input v-model="temp.salePrice" maxlength="125" placeholder="" @keyup.native="temp.salePrice = oninput(temp.salePrice,2)" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">销售日期：</span>
              <el-date-picker v-model="temp.salesDate" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="选择日期"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">备注：</span>
              <el-input v-model="temp.remarks" maxlength="125" placeholder="" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span slot="label">保修卡号：</span>
              <el-input v-model="temp.warrantyCardNo" maxlength="125" placeholder="" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="isProblemVeh">
              <span slot="label">是否为问题车辆：</span>
              <el-radio-group v-model="temp.isProblemVeh">
                <el-radio label="1">是</el-radio>
                <el-radio label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <el-dialog :visible.sync="dialogVisible" width="70%">
      <div>
        <el-form ref="multipleTable" :inline="true" :model="listQuery" class="vinNoForm" label-width="100px">
          <el-col :span="14">
            <el-form-item label="车型:">
              <el-input v-model="listQuery.params.vehicleAlias" clearable class="addinputw" placeholder=""/>
            </el-form-item>
            <el-form-item label="常用配置:">
              <el-input v-model="listQuery.params.configName" clearable class="addinputw" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="dialogBtn">
            <el-button type="primary" size="small" @click="handleConfig">查询</el-button>
          </el-col>
        </el-form>
      </div>
      <el-table :key="tableKey" v-loading="Loading" :data="list" border fit highlight-current-row style="width: 100%;">
        <el-table-column :index="indexMethod" align="center" label="序号" type="index" width="80"/>
        <el-table-column label="操作" width="80" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleConfirm(scope.row)">确定</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" width="120" label="车辆编码" prop="vehicleTypeCode"/>
        <el-table-column align="center" label="车型" prop="vehicleAlias"/>
        <el-table-column align="center" width="120" label="配置编码" prop="configCode"/>
        <el-table-column align="center" label="常用配置" prop="configName"/>
        <el-table-column align="center" label="更多配置" prop="otherConfig"/>
      </el-table>
      <div class="pages">
        <div class="tit"/>
        <!-- 翻页 -->
        <Pagination v-show="list.length > 0" :limit.sync="listQuery.size" :page.sync="listQuery.current" :total="listQuery.total" class="pagination" @pagination="getList"/>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { SaveList, Update, selVehModelByUseOrgSidAll, details, selectSupplier } from '@/api/cheliang/basevehicle'
import { typeValues, fetchDetailsByUseOrgSid, getOrgSidByPath, fetchByUseOrgSid, fetchBySid, selectNameByOrg, brandDown } from '@/api/cheliang/dictcommons'
import Pagination from '@/components/pagination'

export default {
  name: 'CheliangtaizhangAdd',
  components: {
    Pagination
  },
  data() {
    return {
      viewTitle: '',
      tableKey: 0,
      dialogVisible: false,
      Loading: false,
      list: [],
      sids: [],
      listQuery: {
        total: 0,
        size: 5,
        current: 1,
        params: {
          useOrgSid: '',
          vehicleAlias: '',
          configName: '',
          brandSid: ''
        }
      },
      FormLoading: false,
      // 下拉框
      carBrand_list: [],
      orgDept_list: [],
      actualPay_list: [],
      vehicleState_list: [], // 库存
      manPurOrderType_list: [], // 采购订单
      supplier_list: [],
      location_list: [], // 存放地点
      settlementStatus_list: [], // 买断状态
      lockedState_list: [], // 锁定状态
      temp: {
        arrivalDate: '', //	到货日期
        departureDate: '', //	发车日期
        engineNo: '', // 发动机号/许可证号（陕汽必须的字段）
        salePrice: '', //	成交价
        costPrice: '', // 厂家入库价
        locationName: '', // 存放地点
        location: '', // 存放地点（陕汽必须的字段）
        lockedState: '', //	锁定状态
        lockedStateValue: '', //	锁定状态Value
        manPurOrderTypeKey: '', //	厂家采购订单类型key
        manPurOrderTypeValue: '', //	厂家采购订单类型value
        materialSid: '', // 物料sid（陕汽必须的字段）
        modelConfigSid: '', //	车型配置sid
        configName: '',
        modelName: '', //	车型名称
        modelSid: '', // 车型sid（陕汽必须的字段）
        orderingNo: '', //	厂家订单编号
        priceDate: '', //	厂家入库日期
        priced: '', //	厂家入库价
        returnDate: '', //	采购退库日期
        salesDate: '', //	销售日期
        settlementStatus: '', // 结算状态（0：未买断，1预买断，2买断）
        settlementStatusValue: '',
        solidDate: '', //	买断日期
        specialInstructions: '', //	特殊或差异说明
        createOrgSid: '',
        createOrgName: '',
        useOrgSid: '', //	使用组织sid
        useOrgName: '', //	使用组织名称
        vehicleState: '', //	车辆状态key值
        vehicleStateValue: '', //	车辆状态value值
        vinNo: '', // 车架号(VIN)（陕汽必须的字段）
        warrantyCardNo: '', // 保修卡号
        insideCode: '', // 内部编码
        purchaseSystemSid: '',
        purchaseSystemName: '',
        manufSaleAccessSid: '',
        manufSaleAccessName: '',
        rebate1: '',
        isProblemVeh: '',
        carBrandSid: '',
        carBrandName: '',
        supplierName: '',
        supplierSid: '',
        freight: '',
        vehMark: '',
        manDate: ''
      }, // 添加和修改
      dialogFormVisible: false, // 添加修改对话框状态
      dialogStatus: '', // 对话框状态
      rules: {
        purchaseSystemName: [{ required: true, message: '采购系统不能为空', trigger: 'change' }],
        supplierName: [{ required: true, message: '供应商不能为空', trigger: 'change' }],
        carBrandName: [{ required: true, message: '品牌不能为空', trigger: 'change' }],
        vinNo: [{ required: true, message: '车架号不能为空', trigger: 'blur' }],
        manPurOrderTypeValue: [{ required: true, message: '采购类型不能为空', trigger: 'change' }],
        lockedStateValue: [{ required: true, message: '锁定状态不能为空', trigger: 'change' }],
        vehicleStateValue: [{ required: true, message: '库存状态不能为空', trigger: 'change' }],
        priceDate: [{ required: true, message: '厂家入库日期不能为空', trigger: 'blur' }],
        departureDate: [{ required: true, message: '物流发车日期不能为空', trigger: 'blur' }],
        locationName: [{ required: true, message: '存放地点不能为空', trigger: 'change' }],
        manufSaleAccessName: [{ required: true, message: '厂家回款通路不能为空', trigger: 'change' }],
        contractPrice: [{ required: true, message: '厂家合同价（含运费）不能为空', trigger: 'blur' }],
        costPrice: [{ required: true, message: '车辆入库价（含运费）不能为空', trigger: 'blur' }],
        freight: [{ required: true, message: '运费不能为空', trigger: 'blur' }],
        settlementStatusValue: [{ required: true, message: '买断状态不能为空', trigger: 'change' }],
        isProblemVeh: [{ required: true, message: '是否为问题车辆不能为空', trigger: 'change' }],
      }
    }
  },
  methods: {
    // 输入数字正则
    oninput(val, limit = 0) {
      val = val.replace(/[^\d]/g, '') // 保留数字
      val = val.replace(/^00/, '0'); // 开头不能有两个0
      /^0\d+/.test(val) ? val = val.slice(1) : '' // 两位以上数字开头不能为0
      const str = '^(\\d+)\\.(\\d{' + limit + '}).*$'
      const reg = new RegExp(str)
      if (limit === 0) {
        // 不需要小数点
        val = val.replace(reg, '$1')
      } else {
        // 通过正则保留小数点后指定的位数
        val = val.replace(reg, '$1.$2')
      }
      return val
    },
    // 序号
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    getList() {
      selVehModelByUseOrgSidAll(this.listQuery).then((resp) => {
        if (resp.success) {
          this.list = resp.data.records
          this.listQuery.total = resp.data.total
        } else {
          this.list = []
          this.listQuery.total = 0
        }
      })
    },
    handSelect() {
      if (this.temp.carBrandName === '') {
        this.$message({ showClose: true, type: 'error', message: '请先选择品牌' })
        return
      }
      this.dialogVisible = true
      this.listQuery.params.brandSid = this.temp.carBrandSid
      this.getList()
    },
    handleConfig() {
      this.listQuery.current = 1
      this.getList()
    },
    handleConfirm(row) {
      this.dialogVisible = false
      this.temp.modelName = row.vehicleAlias
      this.temp.configName = row.configName
      this.temp.modelSid = row.modelSid
      this.temp.modelConfigSid = row.configSid
      this.temp.price = row.price
      this.temp.insideCode = row.insideCode
    },
    showAdd() {
      this.getType()
      this.getPathSid()
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.dialogStatus = 'add'
      this.viewTitle = '【新增】车辆台账'
      this.temp.lockedState = '03'
      this.temp.lockedStateValue = '未锁定'
      this.temp.vehicleState = '0001'
      this.temp.vehicleStateValue = '库存'
      this.temp.settlementStatus = '0'
      this.temp.settlementStatusValue = '未买断'
      this.temp.freight = 0
      this.temp.isProblemVeh = '0'
    },
    showEdit(sid) {
      this.getType()
      this.getPathSid()
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.dialogStatus = 'update'
      this.viewTitle = '【修改】车辆台账'
      this.temp.sid = sid
      details(sid).then((response) => {
        if (response.code === '200') {
          this.temp = response.data
          selectNameByOrg({ carBrandSid: this.temp.carBrandSid }).then((respsone) => {
            if (respsone.success) {
              this.actualPay_list = respsone.data
            }
          })
        }
      })
    },
    getPathSid() {
      getOrgSidByPath({ orgPath: window.sessionStorage.getItem('defaultOrgPath') }).then((res) => {
        if (res.success) {
          this.listQuery.params.useOrgSid = res.data
          this.temp.useOrgSid = res.data
          this.temp.createOrgSid = res.data
          fetchBySid(res.data).then((respsone) => {
            if (respsone.success) {
              this.temp.createOrgName = respsone.data.name
              this.temp.useOrgName = respsone.data.name
            }
          })
          fetchDetailsByUseOrgSid(this.temp.useOrgSid).then((res) => {
            if (res.success) {
              this.orgDept_list = res.data
            }
          })
          fetchByUseOrgSid({ sid: res.data }).then((resp) => {
            if (resp.success) {
              this.location_list = resp.data
            }
          })
          brandDown({ useOrg: res.data }).then((resp) => {
            if (resp.success) {
              this.carBrand_list = resp.data
              if (this.carBrand_list.length > 0) {
                this.temp.carBrandName = this.carBrand_list[0].brandName
                this.temp.carBrandSid = this.carBrand_list[0].sid
                selectNameByOrg({ carBrandSid: this.temp.carBrandSid }).then((respsone) => {
                  if (respsone.success) {
                    this.actualPay_list = respsone.data
                  }
                })
              }
            }
          })
        }
      })
    },
    // 下拉框
    getType() {
      // 库存
      typeValues({ type: 'vehicleState' }).then((res) => {
        if (res.success) {
          this.vehicleState_list = res.data
        }
      })
      // 采购订单
      typeValues({ type: 'purchaseOrderType' }).then((res) => {
        if (res.success) {
          this.manPurOrderType_list = res.data
        }
      })
      // 锁定状态
      typeValues({ type: 'lockedState' }).then((res) => {
        if (res.success) {
          this.lockedState_list = res.data
        }
      })
      // 结算状态
      typeValues({ type: 'settlementStatus' }).then((res) => {
        if (res.success) {
          this.settlementStatus_list = res.data
        }
      })
    },
    orgDeptChange(val) {
      const choosetItem = this.orgDept_list.filter((item) => item.purchaseSystemName === val)
      this.temp.purchaseSystemSid = choosetItem[0].deptSid
    },
    carBrandChange(val) {
      const choosetItem = this.carBrand_list.filter((item) => item.brandName === val)
      this.temp.carBrandSid = choosetItem[0].sid
      selectNameByOrg({ carBrandSid: this.temp.carBrandSid }).then((respsone) => {
        if (respsone.success) {
          this.actualPay_list = respsone.data
        }
      })
    },
    vehicleStateValueChange(val) {
      const choosetItem = this.vehicleState_list.filter((item) => item.dictKey === val)
      this.temp.vehicleStateValue = choosetItem[0].dictValue
    },
    supplierChange(val) {
      const choosetItem = this.supplier_list.filter((item) => item.manufacturerName === val)
      this.temp.supplierSid = choosetItem[0].sid
    },
    manPurOrderTypeChange(val) {
      const choosetItem = this.manPurOrderType_list.filter((item) => item.dictKey === val)
      this.temp.manPurOrderTypeValue = choosetItem[0].dictValue
      selectSupplier({ manPurOrderTypeKey: this.temp.manPurOrderTypeKey, carBrandSid: this.temp.carBrandSid, orgSid: this.temp.createOrgSid }).then((resp) => {
        if (resp.success) {
          this.supplier_list = resp.data
          if (this.supplier_list.length === 1) {
            this.temp.supplierName = this.supplier_list[0].manufacturerName
            this.temp.supplierSid = this.supplier_list[0].sid
          } else {
            this.temp.supplierName = ''
            this.temp.supplierSid = ''
          }
        }
      })
    },
    settlementStatusChange(val) {
      const choosetItem = this.settlementStatus_list.filter((item) => item.dictKey === val)
      this.temp.settlementStatusValue = choosetItem[0].dictValue
    },
    // 存放地点
    locationChange(val) {
      const choosetItem = this.location_list.filter((item) => item.warehouseName === val)
      this.temp.location = choosetItem[0].sid
    },
    actualPayChange(val) {
      const choosetItem = this.actualPay_list.filter((item) => item.name === val)
      this.temp.manufSaleAccessSid = choosetItem[0].sid
    },
    // 锁定状态
    lockedStateChange(val) {
      const choosetItem = this.lockedState_list.filter((item) => item.dictKey === val)
      this.temp.lockedStateValue = choosetItem[0].dictValue
    },
    // 返回
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      this.temp = {
        arrivalDate: '', //	到货日期
        departureDate: '', //	发车日期
        engineNo: '', // 发动机号/许可证号（陕汽必须的字段）
        salePrice: '', //	成交价
        costPrice: '', // 厂家入库价
        locationName: '', // 存放地点
        location: '', // 存放地点（陕汽必须的字段）
        lockedState: '', //	锁定状态
        lockedStateValue: '', //	锁定状态Value
        manPurOrderTypeKey: '', //	厂家采购订单类型key
        manPurOrderTypeValue: '', //	厂家采购订单类型value
        materialSid: '', // 物料sid（陕汽必须的字段）
        modelConfigSid: '', //	车型配置sid
        configName: '',
        modelName: '', //	车型名称
        modelSid: '', // 车型sid（陕汽必须的字段）
        orderingNo: '', //	厂家订单编号
        priceDate: '', //	厂家入库日期
        priced: '', //	厂家入库价
        returnDate: '', //	采购退库日期
        salesDate: '', //	销售日期
        settlementStatus: '', // 结算状态（0：未买断，1预买断，2买断）
        settlementStatusValue: '',
        solidDate: '', //	买断日期
        specialInstructions: '', //	特殊或差异说明
        createOrgSid: '',
        createOrgName: '',
        useOrgSid: '', //	使用组织sid
        useOrgName: '', //	使用组织名称
        vehicleState: '', //	车辆状态key值
        vehicleStateValue: '', //	车辆状态value值
        vinNo: '', // 车架号(VIN)（陕汽必须的字段）
        warrantyCardNo: '', // 保修卡号
        insideCode: '', // 内部编码
        purchaseSystemSid: '',
        purchaseSystemName: '',
        manufSaleAccessSid: '',
        manufSaleAccessName: '',
        rebate1: '',
        carBrandSid: '',
        carBrandName: '',
        isProblemVeh: '',
        supplierName: '',
        supplierSid: '',
        freight: '',
        vehMark: '',
        manDate: ''
      }
      this.$emit('doback')
    },
    // 提交添加数据
    handleCreate() {
      if (this.temp.modelName === '') {
        this.$message({ showClose: true, type: 'error', message: '请选择车型' })
        return
      }
      if (this.temp.settlementStatusValue !== '' && this.temp.settlementStatusValue === '买断' && this.temp.solidDate === '') {
        this.$message({ showClose: true, type: 'error', message: '因买断状态为买断，则买断日期不能为空' })
        return
      }
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.FormLoading = true
          // 只需添加和修改
          if (this.temp.vinNo.length !== 8 && this.temp.vinNo.length !== 17) {
            this.$message({ showClose: true, type: 'error', message: '请核对车架号的长度8位或17位' })
            return
          }
          if (this.dialogStatus === 'add') {
            SaveList(this.temp).then((response) => {
              this.FormLoading = false
              if (response.code === '200') {
                this.dialogFormVisible = false
                this.$notify({
                  title: '提示',
                  message: '添加成功',
                  type: 'success',
                  duration: 2000
                })
                this.handleReturn('true')
              }
            })
              .catch(e => {
                this.dialogFormVisible = false
              })
          } else {
            Update(this.temp).then((response) => {
              this.FormLoading = false
              if (response.code === '200') {
                this.dialogFormVisible = false
                this.$notify({
                  title: '提示',
                  message: '修改成功',
                  type: 'success',
                  duration: 2000
                })
                this.handleReturn('true')
              }
            })
              .catch(e => {
                this.dialogFormVisible = false
              })
          }
        }
      })
    }
  }
}
</script>
<style scoped>
.tlineheightb {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}
/deep/ .tlineheightb .el-form-item .el-form-item__content {
  line-height: 15px !important;
}
/deep/ .tlineheightb .el-form-item .el-form-item__label {
  line-height: 15px !important;
}
/deep/ .configNameStyle .el-form-item__content {
  margin-left: 1% !important;
}
</style>
