Assign.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. condition: { auditType: void 0 },
  81. list: this.getTenantCredits,
  82. buttons: [
  83. { type: 'add', label: '分配', on: this.onAdd }
  84. ],
  85. filters: [
  86. { key: 'auditType', type: 'select', placeholder: '类型', options: auditTypeOptions }
  87. ],
  88. cols: [
  89. { label: '类型', render: this.transformAuditType, width: 100, align: 'center' },
  90. { prop: 'effectiveDate', label: '生效日期' },
  91. { prop: 'expiryDate', label: '结束日期' },
  92. { prop: 'initialAmount', label: '总次数' },
  93. { prop: 'remaining', label: '剩余次数' },
  94. { type: 'invoke', render: [
  95. { label: '删除', on: this.onDel }
  96. ] }
  97. ]
  98. },
  99. stockSchema: {
  100. condition: { auditType: void 0 },
  101. list: getCredits,
  102. filters: [
  103. { key: 'auditType', type: 'select', placeholder: '类型', options: auditTypeOptions }
  104. ],
  105. cols: [
  106. { label: '类型', render: this.transformAuditType, width: 100, align: 'center' },
  107. { prop: 'effectiveDate', label: '生效日期' },
  108. { prop: 'expiryDate', label: '结束日期' },
  109. { label: '可分配', render: ({ initialAmount, allocatedAmount }) => `${initialAmount - allocatedAmount}` }
  110. ]
  111. },
  112. fromCredit: {},
  113. credit: {},
  114. pickerOptions: {
  115. disabledDate: this.disabledDate
  116. }
  117. }
  118. },
  119. computed: {
  120. remaining () {
  121. return this.fromCredit
  122. ? this.fromCredit.initialAmount - this.fromCredit.allocatedAmount
  123. : 0
  124. }
  125. },
  126. methods: {
  127. disabledDate (date) {
  128. if (this.fromCredit) {
  129. const { effectiveDate, expiryDate } = this.fromCredit
  130. return date < new Date(`${effectiveDate} 00:00:00`) || date > new Date(`${expiryDate} 00:00:00`)
  131. }
  132. return false
  133. },
  134. transformAuditType (data) {
  135. return AssetTypeInfo[data.auditType]
  136. },
  137. onTenantChange (tenant) {
  138. if (!this.tenant || this.tenant.id !== tenant.id) {
  139. this.tenant = tenant
  140. this.$refs.table?.pageTo(1)
  141. }
  142. },
  143. getTenantCredits (params) {
  144. return getTenantCredits({
  145. tenant: this.tenant.path,
  146. ...params
  147. })
  148. },
  149. onAdd () {
  150. this.$refs.stockDialog.show()
  151. },
  152. onChoosen ({ value, done }) {
  153. const { auditType, initialAmount, allocatedAmount, effectiveDate, expiryDate } = value
  154. if (initialAmount - allocatedAmount < 1) {
  155. this.$message({
  156. type: 'warning',
  157. message: '可分配次数不足,请重新选择'
  158. })
  159. return
  160. }
  161. this.fromCredit = value
  162. this.credit = {
  163. auditType,
  164. initialAmount: this.remaining,
  165. date: [effectiveDate, expiryDate]
  166. }
  167. done()
  168. this.$refs.addDialog.show()
  169. },
  170. onSave (done) {
  171. const { auditType, initialAmount, date } = this.credit
  172. if (!date) {
  173. this.$message({
  174. type: 'warning',
  175. message: '请选择有效期'
  176. })
  177. return
  178. }
  179. addCredit({
  180. admin: 0,
  181. fromCredit: this.fromCredit.id,
  182. tenant: this.tenant.path,
  183. auditType,
  184. initialAmount,
  185. effectiveDate: date[0],
  186. expiryDate: date[1]
  187. }).then(() => {
  188. done()
  189. this.$refs.table.pageTo(1)
  190. })
  191. },
  192. onDel (credit) {
  193. deleteCredit(credit).then(() => {
  194. this.$refs.table.decrease(1)
  195. })
  196. }
  197. }
  198. }
  199. </script>