import {
  getClientTypeList
} from '@/api/device/version'

import {
  platform,
  audioType
} from '@/api/music/platform'

import {
  options
} from '@/api/music/radio'

import {
  channelTemplate
} from '@/api/operation/channel'

// 设备列表
const devMixin = {
  data() {
    return {
      devOptions: []
    }
  },
  mounted() {
    getClientTypeList(this.types ? { types: this.types } : {}).then(res => {
      if (res.code === 0) {
        res.data.map(i => {
          this.devOptions.push({
            value: i.clientTypeId,
            label: i.name
          })
        })
      }
    })
  }
}

// 设备模式
const devTypeMixin = {
  data() {
    return {
      typeOptions: [{
        value: 1,
        label: '蓝牙'
      }, {
        value: 2,
        label: 'WIFI'
      }, {
        value: 3,
        label: '传统蓝牙'
      }, {
        value: 4,
        label: '4G'
      }]
    }
  }
}

// 服务时长
const serviceTimeMixin = {
  data() {
    return {
      serviceTimeOptions: [{
        value: -1,
        label: '1天'
      }, {
        value: 1,
        label: '7天'
      }, {
        value: 2,
        label: '14天'
      }, {
        value: 3,
        label: '1个月'
      }, {
        value: 4,
        label: '3个月'
      }, {
        value: 5,
        label: '6个月'
      }, {
        value: 6,
        label: '1年'
      }, {
        value: 7,
        label: '2年'
      }, {
        value: 8,
        label: '3年'
      }, {
        value: 9,
        label: '5年'
      }, {
        value: 0,
        label: '永久'
      }]
    }
  }
}

const serviceTypeMixin = {
  data() {
    return {
      // 服务类型
      serviceTypeOptions: [{
        value: 0,
        label: '签到'
      }, {
        value: 1,
        label: '收听奖励'
      }, {
        value: 2,
        label: '积分抽奖'
      }, {
        value: 3,
        label: '打开手机通知'
      }, {
        value: 4,
        label: '积分兑换'
      }, {
        value: 5,
        label: '会员中心'
      }],
    }
  }
}

// 是否免费
const isFreeMixin = {
  data() {
    return {
      freeOptions: [{
        value: 0,
        label: '付费'
      }, {
        value: 1,
        label: '免费'
      }]
    }
  }
}

// 音频类型
const audioMixin = {
  data() {
    return {
      audioOptions: [{
        value: 2,
        label: '广播电台'
      }, {
        value: 6,
        label: '节目'
      }, {
        value: 8,
        label: '播客专辑'
      }, {
        value: 9,
        label: '歌手'
      }, {
        value: 10,
        label: '歌单'
      }, {
        value: 11,
        label: '歌曲'
      }, {
        value: 12,
        label: '主播'
      }, {
        value: 15,
        label: '音乐专辑'
      }],
      audioTypeOptions: []
    }
  },
  methods: {
    // 通过平台获取对应的音频类型
    getAudioType(e) {
      return new Promise((resolve, reject) => {
        platform(e).then(res => {
          if (res.code === 0) {
            resolve(this.audioTypeOptions = res.data[0].audioType.split(',').map(i => this.audioOptions.find(j => j.value == i)))
          }
        })
      }).catch(err => {
        reject()
      })
    }
  }
}

// 性别
const sexMixin = {
  data() {
    return {
      sexOptions: [{
        value: 0,
        label: '男'
      }, {
        value: 1,
        label: '女'
      }, {
        value: 2,
        label: '未知'
      }]
    }
  }
}

// 所属地区
const regionMixin = {
  data() {
    return {
      regionOptions: [{
        value: 0,
        label: '内地'
      }, {
        value: 1,
        label: '港台'
      }, {
        value: 2,
        label: '欧美'
      }, {
        value: 3,
        label: '日本'
      }, {
        value: 4,
        label: '韩国'
      }, {
        value: 5,
        label: '其他'
      }]
    }
  }
}

// 语种
const languageMixin = {
  data() {
    return {
      languageOptions: [{
        value: 1,
        label: '国语'
      }, {
        value: 2,
        label: '欧美'
      }, {
        value: 3,
        label: '粤语'
      }, {
        value: 4,
        label: '韩语'
      }, {
        value: 5,
        label: '日语'
      }, {
        value: 6,
        label: '其他'
      }]
    }
  }
}

// 所属平台
const platformMixin = {
  data() {
    return {
      platformTypeOptions: [],
      platformOptions: [],
    }
  },
  methods: {
    // 通过音频类型获取对应的平台
    getPlatform(e) {
      this.platformOptions = []
      return new Promise((resolve, reject) => {
        audioType(e).then(res => {
          if (res.code === 0) {
            res.data.map(i => this.platformOptions.push({
              value: Number(i.id),
              label: i.name,
              joinType: i.joinType
            }))
            e ? this.platformTypeOptions = this.platformOptions : ''
            resolve(this.platformOptions, this.platformTypeOptions)
          }
        }).catch(err => {
          reject()
        })
      })
    },

    // 第三方资源平台不可编辑
    disabledPlatformId(e) {
      let value = this.platformOptions.find(i => i.value == e)
      if (value) {
        return value.joinType.includes('1') ? true : false
      }
    },

    // 禁止选择第三方平台
    disabledJoinType(e) {
      return e.split(',').includes('1')
    }
  }
}

