index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 { goodsList } from '@/api/service/musicPackage'
  52. const goodsMixin = {
  53. data() {
  54. return {
  55. // 流量套餐
  56. goodsOptions: []
  57. }
  58. },
  59. mounted() {
  60. goodsList().then(res => {
  61. if (res.code === 0) {
  62. this.goodsOptions = res.data
  63. }
  64. })
  65. },
  66. }
  67. import {
  68. list,
  69. remove,
  70. shelve
  71. } from '@/api/service/musicPackage'
  72. const indexMixin = {
  73. data() {
  74. return {
  75. // 遮罩层
  76. loading: false,
  77. // 列表
  78. tableData: [],
  79. total: 0
  80. }
  81. },
  82. mounted() {
  83. this.getList()
  84. },
  85. methods: {
  86. // 列表
  87. getList() {
  88. this.loading = true
  89. list(this.form).then(res => {
  90. if (res.code === 0) {
  91. this.tableData = res.data.records
  92. this.total = res.data.total
  93. this.loading = false
  94. }
  95. })
  96. },
  97. // 搜索
  98. getSearch() {
  99. this.form.pageNum = 1
  100. this.getList()
  101. },
  102. // 删除
  103. getDelete(row) {
  104. this.$confirm(`是否删除${row.name}?`, '提示', {
  105. 'confirmButtonText': '确定',
  106. 'cancelButtonText': '取消',
  107. type: 'warning'
  108. }).then(() => {
  109. remove(row.id).then(res => {
  110. if (res.code === 0) {
  111. this.$message.success('删除成功!')
  112. this.getList()
  113. }
  114. })
  115. }).catch(() => {})
  116. },
  117. // 下架
  118. getChange(row) {
  119. this.$confirm(`是否下架${row.name}?`, '提示', {
  120. 'confirmButtonText': '确定',
  121. 'cancelButtonText': '取消',
  122. type: 'warning'
  123. }).then(() => {
  124. shelve(row.id).then(res => {
  125. if (res.code === 0) {
  126. this.$message.success('下架成功!')
  127. this.getList()
  128. }
  129. })
  130. }).catch(() => {})
  131. },
  132. // 当前状态
  133. statusFormatter(row) {
  134. return this.selectDictLabel(this.statusOptions, row.status)
  135. },
  136. // 是否推荐
  137. recommendFormatter(row) {
  138. return this.selectDictLabel(this.recommendOptions, row.isRecommend)
  139. },
  140. // 关联设备
  141. devFormatter(row) {
  142. return row.deviceIds ? row.deviceIds.split(',').map(i => this.selectDictLabel(this.devOptions, i)).join(',') : ''
  143. },
  144. },
  145. }
  146. import {
  147. detail,
  148. edit,
  149. create
  150. } from '@/api/service/musicPackage'
  151. const detailMixin = {
  152. data() {
  153. let checkedPrice = (rule, value, callback) => {
  154. if (Number(value) > 500) {
  155. callback(new Error('原价不得超过500'))
  156. } else {
  157. if (this.form.discount !== undefined) {
  158. this.$refs.form.validateField('discount')
  159. }
  160. callback()
  161. }
  162. }
  163. let checkedDiscount = (rule, value, callback) => {
  164. if (Number(value) > Number(this.form.price)) {
  165. callback(new Error('活动价不得大于原价!'))
  166. } else {
  167. callback()
  168. }
  169. }
  170. return {
  171. // 关联设备
  172. deviceIds: [],
  173. // 校验
  174. rules: {
  175. price: [{
  176. validator: checkedPrice,
  177. trigger: 'blur'
  178. }],
  179. discount: [{
  180. validator: checkedDiscount,
  181. trigger: 'blur'
  182. }]
  183. }
  184. }
  185. },
  186. watch: {
  187. deviceIds(val) {
  188. this.form.deviceIds = val.join(',')
  189. }
  190. },
  191. mounted() {
  192. if (this.$route.query.id) {
  193. this.form.id = this.$route.query.id
  194. this.getList()
  195. }
  196. },
  197. methods: {
  198. // 详情
  199. getList() {
  200. detail(this.form.id).then(res => {
  201. if (res.code === 0) {
  202. this.form = res.data
  203. this.deviceIds = res.data.deviceIds.split(',')
  204. }
  205. })
  206. },
  207. // 提交
  208. getSubmit() {
  209. this.$refs.form.validate((valid) => {
  210. if (valid) {
  211. if (this.form.id) {
  212. edit(this.form).then(res => {
  213. if (res.code === 0) {
  214. this.$message.success('修改成功!')
  215. this.cancel()
  216. }
  217. })
  218. } else {
  219. create(this.form).then(res => {
  220. if (res.code === 0) {
  221. this.$message.success('新增成功!')
  222. this.cancel()
  223. }
  224. })
  225. }
  226. } else {
  227. return false
  228. }
  229. })
  230. }
  231. }
  232. }
  233. export {
  234. mixin,
  235. flowPackageMixin,
  236. musicPackageMixin,
  237. indexMixin,
  238. detailMixin,
  239. goodsMixin
  240. }