DispatchForm.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="800"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-form :form="form">
  10. <row-list :col="2">
  11. <row-item>
  12. <a-form-item
  13. label="维修负责人"
  14. :labelCol="BaseTool.Constant.labelCol"
  15. :wrapperCol="BaseTool.Constant.wrapperCol"
  16. >
  17. <div style="position: relative;">
  18. <a-input
  19. v-model="searchKeyword"
  20. placeholder="点击选择维修负责人"
  21. readonly
  22. @click="showDropdown = !showDropdown"
  23. >
  24. <a-icon
  25. slot="suffix"
  26. type="down"
  27. @click="showDropdown = !showDropdown"
  28. />
  29. </a-input>
  30. <div
  31. v-if="showDropdown"
  32. style="
  33. position: absolute;
  34. top: 100%;
  35. left: 0;
  36. right: 0;
  37. background: #fff;
  38. border: 1px solid #d9d9d9;
  39. border-radius: 4px;
  40. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  41. max-height: 300px;
  42. overflow-y: auto;
  43. z-index: 1000;
  44. margin-top: 4px;
  45. "
  46. @mouseleave="onDropdownMouseLeave"
  47. >
  48. <div style="padding: 8px; border-bottom: 1px solid #f0f0f0; position: sticky; top: 0; background: #fff; z-index: 1;">
  49. <a-input
  50. v-model="filterKeyword"
  51. placeholder="搜索姓名"
  52. size="small"
  53. @click.stop
  54. />
  55. </div>
  56. <div
  57. v-for="item in filteredDeptUserList"
  58. :key="item.userId"
  59. @click="selectUser(item)"
  60. :style="{
  61. padding: '8px 12px',
  62. cursor: 'pointer',
  63. background: selectedUserId === item.userId ? '#e6f7ff' : 'transparent'
  64. }"
  65. @mouseenter="($event.target.style.background = selectedUserId === item.userId ? '#e6f7ff' : '#f5f5f5')"
  66. @mouseleave="($event.target.style.background = selectedUserId === item.userId ? '#e6f7ff' : 'transparent')"
  67. >
  68. {{ item.realName }}
  69. </div>
  70. <div v-if="filteredDeptUserList.length === 0" style="padding: 16px; text-align: center; color: #999;">
  71. 无匹配结果
  72. </div>
  73. </div>
  74. </div>
  75. </a-form-item>
  76. </row-item>
  77. </row-list>
  78. <row-list :col="1">
  79. <row-item>
  80. <a-form-item
  81. label="备注"
  82. :labelCol="BaseTool.Constant.labelCol2"
  83. :wrapperCol="BaseTool.Constant.wrapperCol2"
  84. >
  85. <a-textarea
  86. :rows="4"
  87. v-decorator="['repairDispatchRemark']"/>
  88. </a-form-item>
  89. </row-item>
  90. </row-list>
  91. </a-form>
  92. <template slot="footer">
  93. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  94. </template>
  95. </a-modal>
  96. </template>
  97. <script>
  98. import { dispatchModelByDTO } from '@/api/repair/application-form'
  99. import { queryUserDept } from '@/api/upms/user-dept'
  100. import { queryUser } from '@/api/upms/user'
  101. export default {
  102. name: 'DispatchForm',
  103. data () {
  104. return {
  105. confirmLoading: false,
  106. modalTitle: null,
  107. form: this.$form.createForm(this),
  108. visible: false,
  109. sourceMap: {},
  110. levelMap: {},
  111. statusMap: {},
  112. record: {},
  113. userList: [],
  114. deptUserList: [],
  115. showDropdown: false,
  116. searchKeyword: '',
  117. filterKeyword: '',
  118. selectedUserId: null,
  119. selectedUserName: ''
  120. }
  121. },
  122. computed: {
  123. filteredDeptUserList () {
  124. if (!this.filterKeyword) {
  125. return this.deptUserList
  126. }
  127. return this.deptUserList.filter(item =>
  128. item.realName.toLowerCase().includes(this.filterKeyword.toLowerCase())
  129. )
  130. }
  131. },
  132. created () {
  133. this.sourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_SOURCE)
  134. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_LEVEL)
  135. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_STATUS)
  136. this.getUsers()
  137. this.getDeptUsers()
  138. },
  139. mounted () {
  140. document.addEventListener('click', this.handleDocumentClick)
  141. },
  142. beforeDestroy () {
  143. document.removeEventListener('click', this.handleDocumentClick)
  144. },
  145. methods: {
  146. handleDocumentClick (e) {
  147. if (this.showDropdown && !e.target.closest('.ant-input-affix-wrapper')) {
  148. this.showDropdown = false
  149. }
  150. },
  151. onDropdownMouseLeave () {
  152. },
  153. selectUser (item) {
  154. this.selectedUserId = item.userId
  155. this.selectedUserName = item.realName
  156. this.searchKeyword = item.realName
  157. this.showDropdown = false
  158. this.form.setFieldsValue({ repairUserId: item.userId })
  159. },
  160. base (record) {
  161. this.visible = true
  162. this.modalTitle = '派工'
  163. this.record = record
  164. this.$nextTick(() => {
  165. this.form.resetFields()
  166. this.selectedUserId = null
  167. this.selectedUserName = ''
  168. this.searchKeyword = ''
  169. this.filterKeyword = ''
  170. this.showDropdown = false
  171. })
  172. },
  173. getDeptUsers () {
  174. queryUserDept({ deptCode: this.DictCache.VALUE.SYS_DEPT_CODE.XIAN_CHANG_WEI_XIU_ZU, userStatus: 1 }).then(res => {
  175. queryUserDept({ deptCode: this.DictCache.VALUE.SYS_DEPT_CODE.CHANG_NEI_WEI_XIU_ZU, userStatus: 1 }).then(res2 => {
  176. this.deptUserList = res.data.concat(res2.data)
  177. })
  178. })
  179. },
  180. getUsers () {
  181. queryUser({ status: 1 }).then(res => {
  182. this.userList = res.data
  183. })
  184. },
  185. save () {
  186. if (!this.selectedUserId) {
  187. this.$message.warning('请选择维修负责人')
  188. return
  189. }
  190. const { form: { validateFieldsAndScroll } } = this
  191. this.confirmLoading = true
  192. validateFieldsAndScroll((errors, values) => {
  193. if (errors) {
  194. this.confirmLoading = false
  195. return
  196. }
  197. values.id = this.record.id
  198. values.repairUserId = this.selectedUserId
  199. dispatchModelByDTO(values)
  200. .then(() => {
  201. this.handleCancel(values)
  202. }).catch(() => {
  203. this.confirmLoading = false
  204. })
  205. })
  206. },
  207. handleCancel (values) {
  208. this.visible = false
  209. this.confirmLoading = false
  210. this.form.resetFields()
  211. if (this.BaseTool.Object.isNotBlank(values)) {
  212. this.$emit('ok')
  213. }
  214. }
  215. }
  216. }
  217. </script>