ChallengeScoreConfig.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="challenge-score-config admin-page">
  3. <PageHeader title="挑战评分配置" subtitle="家庭挑战 发起/同意/拒绝 的方向性关系评分与能量增减(可正可负)" />
  4. <div class="adm-table-wrap">
  5. <el-table :data="matrix" v-loading="loading" border stripe height="100%">
  6. <el-table-column label="动作" width="120">
  7. <template slot-scope="{ row }">
  8. <StatusTag size="mini" :type="row.action === 'reject' ? 'danger' : 'success'" :text="actionLabel(row.action)" />
  9. </template>
  10. </el-table-column>
  11. <el-table-column label="能量(行维度)" width="140">
  12. <template slot-scope="{ row }">
  13. <el-input-number v-model="row.energy" :min="-10" :max="10" size="mini" />
  14. </template>
  15. </el-table-column>
  16. <el-table-column label="信任(方向)" width="140">
  17. <template slot-scope="{ row }">
  18. <el-input-number v-model="row.trust" :min="-10" :max="10" size="mini" />
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="亲近(方向)" width="140">
  22. <template slot-scope="{ row }">
  23. <el-input-number v-model="row.intimacy" :min="-10" :max="10" size="mini" />
  24. </template>
  25. </el-table-column>
  26. <el-table-column label="沟通(方向)" width="140">
  27. <template slot-scope="{ row }">
  28. <el-input-number v-model="row.communication" :min="-10" :max="10" size="mini" />
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="操作" width="120" fixed="right">
  32. <template slot-scope="{ row }">
  33. <el-button size="mini" type="primary" @click="saveRow(row)">保存</el-button>
  34. </template>
  35. </el-table-column>
  36. </el-table>
  37. </div>
  38. <div class="footer-tip">注:reject 的沟通方向由代码固定(拒绝人→发起人 +、发起人→拒绝人 -、已同意成员→拒绝人 -),此处的值为增减幅度。信任/亲近为单向扣减(发起人→拒绝人)。</div>
  39. </div>
  40. </template>
  41. <script>
  42. import { getChallengeScoreConfigList, updateChallengeScoreConfig } from '@/api/challengeScore'
  43. export default {
  44. name: 'ChallengeScoreConfig',
  45. data() {
  46. return {
  47. loading: false,
  48. matrix: []
  49. }
  50. },
  51. created() {
  52. this.loadList()
  53. },
  54. methods: {
  55. actionLabel: function(action) {
  56. var map = { initiate: '发起', agree: '同意', reject: '拒绝' }
  57. return map[action] || action
  58. },
  59. loadList: function() {
  60. var self = this
  61. self.loading = true
  62. getChallengeScoreConfigList().then(function(res) {
  63. var list = (res && res.data) || []
  64. var matrix = []
  65. var actions = ['initiate', 'agree', 'reject']
  66. for (var i = 0; i < actions.length; i++) {
  67. var row = { action: actions[i], energy: 0, trust: 0, intimacy: 0, communication: 0 }
  68. for (var j = 0; j < list.length; j++) {
  69. var item = list[j]
  70. if (item.action !== row.action) continue
  71. if (item.scoreType === 'energy') row.energy = item.value
  72. if (item.scoreType === 'trust') row.trust = item.value
  73. if (item.scoreType === 'intimacy') row.intimacy = item.value
  74. if (item.scoreType === 'communication') row.communication = item.value
  75. }
  76. matrix.push(row)
  77. }
  78. self.matrix = matrix
  79. }).catch(function() {
  80. self.matrix = []
  81. }).finally(function() {
  82. self.loading = false
  83. })
  84. },
  85. saveRow: function(row) {
  86. var self = this
  87. var items = [
  88. { action: row.action, scoreType: 'energy', value: row.energy },
  89. { action: row.action, scoreType: 'trust', value: row.trust },
  90. { action: row.action, scoreType: 'intimacy', value: row.intimacy },
  91. { action: row.action, scoreType: 'communication', value: row.communication }
  92. ]
  93. var promises = items.map(function(item) {
  94. return updateChallengeScoreConfig(item)
  95. })
  96. Promise.all(promises).then(function() {
  97. self.$message.success(row.action + ' 配置已保存')
  98. }).catch(function() {
  99. self.$message.error('保存失败')
  100. })
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. .footer-tip { margin-top: 12px; color: var(--adm-text-45); font-size: 12px; line-height: 1.6; }
  107. </style>