123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- const mixin = {
- data() {
- return {
- // 是否推荐
- recommendOptions: [{
- value: 0,
- label: '是'
- }, {
- value: 1,
- label: '否'
- }],
- // 当前状态
- statusOptions: [{
- value: 1,
- label: '上架'
- }, {
- value: 4,
- label: '下架'
- }]
- }
- }
- }
- const flowPackageMixin = {
- data() {
- return {
- // 运营商
- operatorOptions: [{
- value: 0,
- label: '移动'
- }, {
- value: 1,
- label: '联通'
- }, {
- value: 2,
- label: '双网双号'
- }]
- }
- }
- }
- const musicPackageMixin = {
- data() {
- return {
- // 资源平台
- platformOptions: [{
- value: 1,
- label: 'QQ音乐'
- }]
- }
- }
- }
- import {
- goodsList
- } from '@/api/service/musicPackage'
- const goodsMixin = {
- data() {
- return {
- // 流量套餐
- goodsOptions: []
- }
- },
- mounted() {
- goodsList().then(res => {
- if (res.code === 0) {
- this.goodsOptions = res.data
- }
- })
- },
- }
- import {
- list,
- remove,
- shelve
- } from '@/api/service/musicPackage'
- const indexMixin = {
- data() {
- return {
- // 遮罩层
- loading: false,
- // 列表
- tableData: [],
- total: 0
- }
- },
- mounted() {
- this.getList()
- },
- methods: {
- // 列表
- getList() {
- this.loading = true
- list(this.form).then(res => {
- if (res.code === 0) {
- this.tableData = res.data.records
- this.total = res.data.total
- this.loading = false
- }
- })
- },
- // 搜索
- getSearch() {
- this.form.pageNum = 1
- this.getList()
- },
- // 删除
- getDelete(row) {
- this.$confirm(`是否删除${row.name}?`, '提示', {
- 'confirmButtonText': '确定',
- 'cancelButtonText': '取消',
- type: 'warning'
- }).then(() => {
- remove(row.id).then(res => {
- if (res.code === 0) {
- this.$message.success('删除成功!')
- this.getList()
- }
- })
- }).catch(() => {})
- },
- // 下架
- getChange(row) {
- this.$confirm(`是否下架${row.name}?`, '提示', {
- 'confirmButtonText': '确定',
- 'cancelButtonText': '取消',
- type: 'warning'
- }).then(() => {
- shelve(row.id).then(res => {
- if (res.code === 0) {
- this.$message.success('下架成功!')
- this.getList()
- }
- })
- }).catch(() => {})
- },
- // 当前状态
- statusFormatter(row) {
- return this.selectDictLabel(this.statusOptions, row.status)
- },
- // 是否推荐
- recommendFormatter(row) {
- return this.selectDictLabel(this.recommendOptions, row.isRecommend)
- },
- // 关联设备
- devFormatter(row) {
- return row.deviceIds ? row.deviceIds.split(',').map(i => this.selectDictLabel(this.devOptions, i)).join(',') : ''
- },
- // 字典翻译
- sortFormatter(row) {
- return row.businessType === 5 ? row.sort : '/'
- }
- },
- }
- import {
- detail,
- edit,
- create
- } from '@/api/service/musicPackage'
- const detailMixin = {
- data() {
- let checkedPrice = (rule, value, callback) => {
- if (Number(value) > 500) {
- callback(new Error('原价不得超过500'))
- } else {
- if (this.form.discount !== undefined) {
- this.$refs.form.validateField('discount')
- }
- callback()
- }
- }
- let checkedDiscount = (rule, value, callback) => {
- if (Number(value) > Number(this.form.price)) {
- callback(new Error('活动价不得大于原价!'))
- } else {
- callback()
- }
- }
- return {
- // 关联设备
- deviceIds: [],
- // 校验
- rules: {
- price: [{
- validator: checkedPrice,
- trigger: 'blur'
- }],
- discount: [{
- validator: checkedDiscount,
- trigger: 'blur'
- }]
- },
- // 服务类型
- businessOptions: [{
- value: 0,
- label: '签到'
- }, {
- value: 1,
- label: '收听奖励'
- }, {
- value: 2,
- label: '积分抽奖'
- }, {
- value: 3,
- label: '打开手机通知'
- }, {
- value: 4,
- label: '积分兑换'
- }, {
- value: 5,
- label: '服务中心'
- }]
- }
- },
- watch: {
- deviceIds(val) {
- this.form.deviceIds = val.join(',')
- }
- },
- mounted() {
- if (this.$route.query.id) {
- this.form.id = this.$route.query.id
- this.getList()
- }
- },
- methods: {
- // 详情
- getList() {
- detail(this.form.id).then(res => {
- if (res.code === 0) {
- this.form = res.data
- this.deviceIds = res.data.deviceIds.split(',')
- }
- })
- },
- // 提交
- getSubmit() {
- this.$refs.form.validate((valid) => {
- if (valid) {
- if (this.form.id) {
- edit(this.form).then(res => {
- if (res.code === 0) {
- this.$message.success('修改成功!')
- this.cancel()
- }
- })
- } else {
- create(this.form).then(res => {
- if (res.code === 0) {
- this.$message.success('新增成功!')
- this.cancel()
- }
- })
- }
- } else {
- return false
- }
- })
- }
- }
- }
- export {
- mixin,
- flowPackageMixin,
- musicPackageMixin,
- indexMixin,
- detailMixin,
- goodsMixin
- }
|