ManageTeamOperate.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <script>
  2. import { get, post, put, postWithHeader, putWithHeader } from '../../../utils/request'
  3. export default {
  4. data () {
  5. return {
  6. formData: {
  7. teamName: '',
  8. teamDescription: '',
  9. teamAdminId: [],
  10. productList: [{
  11. productId: '',
  12. licenseNumber: ''
  13. }]
  14. },
  15. flag: '',
  16. adminOptions: [],
  17. projectOptions: [],
  18. click: true
  19. }
  20. },
  21. computed: {
  22. disabled () {
  23. let isEmpty = true
  24. isEmpty = this.formData.teamName.trim() === '' && this.formData.teamDescription.trim() === '' && this.formData.teamAdminId.length === 0
  25. this.formData.productList.forEach((item)=>{
  26. Object.keys(item).forEach((key)=>{
  27. if (item[key] !== '' && item[key] !== null && item[key] !== undefined) {
  28. isEmpty = false
  29. }
  30. })
  31. })
  32. return isEmpty
  33. }
  34. },
  35. created () {
  36. let rowData = {}
  37. if (!Object.keys(this.$route.params).length) {
  38. rowData = JSON.parse(localStorage.getItem('rowData'))
  39. } else {
  40. rowData = this.$route.params
  41. localStorage.setItem('rowData', JSON.stringify(this.$route.params))
  42. }
  43. this.flag = rowData.flag
  44. if (rowData.flag === 'edit') {
  45. if (rowData.teamInfo) {
  46. this.formData.teamId = rowData.teamInfo.id
  47. this.formData.teamName = rowData.teamInfo.name
  48. this.formData.teamDescription = rowData.teamInfo.description
  49. this.formData.productList[0].licenseNumber = rowData.teamInfo.licenseAmount
  50. }
  51. }
  52. this.getAdmin()
  53. this.getProduct()
  54. },
  55. methods: {
  56. // 提交表单
  57. submitForm () {
  58. if(this.click){
  59. this.click = false
  60. let emptyFlag = true
  61. let productArr = []
  62. for (const item of this.formData.productList) {
  63. productArr.push(item['productId'])
  64. }
  65. emptyFlag = productArr.includes('')
  66. if (this.formData.teamName.trim() === '' || emptyFlag) {
  67. this.$message.error({duration: 5000, message: 'Missing required information'})
  68. //限制点击
  69. setTimeout(() => {
  70. this.click = true
  71. }, 3000)
  72. } else {
  73. if (this.flag === 'create') this.createTeam()
  74. if (this.flag === 'edit') this.editTeam()
  75. }
  76. }
  77. },
  78. // 重置表单
  79. resetForm (formName) {
  80. this.$refs[formName].resetFields()
  81. },
  82. removeDomain(item) {
  83. var index = this.formData.productList.indexOf(item)
  84. if (index !== -1) {
  85. this.formData.productList.splice(index, 1)
  86. }
  87. console.log(this.formData.productList)
  88. },
  89. // 添加卡片
  90. addDomain () {
  91. this.formData.productList.push({
  92. licenseNumber: '',
  93. productId: ''
  94. })
  95. console.log(this.formData.productList)
  96. },
  97. // 创建团队
  98. createTeam () {
  99. let data = JSON.parse(JSON.stringify(this.formData))
  100. data.productList.forEach(item =>{
  101. if (item.licenseNumber === null || item.licenseNumber === '') {
  102. item.licenseNumber = 0
  103. }
  104. })
  105. data.teamAdminId = data.teamAdminId.filter((item) => {
  106. return item !== 'All'
  107. })
  108. postWithHeader('/pdf-tech/vppTeam/createTeam', JSON.stringify(data)).then((res) => {
  109. //限制点击
  110. setTimeout(() => {
  111. this.click = true
  112. }, 1000)
  113. if (res.data.code === 200) {
  114. this.$message({
  115. duration: 5000,
  116. message: 'Change Success',
  117. type: 'success'
  118. })
  119. this.$router.push({name:'ManageTeam'})
  120. } else (
  121. this.$message.error({duration: 5000, message:res.data.msg})
  122. )
  123. })
  124. },
  125. // 编辑团队
  126. editTeam () {
  127. let data = JSON.parse(JSON.stringify(this.formData))
  128. data.productList.forEach(item =>{
  129. if (item.licenseNumber === null || item.licenseNumber === '') {
  130. item.licenseNumber = 0
  131. }
  132. })
  133. data.teamAdminId = data.teamAdminId.filter((item) => {
  134. return item !== 'All'
  135. })
  136. putWithHeader('/pdf-tech/vppTeam/editTeam', JSON.stringify(data)).then((res) => {
  137. //限制点击
  138. setTimeout(() => {
  139. this.click = true
  140. }, 1000)
  141. if (res.data.code === 200) {
  142. this.$message({
  143. duration: 5000,
  144. message: 'Change Success',
  145. type: 'success'
  146. })
  147. this.$router.push({name:'ManageTeam'})
  148. } else (
  149. this.$message.error(res.data.msg)
  150. )
  151. })
  152. },
  153. // 获取所有管理员
  154. getAdmin () {
  155. get('/pdf-tech/vppRTeamMemberRole/pageForAdmin').then((res) => {
  156. if (res.data.code === 200) {
  157. res.data.result.list.forEach(item => {
  158. if (item.memberRole !== '1') {
  159. this.adminOptions.push({
  160. label: item.email,
  161. value: item.id
  162. })
  163. }
  164. })
  165. }
  166. })
  167. },
  168. // 获取所有产品
  169. getProduct () {
  170. get('/pdf-tech/product/listWithAdmin').then((res) => {
  171. if (res.data.code === 200) {
  172. res.data.result.forEach(item => {
  173. this.projectOptions.push({
  174. label: item.name,
  175. value: item.id
  176. })
  177. })
  178. }
  179. })
  180. },
  181. // Team Admin下拉框全选功能
  182. selectAllAdmin() {
  183. if (this.formData.teamAdminId.length < this.adminOptions.length) {
  184. this.formData.teamAdminId = []
  185. this.adminOptions.map((item) => {
  186. this.formData.teamAdminId.push(item.value)
  187. })
  188. this.formData.teamAdminId.unshift('All')
  189. } else {
  190. this.formData.teamAdminId = []
  191. }
  192. },
  193. changeSelectAdmin(val) {
  194. if (!val.includes('All') && val.length === this.adminOptions.length) {
  195. this.formData.teamAdminId.unshift('All')
  196. } else if (val.includes('All') && (val.length - 1) < this.adminOptions.length) {
  197. this.formData.teamAdminId = this.formData.teamAdminId.filter((item) => {
  198. return item !== 'All'
  199. })
  200. }
  201. },
  202. removeTag(val) {
  203. if (val === 'All') {
  204. this.formData.teamAdminId = []
  205. }
  206. }
  207. },
  208. // 切换路由时清除本地存储数据
  209. beforeRouteLeave (to, from, next) {
  210. localStorage.removeItem('rowData')
  211. next()
  212. }
  213. }
  214. </script>
  215. <template>
  216. <div>
  217. <h1>Team {{ flag === 'create' ? 'Create' : 'Edit'}}</h1>
  218. <div class="block mt-24px p-40px pr-50px">
  219. <el-form label-position="top" label-width="80px" :model="formData" ref="formData">
  220. <el-form-item>
  221. <template slot="label">
  222. <span>Team Name</span>
  223. <span class="text-[#FF5054]">*</span>
  224. </template>
  225. <el-input v-model="formData.teamName" class="under-border"></el-input>
  226. </el-form-item>
  227. <el-form-item label="Team Description">
  228. <el-input v-model="formData.teamDescription" class="under-border"></el-input>
  229. </el-form-item>
  230. <el-form-item label="Team Admin">
  231. <el-select
  232. v-model="formData.teamAdminId"
  233. @change='changeSelectAdmin'
  234. @remove-tag='removeTag'
  235. multiple
  236. placeholder=""
  237. class="w-600px">
  238. <el-option value="All" @click.native='selectAllAdmin'>All</el-option>
  239. <el-option
  240. v-for="item in adminOptions"
  241. :key="item.value"
  242. :label="item.label"
  243. :value="item.value">
  244. </el-option>
  245. </el-select>
  246. </el-form-item>
  247. <div class="w-600px border-1 border-[#1460F3] rounded-8px p-12px pb-0 mb-24px relative" v-for="(item, index) in formData.productList" :key="index">
  248. <img v-show="formData.productList.length > 1" src="@/assets/images/minus.png" alt="minus" class="w-24px h-24px absolute top-[-12px] right-[-12px] cursor-pointer" @click.prevent="removeDomain(item)">
  249. <el-form-item>
  250. <template slot="label">
  251. <span>Product</span>
  252. <span class="text-[#FF5054]">*</span>
  253. </template>
  254. <select v-model="item.productId" placeholder="Project" class="w-[100%] !h-40px !pl-12px focus-visible:(outline-none)" :class="{ '!text-[#232A40]': item.productId !== '' }">
  255. <option value="">Project</option>
  256. <option v-for="item in projectOptions" :key="item.value" :value="item.value">{{ item.label }}</option>
  257. </select>
  258. </el-form-item>
  259. <el-form-item label="Team License Number" class="!mb-22px">
  260. <el-input v-model.number="item.licenseNumber"></el-input>
  261. </el-form-item>
  262. </div>
  263. <div class="w-600px h-48px border-1 border-dashed border-[#1460F3] rounded-8px flex justify-center items-center">
  264. <img src="@/assets/images/add.png" alt="add" class="w-24px h-24px cursor-pointer" @click="addDomain">
  265. </div>
  266. <div class="mt-32px flex">
  267. <router-link :to="{ name: 'ManageTeam' }">
  268. <div class="w-152px h-40px border-1 border-[#1460F3] rounded-8px text-center text-16px text-[#1460F3] font-700 leading-40px mr-16px"
  269. @click="resetForm('formData')">Cancel</div>
  270. </router-link>
  271. <div :class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'">
  272. <div class="w-152px h-40px border-1 border-[#1460F3] rounded-8px bg-[#1460F3] text-center text-16px text-[#fff] font-700 leading-40px"
  273. :class="disabled ? 'opacity-20 pointer-events-none' : 'hover:bg-[#3776f2]'"
  274. @click="submitForm()">Save</div>
  275. </div>
  276. </div>
  277. </el-form>
  278. </div>
  279. <!-- <el-dialog
  280. title=""
  281. :visible.sync="dialogVisible"
  282. width="376px"
  283. center
  284. :show-close="false"
  285. >
  286. <img src="@/assets/images/close_user.png" alt="close_user" class="inline-block w-48px h-48px">
  287. <div class="mt-16px text-16px leading-24px text-[#232A40]">
  288. <p>Your TEAM ADMIN is not on the team.<br />Invite <span class="font-bold">{{ formData.teamAdminId[0] }}</span> to Team Kdan?</p>
  289. </div>
  290. <span slot="footer" class="dialog-footer">
  291. <el-button @click="dialogVisible = false">Change Admin</el-button>
  292. <el-button type="primary" @click="dialogVisible = false">Invite</el-button>
  293. </span>
  294. </el-dialog> -->
  295. </div>
  296. </template>
  297. <style lang="scss" scoped>
  298. ::v-deep .el-form-item {
  299. margin-bottom: 24px;
  300. }
  301. ::v-deep .under-border .el-input__inner {
  302. border-top: none;
  303. border-left: none;
  304. border-right: none;
  305. border-radius: 0;
  306. }
  307. ::v-deep.el-form--label-top .el-form-item__label {
  308. padding: 0 0 4px 12px;
  309. font-size: 14px;
  310. line-height: 20px;
  311. color: #232A40;
  312. font-weight: 700;
  313. }
  314. ::v-deep .el-select {
  315. .el-input__inner {
  316. border-color: #D9D9D9;
  317. }
  318. .el-input .el-select__caret {
  319. color: #808185;
  320. font-weight: bold;
  321. }
  322. .el-tag {
  323. border-color: #8D9CB9;
  324. background-color: #EEF4FF;
  325. margin-left: 8px;
  326. }
  327. .el-tag.el-tag--info {
  328. color: #505258;
  329. font-size: 14px;
  330. padding-left: 4px;
  331. }
  332. .el-tag__close.el-icon-close {
  333. background-color: transparent;
  334. color: #8D9CB9;
  335. font-size: 20px;
  336. font-weight: bold;
  337. }
  338. }
  339. ::v-deep .el-dialog {
  340. border-radius: 8px;
  341. .el-dialog__header {
  342. display: none;
  343. }
  344. .el-dialog__body {
  345. text-align: center;
  346. padding: 24px;
  347. }
  348. .el-dialog__footer {
  349. padding: 0 24px 24px;
  350. .el-button {
  351. width: 133px;
  352. height: 32px;
  353. padding: 0;
  354. &.el-button--default {
  355. border-color: #1460F3;
  356. span {
  357. color: #1460F3;
  358. }
  359. }
  360. span {
  361. line-height: 20px;
  362. }
  363. }
  364. .el-button + .el-button {
  365. margin-left: 8px;
  366. }
  367. }
  368. }
  369. </style>