<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      @close="close"
      @keyup.enter.native="doSubmit"
      v-model="visible">
      <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
               label-width="120px" @submit.native.prevent>
        <el-row  :gutter="15">
          <el-col :span="12">
            <el-form-item label="入驻平台名称" prop="name"
                          :rules="[
                          {required: true, message:'入驻平台名称不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.name" placeholder="请填写入驻平台名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序" prop="sort"
                          :rules="[
                          {required: true, message:'排序不能为空', trigger:'blur'}
                 ]">
              <el-input-number v-model="inputForm.sort"
							   style="width:100%;"
							   :min="0"
							   placeholder="请填写排序"
			  ></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks"
                          :rules="[
                 ]">
              <el-input type="textarea" maxlength="255" v-model="inputForm.remarks" placeholder="请填写备注"  show-word-limit   ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
		<template #footer>
			<span class="dialog-footer">
			  <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			  <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
			</span>
		</template>
    </el-dialog>
  </div>
</template>

<script>
  import settledPlatformService from '@/api/wdt/settledPlatform/SettledPlatformService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
			name: '',
			sort: 0,
         	remarks: '',
        }
      }
    },
    created () {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm = {
          name: '',
          sort: '',
          remarks: '',
          parentId: ''
        }
        if (method === 'add') {
          this.title = `新增入驻平台信息`
        } else if (method === 'edit') {
          this.inputForm.id = id
          this.title = '修改入驻平台信息'
        } else if (method === 'view') {
          this.inputForm.id = id
          this.title = '查看入驻平台信息'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
			  settledPlatformService.queryById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
			  settledPlatformService.save(this.inputForm).then((data) => {
              this.close()
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      close () {
        this.$refs.inputForm.resetFields()
        this.visible = false
      }
    }
  }
</script>
