index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. const mixin = {
  2. data() {
  3. return {
  4. // 是否推荐
  5. recommendOptions: [{
  6. value: 0,
  7. label: '是'
  8. }, {
  9. value: 1,
  10. label: '否'
  11. }],
  12. // 当前状态
  13. statusOptions: [{
  14. value: 1,
  15. label: '上架'
  16. }, {
  17. value: 4,
  18. label: '下架'
  19. }]
  20. }
  21. }
  22. }
  23. const flowPackageMixin = {
  24. data() {
  25. return {
  26. // 运营商
  27. operatorOptions: [{
  28. value: 0,
  29. label: '移动'
  30. }, {
  31. value: 1,
  32. label: '联通'
  33. }, {
  34. value: 2,
  35. label: '双网双号'
  36. }]
  37. }
  38. }
  39. }
  40. const musicPackageMixin = {
  41. data() {
  42. return {
  43. // 资源平台
  44. platformOptions: [{
  45. value: 1,
  46. label: 'QQ音乐'
  47. }]
  48. }
  49. }
  50. }
  51. import {
  52. goodsList
  53. } from '@/api/service/musicPackage'
  54. const goodsMixin = {
  55. data() {
  56. return {
  57. // 流量套餐
  58. goodsOptions: []
  59. }
  60. },
  61. mounted() {
  62. goodsList().then(res => {
  63. if (res.code === 0) {
  64. this.goodsOptions = res.data
  65. }
  66. })
  67. },
  68. }
  69. import {
  70. list,
  71. remove,
  72. shelve
  73. } from '@/api/service/musicPackage'
  74. const indexMixin = {
  75. data() {
  76. return {
  77. // 遮罩层
  78. loading: false,
  79. // 列表
  80. tableData: [],
  81. total: 0
  82. }
  83. },
  84. mounted() {
  85. this.getList()
  86. },
  87. methods: {
  88. // 列表
  89. getList() {
  90. this.loading = true
  91. list(this.form).then(res => {
  92. if (res.code === 0) {
  93. this.tableData = res.data.records
  94. this.total = res.data.total
  95. this.loading = false
  96. }
  97. })
  98. },
  99. // 搜索
  100. getSearch() {
  101. this.form.pageNum = 1
  102. this.getList()
  103. },
  104. // 删除
  105. getDelete(row) {
  106. this.$confirm(`是否删除${row.name}?`, '提示', {
  107. 'confirmButtonText': '确定',
  108. 'cancelButtonText': '取消',
  109. type: 'warning'
  110. }).then(() => {
  111. remove(row.id).then(res => {
  112. if (res.code === 0) {
  113. this.$message.success('删除成功!')
  114. this.getList()
  115. }
  116. })
  117. }).catch(() => {})
  118. },
  119. // 下架
  120. getChange(row) {
  121. this.$confirm(`是否下架${row.name}?`, '提示', {
  122. 'confirmButtonText': '确定',
  123. 'cancelButtonText': '取消',
  124. type: 'warning'
  125. }).then(() => {
  126. shelve(row.id).then(res => {
  127. if (res.code === 0) {
  128. this.$message.success('下架成功!')
  129. this.getList()
  130. }
  131. })
  132. }).catch(() => {})
  133. },
  134. // 当前状态
  135. statusFormatter(row) {
  136. return this.selectDictLabel(this.statusOptions, row.status)
  137. },
  138. // 是否推荐
  139. recommendFormatter(row) {
  140. return this.selectDictLabel(this.recommendOptions, row.isRecommend)
  141. },
  142. // 关联设备
  143. devFormatter(row) {
  144. return row.deviceIds ? row.deviceIds.split(',').map(i => this.selectDictLabel(this.devOptions, i)).join(',') : ''
  145. },
  146. // 字典翻译
  147. sortFormatter(row) {
  148. return row.businessType === 5 ? row.sort : '/'
  149. }
  150. },
  151. }
  152. import {
  153. detail,
  154. edit,
  155. create
  156. } from '@/api/service/musicPackage'
  157. const detailMixin = {
  158. data() {
  159. let checkedPrice = (rule, value, callback) => {
  160. if (Number(value) > 500) {
  161. callback(new Error('原价不得超过500'))
  162. } else {
  163. if (this.form.discount !== undefined) {
  164. this.$refs.form.validateField('discount')
  165. }
  166. callback()
  167. }
  168. }
  169. let checkedDiscount = (rule, value, callback) => {
  170. if (Number(value) > Number(this.form.price)) {
  171. callback(new Error('活动价不得大于原价!'))
  172. } else {
  173. callback()
  174. }
  175. }
  176. return {
  177. // 关联设备
  178. deviceIds: [],
  179. // 校验
  180. rules: {
  181. price: [{
  182. validator: checkedPrice,
  183. trigger: 'blur'
  184. }],
  185. discount: [{
  186. validator: checkedDiscount,
  187. trigger: 'blur'
  188. }]
  189. },
  190. // 服务类型
  191. businessOptions: [{
  192. value: 0,
  193. label: '签到'
  194. }, {
  195. value: 1,
  196. label: '收听奖励'
  197. }, {
  198. value: 2,
  199. label: '积分抽奖'
  200. }, {
  201. value: 3,
  202. label: '打开手机通知'
  203. }, {
  204. value: 4,
  205. label: '积分兑换'
  206. }, {
  207. value: 5,
  208. label: '服务中心'
  209. }]
  210. }
  211. },
  212. watch: {
  213. deviceIds(val) {
  214. this.form.deviceIds = val.join(',')
  215. }
  216. },
  217. mounted() {
  218. if (this.$route.query.id) {
  219. this.form.id = this.$route.query.id
  220. this.getList()
  221. }
  222. },
  223. methods: {
  224. // 详情
  225. getList() {
  226. detail(this.form.id).then(res => {
  227. if (res.code === 0) {
  228. this.form = res.data
  229. this.deviceIds = res.data.deviceIds.split(',')
  230. }
  231. })
  232. },
  233. // 提交
  234. getSubmit() {
  235. this.$refs.form.validate((valid) => {
  236. if (valid) {
  237. if (this.form.id) {
  238. edit(this.form).then(res => {
  239. if (res.code === 0) {
  240. this.$message.success('修改成功!')
  241. this.cancel()
  242. }
  243. })
  244. } else {
  245. create(this.form).then(res => {
  246. if (res.code === 0) {
  247. this.$message.success('新增成功!')
  248. this.cancel()
  249. }
  250. })
  251. }
  252. } else {
  253. return false
  254. }
  255. })
  256. }
  257. }
  258. }
  259. export {
  260. mixin,
  261. flowPackageMixin,
  262. musicPackageMixin,
  263. indexMixin,
  264. detailMixin,
  265. goodsMixin
  266. }