BackForm.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1300"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-button icon="plus" type="primary" @click="$refs.sbSelect.base()">选择设备</a-button>
  10. <br>
  11. <br>
  12. <a-table
  13. bordered
  14. :data-source="dataList"
  15. :columns="columns"
  16. :scroll="{x: 1300, y: BaseTool.Constant.scrollY}"
  17. >
  18. <span slot="status" slot-scope="text">
  19. <badge :status="DictCache.COLOR.SB_INFO_STATUS[text]" :text="statusMap[text]" />
  20. </span>
  21. </a-table>
  22. <br>
  23. <a-form :form="form">
  24. <row-list :col="2">
  25. <row-item>
  26. <a-form-item
  27. label="设备位置"
  28. :labelCol="BaseTool.Constant.labelCol2"
  29. :wrapperCol="BaseTool.Constant.wrapperCol2"
  30. >
  31. <a-tree-select
  32. style="width: 100%"
  33. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  34. :treeData="treeData"
  35. :treeNodeFilterProp="'title'"
  36. :showSearch="true"
  37. v-decorator="['positionId', {rules: [{required: true, message: '设备位置不能为空'}]}]"
  38. placeholder="请选择">
  39. </a-tree-select>
  40. </a-form-item>
  41. </row-item>
  42. <row-item>
  43. <a-form-item
  44. label="备注"
  45. :labelCol="BaseTool.Constant.labelCol2"
  46. :wrapperCol="BaseTool.Constant.wrapperCol2"
  47. >
  48. <a-textarea
  49. :rows="4"
  50. v-decorator="['remark']"/>
  51. </a-form-item>
  52. </row-item>
  53. </row-list>
  54. </a-form>
  55. <template slot="footer">
  56. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  57. </template>
  58. <SbInfoSelectModal ref="sbSelect" @selected="handleSelected" />
  59. </a-modal>
  60. </template>
  61. <script>
  62. import { batchBack, batchOut } from '@/api/repair/application-form'
  63. import SbInfoSelectModal from './SbInfoSelectModal2.vue'
  64. import { getSbPositionTree } from '@/api/sb/position'
  65. export default {
  66. name: 'BackForm',
  67. components: {
  68. SbInfoSelectModal
  69. },
  70. data () {
  71. return {
  72. confirmLoading: false,
  73. modalTitle: null,
  74. form: this.$form.createForm(this),
  75. visible: false,
  76. // 下拉框map
  77. sbIds: [],
  78. dataList: [],
  79. treeData: [],
  80. columns: [
  81. {
  82. title: '状态',
  83. checked: true,
  84. dataIndex: 'status',
  85. align: 'center',
  86. width: 100,
  87. scopedSlots: { customRender: 'status' }
  88. },
  89. {
  90. title: '父位号',
  91. dataIndex: 'no',
  92. width: 100,
  93. checked: true
  94. },
  95. {
  96. title: '设备名称',
  97. checked: true,
  98. dataIndex: 'name',
  99. width: 150
  100. },
  101. {
  102. title: '规格、型号',
  103. dataIndex: 'model',
  104. width: 150,
  105. checked: true
  106. },
  107. {
  108. title: '出厂编号',
  109. dataIndex: 'zzh',
  110. width: 100,
  111. checked: true
  112. },
  113. {
  114. title: '管理编号',
  115. dataIndex: 'positionNo',
  116. width: 120,
  117. checked: true
  118. }
  119. ],
  120. status: 0,
  121. type: 1,
  122. statusMap: {}
  123. }
  124. },
  125. props: {
  126. },
  127. created () {
  128. // 下拉框map
  129. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_INFO_STATUS)
  130. getSbPositionTree().then((res) => {
  131. this.treeData = res.data
  132. })
  133. },
  134. methods: {
  135. base (status, type) {
  136. this.visible = true
  137. // 如果是空标识添加
  138. this.modalTitle = this.statusMap[status]
  139. this.status = status
  140. this.type = type
  141. this.dataList = []
  142. },
  143. save () {
  144. const { form: { validateFieldsAndScroll } } = this
  145. this.confirmLoading = true
  146. validateFieldsAndScroll((errors, values) => {
  147. if (errors) {
  148. this.confirmLoading = false
  149. return
  150. }
  151. values.sbIds = this.dataList.map((value) => value.id)
  152. values.status = this.status
  153. if (this.type === 1) {
  154. batchBack(values).then(res => {
  155. this.confirmLoading = false
  156. this.handleCancel()
  157. })
  158. } else {
  159. batchOut(values).then(res => {
  160. this.confirmLoading = false
  161. this.handleCancel()
  162. })
  163. }
  164. })
  165. },
  166. handleSelected (keys, rows) {
  167. rows.forEach((item) => {
  168. if (!this.dataList.map((company) => company.id).includes(item.id)) {
  169. this.dataList.push(item)
  170. }
  171. })
  172. },
  173. handleCancel (values) {
  174. this.visible = false
  175. this.confirmLoading = false
  176. this.form.resetFields()
  177. this.$emit('ok', values)
  178. }
  179. }
  180. }
  181. </script>