addEditDepart.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. title="设置部门"
  5. :center="true"
  6. align="left"
  7. top="10vh"
  8. width="750px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="handleClose"
  15. >
  16. <el-card style="margin-top: -20px">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. ref="ruleForm"
  21. :model="ruleForm"
  22. status-icon
  23. :size="'mini'"
  24. :rules="rules"
  25. label-width="80px"
  26. class="demo-ruleForm"
  27. >
  28. <el-row style="margin-bottom:20px">
  29. <el-col :span="24">
  30. <el-form-item label="真实姓名" prop="nickname">
  31. <el-input
  32. v-model="ruleForm.nickname"
  33. :placeholder="'真实姓名'"
  34. :disabled="isDetail"
  35. maxlength="100"
  36. />
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="24">
  40. <el-form-item label="手机号" prop="mobile">
  41. <el-input
  42. v-model="ruleForm.mobile"
  43. :placeholder="'手机号'"
  44. maxlength="11"
  45. :disabled="isDetail"
  46. />
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="24">
  50. <el-form-item label="业务公司" required>
  51. <search-work-company
  52. :value="companyNo"
  53. :placeholder="'业务公司'"
  54. :size="'mini'"
  55. @searchChange="companyNosearchChange"
  56. />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="24">
  60. <el-form-item v-loading="departLoading" label="部门" prop="itemid">
  61. <el-cascader
  62. v-model="ruleForm.itemid"
  63. :disabled="!companyNo"
  64. style="width: 100%"
  65. :options="departData"
  66. :props="{value:'id',label:'name',children:'child',expandTrigger:'hover'}"
  67. placeholder="请选择部门"
  68. @change="handleDepartChange"
  69. />
  70. </el-form-item>
  71. </el-col>
  72. </el-row>
  73. </el-form>
  74. </el-col>
  75. <el-col :span="6" class="bottom-btn">
  76. <el-button
  77. type="primary"
  78. :size="'mini'"
  79. @click="submitForm"
  80. >保 存
  81. </el-button>
  82. <el-button :size="'mini'" @click="showModelThis = false">{{
  83. isDetail ? "关 闭" : "取 消"
  84. }}</el-button>
  85. </el-col>
  86. </el-row>
  87. </el-card>
  88. </el-dialog>
  89. </template>
  90. <script>
  91. import asyncRequest from '@/apis/service/interest/account'
  92. import companyHelper from '@/mixins/companyHelper'
  93. import resToken from '@/mixins/resToken'
  94. export default {
  95. name: 'Account',
  96. mixins: [resToken, companyHelper],
  97. props: ['showModel', 'id', 'isDetail', 'sitem'],
  98. data() {
  99. return {
  100. companyNo: '',
  101. roleList: [],
  102. loading: false,
  103. title: '添加账号',
  104. organizeList: [],
  105. showModelThis: this.showModel,
  106. coptions: [],
  107. companyList: [],
  108. is_mainoptions: [],
  109. isIndeterminate: false,
  110. inital: true,
  111. departData: [],
  112. itemlist: [],
  113. ruleForm: {
  114. nickname: '', // 真实姓名
  115. mobile: '', // 手机号
  116. itemid: [], // 角色id
  117. company_relaton: []
  118. },
  119. platformoptions: [],
  120. rulesThis: this.rules,
  121. rules: {
  122. itemid: [
  123. {
  124. type: 'array',
  125. required: true,
  126. message: '请选择部门',
  127. trigger: 'change'
  128. }
  129. ]
  130. }
  131. }
  132. },
  133. watch: {
  134. showModel: function(val) {
  135. this.showModelThis = val
  136. if (val) {
  137. this.initForm()
  138. // this.initDepartData()
  139. }
  140. },
  141. showModelThis(val) {
  142. if (!val) {
  143. this.$emit('cancel')
  144. }
  145. },
  146. companyNo() {
  147. this.ruleForm.itemid = []
  148. if (!this.companyNo) return
  149. this.initDepartData()
  150. }
  151. },
  152. methods: {
  153. handleClose() {
  154. this.showModelThis = false
  155. this.companyNo = ''
  156. this.inital = true
  157. this.itemlist = []
  158. },
  159. handleDepartChange() {
  160. this.$nextTick(() => this.$refs.ruleForm.validateField('itemid'))
  161. },
  162. async initForm() {
  163. this.loading = true
  164. if (this.id === 'add') {
  165. await this.resetForm()
  166. } else {
  167. await this.initData()
  168. }
  169. if (this.id === 'add') {
  170. this.rulesThis = this.rules
  171. }
  172. this.loading = false
  173. },
  174. async initDepartData() {
  175. if (this.departLoading) return
  176. this.departLoading = true
  177. const { data } = await asyncRequest.depart({ companyNo: this.companyNo })
  178. this.departLoading = false
  179. if (data.length === 0) return (this.departData = [])
  180. const dfs = (data) => {
  181. data.forEach(item => {
  182. if (item.child) dfs(item.child)
  183. if (item.child && item.child.length === 0) delete item.child
  184. })
  185. }
  186. dfs(data[0].child)
  187. this.departData = data[0].child
  188. if (this.inital) {
  189. this.inital = false
  190. this.ruleForm.itemid = this.itemlist ? this.itemlist.map(({ id }) => id) : []
  191. }
  192. },
  193. async getClist() {
  194. this.organizeList = []
  195. const { code, data, message } = await asyncRequest.getClist({
  196. size: 10000
  197. })
  198. if (code === 0) {
  199. this.organizeList = data
  200. this.recursion(this.organizeList)
  201. } else if (code >= 100 && code <= 104) {
  202. await this.logout()
  203. } else {
  204. this.$message.warning(message)
  205. }
  206. },
  207. handleCheckedCitiesChange(value) {
  208. const checkedCount = value.length
  209. this.ruleForm.is_all = checkedCount === this.coptions.length
  210. this.isIndeterminate = checkedCount > 0 && checkedCount < this.coptions.length
  211. },
  212. async companyNosearchChange(e) {
  213. const { code } = e
  214. this.companyNo = code || ''
  215. },
  216. recursion(list) {
  217. list.map((v) => {
  218. if (v && Array.isArray(v.child)) {
  219. v.value = v.id + ''
  220. v.label = v.name
  221. if (v.child.length === 0) {
  222. delete v['child']
  223. } else {
  224. this.recursion(v.child)
  225. }
  226. }
  227. return v
  228. })
  229. },
  230. async getRole() {
  231. const model = {
  232. status: '', // 状态
  233. level: '', // 姓名
  234. role_name: ''
  235. }
  236. const res = await asyncRequest.getRole(model)
  237. if (res && res.code === 0 && res.data) {
  238. this.roleList = res.data
  239. this.roleList.map((v1) => {
  240. v1.id += ''
  241. v1.status += ''
  242. return v1
  243. })
  244. }
  245. },
  246. async initData() {
  247. const { code, data, message } = await asyncRequest.detail({
  248. id: this.id
  249. })
  250. if (code === 0) {
  251. await this.resetForm(data)
  252. } else if (code >= 100 && code <= 104) {
  253. await this.logout()
  254. } else {
  255. this.$message.warning(message)
  256. }
  257. },
  258. async resetForm(sitem) {
  259. // 重置
  260. await this.$nextTick(() => {
  261. if (this.$refs.ruleForm) {
  262. this.$refs.ruleForm.resetFields()
  263. this.$refs.ruleForm.clearValidate()
  264. if (sitem) {
  265. const {
  266. item_companyNo,
  267. item_list,
  268. nickname,
  269. mobile,
  270. id
  271. } = sitem
  272. this.itemlist = item_list
  273. this.companyList = sitem.company_relaton
  274. this.companyNo = item_companyNo || this.companyList[0].companyCode
  275. this.ruleForm = {
  276. id,
  277. mobile: mobile || '',
  278. nickname: nickname || ''
  279. }
  280. }
  281. }
  282. })
  283. },
  284. async submitForm() {
  285. await this.$refs.ruleForm.validate(async(valid) => {
  286. if (valid) {
  287. if (!this.loading) {
  288. this.loading = true
  289. const {
  290. nickname,
  291. mobile,
  292. itemid,
  293. id
  294. } = JSON.parse(JSON.stringify(this.ruleForm))
  295. const model = {
  296. nickname,
  297. mobile,
  298. itemid: itemid[itemid.length - 1],
  299. id
  300. }
  301. const res = await asyncRequest.update(model)
  302. this.loading = false
  303. if (res && res.code === 0) {
  304. const title = this.id === 'add' ? '添加成功' : '修改成功'
  305. this.$notify.success({
  306. title,
  307. message: ''
  308. })
  309. this.showModelThis = false
  310. // 刷新
  311. this.$emit('refresh')
  312. } else if (res && res.code >= 100 && res.code <= 104) {
  313. await this.logout()
  314. } else {
  315. this.$message.warning(res.message)
  316. }
  317. }
  318. } else {
  319. console.log('error submit!!')
  320. return false
  321. }
  322. })
  323. }
  324. }
  325. }
  326. </script>
  327. <style lang="scss" scoped>
  328. .account {
  329. .bottom-btn {
  330. position: absolute;
  331. bottom: 0px;
  332. right: 0;
  333. text-align: right;
  334. z-index: 2;
  335. }
  336. }
  337. </style>