<template>
    <div 
    style="padding: 40px;"
    v-loading="loading"
    :element-loading-text="loadingText"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
    >
        <el-form :model="form" ref="form" size="small" :rules="rules" label-width="120px">
          <el-form-item label="景区名称" prop="scenicName">
            <el-input
              v-model="form.scenicName"
              placeholder="请输入景区名称"
              clearable
              style="width: 300px"
            />
          </el-form-item>
          <el-form-item label="开放时间" prop="developDate">
            <el-date-picker
            style="width: 300px"
            v-model="form.developDate"
            type="date"
            placeholder="请选择开放时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="联系电话" prop="scenicPhone">
            <el-input
              v-model="form.scenicPhone"
              placeholder="请输入联系电话"
              clearable
              style="width: 300px"
            />
          </el-form-item>
          <el-form-item label="景区地址" prop="scenicAddress">
            <el-input
              v-model="form.scenicAddress"
              placeholder="请输入景区地址"
              clearable
              style="width: 300px"
            />
          </el-form-item>
          <div>
            <el-form-item label="经度" prop="longitude">
                <el-input
                v-model="form.longitude"
                placeholder="请输入经度"
                clearable
                style="width: 300px"
                />
            </el-form-item>
            <el-form-item label="纬度" prop="latitude">
                
                <el-input
                v-model="form.latitude"
                placeholder="请输入纬度"
                clearable
                style="width: 300px"
                />
            </el-form-item>   
          </div>
          
          <el-form-item>
            <el-button
                type="primary"
                @click="submitForm"
                :loading="loading"
                element-loading-text="提交中..."
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.8)"
            > 
                {{ loading ? '提交中...' : '保存' }}
            </el-button>
          </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { 
  getTableDeatilsByIdApi,
  updateTableApi,
 } from '@/api/CURD'
export default {
  name: "AttractionInfoBeas",
  dicts: [],
  components: {},
  data() {
    return {
        title: "基本信息",// 通用标题
        loading: false,
        loadingText: "拼命加载数据中...",
        configPermi: {
            add: ['system:user:edit'], // 新增权限
            details: ['system:user:details'], // 详情权限
            delect: ['system:user:remove'], // 删除权限
            edit: ['system:user:edit'], // 编辑权限http://localhost/scenicAreaManagement/contentManagement/scenicAreaManagement/contentManagement/questions
            upload: ['system:user:upload'],// 导入权限
            export: ['system:user:export'],// 导出权限http://localhost/scenicAreaManagement/contentManagement/scenicAreaManagement/contentManagement/suggestions
            release: ['system:user:release']
        },
        configUrl: {
            details: '/merchant/merchantInfo/getMerchantInfo', // 详情地址
            edit: '/merchant/merchantInfo/updateScenic', // 编辑地址
        },
        form: {},
        rules: {
            scenicName: [{ required: true, message: "请输入标题名称", trigger: ["change","blur"] }],
            developDate: [{ required: true, message: "请选择开放时间", trigger: ["change","blur"] }],
            scenicPhone: [{ required: true, message: "请输入联系电话", trigger: ["change","blur"] }],
            scenicAddress: [{ required: true, message: "请输入景区地址", trigger: ["change","blur"] }],
            longitude: [{ required: true, message: "请输入经度", trigger: ["change","blur"] }],
            latitude: [{ required: true, message: "请输入纬度", trigger: ["change","blur"] }],
        },
    }
  },
  methods: {
    /**  初始化  */
    initData() {
        this.loadingText = "拼命加载数据中..."
        this.loading = true
        this.getTableDeatilsFun()
    },
    /** 获取详情 */
    async getTableDeatilsFun(row) {
      this.loading = true
      try {
        let res = await getTableDeatilsByIdApi(this.configUrl.details,{})
        if(res.code == 200) {
          let obj = {
          ...res.data
        }
          this.$set(this,'form',JSON.parse(JSON.stringify(obj)))
          this.formStatus = 1
        }else {
          this.$message.error('获取详情失败!!!');
          this.formStatus = 2
          this.loading = false
          this.open = false;
        }
        this.$nextTick(()=>{
            this.reset()
        })
        this.loading = false
      } catch (error) {
        console.error('获取详情失败!!!!',error)
        this.formStatus = 2
        this.loading = false
        this.open = false;
      }
    },
    /**
     * 保存
     * @date 2023-11-22
     * @returns {any}
     */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loadingText = "提交数据中..."
          this.loading = true
          updateTableApi(
            this.configUrl.edit,{
            ...this.form
            }).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.loading = false
            this.initData()
            }).catch(()=>{
            this.$message.error("修改失败!!!");
            this.loading = false
        })
        }
      });
    },
    /**
     * 重置
     * @date 2023-11-22
     * @returns {any}
     */
    reset() {
      if(this.$refs["form"]) {
        this.$refs["form"].clearValidate();
      }
    },
  },
}
</script>
<style lang="scss" scoped>
</style>