<template>
  <div class="app-container">
    <div class="tab-header webtop">
      <div>价格维护</div>
    </div>
    <div class="listconadd">
      <el-form ref="weihuForm" :model="temp" label-position="right" class="formadd" :rules="rules">
        <el-row class="tleftb_one">
          <el-col :span="6" class="tleftb">
            <span>车型名称</span>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <span>{{ temp.vehicleAlias }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="tleftb">
            <span>内部编码</span>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-input v-model="temp.insideCode" maxlength="125" placeholder="请输入内部编码"
                        class="addinputw" clearable/>
<!--              <span>{{ temp.insideCode }}</span>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="tleftb">
            <span>常用配置</span>
          </el-col>
          <el-col :span="18" class="tleftb_chang">
            <el-form-item>
              <span>{{ temp.configName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="tleftb">
            <span>更多配置</span>
          </el-col>
          <el-col :span="18" class="break_word">
            <el-form-item>
              <span>{{ temp.otherConfig }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="tleftb">
            <span><span class="icon">*</span>销售指导价(贷款)</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="manufactorSettlementPrice">
              <el-input v-model="temp.manufactorSettlementPrice" maxlength="125" placeholder="请输入销售指导价(贷款)"
                        class="addinputw addinputw_jia" clearable/>
              <span style="font-size: 16px">元</span>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="tleftb">
            <span><span class="icon">*</span>销售指导价(全款)</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="guidedPrice">
              <el-input v-model="temp.guidedPrice" maxlength="125" placeholder="请输入销售指导价(全款)" class="addinputw addinputw_jia"
                        clearable/>
              <span style="font-size: 16px">元</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="form_btn">
        <el-button type="primary" size="small" @click="handleCreate()">确认</el-button>
        <el-button type="info" size="small" @click="handleReturn()">返回</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { fetchBySid, update } from '@/api/cheliang/basemodelconfig'

export default {
  name: 'chexingpeizhijiageweihu',
  data() {
    return {
      temp: {
        sid: '', // 一条数据的sid
        vehicleAlias: '', // 车型名称(产品名称 陕汽必须1)
        manufactorSettlementPrice: '', // 厂家结算价
        guidedPrice: '', // 销售指导价
        insideCode:''
      },
      rules: {
        manufactorSettlementPrice: [{ required: true, message: '销售指导价(贷款)不能为空', trigger: 'blur' }],
        guidedPrice: [{ required: true, message: '销售指导价(全款)不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    showWeiHu(sid) {
      this.$nextTick(() => {
        this.$refs['weihuForm'].clearValidate()
      })
      fetchBySid(sid).then(resp => {
        if (resp.success) {
          const data = resp.data
          this.temp = data
          this.temp.sid = sid
        }
      })
    },
    // 返回
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      this.temp = {}
      this.$emit('doback')
      console.log('价格维护返回', 112233)
    },
    // 保存修改数据
    handleCreate() {
      this.$refs['weihuForm'].validate(valid => {
        if (valid) {
          const tip = '请确认是否保存信息'
          this.$confirm(tip, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            const temp = {
              sid: this.temp.sid,
              manufactorSettlementPrice: this.temp.manufactorSettlementPrice,
              guidedPrice: this.temp.guidedPrice,
              insideCode: this.temp.insideCode
            }
            update(temp).then(resp => {
              if (resp.success) {
                const data = resp.data
                this.temp = data
                this.handleReturn('true')
              }
            })
          })
        }
      })
    }

  }
}
</script>

<style scoped>
.tleftb_one {
  border-top: 1px solid #e0e3eb;
}

.form_btn {
  display: flex;
  justify-content: center;
}

.break_word {
  word-wrap: break-word;
}

.tleftb_chang .el-form-item /deep/ .el-form-item__content {
  line-height: 20px;
}

.addinputw_jia {
  margin-right: 10px;
}
</style>
