index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <schema-table
  9. ref="table"
  10. :schema="schema"
  11. />
  12. <confirm-dialog
  13. ref="editDialog"
  14. title="新增多功能卡"
  15. @confirm="onConfirm"
  16. >
  17. <div class="c-grid-form u-align-self--center">
  18. <span class="c-grid-form__label u-required">厂商</span>
  19. <schema-select
  20. ref="manufacturer"
  21. v-model="item.manufacturerKey"
  22. class="u-width"
  23. placeholder="请选择厂商"
  24. :schema="manufacturerSelectSchema"
  25. />
  26. <span class="c-grid-form__label u-required">型号</span>
  27. <el-input
  28. v-model.trim="item.model"
  29. placeholder="最多50个字符"
  30. maxlength="50"
  31. clearable
  32. />
  33. <span class="c-grid-form__label">端口数</span>
  34. <el-input-number
  35. v-model="item.portCount"
  36. :min="0"
  37. :max="86400"
  38. step-strictly
  39. />
  40. <span class="c-grid-form__label">485接口数</span>
  41. <el-input-number
  42. v-model="item.rs485Count"
  43. :min="0"
  44. :max="86400"
  45. step-strictly
  46. />
  47. <span class="c-grid-form__label u-required">唯一标识</span>
  48. <el-input
  49. v-model.trim="item.identifier"
  50. placeholder="最多50个字符"
  51. maxlength="50"
  52. clearable
  53. />
  54. </div>
  55. </confirm-dialog>
  56. <mesh-dialog ref="meshDialog" />
  57. </wrapper>
  58. </template>
  59. <script>
  60. import { ThirdPartyDevice } from '@/constant'
  61. import {
  62. getManufacturersByType,
  63. getMultifunctionCards,
  64. addMultifunctionCard,
  65. deleteMultifunctionCard
  66. } from '@/api/external'
  67. import MeshDialog from '../components/MeshDialog.vue'
  68. export default {
  69. name: 'MultifunctionCardList',
  70. components: {
  71. MeshDialog
  72. },
  73. data () {
  74. const manufacturerSelectSchema = {
  75. remote: this.getManufacturersByType,
  76. value: 'manufacturerKey',
  77. label: 'manufacturerName'
  78. }
  79. return {
  80. item: {},
  81. manufacturerSelectSchema,
  82. schema: {
  83. list: getMultifunctionCards,
  84. buttons: [
  85. { type: 'add', on: this.onAdd }
  86. ],
  87. filters: [
  88. { key: 'manufacturerKey', type: 'select', placeholder: '厂商', ...manufacturerSelectSchema },
  89. { key: 'boundFlag', type: 'select', placeholder: '使用情况', options: [
  90. { value: 0, label: '已使用' },
  91. { value: 1, label: '未使用' }
  92. ] },
  93. { key: 'identifier', type: 'search', placeholder: '唯一标识' }
  94. ],
  95. cols: [
  96. { prop: 'manufacturerName', label: '厂商' },
  97. { prop: 'model', label: '型号' },
  98. { prop: 'identifier', label: '唯一标识' },
  99. { prop: 'portCount', label: '端口数', align: 'center' },
  100. { prop: 'rs485Count', label: '485接口数', align: 'center' },
  101. { label: '使用情况', type: 'tag', render: ({ bound }) => bound
  102. ? { type: 'success', label: '已使用' }
  103. : { type: 'primary', label: '未使用' } },
  104. { type: 'invoke', render: [
  105. { label: '所属网点', allow: ({ bound }) => bound, on: this.onViewMesh },
  106. { label: '删除', allow: ({ bound }) => !bound, on: this.onDel }
  107. ], width: 200 }
  108. ]
  109. }
  110. }
  111. },
  112. methods: {
  113. getManufacturersByType () {
  114. return getManufacturersByType(ThirdPartyDevice.MULTI_FUNCTION_CARD)
  115. },
  116. onAdd () {
  117. this.item = {
  118. identifier: '',
  119. manufacturerKey: '',
  120. model: '',
  121. portCount: 0,
  122. rs485Count: 0
  123. }
  124. this.$refs.editDialog.show()
  125. },
  126. onConfirm (done) {
  127. if (!this.item.manufacturerKey) {
  128. this.$message({
  129. type: 'warning',
  130. message: '请选择厂商'
  131. })
  132. return
  133. }
  134. if (!this.item.model) {
  135. this.$message({
  136. type: 'warning',
  137. message: '请填写型号'
  138. })
  139. return
  140. }
  141. if (!this.item.identifier) {
  142. this.$message({
  143. type: 'warning',
  144. message: '请填写唯一标识'
  145. })
  146. return
  147. }
  148. const key = this.item.manufacturerKey
  149. addMultifunctionCard({
  150. manufacturerName: this.$refs.manufacturer.getOptions().find(({ value }) => value === key).label,
  151. ...this.item
  152. }).then(() => {
  153. done()
  154. this.$refs.table.resetCondition({
  155. manufacturerKey: key,
  156. identifier: this.item.identifier
  157. })
  158. })
  159. },
  160. onDel (item) {
  161. deleteMultifunctionCard(item).then(() => {
  162. this.$refs.table.decrease(1)
  163. })
  164. },
  165. onViewMesh ({ id }) {
  166. this.$refs.meshDialog.show(id)
  167. }
  168. }
  169. }
  170. </script>