<template>
  <div>
    <Base :form-data="formData" page-type="frock" :module="module" :common-data="commonData" />
    <Model :form-data="formData" page-type="frock" :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 { addLoginFrock, editLoginFrock, submitLoginFrock } from '@/api/frock'
export default {
  components: {
    Base,
    Model
  },
  mixins: [Mixin],
  methods: {
    onSbumit(type) {
      const params = {
        ...this.formData,
        joinData : function () {
          this.joinAddress = (this.province || '') + (this.city || '') + (this.area || '') + (this.street || '') + (this.address || '')
        }
      }
      params.joinData()
      if (params.fileList.length) {
        params.drawUpload = params.fileList[0].url
      }
      if(!this.verificationModel())return
      if (type === 1) {
        submitLoginFrock(params).then(res => {
          this.commonFn('提交成功')
        })
      } else {
        if (!this.detailId) {
          addLoginFrock(params).then(res => {
            this.commonFn('新增成功')
          })
          return
        }
        editLoginFrock(params).then(res => {
          this.commonFn('编辑成功')
        })
      }
    },
    commonFn(name) {
      this.$successMsg(name)
      this.$emit('updateList')
    }
  }
}
</script>

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