const util = require('../../../utils/util.js');
Component({
  options: {
    addGlobalClass: true
  }, //使用全局css样式
  properties: {
    show: {
      type: Boolean,
      observer: function (newVal) {
        this.setData({
          show: newVal
        });
      }
    },
    aid: {
      type: String,
      observer: function (newVal) {
        this.setData({
          aid: newVal
        });
      }
    },
    checkedTime: {
      type: Number,
      observer: function (newVal) {
        console.log('checkedTime', newVal)
        this.setData({
          checkedTime: newVal
        });
      }
    },city: {
      type: String,
      observer: function (newVal) {
        console.log('city', newVal)
        this.setData({
          city: newVal
        });
      }
    },
    
  },
  data: {
    aid: '',
    show: false,
    checkedTime: 5,
    city:''
  },
  methods: {
  
    close() {
      this.triggerEvent('close')
    },
   
    sub() {
      let that = this;
      util.ajax({
        func: 'v2/article/advance/buy',
        data: {
          minuteNum: this.data.checkedTime,
          aid: this.data.aid
        },
        load: false
      }, function (res) {
        if (res.code == 0) {
          that.triggerEvent('changePrivilege', {
            time: that.data.checkedTime
          })
        } else {
          util.showTips(res.reason);
        }
      })
    }
  }
})