import { checkString } from '@/views/book/courseware/data/common';

import SerailNumber from '@/views/book/courseware/create/components/common/SerialNumber.vue';

const mixin = {
  data() {
    return {
      param: {}, // 组件设置时传过来的特有参数
      checkString,
    };
  },
  components: {
    SerailNumber,
  },
  watch: {
    'property.serial_number': {
      handler(val) {
        this.property.sn_type = checkString(val); // 序号与序号类型需保持匹配
      },
    },
  },
  provide() {
    return {
      updateProperty: this.updateProperty,
    };
  },
  methods: {
    /**
     * @description 设置属性
     * @param {object} property 属性
     * @param {object} param 参数
     */
    setSetting(property, param) {
      this.property = property;
      this.param = param;
    },
    /**
     * @description 更新属性
     * @param {string} key
     * @param {string|number} value
     */
    updateProperty(key, value) {
      this.property[key] = value;
    },
  },
};

export default mixin;
