var lib = new DirewolfLibrary()
// eslint-disable-next-line no-new
new window.Vue({
  el: '#app',
  data: function () {
    return {
      /**
       * 微服务配置
       */
      msConfig: window.__CONTRACT_CONFIG__,
      formLoading: true,
      /**
       * 实体对象数据
       */
      entity: {
        /**
         * 主键
         */
        id: lib.$$utils.getQueryString('id') || '',
        /**
         * 操作日期
         */
        operTime: '',
        /**
         * 操作日期区间，格式参考['2018-10-01', '2018-10-30']
         */
        operTimeRange: [],
        /**
         * 操作人员账号
         */
        operPerAccount: '',
        /**
         * 操作模块
         */
        operModule: '',
        /**
         * 操作动作
         */
        operAction: '',
        /**
         * 运维人员
         */
        operMaintenPer: '',
        /**
         * URL
         */
        operUrl: '',
        /**
         * 合同编号
         */
        operContractCode: '',
        /**
         * 采购申请号
         */
        operPurchaseApplyCode: '',
        /**
         * 订单编号
         */
        operOrderCode: '',
        /**
         * 提交次数
         */
        operSubmitCount: null,
        /**
         * 备注
         */
        operRemark: '',
      },
      /**
       * 页面编辑类型，控制页面组件是否可用
       */
      editType: lib.$$utils.getQueryString('editType'),
      /**
       * 校验规则，对应页面el-form-item的prop属性值
       */
      rules: {
        operTime: [
        ],
        operPerAccount: [
          { max: 60, message: '长度不能超过 60 个字符', trigger: 'change' },
        ],
        operModule: [
          { max: 100, message: '长度不能超过 100 个字符', trigger: 'change' },
        ],
        operAction: [
          { max: 100, message: '长度不能超过 100 个字符', trigger: 'change' },
        ],
        operMaintenPer: [
          { max: 50, message: '长度不能超过 50 个字符', trigger: 'change' },
        ],
        operUrl: [
          { max: 500, message: '长度不能超过 500 个字符', trigger: 'change' },
        ],
        operContractCode: [
          { max: 1000, message: '长度不能超过 1000 个字符', trigger: 'change' },
        ],
        operPurchaseApplyCode: [
          { max: 3000, message: '长度不能超过 3000 个字符', trigger: 'change' },
        ],
        operOrderCode: [
          { max: 1000, message: '长度不能超过 1000 个字符', trigger: 'change' },
        ],
        operSubmitCount: [
          { validator: lib.$$utils.validator.checkNumber, max: 10, precision: 0, name: '提交次数', trigger: 'change' },
        ],
      },
    }
  },
  computed: {
    /**
     * 页面是否处于查看模式
     */
    inViewMode: function () {
      return this.editType === 'view'
    },
    /**
     * 页面请求前缀
     */
    urlPrefix: function () {
      return this.msConfig['gatewayRoute'] + this.msConfig['direwolfAdmin'] + '/contract/common/tOperatingLog'
    },
  },
  methods: {
    /**
     * 初始化表单数据
     */
    initFormData: function () {
      var vm = this
      var pkValue = vm.entity.id
      if (pkValue) {
        vm.$$utils.axiosRequest(vm.urlPrefix + '/getEntity?id=' + pkValue,
          '获取日志信息信息')
          .then(function (result) {
            vm.formLoading = false
            vm.entity = result.data
          })
      } else {
        vm.formLoading = false
      }
    },
    /**
     * 保存数据
     *
     * @param {function} success 成功回调
     */
    save (success) {
      this.$$utils.eleFormSubmit({
        vueIns: this,
        saveUrl: this.urlPrefix + '/save',
        formRef: 'tOperatingLogForm',
        info: '保存日志信息',
        success,
      })
    },
  },
  created: function () {
    var vm = this
    vm.$$utils.permission.checkPagePermission(vm.urlPrefix + '/checkTOperatingLogFormPermission')
      .then(function (hasPermission) {
        vm.initFormData()
      })
  },
})
