<template>
  <div>
    <div class="dialog-h-content scroll-h  m-edit">
      <el-form ref="ref_form"
               :inline="true"
               :model="dataForm"
               label-width="90px"
               :rules="dataRule"
               class="m-form">
        <template >
          <el-form-item class="top24" label="当前组织"
                        style="display: block"
                       >
                       {{resideathAddObj.GRID_ID}}
          </el-form-item>
        </template>
        <template>
          <el-form-item label="姓名"
                        style="display: block"
                       >
                       {{resideathAddObj.name}}
          </el-form-item>
        </template>
       
        <el-form-item label="死亡日期"
                      style="display: block"
                      prop="deathDate">
          <el-date-picker v-model="dataForm.deathDate"
                          class="item_width_daterange"
                          type="date"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          format="yyyy-MM-dd"
                          placeholder="选择日期"
                          :clearable="false">
          </el-date-picker>
        </el-form-item>
        <div class="item-textarea">
          <el-form-item label="死亡原因"
                        style="display: block"
                        prop="blacklistReason">
            <el-input type="textarea"
                      resize="none"
                      class="item_width_daterange"
                      placeholder='请输入死亡原因'
                      v-model="dataForm.blacklistReason">
            </el-input>
          </el-form-item>
        </div>
        <!-- <el-form-item label="享受福利"
                      style="display: block"
                      prop="welfareFlag">
          <el-checkbox v-model="dataForm.welfareFlag">享受</el-checkbox>
        </el-form-item> -->
      </el-form>

    </div>
    <div class="div_btn">
      <el-button size="small"
                 class=""
                 @click="handleCancle">取 消</el-button>
      <el-button size="small"
                 class="diy-button--blue"
                 :loading="btnDisable"
                 @click="handleComfirm">提 交</el-button>
    </div>

  </div>
</template>

<script>
import util from '@js/util.js';
import { Loading } from 'element-ui' // 引入Loading服务
import { requestPost, requestGet } from '@/js/dai/request'

let loading // 加载动画
export default {
  data () {
    return {

      btnDisable: false,

      dataForm: {
        blacklistReason: '',
        deathDate: '',
      },




    }
  },
  components: {

  },
  mounted () {
  },
  computed: {
    dataRule () {
      return {
        blacklistReason: [
          { required: true, message: '死亡原因不能为空', trigger: 'blur' },
        ],
        deathDate: [
          { required: true, message: '死亡日期不能为空', trigger: 'blur' }
        ],


      }
    },

  },
  methods: {
    async initForm (row) {
      this.customerId = localStorage.getItem("customerId");

      this.$refs.ref_form.resetFields();

      this.dataForm.idCard = row.ID_CARD
      this.dataForm.name = row.NAME
      this.dataForm.mobile = row.MOBILE
      this.dataForm.gender = row.GENDER == '女' ? '0' : row.GENDER == '男' ? '1' : ''
      this.dataForm.type = '1'
      this.dataForm.userId = row.icResiUserId

    },

    async handleComfirm () {
      this.btnDisable = true
      setTimeout(() => {
        this.btnDisable = false
      }, 2000)
      this.$refs['ref_form'].validate((valid, messageObj) => {
        if (!valid) {
          // app.util.validateRule(messageObj)
          console.log('error submit!')

        } else {

          this.saveForm()
        }

      })
    },

    async saveForm () {


      const url = '/epmetuser/rentDeath/save'


      const { data, code, msg } = await requestPost(url, this.dataForm)

      if (code === 0) {
        this.$message.success('操作成功')
        this.handleCancle()
      } else {
        this.$message.error(msg)
      }
    },


    handleCancle () {
      this.resetData()
      this.$emit('dialogCancle')

    },

    resetData () {
      this.dataForm = {
        icUserId: '', // 被调动人ID
        type: 'in',//操作类型【客户外out,客户内in】
        agencyId: '',//调动到的组织Id
        gridId: '',//调动到的网格Id
        villageId: '',//调动到的小区ID
        buildId: '',//调动到的楼宇Id
        unitId: '',//调动到的单元Id
        homeId: '', //调动到的房屋Id
        transferTime: '', //调动时间【日期类型】
        reason: '', //备注
        outOfTime: '',
        welfareFlag: false
      }




    },
    // 开启加载动画
    startLoading () {
      loading = Loading.service({
        lock: true, // 是否锁定
        text: '正在加载……', // 加载中需要显示的文字
        background: 'rgba(0,0,0,.7)' // 背景颜色
      })
    },
    // 结束加载动画
    endLoading () {
      // clearTimeout(timer);
      if (loading) {
        loading.close()
      }
    }
  },
  props: {
    resideathAddObj:{
      type:Object,
      default: ()=>{ return {} }
    }
  }
}
</script>
<style lang="scss" scoped>
@import "@/assets/scss/modules/management/edit-main.scss";
@import "@/assets/scss/modules/management/list-main.scss";

.resi-cell-col {
  width: 750px;
  display: flex;
  justify-content: flex-start;
}

.margin_left10 {
  margin-left: 10px;
}
</style>
