wk-audit-add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view class="wk-audit-add">
  3. <view class="header">
  4. 审核信息
  5. </view>
  6. <view v-if="flowList.length > 0" class="content">
  7. <view
  8. v-for="(flowItem, flowIndex) in flowList"
  9. :key="flowItem.flowId"
  10. class="flow-item">
  11. <view class="flow-item-title">
  12. <view class="dot-circle" />
  13. <view class="text">
  14. {{ flowItem.name }}
  15. </view>
  16. <view class="badge">
  17. {{ getBadge(flowItem) }}
  18. </view>
  19. </view>
  20. <view class="flow-item-body">
  21. <template v-if="flowItem.examineType !== 4">
  22. <!-- 若只有一个人审批 -->
  23. <template v-if="flowItem.userList.length === 1">
  24. <view
  25. v-for="(user, index) in flowItem.userList"
  26. :key="user.userId"
  27. class="user-box">
  28. <wk-avatar
  29. :name="user.realname"
  30. :avatar="user.img"
  31. :size="12"
  32. :preview="false"
  33. class="avatar"
  34. @click="handleClickUser(flowItem, flowIndex, index)" />
  35. <text class="name">
  36. {{ user.realname }}
  37. </text>
  38. <text class="grade">
  39. 第{{ index + 1 }}级
  40. </text>
  41. </view>
  42. </template>
  43. <!-- 指定成员,角色审批合并 -->
  44. <view
  45. v-else-if="[1, 3].includes(flowItem.examineType)"
  46. class="user-box">
  47. <image :src="$static('images/avatar.png')" class="avatar" />
  48. <text class="name">
  49. {{ flowItem.userList.length }}人{{ getFlowAuditType(flowItem) }}
  50. </text>
  51. <text class="grade">
  52. 第1级
  53. </text>
  54. </view>
  55. <!-- 上级和连续多级上级 -->
  56. <template v-else>
  57. <template v-if="flowItem.userList.length > 0">
  58. <view
  59. v-for="(user, index) in flowItem.userList"
  60. :key="user.userId"
  61. class="user-box">
  62. <wk-avatar
  63. :name="user.realname"
  64. :avatar="user.img"
  65. :size="12"
  66. :preview="false"
  67. class="avatar"
  68. @click="handleClickUser(flowItem, flowIndex, index)" />
  69. <text class="name">
  70. {{ user.realname }}
  71. </text>
  72. <text class="grade">
  73. 第{{ index + 1 }}级
  74. </text>
  75. </view>
  76. </template>
  77. <template v-else>
  78. <view class="user-box">
  79. <image :src="$static('images/avatar.png')" class="avatar" />
  80. <text class="name">
  81. XX
  82. </text>
  83. <text class="grade">
  84. 第1级
  85. </text>
  86. </view>
  87. </template>
  88. </template>
  89. </template>
  90. <template v-else>
  91. <view
  92. v-for="(user, index) in flowItem.userList"
  93. :key="user.userId"
  94. class="user-box">
  95. <wk-avatar
  96. :name="user.realname"
  97. :avatar="user.img"
  98. :size="12"
  99. :preview="false"
  100. class="avatar"
  101. @click="handleClickUser(flowItem, flowIndex, index)" />
  102. <text class="name">
  103. {{ user.realname }}
  104. </text>
  105. <text class="grade">
  106. 第{{ index + 1 }}级
  107. </text>
  108. <image
  109. v-if="flowItem.examineType === 4"
  110. :src="$static('images/icon/delete_fill.png')"
  111. class="delete-icon"
  112. @click="handleRemoveUser(flowItem, flowIndex, index)" />
  113. </view>
  114. </template>
  115. <view v-if="canChooseUser(flowItem)" class="user-box">
  116. <view class="avatar add" @click="handlerAddUser(flowItem, flowIndex)">
  117. +
  118. </view>
  119. <text class="name">
  120. 多人{{ getFlowAuditType(flowItem) }}
  121. </text>
  122. <text class="grade">
  123. 第{{ flowItem.userList.length + 1 }}级
  124. </text>
  125. </view>
  126. </view>
  127. <view v-if="flowIndex < flowList.length - 1" class="line" />
  128. </view>
  129. </view>
  130. <view v-else class="content">
  131. 审核人为空,审核将自动通过。
  132. </view>
  133. </view>
  134. </template>
  135. <script>
  136. import { PreviewExamineFlow } from 'API/examine'
  137. import { deepCopy } from '@/utils/lib.js'
  138. export default {
  139. name: 'WkAuditAdd',
  140. props: {
  141. params: {
  142. type: Object,
  143. default: () => {}
  144. }
  145. },
  146. data() {
  147. return {
  148. guid: null,
  149. auditInfo: {},
  150. flowList: [],
  151. activeFlowIndex: -1,
  152. activeUserIndex: -1
  153. }
  154. },
  155. created() {
  156. this.guid = this.$guid()
  157. },
  158. methods: {
  159. /**
  160. * 获取审批流信息
  161. */
  162. getAuditInfo(params = {}) {
  163. // { name: '合同', value: 1 },
  164. // { name: '回款', value: 2 },
  165. // { name: '发票', value: 3 },
  166. // { name: '薪资', value: 4 },
  167. // { name: '采购审批', value: 5 },
  168. // { name: '采购退货审批', value: 6 },
  169. // { name: '销售审批', value: 7 },
  170. // { name: '销售退货审批', value: 8 },
  171. // { name: '付款审批', value: 9 },
  172. // { name: '办公审批', value: 10 },
  173. // { name: '盘点审批', value: 11 },
  174. // { name: '调拨审批', value: 12 }
  175. PreviewExamineFlow(params).then(res => {
  176. this.auditInfo = res
  177. const list = deepCopy(res.examineFlowList || [])
  178. list.forEach(o => {
  179. if (o.examineType === 4) {
  180. o.userList = []
  181. }
  182. })
  183. this.flowList = list
  184. }).catch(() => {
  185. this.auditInfo = {}
  186. this.flowList = []
  187. this.remarks = ''
  188. })
  189. },
  190. getBadge(flowItem) {
  191. return {
  192. 1: '指定成员',
  193. 2: '上级',
  194. 3: '角色',
  195. 4: '发起人自选',
  196. 5: '连续多级上级'
  197. }[flowItem.examineType] || ''
  198. },
  199. getFlowAuditType(flowItem) {
  200. return {
  201. 1: '依次审批',
  202. 2: '会签',
  203. 3: '或签'
  204. }[flowItem.type] || ''
  205. },
  206. /**
  207. * 判断是否可以选人
  208. * @param {Object} flowItem
  209. */
  210. canChooseUser(flowItem) {
  211. if (flowItem.examineType !== 4) return false // 自选
  212. if (flowItem.chooseType === 1) return flowItem.userList.length < 1 // 自选1人
  213. if (flowItem.chooseType === 2) return true // 自选多人
  214. return false
  215. },
  216. /**
  217. * 点击审批人头像
  218. */
  219. handleClickUser(flowItem, flowIndex, userIndex) {
  220. if (flowItem.examineType !== 4) return // 自选
  221. this.handlerAddUser(flowItem, flowIndex, userIndex)
  222. },
  223. /**
  224. * 移除
  225. */
  226. handleRemoveUser(flowItem, flowIndex, userIndex) {
  227. this.activeFlowIndex = -1
  228. this.activeUserIndex = -1
  229. this.flowList[flowIndex].userList.splice(userIndex, 1)
  230. },
  231. /**
  232. * 自选审核人
  233. */
  234. handlerAddUser(flowItem, flowIndex, userIndex = -1) {
  235. const bridge = getApp().globalData.selectedValBridge
  236. let defaultVal = []
  237. if (userIndex !== -1) {
  238. defaultVal = [flowItem.userList[userIndex]]
  239. this.activeUserIndex = userIndex
  240. }
  241. this.activeFlowIndex = flowIndex
  242. this.activeUserIndex = userIndex
  243. // 1 全公司 2 指定成员 3 指定角色
  244. if (flowItem.rangeType === 1) {
  245. // 从全公司中选人
  246. bridge.user = {
  247. title: '选择审核人',
  248. maxlength: 1,
  249. guid: this.guid,
  250. defaultVal: defaultVal
  251. }
  252. } else {
  253. // 部分选人
  254. bridge.user = {
  255. title: '选择审核人',
  256. maxlength: 1,
  257. guid: this.guid,
  258. list: this.auditInfo.examineFlowList[flowIndex].userList,
  259. defaultVal: defaultVal
  260. }
  261. }
  262. uni.$on('selected-user', this.selectedUser)
  263. this.$Router.navigateTo('/pages_common/selectList/user')
  264. },
  265. /**
  266. * 选中员工
  267. * @param {Object} data
  268. */
  269. selectedUser(data) {
  270. if (this.guid === data.guid) {
  271. if (data.data.length > 0) {
  272. const user = data.data[0]
  273. console.log('activeFlowIndex', this.activeFlowIndex)
  274. const findIndex = this.flowList[this.activeFlowIndex].userList.findIndex(o => o.userId === user.userId)
  275. if (findIndex !== -1 && findIndex !== this.activeUserIndex) {
  276. setTimeout(() => {
  277. this.$toast('已经选择过该审批人啦')
  278. }, 100)
  279. } else {
  280. if (this.activeUserIndex !== -1) {
  281. this.flowList[this.activeFlowIndex].userList.splice(this.activeUserIndex, 1, user)
  282. } else {
  283. this.flowList[this.activeFlowIndex].userList.push(user)
  284. }
  285. }
  286. }
  287. }
  288. this.activeFlowIndex = -1
  289. uni.$off('selected-user')
  290. },
  291. getSaveData() {
  292. if (this.flowList.length === 0) return {}
  293. const optionalList = []
  294. for (let i = 0; i < this.flowList.length; i++) {
  295. const item = this.flowList[i]
  296. if (item.examineType === 4) {
  297. if (this.$isEmpty(item.userList)) {
  298. this.$toast('请完善审批信息')
  299. return null
  300. }
  301. optionalList.push({
  302. flowId: item.flowId,
  303. userList: item.userList.map(u => u.userId)
  304. })
  305. }
  306. }
  307. return { optionalList }
  308. }
  309. }
  310. }
  311. </script>
  312. <style scoped lang="scss">
  313. .wk-audit-add {
  314. width: 100%;
  315. .header {
  316. width: 100%;
  317. font-size: 24rpx;
  318. background-color: #F3F5FA;
  319. padding: 20rpx 30rpx;
  320. }
  321. .content {
  322. width: 100%;
  323. font-size: $wk-font-base;
  324. color: $dark;
  325. background-color: white;
  326. padding: 30rpx 24rpx 40rpx;
  327. .flow-item {
  328. position: relative;
  329. .flow-item-title {
  330. @include left;
  331. .dot-circle {
  332. width: 20rpx;
  333. height: 20rpx;
  334. border-radius: 50%;
  335. background-color: #E1E1E1;
  336. margin-right: 15rpx;
  337. }
  338. .text {
  339. font-size: $wk-font-sm;
  340. }
  341. .badge {
  342. color: white;
  343. font-size: 20rpx;
  344. line-height: normal;
  345. background-color: #FD715A;
  346. margin-left: 15rpx;
  347. padding: 0 15rpx;
  348. border-radius: 30rpx;
  349. }
  350. }
  351. .flow-item-body {
  352. width: 100%;
  353. flex-wrap: wrap;
  354. padding-left: 20rpx;
  355. @include left;
  356. .user-box {
  357. position: relative;
  358. flex-direction: column;
  359. margin: 15rpx 22rpx;
  360. @include center;
  361. .avatar {
  362. width: 70rpx;
  363. height: 70rpx;
  364. margin-bottom: 8rpx;
  365. }
  366. .add {
  367. font-size: 52rpx;
  368. color: $light;
  369. font-weight: 300;
  370. border-radius: 50%;
  371. border: 1rpx dotted #ccc;
  372. @include center;
  373. }
  374. .name {
  375. font-size: 22rpx;
  376. color: $gray;
  377. }
  378. .grade {
  379. font-size: $wk-font-sm;
  380. }
  381. .delete-icon {
  382. position: absolute;
  383. top: -10rpx;
  384. right: 0;
  385. width: 32rpx;
  386. height: 32rpx;
  387. background-color: white;
  388. border-radius: 50%;
  389. }
  390. }
  391. }
  392. .line {
  393. position: absolute;
  394. top: 10rpx;
  395. left: 10rpx;
  396. width: 1rpx;
  397. height: 100%;
  398. background-color: #E1E1E1;
  399. }
  400. }
  401. }
  402. }
  403. </style>