usersDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* eslint-disable vue/require-v-for-key */
  2. <template>
  3. <el-card class="form-container" shadow="never">
  4. <el-form ref="productCateFrom" :model="productCate" :rules="rules" label-width="150px">
  5. <el-form-item label="用户头像">
  6. <single-upload v-model="productCate.icon" />
  7. </el-form-item>
  8. <el-form-item label="归属公司">
  9. <el-select v-model="productCate.parentId" placeholder="请选择公司" @change="changeAttrProductCate">
  10. <el-option v-for="item in selectProductCateList" :key="item.id" :label="item.name" :value="item.id" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="归属部门">
  14. <el-select v-model="productCate.parentId" placeholder="请选择部门" @change="changeAttrProductCate">
  15. <el-option v-for="item in selectProductCateList" :key="item.id" :label="item.name" :value="item.id" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="工号:" prop="number">
  19. <el-input v-model="productCate.name" />
  20. </el-form-item>
  21. <el-form-item label="姓名:" prop="name">
  22. <el-input v-model="productCate.name" />
  23. </el-form-item>
  24. <el-form-item label="登录名:" prop="userName">
  25. <el-input v-model="productCate.name" />
  26. </el-form-item>
  27. <el-form-item label="密码:" prop="password">
  28. <el-input v-model="productCate.productUnit" />
  29. </el-form-item>
  30. <el-form-item label="确认密码:" prop="password">
  31. <el-input v-model="productCate.productUnit" />
  32. </el-form-item>
  33. <el-form-item label="邮箱:">
  34. <el-input v-model="productCate.productUnit" />
  35. </el-form-item>
  36. <el-form-item label="电话:">
  37. <el-input v-model="productCate.productUnit" />
  38. </el-form-item>
  39. <el-form-item label="手机:">
  40. <el-input v-model="productCate.sort" />
  41. </el-form-item>
  42. <el-form-item label="是否阻止登录:">
  43. <el-radio-group v-model="productCate.showStatus">
  44. <el-radio :label="1">是</el-radio>
  45. <el-radio :label="0">否</el-radio>
  46. </el-radio-group>
  47. </el-form-item>
  48. <el-form-item label="用户类型">
  49. <el-select v-model="productCate.typeId" placeholder="请选择" @change="changeAttrProductCate">
  50. <el-option v-for="item in selectUserTypeList" :key="item.id" :label="item.name" :value="item.id" />
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item label="备注:">
  54. <el-input v-model="productCate.description" type="textarea" :autosize="true" />
  55. </el-form-item>
  56. <el-form-item label="用户角色:">
  57. <el-checkbox-group v-model="checkList">
  58. <el-checkbox v-for="item in selectRolesList" :key="item" :label="item.name" class="littleMarginLeft" />
  59. </el-checkbox-group>
  60. </el-form-item>
  61. <el-form-item>
  62. <el-button type="primary" @click="onSubmit('productCateFrom')">保存</el-button>
  63. <el-button v-if="!isEdit" @click="resetForm('productCateFrom')">返回</el-button>
  64. </el-form-item>
  65. </el-form>
  66. </el-card>
  67. </template>
  68. <script>
  69. // import { fetchList, createProductCate, updateProductCate, getProductCate } from '@/api/productCate'
  70. import SingleUpload from '@/components/Upload/singleUpload'
  71. const defaultProductCate = {
  72. description: '',
  73. icon: '',
  74. keywords: '',
  75. name: '',
  76. navStatus: 0,
  77. parentId: 0,
  78. productUnit: '',
  79. showStatus: 0,
  80. sort: 0,
  81. productAttributeIdList: []
  82. }
  83. export default {
  84. name: 'ProductCateDetail',
  85. components: { SingleUpload },
  86. filters: {
  87. filterLabelFilter(index) {
  88. if (index === 0) {
  89. return '筛选属性:'
  90. } else {
  91. return ''
  92. }
  93. }
  94. },
  95. props: {
  96. isEdit: {
  97. type: Boolean,
  98. default: false
  99. }
  100. },
  101. data() {
  102. return {
  103. productCate: Object.assign({}, defaultProductCate),
  104. selectUserTypeList: [
  105. { name: '系统管理', typeId: 1 },
  106. { name: '部门经理', typeId: 2 },
  107. { name: '普通用户', typeId: 3 }
  108. ],
  109. rules: {
  110. number: { required: true, message: '请输入工号', trigger: 'blur' },
  111. name: [
  112. { required: true, message: '请输入姓名', trigger: 'blur' },
  113. { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
  114. ],
  115. userName: [
  116. { required: true, message: '请输入登录名', trigger: 'blur' },
  117. { min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur' }
  118. ],
  119. password: [
  120. { required: true, message: '请输入密码', trigger: 'blur' },
  121. { min: 6, max: 30, message: '长度在 6 到 30 个字符', trigger: 'blur' }
  122. ]
  123. },
  124. filterAttrs: [],
  125. filterProductAttrList: [
  126. {
  127. value: []
  128. }
  129. ],
  130. changOptionName: '',
  131. selectRolesList: [
  132. { name: 'aduit', id: 0 },
  133. { name: '阿斯达', id: 0 },
  134. { name: '电饭锅', id: 0 },
  135. { name: '很反感和', id: 0 },
  136. { name: '意义', id: 0 }
  137. ],
  138. checkList: ['选中且禁用', '复选框 A']
  139. }
  140. },
  141. created() {
  142. if (this.isEdit) {
  143. // getProductCate(this.$route.query.id).then(response => {
  144. // this.productCate = response.data
  145. // })
  146. // getProductAttrInfo(this.$route.query.id).then(response => {
  147. // if (response.data != null && response.data.length > 0) {
  148. // this.filterProductAttrList = []
  149. // for (let i = 0; i < response.data.length; i++) {
  150. // this.filterProductAttrList.push({
  151. // key: Date.now() + i,
  152. // value: [response.data[i].attributeCategoryId, response.data[i].attributeId]
  153. // })
  154. // }
  155. // }
  156. // })
  157. } else {
  158. this.productCate = Object.assign({}, defaultProductCate)
  159. }
  160. this.getSelectProductCateList()
  161. },
  162. methods: {
  163. getSelectProductCateList() {
  164. // fetchList(0, { pageSize: 100, pageNum: 1 }).then(response => {
  165. // this.selectProductCateList = response.data.list
  166. // this.selectProductCateList.unshift({ id: 0, name: '无上级分类' })
  167. // this.selectProductCateList.forEach(el => {
  168. // // eslint-disable-next-line eqeqeq
  169. // if (el.id == this.productCate.parentId) {
  170. // this.changOptionName = el.name
  171. // }
  172. // })
  173. // console.log(this.changOptionName)
  174. // this.getProductAttrCateList()
  175. // })
  176. },
  177. getProductAttrCateList() {
  178. console.log(this.changOptionName)
  179. // const params = { productAttrCateId: null, parentName: this.changOptionName }
  180. // fetchListWithAttr(params).then(response => {
  181. // const list = response.data
  182. // for (let i = 0; i < list.length; i++) {
  183. // const productAttrCate = list[i]
  184. // const children = []
  185. // if (productAttrCate.productAttributeList != null && productAttrCate.productAttributeList.length > 0) {
  186. // for (let j = 0; j < productAttrCate.productAttributeList.length; j++) {
  187. // children.push({
  188. // label: productAttrCate.productAttributeList[j].name,
  189. // value: productAttrCate.productAttributeList[j].id
  190. // })
  191. // }
  192. // }
  193. // // this.filterAttrs.push({label: productAttrCate.name, value: productAttrCate.id, children: children});
  194. // this.filterAttrs.push({ label: productAttrCate.name, value: productAttrCate.id })
  195. // }
  196. // })
  197. },
  198. getProductAttributeIdList() {
  199. // 获取选中的筛选商品属性
  200. const productAttributeIdList = []
  201. for (let i = 0; i < this.filterProductAttrList.length; i++) {
  202. const item = this.filterProductAttrList[i]
  203. if (item.value !== null && item.value.length === 1) {
  204. productAttributeIdList.push(item.value[0])
  205. }
  206. }
  207. return productAttributeIdList
  208. },
  209. changeAttrProductCate(value) {
  210. this.selectProductCateList.forEach(el => {
  211. // eslint-disable-next-line eqeqeq
  212. if (value == el.id) {
  213. this.changOptionName = el.name
  214. }
  215. })
  216. console.log(this.changOptionName)
  217. },
  218. changeFilterProductAttrFn(value) {
  219. console.log(value)
  220. },
  221. onSubmit(formName) {
  222. this.$refs[formName].validate(valid => {
  223. if (valid) {
  224. this.$confirm('是否提交数据', '提示', {
  225. confirmButtonText: '确定',
  226. cancelButtonText: '取消',
  227. type: 'warning'
  228. }).then(() => {
  229. if (this.isEdit) {
  230. this.productCate.productAttributeIdList = this.getProductAttributeIdList()
  231. // updateProductCate(this.$route.query.id, this.productCate).then(response => {
  232. // this.$message({
  233. // message: '修改成功',
  234. // type: 'success',
  235. // duration: 1000
  236. // })
  237. // this.$router.back()
  238. // })
  239. } else {
  240. this.productCate.productAttributeIdList = this.getProductAttributeIdList()
  241. // createProductCate(this.productCate).then(response => {
  242. // this.$refs[formName].resetFields()
  243. // this.resetForm(formName)
  244. // this.$message({
  245. // message: '提交成功',
  246. // type: 'success',
  247. // duration: 1000
  248. // })
  249. // })
  250. }
  251. })
  252. } else {
  253. this.$message({
  254. message: '验证失败',
  255. type: 'error',
  256. duration: 1000
  257. })
  258. return false
  259. }
  260. })
  261. },
  262. resetForm(formName) {
  263. this.$refs[formName].resetFields()
  264. this.productCate = Object.assign({}, defaultProductCate)
  265. this.getSelectProductCateList()
  266. this.filterProductAttrList = [
  267. {
  268. value: []
  269. }
  270. ]
  271. },
  272. removeFilterAttr(productAttributeId) {
  273. if (this.filterProductAttrList.length === 1) {
  274. this.$message({
  275. message: '至少要留一个',
  276. type: 'warning',
  277. duration: 1000
  278. })
  279. return
  280. }
  281. var index = this.filterProductAttrList.indexOf(productAttributeId)
  282. if (index !== -1) {
  283. this.filterProductAttrList.splice(index, 1)
  284. }
  285. },
  286. handleAddFilterAttr() {
  287. if (this.filterProductAttrList.length === 3) {
  288. this.$message({
  289. message: '最多添加三个',
  290. type: 'warning',
  291. duration: 1000
  292. })
  293. return
  294. }
  295. this.filterProductAttrList.push({
  296. value: null,
  297. key: Date.now()
  298. })
  299. }
  300. }
  301. }
  302. </script>
  303. <style scoped>
  304. .form-container {
  305. width: 800px;
  306. }
  307. </style>