// 上下架状态
const onOrOffMixin = {
  data() {
    return {
      onOrOffOptions: [{
        value: 1,
        label: '上架'
      }, {
        value: 2,
        label: '下架'
      }]
    }
  }
}

// 上下架状态
const disabledMixin = {
  data() {
    return {
      disabledOptions: [{
        value: 0,
        label: '上架'
      }, {
        value: 1,
        label: '下架'
      }]
    }
  }
}

// 付费类型
const payTypeMixin = {
  data() {
    return {
      payTypeOptions: [{
        value: 1,
        label: '免费'
      }, {
        value: 2,
        label: '全集购买'
      }, {
        value: 3,
        label: '单集购买'
      }, {
        value: 4,
        label: 'Vip专享'
      }, {
        value: 5,
        label: '亲子付费'
      }]
    }
  }
}

// 专辑类型
const albumTypeMixin = {
  data() {
    return {
      albumTypeOptions: [{
        value: 1,
        label: 'Single'
      }, {
        value: 2,
        label: 'EP'
      }, {
        value: 3,
        label: 'Album'
      }, {
        value: 4,
        label: '古典专辑'
      }, {
        value: 5,
        label: '自制专辑'
      }]
    }
  }
}

// 地域分类
const addressMixin = {
  data() {
    return {
      addressOptions: []
    }
  },
  mounted() {
    this.getAddress()
  },
  methods: {
    getAddress() {
      options(2).then(res => {
        if (res.code === 0) {
          res.data.map(i => {
            this.addressOptions.push({
              value: i.id,
              label: i.name
            })
          })
        }
      })
    }
  }
}

// 内容分类
const contentMixin = {
  data() {
    return {
      contentOptions: []
    }
  },
  mounted() {
    this.getContent()
  },
  methods: {
    getContent() {
      options(1).then(res => {
        if (res.code === 0) {
          res.data.map(i => {
            this.contentOptions.push({
              value: i.id,
              label: i.name
            })
          })
        }
      })
    }
  }
}

// 奖励类型
const rewardMixin = {
  data() {
    return {
      rewardOptions: [{
        //   value: 0,
        //   label: '音乐套餐'
        // }, {
        //   value: 1,
        //   label: '流量套餐'
        // }, {
        //   value: 2,
        //   label: '亲子礼包'
        // }, {
        //   value: 3,
        //   label: '音响实物'
        // }, {
        //   value: 4,
        //   label: '积分'
        // },{
        //   value: 5,
        //   label: '谢谢惠顾'
      }]
    }
  }
}

// 分类
const classifyMixin = {
  data() {
    return {
      classifyOptions: []
    }
  },
  methods: {
    getClassify(e) {
      channelTemplate({
        audioType: e
      }).then(res => {
        if (res.code === 0) {
          res.data.map(i => {
            this.classifyOptions.push({
              value: i.id,
              label: i.name
            })
          })
        }
      })
    }
  }
}

// 时效性
const currentMixin = {
  data() {
    return {
      currentOptions: [{
        value: 0,
        label: '已生效'
      }, {
        value: 1,
        label: '待生效'
      }, {
        value: 2,
        label: '已失效'
      }]
    }
  }
}

// 封面类型
const coverMixin = {
  data() {
    return {
      coverOptions: [{
        value: 0,
        label: '自定义封面'
      }, {
        value: 1,
        label: '内容封面'
      }]
    }
  }
}

// 通过频道属性查找音频类型
const channelMixin = {
  data() {
    return {
      channelOptions: {
        2: [{
          value: 2,
          label: '广播电台'
        }],
        6: [{
          value: 6,
          label: '节目'
        }, {
          value: 11,
          label: '歌曲'
        }],
        8: [{
          value: 8,
          label: '播客专辑'
        }, {
          value: 10,
          label: '歌单'
        }, {
          value: 15,
          label: '音乐专辑'
        }],
        16: [{
          value: 8,
          label: '播客专辑'
        }],
        17: [{
          value: 2,
          label: '广播电台'
        }]
      }
    }
  }
}

// 手机系统
const systemMixin = {
  data() {
    return {
      systemOptions: [{
        value: 1,
        label: 'Android'
      }, {
        value: 2,
        label: 'iOS'
      }]
    }
  }
}

export {
  devMixin,
  devTypeMixin,
  serviceTimeMixin,
  serviceTypeMixin,
  isFreeMixin,
  audioMixin,
  sexMixin,
  regionMixin,
  languageMixin,
  platformMixin,
  onOrOffMixin,
  disabledMixin,
  payTypeMixin,
  albumTypeMixin,
  addressMixin,
  contentMixin,
  rewardMixin,
  classifyMixin,
  currentMixin,
  coverMixin,
  channelMixin,
  systemMixin
}
