import moment from "moment";

/**
 * 基本CRUD视图功能
 */
export default {
  computed: {
    sysCode() {
      return this.$store.state.base.sysCode;
    }
  },
  methods: {
    /**
     * 时间列格式化
     */
    formatterDate(row, column, cellValue) {
      return cellValue ? moment(cellValue).format("LL") : null;
    },
    formatterDateTime(row, column, cellValue) {
      return cellValue ? moment(cellValue).format("LL LTS") : null;
    },
    simpleFormatterDate(cellValue, defaultValue = null) {
      return cellValue ? moment(cellValue).format("LL LTS") : defaultValue;
    },

    /**
     * 使用确认框
     */
    confirm(data, txt = "您确定要这样做么?") {
      return this.$confirm(txt, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => data);
    },

    addView(name, path, propsData) {
      let idx = this.$tabView.viewList.findIndex(item => item.name === name);
      if (idx === -1) this.$tabView.viewList.push({name, path, propsData});
      this.$tabView.active = name;
    },
    removeView(name) {
      let idx = this.$tabView.viewList.findIndex(item => item.name === name);
      if (idx > -1) {
        this.$tabView.active = this.$tabView.viewList[idx - 1].name;
        this.$tabView.viewList.splice(idx, 1);
      }
    }
  }
};
