<template>
  <div>
    <el-radio-group v-model="current" size="mini">
      <el-radio-button class="my-width" label="detail">审核</el-radio-button>
      <el-radio-button class="my-width" label="record">操作记录</el-radio-button>
    </el-radio-group>
    <div v-show="current === 'detail'">
      <el-form disabled>
        <Base :form-data="formData" page-type="cross" :module="module" :common-data="commonData" />
        <Model :form-data="formData" page-type="cross" :module="module" :common-data="commonData" />
      </el-form>
      <Examine :form-data="formData" page-type="cross" :module="module" :common-data="commonData" />
      <div style="margin: 20px 0">
        <el-button type="primary" size="small" @click="onSbumit">提交</el-button>
        <el-button size="small" @click="handleBack">返回</el-button>
      </div>
    </div>
    <OperationRecords v-show="current === 'record'" :detail-id="detailId" />

  </div>
</template>

<script>
import Base from '../components/base.vue'
import Model from '../components/model.vue'
import Examine from '../components/examine.vue'
import Mixin from '../mixin'
import { examineLoginHomeDecoration } from '@/api/crossDistrict'
import OperationRecords from '../components/operationRecords.vue'

export default {
  components: {
    Base,
    Model,
    Examine,
    OperationRecords
  },
  mixins: [Mixin],
  data() {
    return {
      current: 'detail'
    }
  },
  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 (this.formData.files.length) {
        params.files = this.formData.files.map(k => {
          return {
            ...k,
            fileName: k.name,
            fileUrl: k.url
          }
        })
      }
      if (params.loginStatus === 'FAIL' && !params.projectNo) {
        this.$errorMsg('请填写项目编号')
        return
      }

      if (params.loginStatus === 'REJECT' && !params.note) {
        this.$errorMsg('请填写审核备注')
        return
      }
      if (params.loginStatus === 'FAIL' && params.projectNo === params.successLoginProject) {
        this.$errorMsg('项目编号不能审核项目编号')
        return
      }
      if (params.orderType === 'HOME' && params.orderType === 'HOME' && params.homeProjectNameRadio) {
        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
      }

      examineLoginHomeDecoration(params).then(res => {
        this.commonFn('审核成功')
      })
    },
    commonFn(name) {
      this.$successMsg(name)
      this.handleBack()
    },
    handleBack() {
      this.$emit('updateList')
    }
  }
}
</script>

<style lang="scss" scoped>
.my-width ::v-deep .el-radio-button__inner {
  width: 100px;
}
</style>
