RequirementDrawer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <el-drawer
  3. v-model="showDrawer"
  4. :size="650"
  5. :before-close="(done) => {
  6. isEditing = false;
  7. done();
  8. }">
  9. <template #title>
  10. <el-row class="entry-row">
  11. <el-col :span="2">
  12. <div class="node-type">{{type}}</div>
  13. </el-col>
  14. <el-col :span="4">
  15. <template class="entry-row">
  16. <span>#{{id}}</span>
  17. </template>
  18. </el-col>
  19. <el-col :span="8">
  20. <template class="entry-row" v-if="isEditing">
  21. <el-input placeholder="请输入标题" size="mini" style="width: 200px;display: inline;" v-model="editedRequirement.title"/>
  22. </template>
  23. <template v-else><h3>{{title}}</h3></template>
  24. </el-col>
  25. <el-col :span="6" :offset="2">
  26. <el-switch
  27. v-if="activeTab ==='basic_info'"
  28. style="float: right;"
  29. v-model="isEditing"
  30. active-text="编辑"
  31. @change="(isEditing) => {
  32. isEditing && fillDefaultValue();
  33. }">
  34. </el-switch>
  35. </el-col>
  36. </el-row>
  37. </template>
  38. <template #default>
  39. <el-row type="flex" justify="center">
  40. <el-col :span="20">
  41. <el-tabs
  42. class="tabs"
  43. v-model="activeTab"
  44. @tab-click="(tab) => {
  45. if(tab.panename !== 'basic_info')
  46. isEditing = false;
  47. }"
  48. >
  49. <el-tab-pane label="基本信息" name="basic_info">
  50. <el-row class="entry-row" style="margin-top: 15px">
  51. <h4>需求描述</h4>
  52. </el-row>
  53. <el-row class="entry-row">
  54. <div v-if="isEditing">
  55. <el-input placeholder="请输入描述"
  56. type="textarea"
  57. maxlength="120"
  58. show-word-limit
  59. :rows="3" style="width: 300px;" v-model="editedRequirement.description" />
  60. <br/>
  61. </div>
  62. <p v-else>{{description}}</p>
  63. </el-row>
  64. <!-- 状态、优先级等 -->
  65. <el-row class="entry-row" style="margin-top: 15px">
  66. <h4>详情</h4>
  67. </el-row>
  68. <el-row style="margin: 3px 20px;width: 100%">
  69. <el-col :span="12">
  70. <RowItem :label="'状态:'">
  71. <div v-if="!isEditing" class="detail-value">
  72. <StateTag :state="state"></StateTag>
  73. </div>
  74. <div v-else>
  75. <el-select style="width: 160px" size="mini" v-model="editedRequirement.state">
  76. <el-option
  77. v-for="item in stateOptions"
  78. :key="item.value"
  79. :value="item.value"
  80. :label="item.value" />
  81. </el-select>
  82. </div>
  83. </RowItem>
  84. <RowItem :label="'优先级:'">
  85. <div class="detail-value" v-if="!isEditing">
  86. <PriorityTag :priority="priority"></PriorityTag>
  87. </div>
  88. <div v-else>
  89. <el-select style="width: 160px" size="mini" v-model="editedRequirement.priority">
  90. <el-option
  91. v-for="item in priorityOptions"
  92. :key="item.value"
  93. :value="item.value"
  94. :label="item.label" />
  95. </el-select>
  96. </div>
  97. </RowItem>
  98. <RowItem :label="'经办人:'">
  99. <div class="detail-value" v-if="!isEditing">
  100. <el-tag>{{processorName}}</el-tag>
  101. </div>
  102. <div v-else>
  103. <el-select style="width: 160px" size="mini" v-model="editedRequirement.processorId" >
  104. <el-option
  105. v-for="item in userOptions"
  106. :key="item.value"
  107. :value="item.value"
  108. :label="item.label" />
  109. </el-select>
  110. </div>
  111. </RowItem>
  112. </el-col>
  113. <el-col :span="12">
  114. <RowItem :label="'工作量:'">
  115. <div class="detail-value" v-if="!isEditing">
  116. <span>{{timeToTake}}人日</span>
  117. </div>
  118. <div v-else>
  119. <el-input-number size="mini" v-model="editedRequirement.timeToTake" :min="1" :max="200">
  120. </el-input-number>
  121. </div>
  122. </RowItem>
  123. <RowItem :label="'开始时间:'"><span>{{formatter(startTime)}}</span></RowItem>
  124. <RowItem :label="'完成时间:'"><span>{{formatter(endTime)}}</span></RowItem>
  125. </el-col>
  126. </el-row>
  127. <!-- 相关需求 -->
  128. <template v-if="showSons">
  129. <el-row class="entry-row" style="margin-top: 15px">
  130. <h4>子需求</h4>
  131. </el-row>
  132. <template v-if="(childs && childs.length) || false">
  133. <el-row style="margin: 10px 25px;" v-for="item in childs" :key="item.id">
  134. <el-link @click.prevent="changeContent(item.id)" type="primary">{{item.title}}</el-link>
  135. </el-row>
  136. </template>
  137. <template v-else>
  138. <el-row style="margin: 0px 25px;">
  139. 没有子需求
  140. </el-row>
  141. </template>
  142. </template>
  143. <el-row v-if="isEditing" class="entry-row" style="margin-top: 15px">
  144. <el-button @click="submitEdit" v-loading="confirmLoading" size="mini" type="primary">提交</el-button>
  145. <el-button @click="cancelEdit" size="mini">取消</el-button>
  146. </el-row>
  147. </el-tab-pane>
  148. <template v-if="type!=='任务'">
  149. <el-tab-pane label="历史提交" name="commit_history">
  150. <!-- 相关提交 -->
  151. <el-row class="entry-row" style="margin-top: 15px">
  152. <el-table :data="commits">
  153. <el-table-column type="expand">
  154. <template #default="scope">
  155. <RowItem :label="'message:'" :label-span="5" :value-span="19">{{scope.row.message}}</RowItem>
  156. <RowItem :label="'timestamp:'" :label-span="5" :value-span="19">{{scope.row.timestamp}}</RowItem>
  157. </template>
  158. </el-table-column>
  159. <el-table-column
  160. prop="id"
  161. label="ID"
  162. align="center"
  163. >
  164. </el-table-column>
  165. <el-table-column
  166. prop="title"
  167. label="标题"
  168. align="center"
  169. >
  170. </el-table-column>
  171. <el-table-column
  172. prop="gitlabUsername"
  173. label="用户"
  174. align="center"
  175. >
  176. </el-table-column>
  177. </el-table>
  178. </el-row>
  179. </el-tab-pane>
  180. </template>
  181. </el-tabs>
  182. </el-col>
  183. </el-row>
  184. </template>
  185. </el-drawer>
  186. </template>
  187. <script>
  188. import { RequirementAPI } from '@/api';
  189. import PriorityTag from '@/components/PriorityTag.vue';
  190. import StateTag from '@/components/StateTag.vue';
  191. import { priorityOptions, stateOptions } from '@/utils/constants';
  192. import { formatter } from '@/utils/time';
  193. import RowItem from './RowItem.vue';
  194. export default {
  195. name: 'RequirementDrawers',
  196. components: { RowItem, PriorityTag, StateTag },
  197. emits: ['change', 'requirement-update'],
  198. props: {
  199. id: Number,
  200. type: String,
  201. title: String,
  202. description: String,
  203. state: String,
  204. priority: String,
  205. processorId: Number,
  206. processorName: String,
  207. timeToTake: Number,
  208. startTime: String,
  209. endTime: String,
  210. childs: Array,
  211. parentId: Number,
  212. commits: Array,
  213. showSons: {
  214. type: Boolean,
  215. default: true,
  216. },
  217. },
  218. data() {
  219. return {
  220. activeTab: 'basic_info',
  221. showDrawer: false,
  222. isEditing: false,
  223. editedRequirement: {
  224. title: null,
  225. description: null,
  226. state: null,
  227. timeToTake: null,
  228. priority: null,
  229. processorId: null,
  230. processorName: null,
  231. },
  232. confirmLoading: false,
  233. stateOptions,
  234. priorityOptions,
  235. };
  236. },
  237. computed: {
  238. userOptions() {
  239. return this.$store.getters.userOptions;
  240. },
  241. },
  242. methods: {
  243. formatter,
  244. show() {
  245. this.showDrawer = true;
  246. },
  247. fillDefaultValue() {
  248. this.editedRequirement.title = this.title;
  249. this.editedRequirement.description = this.description;
  250. this.editedRequirement.state = this.state;
  251. this.editedRequirement.timeToTake = this.timeToTake;
  252. this.editedRequirement.priority = this.priority;
  253. this.editedRequirement.processorId = this.processorId;
  254. this.editedRequirement.processorName = this.processorName;
  255. },
  256. submitEdit() {
  257. this.confirmLoading = true;
  258. const param = {
  259. id: this.id,
  260. title: this.editedRequirement.title,
  261. description: this.editedRequirement.description,
  262. state: this.editedRequirement.state,
  263. timeToTake: this.editedRequirement.timeToTake,
  264. priority: this.editedRequirement.priority,
  265. processorId: this.editedRequirement.processorId,
  266. };
  267. RequirementAPI.updateTreeNode(param).then((res) => {
  268. this.isEditing = false;
  269. this.$emit('requirement-update');
  270. this.showDrawer = false;
  271. });
  272. this.confirmLoading = false;
  273. },
  274. cancelEdit() {
  275. this.isEditing = false;
  276. this.fillDefaultValue();
  277. },
  278. changeContent(id) {
  279. this.$emit('change', id);
  280. },
  281. },
  282. };
  283. </script>
  284. <style lang="scss" scoped>
  285. .entry-row{
  286. width: 100%;
  287. margin: 3px 20px;
  288. display: flex;
  289. flex-direction: row;
  290. align-items: center;
  291. justify-content: flex-start;
  292. h3, h4{
  293. color: #172b4d
  294. }
  295. }
  296. .detail-row{
  297. display: flex;
  298. flex-direction: row;
  299. align-items: center;
  300. line-height: 24px;
  301. margin: 3px 0;
  302. }
  303. .detail-value{
  304. display: flex;
  305. flex-direction: row;
  306. align-items: center;
  307. }
  308. .node-type{
  309. color: #FFFFFF;
  310. border-radius: 3px;
  311. font-size: 14px;
  312. background-color: #42b983;
  313. text-align: center;
  314. }
  315. .state-entry{
  316. border-radius: 5px;
  317. background-color: cornflowerblue;
  318. font-size: 12px;
  319. color: #FFFFFF;
  320. padding: 0px 4px;
  321. cursor: pointer
  322. }
  323. </style>