ce.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. // 创建与编辑通用页面组件
  2. <template>
  3. <ws-page :menuIndex="1">
  4. <section class="group-edit">
  5. <h2>{{isEdit ? '编辑' : '创建'}}云端协作群组</h2>
  6. <section class="inputs">
  7. <section class="input">
  8. 群组名称:
  9. <el-input placeholder="请输入" v-model="group"></el-input>
  10. </section>
  11. <section class="input">
  12. 管理人员:
  13. <el-input placeholder="请输入项目经理ID,多个以逗号,隔开" v-model="manager"></el-input>
  14. </section>
  15. </section>
  16. <p class="bold">关联工作</p>
  17. <el-table
  18. v-if="list.length"
  19. ref="multipleTable"
  20. :data="list"
  21. tooltip-effect="dark"
  22. style="width: 100%;"
  23. @select="handleSelectCell"
  24. @selection-change="handleSelectionChange"
  25. >
  26. <el-table-column type="selection"></el-table-column>
  27. <el-table-column prop="id" label="工作ID">
  28. <template slot-scope="scope">{{ scope.row.id }}</template>
  29. </el-table-column>
  30. <el-table-column prop="nickname" label="开发者">
  31. <template slot-scope="scope">{{ `${scope.row.nickname}(${scope.row.developer_uid})` }}</template>
  32. </el-table-column>
  33. <el-table-column prop="occupation_name" label="职业方向"></el-table-column>
  34. <el-table-column prop="status_name" label="状态"></el-table-column>
  35. </el-table>
  36. <section class="list-empty" v-else>
  37. <img src="~@/assets/img/group/empty.png" alt="empty">
  38. <p>没有符合条件的云端工作</p>
  39. </section>
  40. <el-pagination
  41. class="pagination"
  42. v-if="pageTotal"
  43. background
  44. layout="prev, pager, next"
  45. :total="pageTotal"
  46. :page-size="pageSize"
  47. @current-change="changePage"
  48. ></el-pagination>
  49. <section class="ctrls">
  50. <el-button type="primary" @click="clickSave">保存</el-button>
  51. <el-button @click="clickCancel">取消</el-button>
  52. </section>
  53. </section>
  54. </ws-page>
  55. </template>
  56. <script>
  57. import mixinGroup from '@/mixins/group'
  58. export default {
  59. head() {
  60. return {
  61. title: '编辑云端工作群组',
  62. }
  63. },
  64. mixins: [mixinGroup],
  65. data() {
  66. return {
  67. // 当前页面
  68. currentPage: 1,
  69. // 列表数据
  70. list: [],
  71. // 群组名称
  72. group: '',
  73. // 管理人员
  74. manager: '',
  75. // 是否是编辑
  76. isEdit: !!this.$route.query.isEdit,
  77. // 总条目
  78. pageTotal: 0,
  79. pageSize: 8,
  80. // 初次请求info, 防止点击页码刷掉input内容
  81. isInitial: true,
  82. hash: {},
  83. // 列表缓存数据, 用来保存状态
  84. tempListData: {},
  85. }
  86. },
  87. computed: {
  88. },
  89. mounted() {
  90. if (this.hasLogined) {
  91. this.getInfo()
  92. } else {
  93. // 前往登录页
  94. this.goLogin()
  95. }
  96. },
  97. methods: {
  98. /**
  99. * 页码变化
  100. */
  101. changePage(page) {
  102. this.currentPage = page
  103. this.getInfo()
  104. },
  105. async getInfo() {
  106. let jobList
  107. let res
  108. let tempBobList = this.tempListData[this.currentPage]
  109. if (tempBobList) jobList = tempBobList
  110. else {
  111. let body = { page: this.currentPage, page_size: this.pageSize }
  112. if (this.isEdit) body.id = this.detailID
  113. res = await this.$axios.$post(`/api/group/getInfo`, body)
  114. }
  115. // page 默认1 page_size 默认8 id 编辑时必填,创建时不传
  116. let data
  117. if (!jobList && res) {
  118. data = res.data
  119. jobList = data.job_list
  120. } else if (!jobList && !res) {
  121. this.$message({
  122. message: '请求错误',
  123. type: 'error',
  124. })
  125. }
  126. this.tempListData[this.currentPage] = jobList
  127. this.list = jobList.list
  128. this.pageTotal = jobList.total
  129. if (this.isInitial) {
  130. this.isInitial = false
  131. this.group = data.name || ``
  132. this.manager = data.manager_uids || ``
  133. }
  134. this.$nextTick(() => {
  135. this.list.forEach(i => {
  136. if (i.selected) this.$refs.multipleTable.toggleRowSelection(i, true)
  137. })
  138. })
  139. },
  140. /**
  141. * 多选控制器处理
  142. */
  143. handleSelectionChange(vals) {
  144. },
  145. /**
  146. * 手动点击选项
  147. */
  148. handleSelectCell(vals, row) {
  149. row.selected = !row.selected
  150. },
  151. /**
  152. * (1)点击“保存”,对表单字段进行如下检测:
  153. 如果群组名称为空,toast提示:请输入群组名称
  154. 如果有输入管理人员,进行用户查询,不存在则toast提示:请输入正确的用户ID
  155. 如果没有勾选关联任一工作,toast提示:请选择要关联的工作
  156. 以上检测通过,则向后端提交,成功后弹toast提示:保存成功,然后跳到对应的详情页
  157. */
  158. async clickSave() {
  159. let job_ids = this.getIds()
  160. if (!this.group) {
  161. this.$message({
  162. message: '请输入群组名称',
  163. icon: 'error',
  164. })
  165. return
  166. } else if (!job_ids.length) {
  167. this.$message({
  168. message: '请选择要关联的工作',
  169. icon: 'error',
  170. })
  171. return
  172. }
  173. /**
  174. * 更新
  175. /api/group/update
  176. 参数:
  177. name
  178. manager_uids
  179. job_ids
  180. id 必填
  181. */
  182. let body = {
  183. name: this.group,
  184. manager_uids: this.manager,
  185. job_ids,
  186. }
  187. if (this.isEdit) body.id = this.detailID
  188. let res = await this.$axios.$post(`/api/group/${this.isEdit ? 'update' : 'create'}`, body)
  189. if (res) {
  190. this.$message({
  191. message: '保存成功',
  192. type: 'success'
  193. })
  194. setTimeout(() => {
  195. this.$router.go(-1)
  196. }, 1500)
  197. }
  198. },
  199. /**
  200. * 基于tempListData的全部列表筛选出ids
  201. */
  202. getIds() {
  203. let ids = ``
  204. Object.keys(this.tempListData).forEach(key => {
  205. this.tempListData[key].list.forEach(i => {
  206. if (i.selected) ids += `${i.id},`
  207. })
  208. })
  209. return ids.replace(/,$/, ``)
  210. },
  211. clickCancel() {
  212. this.$confirm('确定不保存已修改的内容吗?', '提示', {
  213. confirmButtonText: '确定',
  214. cancelButtonText: '取消',
  215. type: 'warning'
  216. }).then(() => {
  217. this.$router.go(-1)
  218. }).catch(() => {
  219. this.$message({
  220. type: 'info',
  221. message: '已取消'
  222. })
  223. })
  224. },
  225. }
  226. }
  227. </script>
  228. <style scoped>
  229. h2 {
  230. margin: 5px 0 25px;
  231. text-align: center;
  232. }
  233. .group-edit {
  234. display: flex;
  235. flex-direction: column;
  236. width: 816px;
  237. background: white;
  238. padding: 20px;
  239. }
  240. .input,
  241. .bold {
  242. font-weight: 800;
  243. font-size: 14px;
  244. }
  245. .input {
  246. display: flex;
  247. align-items: center;
  248. margin-top: 20px;
  249. }
  250. .el-input {
  251. display: flex;
  252. align-items: center;
  253. width: 304px;
  254. }
  255. .bold {
  256. margin: 25px 0 10px;
  257. }
  258. .list-empty {
  259. display: flex;
  260. flex-direction: column;
  261. justify-content: center;
  262. align-items: center;
  263. min-height: 500px;
  264. color: #999;
  265. font-size: 14px;
  266. }
  267. .pagination {
  268. margin: 30px 0;
  269. }
  270. .ctrls {
  271. margin: 0 0 150px;
  272. }
  273. .el-button {
  274. width: 120px;
  275. border: none;
  276. }
  277. .el-button:nth-child(2) {
  278. background: #ececec;
  279. }
  280. </style>