<!--
 * @Description: 新增/编辑弹框
 * @Author: 空白格
 * @Date: 2023-07-04 13:55:00
 * @LastEditors: 空白格
 * @LastEditTime: 2023-07-06 09:08:39
 * @FilePath: \cattle_webui\src\views\system\noticeMgr\Dialog\AddOrEditDialog.vue
 * @Copyright: Copyright (c) 2016~2023 by 空白格, All Rights Reserved.
-->
<template>
  <el-dialog
    :visible.sync="open"
    width="800px"
    :close-on-click-modal="false"
    @close="cancel"
  >
    <div class="dialog"
    v-loading="loading"
    >
      <el-descriptions title="用户信息">
          <el-descriptions-item label="用户名">{{ form.name }}</el-descriptions-item>
          <el-descriptions-item label="手机号">{{ form.mobile }}</el-descriptions-item>
          <el-descriptions-item label="真实姓名">{{ form.realName }}</el-descriptions-item>
          <el-descriptions-item label="身份证号码">{{ form.cardId }}</el-descriptions-item>
          <el-descriptions-item label="累计消费">{{ form.consumeTotal }}</el-descriptions-item>
          <el-descriptions-item label="是否实名">
            <dict-tag :options="dict.type.user_certification" :value="form.isAuth"/>
          </el-descriptions-item>
          <el-descriptions-item label="是否加入黑名单">
            <dict-tag :options="dict.type.user_is_black_list" :value="form.isBlackList"/>
          </el-descriptions-item>
          <el-descriptions-item label="注册渠道">
            <dict-tag :options="dict.type.user_source_type" :value="form.regSource"/>
          </el-descriptions-item>
          <el-descriptions-item label="注册时间">{{ form.createTime }}</el-descriptions-item>
      </el-descriptions>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancel">关闭</el-button>
      <el-button
        type="primary"
        @click="submitForm"
        :loading="loading"
        element-loading-text="提交中..."
        v-if="type!=3"
      >
      保存
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getSelectById } from '@/api/userMr/userMr'
export default {
  name: "addAndEdit",
  dicts:['user_source_type','user_is_black_list','user_certification'],
  data() {
    return {
      title: "编辑",
      type: 0,
      model: "EDIT",
      open: false,
      loading: false,
      form: {},
      rules: {
        deviceName: [{ required: true, message: "请输入设备名称", trigger: ["change","blur"] }],
        deviceNo: [
          { required: true, message: "请输入设备编号", trigger: ["change","blur"] },
        ],
        deviceType: [
          { required: true, message: "请输入设备类型", trigger: ["change","blur"] },
        ],
        deviceAddress: [
          { required: true, message: "请输入所在位置", trigger: ["change","blur"] },
        ],
      },
    };
  },
  methods: {
    /**
     * 打开弹框
     * @date 2022-09-20
     * @param {any} obj
     * @returns {any}
     */
    openDialog(title, obj,type) {
      this.title = title;
      this.type = type
      this.open = true;
      if (obj){
        this.getSelectByIdFun(obj)
        // this.$nextTick(() => {
        //   this.form = Object.assign({},this.form,obj)
        // });
      }else{
        this.$nextTick(() => {
          this.$refs["form"].clearValidate();
          this.$set(this.form,'deviceType',5)
        });
      }
    },
    /**  获取详情  */
    async getSelectByIdFun(data) {
      try {
        this.loading = true
        let res = await getSelectById({id:data.id})
        if(res.code == 200){
          this.form = JSON.parse(JSON.stringify(res.data))
          this.loading = false
        }else {
          throw new Error(res)
        }
      } catch (error) {
        console.error("error==",error)
        this.loading = false
        this.open = false
      }
    },
    /**
     * 保存
     * @date 2022-09-20
     * @returns {any}
     */
    submitForm() {
      this.$refs["form"].validate(async (valid) => {
        if (valid) {
          try {
            this.loading = true;
            
          } catch (error) {
          } finally {
            this.loading = false;
          }
        }
      });
    },
    /**
     * 重置
     * @date 2022-09-20
     * @returns {any}
     */
    reset() {
      
    },
    /**
     * 关闭弹框
     * @date 2022-09-20
     * @returns {any}
     */
    cancel() {
      this.open = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  padding: 0 30px;
  max-height: 65vh;
  overflow-y: auto;
}
</style>
