import './list.scss'

export default {
  name: 'FeatureList',
  components: {},
  data () {
    return {
      miniPageList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      }
    }
  },
  computed: {},
  mounted () {
    // 获取微页面列表
    this.getMiniPagesList()
  },
  // activated () {
  //   // 获取微页面列表
  //   this.getMiniPagesList()
  // },
  methods: {
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getMiniPagesList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getMiniPagesList()
    },
    /**
     * 获取微页面列表
     */
    getMiniPagesList () {
      if (this.pageIndex) {
        let size = Math.ceil(this.totalPage / this.pageSize)
        this.pageIndex = (this.pageIndex > size ? size : this.pageIndex) || 1
      }
      this.$http({
        url: this.$http.adornUrl('/shop/shopRenovation/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: this.pageIndex,
              size: this.pageSize
            }
          )
        )
      }).then(({ data }) => {
        this.miniPageList = data.records
        this.totalPage = data.total
      }).catch((error) => {
        console.log('err', error)
      })
    },
    /** 跳转编辑页面 */
    goCreatePage () {
      this.$router.push({
        path: '/shop-feature/create/edit/index'
      })
    },
    /** 点击编辑 */
    handleEdit (item) {
      this.$router.push({
        path: '/shop-feature/create/edit/index',
        query: {
          renovationId: item.renovationId,
          type: 'edit'
        }
      })
    },
    /** 点击删除 */
    handleDelete (item) {
      let ids = item ? [item] : this.dataListSelections.map(item => {
        return item.renovationId
      })
      this.$confirm(this.$i18n.t('shopFeature.list.deleteTips'), this.$i18n.t('shopFeature.list.tips'), {
        confirmButtonText: this.$i18n.t('shopFeature.edit.confirm'),
        cancelButtonText: this.$i18n.t('shopFeature.edit.cancel'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/shop/shopRenovation/' + item.renovationId),
          method: 'delete'
        }).then(({ data }) => {
          this.totalPage = this.totalPage - ids.length
          this.$newMessage.success(this.$i18n.t('shopFeature.list.deleteSuccess'))
          this.getMiniPagesList()
        }).catch((error) => {
          console.log('err', error)
        })
      }).catch(() => {

      })
    },

    /**
     * 设置主页
     */
    handleSetHomePage (renovationId) {
      this.$http({
        url: this.$http.adornUrl('/shop/shopRenovation/updateHomePage/' + renovationId),
        method: 'put'
      }).then(({ data }) => {
        console.warn(data)
        this.$newMessage.success(this.$i18n.t('shopFeature.list.operSuccess'))
        this.getMiniPagesList()
      }).catch((error) => {
        console.log('err', error)
      })
    }
  }
}
