<template>
  <div class="select-goodsClass">
    <el-cascader
      v-if="!loading"
      :size="size || 'medium'"
      style="width: 100%"
      filterable
      clearable
      v-model="value"
      :placeholder="placeholder || ''"
      :props="props"
      :disabled="disabled"
      @change="handleChange"
    ></el-cascader>
  </div>
</template>

<script>
import asyncRequest from "./http";
import resToken from "@/mixins/resToken";
export default {
  name: "goodClass",
  mixins: [resToken],
  props: ["size", "value", "placeholder", "isDetail", "disabled"],
  /**
   * 属性集合
   * @param {String}        size             : 组件大小            非必填
   * @param {Array}         value            : 选中值              必填
   * @param {String}        placeholder      : 提示信息            非必填
   * @param {Boolean}       isDetail         : 是否是详情逻辑       必填
   * @param {Boolean}       disabled         : 是否禁用            必填
   */
  /**
   * 事件集合
   * @searchChange             : 选中值变化调用   抛出选中数据
   */
  data() {
    return {
      loading: false,
      props: {
        checkStrictly: true,
        expandTrigger: "hover",
        lazy: true, //开启远程加载
        async lazyLoad(node, resolve) {
          // console.log(node);
          const { level, value, root, loading } = node;
          let model = {
            cat_name: "",
            pid: "",
            status: "",
          };
          let list = [];
          if (level === 0) {
            model.pid = "0";
          } else {
            model.pid = value;
          }
          const { code, data } = await asyncRequest.list(model);
          // const { code, data } = await this.useResHandle(res);
          if (code === 0) {
            data.forEach((v1) => {
              const province = {
                value: v1.id,
                label: v1.cat_name,
                leaf: level >= 2,
                desc: v1.cat_desc,
              };
              list.push(province);
            });
            resolve(list);
          } else {
            resolve([]);
          }
        },
      },
    };
  },
  // watch: {
  //   // value: function (val, old) {
  //   //   if (val) {
  //   //     this.loading = true;
  //   //     setTimeout(() => {
  //   //       this.loading = false;
  //   //     }, 10);
  //   //   }
  //   // },
  // },
  mounted() {
    this.options = [];
    this.selectLoading = false;
  },
  methods: {
    async handleChange(value) {
      this.$emit("handleChange", value);
    },
  },
};
</script>

<style lang="scss" scoped>
.select-goodsClass {
  .loading-input {
    background-color: transparent;
    border: 1px solid #dfe4ed;
    color: #c0c4cc;
    width: 100%;
    height: 36px;
    line-height: 36px;
    padding: 0 30px 0 12px;
    border-radius: 4px;
    &.disabled {
      background-color: #f5f7fa;
    }
    span {
      font-size: 16px;
      height: 36px;
      line-height: 36px;
      padding: 0 0 0 3px;
      vertical-align: top;
    }
  }
}
</style>
