task-table.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div>
  3. <div class="full-width flex flex-center flex-justify-between">
  4. <el-button
  5. type="primary"
  6. icon="el-icon-plus"
  7. @click="addTask"
  8. v-if="option.addBtn || option.addBtn === undefined"
  9. >新增任务
  10. </el-button>
  11. <div v-else></div>
  12. <el-button circle icon="Refresh" @click="refresh" />
  13. </div>
  14. <div class="header flex flex-justify-between full-width mt-10">
  15. <div
  16. v-for="(item, index) in option.column"
  17. :key="item.label"
  18. class="full-width"
  19. >
  20. <div
  21. v-if="index === 0"
  22. class="flex-child-shrink flex flex-justify-start first"
  23. :style="`width:` + item.width + 'px'"
  24. >
  25. 共 {{ total }}个任务
  26. </div>
  27. <div v-else class="flex-child-average">
  28. {{ item.label }}
  29. </div>
  30. </div>
  31. </div>
  32. <div class="content full-width">
  33. <div
  34. v-for="row in data"
  35. :key="row.id"
  36. class="flex flex-center full-width row"
  37. @click="rowClick(row)"
  38. >
  39. <div
  40. v-for="(column, index) in option.column"
  41. :key="column.label"
  42. class="full-width full-height"
  43. >
  44. <div
  45. v-if="index === 0"
  46. class="full-height flex flex-center flex-justify-start"
  47. :style="`width:` + column.width + 'px'"
  48. >
  49. <div
  50. class="full-width full-height flex flex-justify-start flex-align-center"
  51. >
  52. <div
  53. class="level"
  54. :style="
  55. `background-color:` +
  56. (row && row.currentLevel ? row.currentLevel.color : 'white')
  57. "
  58. ></div>
  59. <wt-tag
  60. :data="status"
  61. :status="row.taskStatus"
  62. :disabled="true"
  63. />
  64. {{ row[column.prop] }}
  65. </div>
  66. </div>
  67. <div v-else-if="index === 1" class="flex flex-center full-height">
  68. {{ row[column.prop] }}
  69. </div>
  70. <div
  71. v-else-if="index === 2"
  72. class="flex-child-average full-height full-width flex flex-center"
  73. >
  74. <div>
  75. <el-tag v-for="tag in row.tagsArray" :key="tag" class="mr-10"
  76. >{{ tag }}
  77. </el-tag>
  78. </div>
  79. </div>
  80. <div
  81. v-else-if="index === 3"
  82. class="flex-child-average full-height full-width flex flex-center"
  83. >
  84. <div>
  85. <div v-if="row.startTime.length > 0 && row.endTime.length === 0">
  86. {{ row.startTime.substring(5) }} 开始
  87. </div>
  88. <div
  89. v-else-if="row.startTime.length === 0 && row.endTime.length > 0"
  90. >
  91. {{ row.endTime.substring(5) }} 截止
  92. </div>
  93. <div v-else>
  94. {{ row.startTime.substring(5) }} 至
  95. {{ row.endTime.substring(5) }}
  96. </div>
  97. </div>
  98. </div>
  99. <div
  100. v-else
  101. class="flex-child-average full-height full-width flex flex-center"
  102. >
  103. <div v-if="row.users !== undefined" class="flex flex-center">
  104. <div v-for="i in row.users" :key="i.id" class="flex flex-center">
  105. <el-tooltip :content="i.name">
  106. <el-avatar
  107. class="ml-10 mr-10"
  108. :size="25"
  109. :src="
  110. i.avatar.length === 0
  111. ? 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
  112. : i.avatar
  113. "
  114. ></el-avatar>
  115. </el-tooltip>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <task
  123. ref="task"
  124. :task="task"
  125. :project-id="projectId"
  126. @success="refresh"
  127. ></task>
  128. </div>
  129. </template>
  130. <script>
  131. import WtTag from '@/views/task/component/wt-tag.vue'
  132. import Task from '@/views/task/component/task.vue'
  133. export default {
  134. components: { Task, WtTag },
  135. props: {
  136. projectId: {
  137. type: String,
  138. default: ''
  139. },
  140. data: {
  141. type: Array,
  142. default: []
  143. },
  144. option: {
  145. type: Object,
  146. default: null
  147. },
  148. total: {
  149. type: Number,
  150. default: 0
  151. }
  152. },
  153. watch: {
  154. data: {
  155. handler(val) {
  156. val.forEach(item => {
  157. const tmp = this.level.find(ele => ele.value === item.level)
  158. item.currentLevel = tmp
  159. })
  160. },
  161. immediate: true
  162. }
  163. },
  164. data() {
  165. return {
  166. task: null,
  167. info: {
  168. taskStatus: ''
  169. },
  170. status: [
  171. {
  172. title: '待确认',
  173. value: 0,
  174. color: '#D7D7D7',
  175. checked: true
  176. },
  177. {
  178. title: '进行中',
  179. value: 1,
  180. color: '#47A6EA',
  181. checked: false
  182. },
  183. {
  184. title: '已提交',
  185. value: 2,
  186. color: '#ECAB56',
  187. checked: false
  188. },
  189. {
  190. title: '已完成',
  191. value: 3,
  192. color: '#80B336',
  193. checked: false
  194. },
  195. {
  196. title: '已取消',
  197. value: 4,
  198. color: '#C72A29',
  199. checked: false
  200. }
  201. ],
  202. level: [
  203. {
  204. title: 'P1',
  205. value: 0,
  206. color: '#C72A29',
  207. checked: true
  208. },
  209. {
  210. title: 'P2',
  211. value: 1,
  212. color: '#E89D42',
  213. checked: false
  214. },
  215. {
  216. title: 'P3',
  217. value: 2,
  218. color: '#47A6EA',
  219. checked: false
  220. },
  221. {
  222. title: 'P4',
  223. value: 3,
  224. color: '#A0A0A0',
  225. checked: false
  226. }
  227. ]
  228. }
  229. },
  230. methods: {
  231. fetchIndex(list, key) {
  232. const index = list.findIndex(ele => ele.value === key)
  233. if (index > -1) {
  234. list.map(ele => {
  235. ele.checked = false
  236. return ele
  237. })
  238. list[index].checked = true
  239. }
  240. return list
  241. },
  242. addTask() {
  243. this.task = null
  244. this.$refs.task.show(1)
  245. },
  246. rowClick(item) {
  247. this.getTaskInfo(item.id)
  248. this.$emit('rowClick', item)
  249. },
  250. getTaskInfo(id) {
  251. this.$api.task.taskInfo({ id }).then(res => {
  252. if (res.code === 200) {
  253. this.task = res.data
  254. this.$nextTick(() => {
  255. this.$refs.task.show(2)
  256. })
  257. } else {
  258. this.$message.error(res.msg)
  259. }
  260. })
  261. },
  262. refresh() {
  263. this.$emit('refresh')
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. .header {
  270. border-bottom: #f7f8fa solid 1px;
  271. padding: 10px 0;
  272. }
  273. .first {
  274. width: 600px;
  275. }
  276. .row {
  277. height: 60px;
  278. border-bottom: #f7f8fa solid 1px;
  279. }
  280. .row:hover {
  281. height: 60px;
  282. background-color: #f7f9fc;
  283. }
  284. .level {
  285. width: 5px;
  286. height: 100%;
  287. margin-right: 10px;
  288. }
  289. </style>