import { formInit } from '../const'

export const DetailMixins = {
  data() {
    return {
      form: {},
      flag: true,
      formFunc: null,
      isOpenSelect: [{
        key: 0,
        label: "未开通"
      },
      {
        key: 1,
        label: "已开通"
      }],
    }
  },
  watch: {
    type: {
      immediate: true,
      handler(newV) {
        this.formFunc = formInit(newV)
      },
    },
    curInfo: {
      immediate: true,
      handler(newV) {
        this.form = this.formFunc(newV)
      },
    },
  },
  props: {
    curInfo: {
      type: Object,
      default: () => { },
    },
    type: {
      type: Number,
      defualt: null,
    },
  },
  computed: {
    statusList() {
      if (this.form.status) {


        for (let i = 0; i < this.form.status.length; i++) {
          if (i % 2 != 0) {

            this.form.status[i].value = this.dateFormat(this.form.status[i].value, 'yyyy-MM-dd HH:mm:ss')

          }
        }
        return this.form.status
      }
    }
  },
  methods: {
    info() {
      let params = {
        id: this.form.baseInfo.id,
        isOpen: this.form.baseInfo.isOpen
      }
      return params
    },
    editbtn() {
      this.flag = false
    },
    dateFormat(date, format) {
      date = new Date(date);
      var o = {
        'M+': date.getMonth() + 1, //month
        'd+': date.getDate(), //day
        'H+': date.getHours(), //hour
        'm+': date.getMinutes(), //minute
        's+': date.getSeconds(), //second
        'S': date.getMilliseconds() //millisecond
      };
      if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));

      for (var k in o)
        if (new RegExp('(' + k + ')').test(format))
          format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));

      return format;
    }
  },
}
