teamEdit.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="default_page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='编辑团队' :interceptBack="true" @back="requestBack"></cus-header>
  4. <cus-team-info-fill ref="teamRef" :teamId="id" :submitting="saving" @handleConfirm="handleConfirm" :confirmText="confirmText"></cus-team-info-fill>
  5. <view class="dialog adffcacjc" v-if="show">
  6. <view class="dbox">
  7. <view class="dbox-title">温馨提示</view>
  8. <view class="dbox-content">本次团队配置修改将在本团队<span>所有激活状态下的PERILL团队发展动态评估问卷中</span>生效,确定提交吗?</view>
  9. <view class="dbox-btns adfacjb">
  10. <view class="zt_btn" @click="editConfirm">确定</view>
  11. <view class="qx_btn" @click="show=false">取消</view>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import CusTeamInfoFill from '@/components/CusTeamInfoFill/index.vue'
  19. export default {
  20. components:{ CusTeamInfoFill },
  21. data(){
  22. return {
  23. id:'',
  24. teamInfo:null,
  25. confirmText:'确定',
  26. scaleName:'',
  27. hierarchyName:'',
  28. submitDto:null,
  29. show:false,
  30. saving:false,
  31. saveSucceeded:false,
  32. saveStage:'idle',
  33. navigationTimer:null,
  34. navigationReject:null,
  35. pageUnloaded:false
  36. }
  37. },
  38. onLoad(options) {
  39. this.pageUnloaded = false
  40. this.id = options.id;
  41. this.scaleName = options.scaleName;
  42. this.hierarchyName = options.hierarchyName;
  43. this.getDetail()
  44. },
  45. onShow() {
  46. if (!this.id) return
  47. this.$nextTick(() => {
  48. const background = this.$refs.teamRef && this.$refs.teamRef.$refs.backgroundRef
  49. if (background) background.refreshFiles(this.id).catch(error => {
  50. this.$showToast(error && (error.message || error.msg) || '资料列表刷新失败')
  51. })
  52. })
  53. },
  54. onUnload() {
  55. this.pageUnloaded = true
  56. this.cancelPendingRedirect(new Error('页面已离开'))
  57. },
  58. methods:{
  59. hasPendingBackgroundFiles(){
  60. const team = this.$refs.teamRef
  61. return Boolean(team && (team.hasUnresolvedBackgroundFiles()
  62. || team.isBackgroundUploadActive()))
  63. },
  64. requestBack(){
  65. if(this.saving) return this.$showToast('团队正在保存,请稍候')
  66. if(!this.hasPendingBackgroundFiles()) return uni.navigateBack()
  67. uni.showModal({
  68. title:'背景资料尚未完成',
  69. content:'仍有背景资料正在上传或等待重试,返回将丢弃待处理队列;已发出的上传可能仍会完成。确定返回吗?',
  70. confirmText:'仍然返回',
  71. confirmColor:'#FD4F66',
  72. success: result => {
  73. if(result.confirm) uni.navigateBack()
  74. }
  75. })
  76. },
  77. getDetail(){
  78. this.$api.get(`/core/user/team/${this.id}`).then(({data:res})=>{
  79. if(res.code!==0) return this.$showToast(res.msg)
  80. this.teamInfo = res.data;
  81. this.$refs.teamRef.setTeamInfo(res.data)
  82. this.$refs.teamRef.teamInfo.functionIds = res.data.functions.map(f=>f.id);
  83. this.$refs.teamRef.teamInfo.orgIds = res.data.organizations.map(o=>o.id);
  84. this.$refs.teamRef.areaText = res.data.provinceName+res.data.cityName;
  85. this.$refs.teamRef.industryText = res.data.industryName;
  86. this.$refs.teamRef.functionTypeText = res.data.functions.map(f=>f.functionName).join('、');
  87. this.$refs.teamRef.architectureTypeText = res.data.organizations.map(f=>f.orgName).join('、');
  88. this.$refs.teamRef.teamScaleText = this.scaleName;
  89. this.$refs.teamRef.teamLevelText = this.hierarchyName;
  90. })
  91. },
  92. handleConfirm(data){
  93. this.submitDto = data;
  94. this.show = true;
  95. },
  96. async editConfirm(){
  97. if(this.saving) return
  98. this.saving = true
  99. try {
  100. if(!this.saveSucceeded) {
  101. this.saveStage = 'save'
  102. const { data:res } = await this.$api.put('/core/user/team',this.submitDto)
  103. if(res.code!==0){
  104. this.$showToast(res.msg)
  105. return
  106. }
  107. this.saveSucceeded = true
  108. this.show = false
  109. this.$showToast('编辑成功')
  110. }
  111. this.saveStage = 'navigate'
  112. await this.runDelayedRedirect(({ success, fail }) => {
  113. uni.redirectTo({
  114. url:'/pagesMy/team',
  115. success,
  116. fail
  117. })
  118. })
  119. } catch(error) {
  120. if(!this.pageUnloaded) {
  121. const fallback = this.saveStage === 'navigate' ? '页面跳转失败,请重试' : '团队编辑失败,请重试'
  122. const message = error && (error.message || error.msg)
  123. this.$showToast(message && this.saveStage === 'navigate' ? `页面跳转失败:${message}` : message || fallback)
  124. }
  125. } finally {
  126. this.saving = false
  127. }
  128. },
  129. runDelayedRedirect(invokeRedirect) {
  130. return new Promise((resolve, reject) => {
  131. if(this.pageUnloaded) {
  132. reject(new Error('页面已离开'))
  133. return
  134. }
  135. let settled = false
  136. const settle = (callback, value) => {
  137. if(settled) return
  138. settled = true
  139. this.navigationTimer = null
  140. this.navigationReject = null
  141. callback(value)
  142. }
  143. this.navigationReject = error => settle(reject, error)
  144. this.navigationTimer = setTimeout(() => {
  145. this.navigationTimer = null
  146. if(this.pageUnloaded) {
  147. settle(reject, new Error('页面已离开'))
  148. return
  149. }
  150. try {
  151. invokeRedirect({
  152. success: result => {
  153. if(this.pageUnloaded) settle(reject, new Error('页面已离开'))
  154. else settle(resolve, result)
  155. },
  156. fail: error => settle(reject, new Error(error && (error.errMsg || error.message) || '跳转失败'))
  157. })
  158. } catch(error) {
  159. settle(reject, error)
  160. }
  161. },1500)
  162. })
  163. },
  164. cancelPendingRedirect(error) {
  165. if(this.navigationTimer) clearTimeout(this.navigationTimer)
  166. this.navigationTimer = null
  167. const reject = this.navigationReject
  168. this.navigationReject = null
  169. if(reject) reject(error || new Error('跳转已取消'))
  170. }
  171. }
  172. }
  173. </script>
  174. <style scoped lang="scss">
  175. .default_page{
  176. box-sizing: border-box;
  177. }
  178. .dialog{
  179. position: fixed;
  180. left: 0;
  181. right: 0;
  182. top: 0;
  183. bottom: 0;
  184. background: rgba(0, 0, 0, .4);
  185. z-index: 1000;
  186. .dbox{
  187. width: calc(100% - 150rpx);
  188. background: #FFFFFF;
  189. border-radius: 32rpx;
  190. padding: 48rpx 30rpx;
  191. box-sizing: border-box;
  192. &-title{
  193. font-family: PingFang-SC, PingFang-SC;
  194. font-weight: bold;
  195. font-size: 34rpx;
  196. color: #002846;
  197. line-height: 48rpx;
  198. text-align: center;
  199. }
  200. &-content{
  201. padding: 0 14rpx;
  202. font-family: PingFangSC, PingFang SC;
  203. font-weight: 400;
  204. font-size: 32rpx;
  205. color: #002846;
  206. line-height: 54rpx;
  207. text-align: center;
  208. margin-top: 30rpx;
  209. span{
  210. font-weight: bold;
  211. }
  212. }
  213. &-btns{
  214. margin-top: 56rpx;
  215. &>view{
  216. width: calc(50% - 20rpx);
  217. }
  218. }
  219. }
  220. }
  221. </style>