Stock.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <schema-table
  3. ref="table"
  4. :schema="schema"
  5. >
  6. <confirm-dialog
  7. ref="addDialog"
  8. title="新增库存"
  9. @confirm="onSave"
  10. >
  11. <div class="c-grid-form u-align-self--center">
  12. <span class="c-grid-form__label">类型:</span>
  13. <schema-select
  14. v-model="credit.auditType"
  15. :schema="auditTypeSchema"
  16. />
  17. <span class="c-grid-form__label">次数:</span>
  18. <el-input-number
  19. v-model="credit.initialAmount"
  20. :min="1"
  21. :max="999999"
  22. step-strictly
  23. />
  24. <span class="c-grid-form__label required">有效期:</span>
  25. <el-date-picker
  26. v-model="credit.date"
  27. class="u-width--auto"
  28. type="daterange"
  29. range-separator="至"
  30. start-placeholder="开始日期"
  31. end-placeholder="结束日期"
  32. value-format="yyyy-MM-dd"
  33. />
  34. </div>
  35. </confirm-dialog>
  36. <credit-config-dialog ref="creditDialog" />
  37. </schema-table>
  38. </template>
  39. <script>
  40. import {
  41. getCredits,
  42. addCredit,
  43. deleteCredit
  44. } from './api'
  45. import CreditConfigDialog from './components/CreditConfigDialog'
  46. export default {
  47. name: 'AIStock',
  48. components: {
  49. CreditConfigDialog
  50. },
  51. data () {
  52. const auditTypeOptions = [
  53. { value: 1, label: '图片' },
  54. { value: 2, label: '视频' }
  55. ]
  56. return {
  57. auditTypeSchema: {
  58. options: auditTypeOptions
  59. },
  60. schema: {
  61. condition: { auditType: void 0 },
  62. list: getCredits,
  63. buttons: [
  64. { type: 'add', on: this.onAdd },
  65. { label: '阈值配置', on: this.onConfig }
  66. ],
  67. filters: [
  68. { key: 'auditType', type: 'select', placeholder: '全部类型', options: auditTypeOptions }
  69. ],
  70. cols: [
  71. { label: '审核类型', render (data) {
  72. return ['', '图片', '视频'][data.auditType]
  73. } },
  74. { prop: 'effectiveDate', label: '生效日期' },
  75. { prop: 'expiryDate', label: '结束日期' },
  76. { prop: 'initialAmount', label: '总次数' },
  77. { prop: 'remaining', label: '剩余次数' },
  78. { prop: 'allocatedAmount', label: '已分配' },
  79. { label: '可分配', render ({ initialAmount, allocatedAmount }) {
  80. return (initialAmount - allocatedAmount).toString()
  81. } },
  82. { type: 'invoke', render: [
  83. { label: '删除', on: this.onDel }
  84. ] }
  85. ]
  86. },
  87. credit: {}
  88. }
  89. },
  90. methods: {
  91. onAdd () {
  92. this.credit = {
  93. auditType: 1,
  94. initialAmount: 1000,
  95. date: ''
  96. }
  97. this.$refs.addDialog.show()
  98. },
  99. onSave (done) {
  100. const { auditType, initialAmount, date } = this.credit
  101. if (!date) {
  102. this.$message({
  103. type: 'warning',
  104. message: '请选择有效期'
  105. })
  106. return
  107. }
  108. addCredit({
  109. admin: 1,
  110. auditType,
  111. initialAmount,
  112. effectiveDate: date[0],
  113. expiryDate: date[1]
  114. }).then(() => {
  115. done()
  116. this.$refs.table.pageTo(1)
  117. })
  118. },
  119. onDel (credit) {
  120. deleteCredit(credit).then(() => {
  121. this.$refs.table.decrease(1)
  122. })
  123. },
  124. onConfig () {
  125. this.$refs.creditDialog.show()
  126. }
  127. }
  128. }
  129. </script>