<template>
  <div class="wrapper editwrap">
    <el-dialog
            :visible.sync="dialogVisible"
            :title="title"
            :show-close="false"
            :close-on-click-modal="false"
    >
      <el-form ref="editForm" :model="editForm" :rules="rules" label-width="106px">

        <el-form-item label="资源名称" prop="materialName">
          <el-input v-model="editForm.materialName"></el-input>
        </el-form-item>
        <!--<el-form-item label="资源类型" prop="materialType">-->
          <!--<el-input v-model="editForm.materialType"></el-input>-->
        <!--</el-form-item>-->
        <el-form-item label="资源类型" prop="materialType">
          <el-select v-model="editForm.materialType" placeholder="请选择资源类型">
            <el-option label="救援物资" value="救援物资"></el-option>
            <el-option label="专家资源" value="专家资源"></el-option>
            <el-option label="救援队伍" value="救援队伍"></el-option>
            <el-option label="避难场所" value="避难场所"></el-option>
            <el-option label="防护目标" value="防护目标"></el-option>
            <el-option label="医疗卫生单位" value="医疗卫生单位"></el-option>
            <el-option label="通信保障机构" value="通信保障机构"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="资源数量" prop="num">
          <el-input v-model="editForm.num"></el-input>
        </el-form-item>
        <p style="color: #F56C6C;float: left;position: relative;left: 45px;">*</p>
        <el-form-item label="经纬度">
          <el-row>
            <el-col :span="8">
              <!--<el-input v-model="editForm.longitude"></el-input>-->
              <el-form-item prop="longitude" style="margin-right: 9px">
                <el-input v-model="editForm.longitude"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="latitude" style="margin-right: 9px">
                <el-input v-model="editForm.latitude"></el-input>
              </el-form-item>
              <!--<el-input v-model="editForm.latitude"></el-input>-->
            </el-col>
            <el-col :span="6">
              <el-button type="primary" plain @click="MapdialogFun">选择经纬度</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="editForm.address"></el-input>
        </el-form-item>
        <el-form-item label="联系人" prop="contacts">
          <el-input  v-model="editForm.contacts"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="editForm.phone"></el-input>
        </el-form-item>


      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="confirmFun('editForm')">确定</el-button>
        <el-button @click="$emit('dialogFun')" size="small">取消</el-button>
      </span>
    </el-dialog>
    <Mapdialog
            v-if="loadmap"
            :dialogTableVisible="dialogTableVisible"
            @dialogcancelFun="dialogcancelFun"
            :slat="editForm.latitude"
            :slng="editForm.longitude"
            @confirm="qrFun"
    />
  </div>
</template>
<style lang="scss">
</style>
<script lang="ts">
    import { Component, Vue, Provide, Prop, Watch } from "vue-property-decorator";
    import { State, Getter, Mutation, Action } from "vuex-class";
    import Mapdialog from "@/components/maplnglat.vue";
    import METHOD from "@/utils/methods";

    @Component({
        components: { Mapdialog }
    })
    export default class SafetyDeviceMgEdit extends Vue {
        //属性或参数中使用!:表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
        @Prop(Boolean) dialogVisible!: Boolean;
        @Provide() loading: Boolean = false;
        @Prop(Object) editForm!: {
        deviceName: String;
        longitude: Number;
        latitude: Number;
        dataType: String;
        enterpriseId: String;
    };
    @Prop(String) title!: String;
    // @Provide() editForm: any = {};
    @Provide() enterpriseList: any = [];
    @Provide() qvvalue: any = []; //区域值
    @Provide() signsArr: any = []; //图例list
    @Provide() dialogTableVisible: Boolean = false;
    @Provide() rules: any = {
        materialName: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
        materialType: [
            { required: true, trigger: "blur", message: "该项为必填项！" }
        ],
        contacts: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
        num: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
        /*isBigDanger: [
          { required: true, trigger: "blur", message: "该项为必填项！" }
        ],
        dangerGrade: [
          { required: true, trigger: "blur", message: "该项为必填项！" }
        ],*/
        phone: [
            { required: true, trigger: "blur", message: "该项为必填项！" }
        ],
        longitude: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
        latitude: [{ required: true, trigger: "blur", message: "该项为必填项！" }]
    };
    @Provide() loadmap: Boolean = false;
    @Provide() play: Boolean = false;
    @Provide() enterpriseId: string = "dbe0c3268a3c4911913f35a2fdcd0e3e";

    qrFun(v: any) {
        //确认选择经纬度
        this.editForm.longitude = v.lng;
        this.editForm.latitude = v.lat;
    }
    MapdialogFun() {
        this.loadmap = false;
        this.$nextTick(() => {
            this.loadmap = true;
        });
        this.dialogTableVisible = true;
    }
    dialogcancelFun() {
        this.dialogTableVisible = false;
    }
    //取消事件要在父级取消是所以用到 $emit
    confirmFun(formName: string) {
        let that = this,
            params = that.editForm;
        (that as any).$refs[formName].validate((valid: boolean) => {
            if (valid) {
                METHOD.axiosPost(
                    that,
                    `/material/addMaterInfo`,
                    params,
                    function(res: any) {
                        if (res.code == 0) {
                            (that as any).$emit("dialogFun");
                            (that as any).$message({
                                message: "操作成功！",
                                type: "success"
                            });
                            that.$emit("refreshTableData"); //刷新表格
                        }
                    }
                );
            } else {
                return false;
            }
        });
    }
    getnterpriseListInfo() {
        let that = this,
            param ={accountStatus:'0'};
        that.loading = true;
        METHOD.axiosPost(
            that,
            `/enterpriseInfo/queryEnterpriseListInfo`,
            param,
            function(res: any) {
                that.loading = false;
                if (res.code == 0) {
                    that.enterpriseList = res.data;
                }
            }
        );
    }
    getnterpriseListInfo() {
        let that = this,
            param ={accountStatus:'0'};
        that.loading = true;
        METHOD.axiosPost(
            that,
            `/enterpriseInfo/queryEnterpriseListInfo`,
            param,
            function(res: any) {
                that.loading = false;
                if (res.code == 0) {
                    that.enterpriseList = res.data;
                }
            }
        );
    }
    seletChange(enterpriseId: any) {
        let that = this,
            arr;
        arr = that.enterpriseList.filter((ele: any) => enterpriseId == ele.enterpriseId);
        that.editForm.enterpriseListId = arr[0].enterpriseId;
    }
    created() {
        //this.editForm = this.editFormData;
        if(METHOD.enterpriseId){
            this.enterpriseId = METHOD.enterpriseId;
        }else{
            //政府用户
            this.play = true;
            this.getnterpriseListInfo();
        }
    }
    }
</script>
<style lang="scss">
  @import "@/utils/public.scss";
</style>
