<template>
  <div>
    <Base :form-data="formData" page-type="cross" :module="module" :common-data="commonData" />
    <Model :form-data="formData" page-type="cross" :module="module" :common-data="commonData" />
    <div style="margin: 20px 0">
      <el-button type="primary" size="small" @click="onSbumit(1)">提交</el-button>
      <el-button type="primary" size="small" @click="onSbumit(2)">暂存-草稿箱</el-button>
      <el-button size="small" @click="onReset">重置</el-button>
    </div>
  </div>
</template>

<script>
import Base from '../components/base.vue'
import Model from '../components/model.vue'
import Mixin from '../mixin'
import { addLoginHomeDecoration, editLoginHomeDecoration, submitLoginHomeDecoration } from '@/api/crossDistrict'
export default {
  components: {
    Base,
    Model
  },
  mixins: [Mixin],
  methods: {
    onSbumit(type) {
      const params = {
        ...this.formData,
        isSpan: true,
        joinData : function () {
          this.joinAddress = (this.province || '') + (this.city || '') + (this.area || '') + (this.street || '') + (this.address || '')
        }
      }
      params.joinData()
      if(!this.verificationModel())return

      if (params.orderType === 'HOME' && params.homeProjectNameRadio) {
        if (params.homeProjectNameRadio == 'AREA') {
          if (!params.homeProjectNameArea || !params.homeProjectNameSeat || !params.homeProjectNameNumber) {
            this.$errorMsg('工程项目名称信息有误,请填写完整信息。')
            return
          }
        }
        if (params.homeProjectNameRadio == 'SELF') {
          if (!params.homeProjectNameArea2) {
            this.$errorMsg('工程项目名称信息有误,请填写完整信息。')
            return
          }
        }
        if (params.homeProjectNameRadio == 'VILLA') {
          if (!params.homeProjectNameArea3 || !params.homeProjectNameNumber3) {
            this.$errorMsg('工程项目名称信息有误,请填写完整信息。')
            return
          }
        }
        params.projectName = {
          'AREA': params.homeProjectNameArea + '小区' + params.homeProjectNameSeat + '座' + params.homeProjectNameNumber + '号',
          'SELF': params.homeProjectNameArea2 + '（业主名称）自建房',
          'VILLA': params.homeProjectNameArea3 + '小区' + params.homeProjectNameNumber3 + '号'
        }[params.homeProjectNameRadio]
      }
      if (params.homeProjectNameRadio === 'SELF') {
        params.homeProjectNameArea = params.homeProjectNameArea2
      }
      if (params.homeProjectNameRadio === 'VILLA') {
        params.homeProjectNameNumber = params.homeProjectNameNumber3
        params.homeProjectNameArea = params.homeProjectNameArea3
      }
      if (params.fileList.length) {
        params.drawUpload = params.fileList[0].url
      }

      if (type === 1) {
        submitLoginHomeDecoration(params).then(res => {
          this.commonFn('提交成功')
        })
      } else {
        if (!this.detailId) {
          addLoginHomeDecoration(params).then(res => {
            this.commonFn('新增成功')
          })
          return
        }
        editLoginHomeDecoration(params).then(res => {
          this.commonFn('编辑成功')
        })
      }
    },
    commonFn(name) {
      this.$successMsg(name)
      this.$emit('updateList')
    }
  }
}
</script>

<style lang="scss" scoped></style>
