<template>
  <div>
    <el-form ref="form" :rules="rules"  :model="form" label-width="120px">
      <el-form-item
          label="站点名称："
          prop="website_name"
      >
        <el-input v-model="form.website_name"  placeholder="请输入站点名称"></el-input>
      </el-form-item>
      <el-form-item
          label="父级栏目："
          prop="website_column_id"
      >
      <el-cascader
      v-model="form.website_column_id"
      :options="websiteColumnList"
      :props="{
                value:'id',
                label:'column_name',
                children:'children',
              }" 
      clearable></el-cascader>
    </el-form-item>
    <el-form-item
          label="选择城市："
          prop="city_id"
      >
      <el-cascader
          :key="cascaderKey"
          v-model="form.city_id"
          placeholder="选择您要绑定的城市"
          :props="cityData"
          filterable
          clearable
        ></el-cascader>

    </el-form-item>
      <el-form-item label="站点logo：" prop="logo">
        <el-input v-model="form.logo"  placeholder="请输入站点logo" ></el-input>
      </el-form-item>
      <el-form-item label="站点地址：" prop="website_url">
        <el-input v-model="form.website_url"  placeholder="请输入站点地址" ></el-input>
      </el-form-item>
      <el-form-item label="站点标题" prop="title">
        <el-input v-model="form.title"  placeholder="请输入站点标题" ></el-input>
      </el-form-item>
      <el-form-item label="站点关键字" prop="keywords">
        <el-input v-model="form.keywords"  placeholder="请输入站点关键字" ></el-input>
      </el-form-item>
      <el-form-item label="站点描述" prop="description">
        <el-input v-model="form.description"  placeholder="请输入站点描述" ></el-input>
      </el-form-item>
      <el-form-item label="站点状态：" prop="status">
        <el-switch
            v-model="form.status"
            :active-value="1"
            :inactive-value="0"
        >
        </el-switch>
      </el-form-item>
    
      <el-form-item>
        <div style="text-align: center">
          <el-button type="primary" @click="onSubmit" :disabled="Isdisabled" :loading="isloading">保存</el-button>
          <el-button style="color: #5075FC " @click="closeDlg">取消</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  props: {
    websiteDataForm: {
      type: Object,
      default: () => {}
    },
    isloading:{
      type:Boolean,
      default: true
    },
    closeDlg:{
      type:Function
    }
  },
  data() {
    let self = this
    return {
      areaSupplier:[],
      websiteColumnList:[],
      cascaderKey:0,
      cityData: {
        checkStrictly: true,
        lazy: true,
        async lazyLoad (node, resolve) {
          const { level, data } = node;  // 取出当前层级和选择数据
          if (data && data.children && data.children.length !== 0) { // 提前加载数据切换后再点击回数据重复
            return resolve(node)
          }
          console.log(level)
          let parentId = level == 0 ? 0 : data.value
          let parames = {
            'pid':parentId
          }
          let res = await self.$api.publicApi.cityList(parames)
          if (res.data) {
            const nodes = res.data.map(item => ({
              value: item.id,
              label: item.name,
              leaf: level >= 3,
              children: []
            }))
            resolve(nodes)
          }
        }
      },
      form: {
        id:'',
        website_name: '',
        website_column_id:[0],
        logo:"",
        website_url:"",
        city_id:[0],
        title:"",
        description:"",
        status:"",
        title:'',
        keywords:'',
        description:''
      },
      menulist: [],
      Isdisabled: false,
      rules: {
        website_name: [
          { required: true, message: '站点名称必填' },
        ],
        website_column_id: [
          { required: true, message: '请选择栏目' }
        ]
        ,
        website_url: [
          { required: true, message: '网站地址必填' }
        ]
      }
    }
  },
  mounted() {
    if(this.websiteDataForm) {
      this.form = Object.assign({} , this.websiteDataForm)
      this.form.city_id =  this.websiteDataForm.city_arr_id
      console.log("城市信息：",this.form.city_id)
    }

    this.getWebsiteColumnList()
  },
  methods: {
    closeDlg() {
      // this.isloading = false
      console.log("edit提交")
      this.$emit('closeDlg',1)
    },
    onSubmit() {
      let that = this
      that.$refs['form'].validate((valid) => {
        if (valid) {
          this.$emit('websiteSubmitClick', this.form)
        }
      })
    },
    getWebsiteColumnList(){
      let _t= this
      let parames = {}
     this.$api.website.websiteColumnList(parames).then(res=>{
                if(res.code==200){
                   console.log(res.data)
                  _t.websiteColumnList = res.data
                }else{
                    this.$message.error("查询失败")
                }
            })
    },

    
  }
}
</script>
<style>
.el-cascader-node>.el-radio{
  margin-top:25px;
}
</style>
