Assign.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <platform-page @change="onTenantChange">
  3. <template #default>
  4. <schema-table
  5. ref="table"
  6. class="c-sibling-item far"
  7. :schema="schema"
  8. />
  9. <radio-table-dialog
  10. ref="stockDialog"
  11. title="库存"
  12. :schema="stockSchema"
  13. @confirm="onChoosen"
  14. />
  15. <confirm-dialog
  16. ref="addDialog"
  17. title="分配"
  18. @confirm="onSave"
  19. >
  20. <div class="c-grid-form sm u-align-self--center">
  21. <span class="c-grid-form__label">类型</span>
  22. <schema-select
  23. v-model="credit.auditType"
  24. class="u-width--xs"
  25. :schema="auditTypeSchema"
  26. disabled
  27. />
  28. <span class="c-grid-form__label">次数</span>
  29. <div class="l-flex--row">
  30. <el-input-number
  31. v-model="credit.initialAmount"
  32. class="c-sibling-item"
  33. :min="1"
  34. :max="remaining"
  35. step-strictly
  36. />
  37. <span class="c-sibling-item u-color--info light">1 ~ {{ remaining }}</span>
  38. </div>
  39. <span class="c-grid-form__label u-required">有效期</span>
  40. <el-date-picker
  41. v-model="credit.date"
  42. class="u-width--auto"
  43. type="daterange"
  44. range-separator="至"
  45. start-placeholder="开始日期"
  46. end-placeholder="结束日期"
  47. value-format="yyyy-MM-dd"
  48. :picker-options="pickerOptions"
  49. :clearable="false"
  50. />
  51. </div>
  52. </confirm-dialog>
  53. </template>
  54. </platform-page>
  55. </template>
  56. <script>
  57. import {
  58. AssetType,
  59. AssetTypeInfo
  60. } from '@/constant'
  61. import {
  62. getCredits,
  63. getTenantCredits,
  64. addCredit,
  65. deleteCredit
  66. } from './api'
  67. export default {
  68. name: 'StockAssign',
  69. data () {
  70. const auditTypeOptions = [
  71. { value: AssetType.IMAGE, label: AssetTypeInfo[AssetType.IMAGE] },
  72. { value: AssetType.VIDEO, label: AssetTypeInfo[AssetType.VIDEO] }
  73. ]
  74. return {
  75. tenant: null,
  76. auditTypeSchema: {
  77. options: auditTypeOptions
  78. },
  79. schema: {
  80. list: this.getTenantCredits,
  81. buttons: [
  82. { type: 'add', label: '分配', on: this.onAdd }
  83. ],
  84. filters: [
  85. { key: 'auditType', type: 'select', placeholder: '类型', options: auditTypeOptions }
  86. ],
  87. cols: [
  88. { label: '类型', render: this.transformAuditType, width: 100, align: 'center' },
  89. { prop: 'effectiveDate', label: '生效日期' },
  90. { prop: 'expiryDate', label: '结束日期' },
  91. { prop: 'initialAmount', label: '总次数' },
  92. { prop: 'remaining', label: '剩余次数' },
  93. { type: 'invoke', render: [
  94. { label: '删除', on: this.onDel }
  95. ] }
  96. ]
  97. },
  98. stockSchema: {
  99. list: getCredits,
  100. filters: [
  101. { key: 'auditType', type: 'select', placeholder: '类型', options: auditTypeOptions }
  102. ],
  103. cols: [
  104. { label: '类型', render: this.transformAuditType, width: 100, align: 'center' },
  105. { prop: 'effectiveDate', label: '生效日期' },
  106. { prop: 'expiryDate', label: '结束日期' },
  107. { label: '可分配', render: ({ initialAmount, allocatedAmount }) => `${initialAmount - allocatedAmount}` }
  108. ]
  109. },
  110. fromCredit: {},
  111. credit: {},
  112. pickerOptions: {
  113. disabledDate: this.disabledDate
  114. }
  115. }
  116. },
  117. computed: {
  118. remaining () {
  119. return this.fromCredit
  120. ? this.fromCredit.initialAmount - this.fromCredit.allocatedAmount
  121. : 0
  122. }
  123. },
  124. methods: {
  125. disabledDate (date) {
  126. if (this.fromCredit) {
  127. const { effectiveDate, expiryDate } = this.fromCredit
  128. return date < new Date(`${effectiveDate} 00:00:00`) || date > new Date(`${expiryDate} 00:00:00`)
  129. }
  130. return false
  131. },
  132. transformAuditType (data) {
  133. return AssetTypeInfo[data.auditType]
  134. },
  135. onTenantChange (tenant) {
  136. if (!this.tenant || this.tenant.id !== tenant.id) {
  137. this.tenant = tenant
  138. this.$refs.table?.pageTo(1)
  139. }
  140. },
  141. getTenantCredits (params) {
  142. return getTenantCredits({
  143. tenant: this.tenant.path,
  144. ...params
  145. })
  146. },
  147. onAdd () {
  148. this.$refs.stockDialog.show()
  149. },
  150. onChoosen ({ value, done }) {
  151. const { auditType, initialAmount, allocatedAmount, effectiveDate, expiryDate } = value
  152. if (initialAmount - allocatedAmount < 1) {
  153. this.$message({
  154. type: 'warning',
  155. message: '可分配次数不足,请重新选择'
  156. })
  157. return
  158. }
  159. this.fromCredit = value
  160. this.credit = {
  161. auditType,
  162. initialAmount: this.remaining,
  163. date: [effectiveDate, expiryDate]
  164. }
  165. done()
  166. this.$refs.addDialog.show()
  167. },
  168. onSave (done) {
  169. const { auditType, initialAmount, date } = this.credit
  170. if (!date) {
  171. this.$message({
  172. type: 'warning',
  173. message: '请选择有效期'
  174. })
  175. return
  176. }
  177. addCredit({
  178. admin: 0,
  179. fromCredit: this.fromCredit.id,
  180. tenant: this.tenant.path,
  181. auditType,
  182. initialAmount,
  183. effectiveDate: date[0],
  184. expiryDate: date[1]
  185. }).then(() => {
  186. done()
  187. this.$refs.table.pageTo(1)
  188. })
  189. },
  190. onDel (credit) {
  191. deleteCredit(credit).then(() => {
  192. this.$refs.table.decrease(1)
  193. })
  194. }
  195. }
  196. }
  197. </script>