index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2022-12-13 11:41:05
  5. * @LastEditors: Please set LastEditors
  6. * @LastEditTime: 2023-02-01 19:55:07
  7. -->
  8. <template>
  9. <el-dialog
  10. v-model="dialogVisible"
  11. :before-close="handleClose"
  12. title="驻派工厂"
  13. width="600px"
  14. >
  15. <el-form ref="formRef" label-width="120px" :model="form" :rules="rules">
  16. <el-form-item label="驻派工厂:">
  17. <el-select
  18. v-model="factory_id"
  19. filterable
  20. :loading="loading"
  21. placeholder="请选择驻派工厂"
  22. style="width: 100%"
  23. >
  24. <el-option
  25. v-for="item in companyList"
  26. :key="item.id"
  27. :label="item.name"
  28. :value="item.id"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. </el-form>
  33. <template #footer>
  34. <span class="dialog-footer">
  35. <el-button @click="handleClose">取消</el-button>
  36. <el-button type="primary" @click="sure">确定</el-button>
  37. </span>
  38. </template>
  39. </el-dialog>
  40. </template>
  41. <script>
  42. // import { getFactory } from './api/index'
  43. import { useUserStore } from '@/store/modules/user'
  44. export default defineComponent({
  45. name: 'RoleManagementEdit',
  46. setup() {
  47. const state = reactive({
  48. formRef: null,
  49. dialogVisible: false,
  50. factory_id: '',
  51. companyList: [],
  52. })
  53. const showEdit = () => {
  54. factoryList()
  55. state.dialogVisible = true
  56. }
  57. const handleClose = () => {
  58. state.dialogVisible = false
  59. }
  60. const sure = () => {
  61. state.companyList.map((item) => {
  62. if (item.id == state.factory_id) {
  63. localStorage.setItem('factory', JSON.stringify(item))
  64. }
  65. })
  66. state.dialogVisible = false
  67. setTimeout(() => {
  68. location.reload()
  69. }, 1000)
  70. }
  71. //工厂列表
  72. const factoryList = async () => {
  73. const userStore = useUserStore()
  74. const { factories } = storeToRefs(userStore)
  75. state.companyList = factories
  76. let factory = localStorage.getItem('factory')
  77. factory = factory ? JSON.parse(factory) : ''
  78. if (factory) {
  79. state.factory_id = factory.id
  80. } else {
  81. state.factory_id = state.companyList ? state.companyList[0].id : ''
  82. localStorage.setItem('factory', JSON.stringify(state.companyList[0]))
  83. }
  84. state.loading = false
  85. }
  86. onMounted(() => {})
  87. return {
  88. ...toRefs(state),
  89. showEdit,
  90. factoryList,
  91. sure,
  92. handleClose,
  93. }
  94. },
  95. })
  96. </script>
  97. <style lang="scss" scoped>
  98. .text {
  99. display: flex;
  100. line-height: 28px;
  101. .label {
  102. flex: 0 0 80px;
  103. }
  104. .people {
  105. display: inline-block;
  106. margin-right: 5px;
  107. }
  108. }
  109. </style>