index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="hc-tasks-user">
  3. <div class="tasks-user-box">
  4. <div class="tag-user-list" @click="showModalClick">
  5. <template v-for="(item, index) in UserDataList" :key="index">
  6. <el-tag>{{ setCheckboxUserName(item) }}</el-tag>
  7. <HcIcon v-if="(UserDataList.length - 1) > index" name="arrow-right" ui="arrow-icon-tag" />
  8. </template>
  9. <div v-if="UserDataList.length <= 0" class="tasks-placeholder">
  10. 点击这里选择任务人
  11. </div>
  12. </div>
  13. </div>
  14. <!-- 选择任务人 -->
  15. <el-dialog v-model="showModal" class="hc-modal-border hc-modal-nop" destroy-on-close draggable title="选择任务人" width="62rem" append-to-body>
  16. <div class="hc-tasks-user-modal-content-box">
  17. <div class="tree-box">
  18. <el-scrollbar>
  19. <ElTree
  20. v-if="isShowTree" :data="ElTreeData" :default-expanded-keys="[0]" :props="ElTreeProps" accordion
  21. class="hc-tree-node-box" highlight-current node-key="roleId" @node-click="ElTreeNodeClick"
  22. />
  23. </el-scrollbar>
  24. </div>
  25. <div class="user-box">
  26. <div class="y-user-list-box">
  27. <div class="title-box">
  28. <div class="title">
  29. 可选择
  30. </div>
  31. </div>
  32. <div class="user-list">
  33. <el-scrollbar>
  34. <el-checkbox-group v-model="checkboxUserList">
  35. <template v-for="item in signUserList">
  36. <div class="user-item checkbox-li">
  37. <el-checkbox :label="`${item.certificateUserName}-${item.certificateUserId}`">
  38. <div class="item-user-name">
  39. {{ item.certificateUserName }}
  40. </div>
  41. </el-checkbox>
  42. </div>
  43. </template>
  44. </el-checkbox-group>
  45. </el-scrollbar>
  46. </div>
  47. </div>
  48. <div class="s-user-list-box">
  49. <div class="title-box">
  50. <div class="title">
  51. 已选择({{ checkboxUserList.length }})
  52. </div>
  53. <el-button plain size="small" @click="sequenceModal = true">
  54. 调整顺序
  55. </el-button>
  56. </div>
  57. <div class="user-list">
  58. <el-scrollbar>
  59. <template v-for="(item, index) in checkboxUserList" :key="index">
  60. <el-tag closable @close="delCheckboxUser(index)">
  61. {{ setCheckboxUserName(item) }}
  62. </el-tag>
  63. </template>
  64. </el-scrollbar>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. <template #footer>
  70. <div class="dialog-footer">
  71. <el-button size="large" @click="showModal = false">
  72. <HcIcon name="close" />
  73. <span>取消</span>
  74. </el-button>
  75. <el-button :loading="sureSignUserLoading" hc-btn type="primary" @click="sureSignUserClick">
  76. <HcIcon name="check" />
  77. <span>确定</span>
  78. </el-button>
  79. </div>
  80. </template>
  81. </el-dialog>
  82. <!-- 调整顺序 -->
  83. <el-dialog v-model="sequenceModal" class="hc-modal-border" destroy-on-close draggable append-to-body title="调整顺序" width="38rem">
  84. <el-alert :closable="false" title="可拖动排序,也可在后面点击图标,切换排序" type="warning" />
  85. <div class="sort-node-body-box list-group header">
  86. <div class="list-group-item">
  87. <div class="index-box">
  88. 序号
  89. </div>
  90. <div class="title-box">
  91. 任务人
  92. </div>
  93. <div class="icon-box">
  94. 排序
  95. </div>
  96. </div>
  97. </div>
  98. <Draggable :list="checkboxUserList" class="sort-node-body-box list-group" ghost-class="ghost" item-key="id" @end="sortNodeDrag = false" @start="sortNodeDrag = true">
  99. <template #item="{ element, index }">
  100. <div class="list-group-item">
  101. <div class="index-box">
  102. {{ index + 1 }}
  103. </div>
  104. <div class="title-box">
  105. {{ setCheckboxUserName(element) }}
  106. </div>
  107. <div class="icon-box">
  108. <span class="icon" @click="downSortClick(index)">
  109. <HcIcon name="arrow-down" ui="text-lg" />
  110. </span>
  111. <span class="icon" @click="upSortClick(index)">
  112. <HcIcon name="arrow-up" ui="text-lg" />
  113. </span>
  114. </div>
  115. </div>
  116. </template>
  117. </Draggable>
  118. <template #footer>
  119. <div class="dialog-footer">
  120. <el-button size="large" @click="sequenceModal = false">
  121. 取消
  122. </el-button>
  123. <el-button hc-btn type="primary" @click="sequenceModal = false">
  124. 确认
  125. </el-button>
  126. </div>
  127. </template>
  128. </el-dialog>
  129. </div>
  130. </template>
  131. <script setup>
  132. import { onMounted, ref, watch } from 'vue'
  133. import tasksFlowApi from '~api/tasks/flow'
  134. import { deepClone, getArrValue } from 'js-fast-way'
  135. import { useAppStore } from '~src/store'
  136. import Draggable from 'vuedraggable'
  137. //参数
  138. const props = defineProps({
  139. users: {
  140. type: String,
  141. default: '',
  142. },
  143. })
  144. //事件
  145. const emit = defineEmits(['change'])
  146. //初始变量
  147. const useAppState = useAppStore()
  148. const projectId = ref(useAppState.getProjectId)
  149. const contractId = ref(useAppState.getContractId)
  150. //变量
  151. const showModal = ref(false)
  152. const sequenceModal = ref(false)
  153. const checkboxUserList = ref([])
  154. const UserDataList = ref([])
  155. //树数据
  156. const ElTreeProps = { children: 'childRoleList', label: 'roleName' }
  157. const ElTreeData = ref([{
  158. roleName: '全部人员',
  159. roleId: 0,
  160. childRoleList: [],
  161. signPfxFileList: [],
  162. }])
  163. const isShowTree = ref(true)
  164. //监听
  165. watch(() => [
  166. props.users,
  167. props.projectId,
  168. props.contractId,
  169. ], ([users, pid, cid]) => {
  170. projectId.value = pid
  171. contractId.value = cid
  172. setUserDataList(users)
  173. })
  174. //渲染完成
  175. onMounted(() => {
  176. setUserDataList(props.users)
  177. queryAllRoleList()
  178. })
  179. //处理用户数据
  180. const setUserDataList = (users) => {
  181. if (users) {
  182. const usersArr = users.split(',')
  183. UserDataList.value = usersArr
  184. checkboxUserList.value = usersArr
  185. } else {
  186. UserDataList.value = []
  187. checkboxUserList.value = []
  188. }
  189. }
  190. //展开弹窗
  191. const showModalClick = () => {
  192. showModal.value = true
  193. }
  194. //获取系统所有角色划分
  195. const signUserList = ref([])
  196. const queryAllRoleList = async () => {
  197. isShowTree.value = false
  198. const { error, code, data } = await tasksFlowApi.queryAllRoleList({
  199. contractId: contractId.value,
  200. })
  201. isShowTree.value = true
  202. //处理数据
  203. if (!error && code === 200) {
  204. let signList = [], dataArr = getArrValue(data)
  205. ElTreeData.value[0].childRoleList = dataArr
  206. if (dataArr.length > 0) {
  207. dataArr.forEach(item => {
  208. signList = signList.concat(item.signPfxFileList)
  209. })
  210. }
  211. ElTreeData.value[0].signPfxFileList = signList
  212. signUserList.value = signList
  213. } else {
  214. signUserList.value = []
  215. ElTreeData.value[0].childRoleList = []
  216. ElTreeData.value[0].signPfxFileList = []
  217. }
  218. }
  219. //树被点击
  220. const ElTreeNodeClick = (data) => {
  221. signUserList.value = getArrValue(data?.signPfxFileList)
  222. }
  223. //处理已选择的用户问题
  224. const setCheckboxUserName = (item) => {
  225. if (item) {
  226. const itemArr = item.split('-')
  227. if (itemArr.length > 0 && itemArr[0]) {
  228. return itemArr[0]
  229. } else {
  230. return ''
  231. }
  232. } else {
  233. return ''
  234. }
  235. }
  236. //删除已选择的用户
  237. const delCheckboxUser = (index) => {
  238. checkboxUserList.value.splice(index, 1)
  239. }
  240. //排序
  241. const sortNodeDrag = ref(false)
  242. //向下
  243. const downSortClick = (index) => {
  244. const indexs = index + 1
  245. const data = checkboxUserList.value
  246. if (indexs !== data.length) {
  247. const tmp = data.splice(indexs, 1)
  248. checkboxUserList.value.splice(index, 0, tmp[0])
  249. } else {
  250. window?.$message?.warning('已经处于置底,无法下移')
  251. }
  252. }
  253. //向上
  254. const upSortClick = (index) => {
  255. const data = checkboxUserList.value || []
  256. if (index !== 0) {
  257. const tmp = data.splice(index - 1, 1)
  258. checkboxUserList.value.splice(index, 0, tmp[0])
  259. } else {
  260. window?.$message?.warning('已经处于置顶,无法上移')
  261. }
  262. }
  263. //确认选择
  264. const sureSignUserLoading = ref(false)
  265. const sureSignUserClick = async () => {
  266. let flowJson = {}, newUser = [], newUserId = [], users = ''
  267. const dataList = deepClone(checkboxUserList.value)
  268. UserDataList.value = dataList
  269. if (dataList.length <= 0) {
  270. window.$message?.warning('请先选择任务人员,或点击取消')
  271. return false
  272. }
  273. sureSignUserLoading.value = true
  274. //封装数据
  275. dataList.forEach(item => {
  276. const itemArr = item.split('-')
  277. if (itemArr.length > 0 && itemArr[0]) {
  278. users = users ? `${users},${item}` : item
  279. newUser.push({
  280. userId: itemArr[1],
  281. userName: itemArr[0],
  282. })
  283. newUserId.push(itemArr[1])
  284. }
  285. })
  286. //效验人员
  287. console.log(newUserId, 'newUserId')
  288. // const { error, code, data, msg } = await tasksFlowApi.checkTaskUserCertificateInfo({
  289. // userIds: newUserId.join(','),
  290. // })
  291. // if (!error && code === 200) {
  292. // emit('change', newUser, newUserId, users)
  293. // } else {
  294. // window.$message.warning(msg)
  295. // }
  296. //关闭弹窗
  297. showModal.value = false
  298. sureSignUserLoading.value = false
  299. }
  300. </script>
  301. <style lang="scss" scoped>
  302. @import './style.scss';
  303. </style>
  304. <style lang="scss">
  305. .hc-tasks-user .tasks-user-box .tag-user-list {
  306. .el-tag {
  307. --el-icon-size: 14px;
  308. padding: 0 10px;
  309. height: 26px;
  310. margin: 4px 0;
  311. }
  312. }
  313. .hc-tasks-user-modal-content-box {
  314. .checkbox-li .el-checkbox {
  315. width: 100%;
  316. .el-checkbox__input {
  317. position: absolute;
  318. right: 0;
  319. .el-checkbox__inner {
  320. width: 18px;
  321. height: 18px;
  322. &:after {
  323. height: 9px;
  324. left: 6px;
  325. top: 2px;
  326. }
  327. }
  328. }
  329. .el-checkbox__label {
  330. flex: 1;
  331. padding-left: 0;
  332. padding-right: 20px;
  333. }
  334. }
  335. .user-list {
  336. .el-tag {
  337. margin-right: 10px;
  338. margin-top: 12px;
  339. }
  340. }
  341. }
  342. </style>