You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
11 KiB

7 months ago
1 week ago
7 months ago
2 months ago
7 months ago
2 months ago
7 months ago
7 months ago
2 months ago
7 months ago
2 months ago
7 months ago
7 months ago
7 months ago
2 months ago
7 months ago
2 months ago
7 months ago
2 months ago
7 months ago
2 months ago
1 week ago
7 months ago
  1. <template>
  2. <div class="user-add-or-update">
  3. <el-dialog
  4. width="530px"
  5. @close="closeDialog"
  6. :title="!dataForm.id ? buttons.add :buttons.edit"
  7. :close-on-click-modal="false"
  8. :visible.sync="visible">
  9. <!-- 取消 :rules="dataRule"-->
  10. <el-form :inline="true" :model="dataForm" label-position="top" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
  11. <el-form>
  12. <el-form-item :label="buttons.username||'用户账号'" prop="userName">
  13. <el-input v-model="dataForm.userName" style="width: 150px;" placeholder="登录帐号"></el-input>
  14. </el-form-item>
  15. <el-form-item :label="buttons.password||'密码'" prop="password" :class="{ 'is-required': !dataForm.id }">
  16. <el-input v-model="dataForm.password" style="width: 150px;" type="password" ></el-input>
  17. </el-form-item>
  18. <el-form-item :label="buttons.comfirmPassword||'确认密码'" prop="comfirmPassword" :class="{ 'is-required': !dataForm.id }">
  19. <el-input v-model="dataForm.comfirmPassword" style="width: 150px;" type="password"></el-input>
  20. </el-form-item>
  21. </el-form>
  22. <el-form>
  23. <el-form-item :label="buttons.userDisplay||'用户名'" prop="userDisplay">
  24. <el-input v-model="dataForm.userDisplay" style="width: 150px;" ></el-input>
  25. </el-form-item>
  26. <el-form-item :label="buttons.email||'邮箱'" prop="email">
  27. <el-input v-model="dataForm.email" style="width: 150px;" ></el-input>
  28. </el-form-item>
  29. <el-form-item :label="buttons.mobile||'手机号'" prop="mobile">
  30. <el-input v-model="dataForm.mobile" style="width: 150px;" placeholder="手机号"></el-input>
  31. </el-form-item>
  32. </el-form>
  33. <el-form>
  34. <el-form-item :label="buttons.site||'工厂'">
  35. <el-select v-model="dataForm.site" filterable clearable placeholder="请选择工厂" style="width: 150px;">
  36. <el-option
  37. v-for="i in siteOptions"
  38. :key="i.siteid"
  39. :label="i.sitename"
  40. :value="i.siteid">
  41. </el-option>
  42. </el-select>
  43. </el-form-item>
  44. <!-- <el-form-item label="车间">-->
  45. <!-- <el-select v-model="dataForm.workShopId" placeholder="请选择" style="width: 150px;" clearable>-->
  46. <!-- <el-option-->
  47. <!-- v-for = "i in workShopList"-->
  48. <!-- :key = "i.workShopId"-->
  49. <!-- :label = "i.workShopName"-->
  50. <!-- :value = "i.workShopId">-->
  51. <!-- </el-option>-->
  52. <!-- </el-select>-->
  53. <!-- </el-form-item>-->
  54. <el-form-item v-if="showSupplierPicker">
  55. <span slot="label" style="" @click="getBaseList(501)"><a herf="#">{{'供应商'}}</a></span>
  56. <el-input v-model="dataForm.supplierNo" style="width: 150px;" placeholder="供应商"></el-input>
  57. </el-form-item>
  58. </el-form>
  59. <el-form>
  60. <el-form-item label="角色" size="mini" prop="roleIdList">
  61. <el-checkbox-group v-model="dataForm.roleIdList">
  62. <el-checkbox
  63. v-for="role in roleList"
  64. :key="role.roleId"
  65. :label="role.roleId">{{role.roleName}}
  66. </el-checkbox>
  67. </el-checkbox-group>
  68. </el-form-item>
  69. </el-form>
  70. <el-form>
  71. <el-form-item label="状态" size="mini" prop="status">
  72. <el-radio-group v-model="dataForm.status">
  73. <el-radio :label="0">{{buttons.disable||'禁用'}}</el-radio>
  74. <el-radio :label="1">{{buttons.normal||'正常'}}</el-radio>
  75. </el-radio-group>
  76. </el-form-item>
  77. </el-form>
  78. </el-form>
  79. <span slot="footer" class="dialog-footer">
  80. <el-button type="primary" @click="dataFormSubmit()">{{buttons.submit||'确定'}}</el-button>
  81. <el-button @click="visible = false">{{buttons.close||'取消'}}</el-button>
  82. </span>
  83. </el-dialog>
  84. <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
  85. </div>
  86. </template>
  87. <script>
  88. import Chooselist from '@/views/modules/common/Chooselist'
  89. import {getEamWorkShop, getSite2} from "@/api/factory/site.js";
  90. import {searchSysLanguage} from "@/api/sysLanguage.js"
  91. import {
  92. searchFunctionButtonList,
  93. } from "@/api/sysLanguage.js"
  94. export default {
  95. components: {
  96. Chooselist
  97. },
  98. data() {
  99. return {
  100. tagNo:'',
  101. visible: false,
  102. roleList: [],
  103. factorys: [],
  104. languageList: [],
  105. dataForm: {
  106. id: 0,
  107. userName: '',
  108. password: '',
  109. comfirmPassword: '',
  110. languageDefault: 'cn',
  111. salt: '',
  112. email: '',
  113. mobile: '',
  114. roleIdList: [],
  115. status: 1,
  116. site: '',
  117. userDisplay: '',
  118. workShopId:'',
  119. supplierNo: '',
  120. },
  121. buttons: {
  122. add: '添加',
  123. edit: '编辑',
  124. username: '用户账号',
  125. userDisplay: '用户名',
  126. email: '邮箱',
  127. mobile: '手机号',
  128. status: '状态',
  129. disable: '禁用',
  130. normal: '正常',
  131. password:'密码',
  132. comfirmPassword:'确认密码',
  133. submit: '确定',
  134. close: '取消',
  135. site: '工厂',
  136. language: '语言',
  137. },
  138. workShopList:[],
  139. siteOptions: [],
  140. showSupplierPicker: false,
  141. }
  142. },
  143. watch: {
  144. 'dataForm.roleIdList'(val) {
  145. const hasSupplier = Array.isArray(val) && val.some(id => {
  146. const role = this.roleList.find(r => r.roleId === id)
  147. return role && role.roleName === '供应商'
  148. })
  149. if (!hasSupplier) {
  150. // 取消供应商角色时清空供应商相关数据(按需保留/删除)
  151. this.dataForm.supplierNo = ''
  152. }
  153. this.showSupplierPicker = hasSupplier
  154. }
  155. },
  156. methods: {
  157. getFunctionButtonList() {
  158. let queryButton = {
  159. functionId: this.$route.meta.menuId,
  160. tableId: '*',
  161. languageCode: this.$i18n.locale,
  162. objectType: 'button'
  163. }
  164. searchFunctionButtonList(queryButton).then(({data}) => {
  165. if (data.code == 0 && data.data) {
  166. this.buttons = data.data
  167. }
  168. })
  169. },
  170. getBaseData(val){
  171. if (this.tagNo === 501){
  172. this.dataForm.supplierNo = val.supplier_no
  173. }
  174. },
  175. // 获取基础数据列表
  176. getBaseList(val){
  177. this.tagNo = val
  178. this.$nextTick(() => {
  179. let strVal = "";
  180. let conSql = "";
  181. if (val === 501) {
  182. if (!this.dataForm.site) {
  183. this.$message.warning('请先选择工厂')
  184. return
  185. }
  186. strVal = this.dataForm.supplierNo || ''
  187. conSql = " and site = '" + this.dataForm.site + "'"
  188. }
  189. this.$refs.baseList.init(val,strVal,conSql)
  190. })
  191. },
  192. // 加载工厂下拉(site表) - rqrq
  193. loadSiteOptions () {
  194. let inData = {
  195. username: this.$store.state.user.name,
  196. siteid: '',
  197. sitename: ''
  198. }
  199. getSite2(inData).then(({data}) => {
  200. if (data && data.code === 0) {
  201. this.siteOptions = data.rows || []
  202. } else {
  203. this.siteOptions = []
  204. this.$message.error((data && data.msg) || '加载工厂失败')
  205. }
  206. }).catch(() => {
  207. this.siteOptions = []
  208. this.$message.error('加载工厂失败')
  209. })
  210. },
  211. // 获取多语言列表
  212. getLanguageList() {
  213. let queryLanguage = { languageCode: this.$i18n.locale}
  214. searchSysLanguage(queryLanguage).then(({data}) => {
  215. this.languageList = data.rows
  216. })
  217. },
  218. init(id) {
  219. this.dataForm.id = id || 0
  220. this.loadSiteOptions()
  221. this.getLanguageList();
  222. this.$http({
  223. url: this.$http.adornUrl('/sys/role/select'),
  224. method: 'get',
  225. params: this.$http.adornParams()
  226. }).then(({data}) => {
  227. this.roleList = data && data.code === 0 ? data.list : []
  228. }).then(() => {
  229. this.visible = true
  230. this.$nextTick(() => {
  231. this.$refs['dataForm'].resetFields()
  232. })
  233. }).then(() => {
  234. if (this.dataForm.id) {
  235. this.$http({
  236. url: this.$http.adornUrl(`/sys/user/info/${this.dataForm.id}`),
  237. method: 'get',
  238. params: this.$http.adornParams()
  239. }).then(({data}) => {
  240. if (data && data.code === 0) {
  241. this.dataForm.userName = data.user.username
  242. this.dataForm.salt = data.user.salt
  243. this.dataForm.email = data.user.email
  244. this.dataForm.mobile = data.user.mobile
  245. this.dataForm.roleIdList = data.user.roleIdList
  246. this.dataForm.status = data.user.status
  247. this.dataForm.languageDefault = data.user.languageDefault
  248. this.dataForm.site = data.user.site == null ? '' : data.user.site.toString()
  249. this.dataForm.userDisplay = data.user.userDisplay
  250. this.dataForm.workShopId = data.user.workShopId
  251. this.dataForm.supplierNo = data.user.supplierNo
  252. }
  253. })
  254. }
  255. })
  256. getEamWorkShop({}).then(({data}) => {
  257. if (data && data.code === 0) {
  258. this.workShopList=data.rows
  259. }
  260. })
  261. },
  262. // 表单提交
  263. dataFormSubmit() {
  264. if (!this.dataForm.site) {
  265. this.$message.warning('请选择工厂')
  266. return
  267. }
  268. if (!this.dataForm.userDisplay || !String(this.dataForm.userDisplay).trim()) {
  269. this.$message.warning('用户名不能为空')
  270. return
  271. }
  272. if (this.showSupplierPicker && !this.dataForm.supplierNo) {
  273. this.$message.warning('请选择供应商')
  274. return
  275. }
  276. this.$refs['dataForm'].validate((valid) => {
  277. if (valid) {
  278. this.$http({
  279. url: this.$http.adornUrl(`/sys/user/${!this.dataForm.id ? 'save' : 'update'}`),
  280. method: 'post',
  281. data: this.$http.adornData({
  282. 'userId': this.dataForm.id || undefined,
  283. 'username': this.dataForm.userName,
  284. 'password': this.dataForm.password,
  285. 'salt': this.dataForm.salt,
  286. 'email': this.dataForm.email,
  287. 'mobile': this.dataForm.mobile,
  288. 'status': this.dataForm.status,
  289. 'roleIdList': this.dataForm.roleIdList,
  290. 'languageDefault': this.dataForm.languageDefault,
  291. 'site': this.dataForm.site,
  292. 'userDisplay': this.dataForm.userDisplay,
  293. 'workShopId': this.dataForm.workShopId,
  294. 'supplierNo': this.dataForm.supplierNo,
  295. })
  296. }).then(({data}) => {
  297. if (data && data.code === 0) {
  298. this.$message.success( '操作成功')
  299. this.visible = false
  300. this.$emit('refreshDataList')
  301. } else {
  302. this.$message.error(data.msg)
  303. }
  304. })
  305. }
  306. })
  307. },
  308. closeDialog(){
  309. this.dataForm.id = 0
  310. this.dataForm.userName = ''
  311. this.dataForm.password = ''
  312. this.dataForm.comfirmPassword = ''
  313. this.dataForm.email = ''
  314. this.dataForm.mobile = ''
  315. this.dataForm.roleIdList = []
  316. this.dataForm.status = 1
  317. this.dataForm.site = ''
  318. this.dataForm.userDisplay = ''
  319. }
  320. },
  321. created() {
  322. this.getFunctionButtonList()
  323. }
  324. }
  325. </script>
  326. <style lang="scss" scoped>
  327. </style>