VirtualGoodsConfig.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div class="virtual-goods-config admin-page">
  3. <el-card>
  4. <PageHeader slot="header" title="虚拟支付道具">
  5. <el-select v-model="filterGoodsType" placeholder="道具类型" size="small" clearable style="width: 150px;" @change="loadData">
  6. <el-option label="测评套餐" value="ASSESSMENT_PACKAGE" />
  7. <el-option label="会员" value="MEMBERSHIP" />
  8. <el-option label="订阅" value="SUBSCRIPTION" />
  9. </el-select>
  10. <el-select v-model="filterStatus" placeholder="状态" size="small" clearable style="width: 110px;">
  11. <el-option label="启用" value="1" />
  12. <el-option label="停用" value="0" />
  13. </el-select>
  14. <el-button type="primary" size="small" @click="handleCreate">+ 新增道具</el-button>
  15. </PageHeader>
  16. <div class="adm-table-wrap">
  17. <el-table height="100%" :data="filteredList" v-loading="loading" border stripe>
  18. <el-table-column prop="id" label="ID" width="70" />
  19. <el-table-column label="道具类型" width="120">
  20. <template slot-scope="{ row }">
  21. <StatusTag :type="row.goodsType === 'ASSESSMENT_PACKAGE' ? 'primary' : (row.goodsType === 'MEMBERSHIP' ? 'success' : 'warning')" :text="goodsTypeText(row.goodsType)" />
  22. </template>
  23. </el-table-column>
  24. <el-table-column prop="bizKey" label="业务SKU" min-width="120" />
  25. <el-table-column prop="productId" label="道具ID" min-width="140" />
  26. <el-table-column prop="goodsName" label="道具名称" min-width="140" />
  27. <el-table-column label="状态" width="90">
  28. <template slot-scope="{ row }">
  29. <el-switch :value="row.status === 1" disabled />
  30. </template>
  31. </el-table-column>
  32. <el-table-column prop="createTime" label="创建时间" width="170" />
  33. <el-table-column prop="updateTime" label="更新时间" width="170" />
  34. <el-table-column label="操作" width="180" fixed="right">
  35. <template slot-scope="{ row }">
  36. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  37. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  38. <el-button size="mini">
  39. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  40. </el-button>
  41. <el-dropdown-menu slot="dropdown">
  42. <el-dropdown-item command="delete" icon="el-icon-delete">删除</el-dropdown-item>
  43. </el-dropdown-menu>
  44. </el-dropdown>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. </div>
  49. </el-card>
  50. <el-dialog :visible.sync="dialogVisible" :title="isEdit ? '编辑道具' : '新增道具'" width="480px" :close-on-click-modal="false">
  51. <el-form :model="form" label-width="90px">
  52. <el-form-item label="道具类型">
  53. <el-select v-model="form.goodsType" placeholder="选择道具类型" style="width: 220px;">
  54. <el-option label="测评套餐" value="ASSESSMENT_PACKAGE" />
  55. <el-option label="会员" value="MEMBERSHIP" />
  56. <el-option label="订阅" value="SUBSCRIPTION" />
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item label="业务SKU">
  60. <el-input v-model="form.bizKey" placeholder="请输入业务SKU标识" />
  61. </el-form-item>
  62. <el-form-item label="道具ID">
  63. <el-input v-model="form.productId" placeholder="请输入道具ID" />
  64. <div style="color: var(--adm-text-45);font-size:12px;line-height:1.5;margin-top:4px;">需与微信商户后台道具 ID 一致;上线前必须配置</div>
  65. </el-form-item>
  66. <el-form-item label="道具名称">
  67. <el-input v-model="form.goodsName" placeholder="请输入道具名称" />
  68. </el-form-item>
  69. <el-form-item label="状态">
  70. <el-switch v-model="form.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" />
  71. </el-form-item>
  72. </el-form>
  73. <div slot="footer">
  74. <el-button @click="dialogVisible = false">取消</el-button>
  75. <el-button type="primary" @click="handleSubmit" :loading="submitting">保存</el-button>
  76. </div>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. import { getVirtualGoodsList, saveVirtualGoods, deleteVirtualGoods } from '@/api/virtualGoods.js'
  82. export default {
  83. name: 'VirtualGoodsConfig',
  84. data() {
  85. return {
  86. loading: false,
  87. submitting: false,
  88. list: [],
  89. filterGoodsType: '',
  90. filterStatus: '',
  91. dialogVisible: false,
  92. isEdit: false,
  93. form: {
  94. id: null,
  95. goodsType: '',
  96. bizKey: '',
  97. productId: '',
  98. goodsName: '',
  99. status: 1
  100. }
  101. }
  102. },
  103. computed: {
  104. tableHeight() {
  105. return window.innerHeight - 300
  106. },
  107. filteredList() {
  108. if (this.filterStatus === '' || this.filterStatus === null || this.filterStatus === undefined) return this.list
  109. var target = Number(this.filterStatus)
  110. return this.list.filter(function(item) { return item.status === target })
  111. }
  112. },
  113. created() {
  114. this.loadData()
  115. },
  116. methods: {
  117. goodsTypeText(type) {
  118. if (type === 'ASSESSMENT_PACKAGE') return '测评套餐'
  119. if (type === 'MEMBERSHIP') return '会员'
  120. if (type === 'SUBSCRIPTION') return '订阅'
  121. return type || '-'
  122. },
  123. async loadData() {
  124. this.loading = true
  125. try {
  126. var params = this.filterGoodsType ? { goodsType: this.filterGoodsType } : {}
  127. var res = await getVirtualGoodsList(params)
  128. if (res.data) {
  129. this.list = res.data
  130. }
  131. } catch (e) {
  132. this.$message.error('加载道具列表失败')
  133. } finally {
  134. this.loading = false
  135. }
  136. },
  137. handleCreate() {
  138. this.isEdit = false
  139. this.form = { id: null, goodsType: '', bizKey: '', productId: '', goodsName: '', status: 1 }
  140. this.dialogVisible = true
  141. },
  142. handleEdit(row) {
  143. this.isEdit = true
  144. this.form = { id: row.id, goodsType: row.goodsType, bizKey: row.bizKey, productId: row.productId, goodsName: row.goodsName, status: row.status }
  145. this.dialogVisible = true
  146. },
  147. async handleSubmit() {
  148. if (!this.form.goodsType) {
  149. this.$message.warning('请选择道具类型')
  150. return
  151. }
  152. if (!this.form.bizKey || !this.form.bizKey.trim()) {
  153. this.$message.warning('请输入业务SKU')
  154. return
  155. }
  156. if (!this.form.productId || !this.form.productId.trim()) {
  157. this.$message.warning('请输入道具ID')
  158. return
  159. }
  160. if (!this.form.goodsName || !this.form.goodsName.trim()) {
  161. this.$message.warning('请输入道具名称')
  162. return
  163. }
  164. this.submitting = true
  165. try {
  166. await saveVirtualGoods(this.form)
  167. this.$message.success('保存成功')
  168. this.dialogVisible = false
  169. this.loadData()
  170. } catch (e) {
  171. this.$message.error(e.message || '保存失败')
  172. } finally {
  173. this.submitting = false
  174. }
  175. },
  176. async handleDelete(row) {
  177. this.$confirm('确定删除道具「' + row.goodsName + '」吗?', '提示', {
  178. confirmButtonText: '确定',
  179. cancelButtonText: '取消',
  180. type: 'warning'
  181. }).then(async () => {
  182. try {
  183. await deleteVirtualGoods({ id: row.id })
  184. this.$message.success('删除成功')
  185. this.loadData()
  186. } catch (e) {
  187. this.$message.error(e.message || '删除失败')
  188. }
  189. }).catch(() => {})
  190. },
  191. handleActionCmd(row, cmd) {
  192. switch (cmd) {
  193. case 'delete':
  194. this.handleDelete(row)
  195. break
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style scoped>
  202. .virtual-goods-config {
  203. padding: 20px;
  204. }
  205. </style>