<template>
  <div>
    <el-dialog
        title="编辑"
        class="dialog-mini"
        width="800px"
        @close="close"
        :visible.sync="dialogformVisible"
      >
        <el-form :model="ruleForm" :rules="rules" ref="form" style="max-height: 500px;overflow: auto;" label-width="90px" size="small">
          <el-form-item label="店铺名称"  prop="shopName">
            <el-input v-model="ruleForm.shopName"></el-input>
          </el-form-item>
          <el-form-item label="店主"  prop="name">
            <el-input v-model="ruleForm.name"></el-input>
          </el-form-item>
          <el-form-item label="联系方式" prop="phone">
            <el-input v-model="ruleForm.phone"></el-input>
          </el-form-item>
          <el-form-item label="营业面积">
            <el-input v-model="ruleForm.businessArea"></el-input>
          </el-form-item>
          <el-form-item label="经营项目">
            <el-select v-model="ruleForm.businessType" placeholder="请选择" style="width: 100%;">
              <el-option
                v-for="item in bussinessTypeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="道路名称">
            <el-input v-model="ruleForm.street"></el-input>
          </el-form-item>
          <el-form-item label="路段">
            <el-input v-model="ruleForm.roadName"></el-input>
          </el-form-item>
          <el-form-item label="地址">
            <el-input v-model="ruleForm.address"></el-input>
          </el-form-item>
          <el-form-item label="录入人">
            <el-input v-model="ruleForm.createUser"></el-input>
          </el-form-item>
          <el-form-item label="录入单位">
            <el-input v-model="ruleForm.createUnit"></el-input>
          </el-form-item>
          <el-form-item label="经纬度">
            <el-col :span="10">
              <el-input type="number"
                        v-model="ruleForm.lng">
                <template slot="prepend">经度</template>
              </el-input>
            </el-col>
            <el-col :span="14">
              <el-input type="number"
                        v-model="ruleForm.lat">
                <template slot="prepend">纬度</template>
                <template slot="append">
                  <el-button type="success" @click="handlerOpenMap">点击选择定位</el-button>
                </template>
              </el-input>
            </el-col>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="mini" @click="close" >取 消</el-button>
          <el-button size="mini" type="primary" @click="submitBtn('form')">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="选择定位"
        class="dialog-mini"
        width="1070px"
        @close="areaCalcVisible=false"
        :visible.sync="areaCalcVisible"
      >
        <el-container style="width:1050px;height:600px;overflow-y:hidden;">
          <AreaCalc v-if="areaCalcVisible" @pointCancel="showAreaCalcMode = false" :status="mapStatus" @backLngLat="backLngLat"  ></AreaCalc>
        </el-container>
        <div slot="footer" class="dialog-footer">
          <el-button type="danger" size="mini" @click="handleMap('clear')" >清 除</el-button>
          <el-button type="success" size="mini" @click="handleMap('dot')" >打 点</el-button>
          <el-button size="mini" @click="areaCalcVisible=false" >取 消</el-button>
          <el-button size="mini" type="primary" @click="handleLngLat">确 定</el-button>
        </div>
  
      </el-dialog>
      
  
  </div>      
  </template>
  
  <script>
  
  import AreaCalc from "./AreaCalc";
  import {getMethodCommon,postMethodCommon } from "@/api/common"; 
  
  
  export default {
      name: "shujutianbao",
      props:["id"],
      components:{
        AreaCalc
      },
      data() {
          return {
            areaCalcVisible: false,
            dialogformVisible: true,
            ruleForm:{},
            rules:{
              shopName: [
                { required: true, message: '请输入店铺名称', trigger: 'blur' }
              ],
              name: [
                { required: true, message: '请输入店主', trigger: 'blur' }
              ],
              phone: [
                { required: true, message: '请输入联系方式', trigger: 'blur' }
              ],
            },
            mapStatus: null,
            mapLngLat:{},
            bussinessTypeOptions:[]
          }
      },
      watch: {
        id: function (e) {
          console.log('watch',e)
          this.getFormData()
        }
      },
      created() {
         this.getBussinessTypeList()
         this.getFormData()
      },
      mounted(){
          
      },
      methods: {
        close(){
          this.$emit("close")
        },
        handlerOpenMap(){
          this.areaCalcVisible = true
        },
        handleMap(e){
          this.mapStatus = e
        },
        handleLngLat(){
          if(this.mapLngLat.lng){
            this.mapStatus = 'clear'
            this.ruleForm.lng = this.mapLngLat.lng
            this.ruleForm.lat = this.mapLngLat.lat
            
          }else{
  
          }
          this.areaCalcVisible = false
        },
        backLngLat(e){
          this.mapLngLat = e
        },
        getFormData(){
          getMethodCommon("/ShopInfo/GetSingleShopInfo",{id: this.id}).then(res =>{
            this.ruleForm = res.result
          })
        },
        getBussinessTypeList(){
          this.bussinessTypeOptions = []
          getMethodCommon("/categorys/load",{TypeId: "JINGYINGXIANGMU"}).then(res =>{
            res.data.forEach(item =>{
              this.bussinessTypeOptions.push({
                value: item.dtValue,
                label: item.name
              })
            })
          })
        },
        submitBtn(formName){
          console.log('123',this.ruleForm)
          this.$refs[formName].validate((valid) => {
            if (valid) {
              this.submitClick();
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        submitClick(){
          postMethodCommon("/ShopInfo/EditShopInfo",this.ruleForm).then(res =>{
            if(res.code == 200){
              this.$emit("editSuccess");
              this.$message({
                type:"success",
                message: res.message
              })
            }
          })
        },
        
      
  
      }
  }
  </script>
  
  <style>
  .el-dialog__headerbtn{
    top: 0 !important;
  }
   
  /* 滚动条 */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
  ::-webkit-scrollbar-thumb {
    height: 50px;
    background-color: #eee;
    -webkit-border-radius: 10px;
  }
  </style>
  