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.
 
 
 
 
 

286 lines
12 KiB

  1. <template>
  2. <div>
  3. <v-dialog
  4. v-model="progress"
  5. persistent
  6. width="300"
  7. >
  8. <v-card
  9. color="primary"
  10. dark
  11. >
  12. <v-card-text>
  13. 載入中...
  14. <v-progress-linear
  15. indeterminate
  16. color="white"
  17. class="mb-0"
  18. ></v-progress-linear>
  19. </v-card-text>
  20. </v-card>
  21. </v-dialog>
  22. <v-data-table class="" :headers="headers" :items="items"
  23. disable-sort
  24. fixed-header
  25. :footer-props="{'items-per-page-options': [30, 40, 50, 60]}"
  26. :items-per-page="30">
  27. <template v-slot:top>
  28. <v-toolbar flat>
  29. <v-toolbar-title class="title font-weight-bold">帳號管理</v-toolbar-title>
  30. <v-divider
  31. class="mx-4"
  32. inset
  33. vertical
  34. />
  35. <v-spacer/>
  36. <!--新增對話-->
  37. <v-dialog
  38. v-model="dialogInsert"
  39. @click:outside="close"
  40. max-width="500"
  41. >
  42. <template v-slot:activator="{ on, attrs }">
  43. <v-btn
  44. color="white"
  45. class="primary"
  46. v-bind="attrs"
  47. v-on="on"
  48. icon
  49. >
  50. <v-icon>mdi-plus</v-icon>
  51. </v-btn>
  52. </template>
  53. <v-card>
  54. <v-card-title>
  55. <span class="headline font-weight-bold">新增</span>
  56. </v-card-title>
  57. <v-card-text>
  58. <v-container>
  59. <v-text-field v-model="insertItem.id" outlined rounded label="員工編號"/>
  60. <v-text-field v-model="insertItem.username" outlined rounded label="姓名"/>
  61. <v-select v-model="insertItem.department" outlined rounded :items="departments"
  62. label="部門"/>
  63. <v-text-field v-model="insertItem.account" outlined rounded label="帳號"/>
  64. <v-text-field v-model="insertItem.pwd" outlined type='password' rounded label="密碼"/>
  65. <v-select v-model="insertItem.level" outlined rounded label="權限"
  66. :items="levelSelectItem"/>
  67. </v-container>
  68. </v-card-text>
  69. <v-card-actions>
  70. <v-spacer></v-spacer>
  71. <v-btn
  72. color="blue darken-1"
  73. text
  74. @click="close"
  75. >
  76. 取消
  77. </v-btn>
  78. <v-btn
  79. color="blue darken-1"
  80. text
  81. @click="checkIdAndAccountRepeat(insertItem, '新增')"
  82. >
  83. 新增
  84. </v-btn>
  85. </v-card-actions>
  86. </v-card>
  87. </v-dialog>
  88. </v-toolbar>
  89. </template>
  90. <template v-slot:item.pwd="{ item }">
  91. <v-text-field hide-details dense type="password" disabled :value="item.pwd" class="" />
  92. </template>
  93. <template v-slot:item.level="{ item }">
  94. <p>{{item.level === '0' ? '超級管理員' : ''}}</p>
  95. <p>{{item.level === '1' ? '一般管理員' : ''}}</p>
  96. <p>{{item.level === '2' ? '一般使用者' : ''}}</p>
  97. <p>{{item.level === '3' ? '稽核人員' : ''}}</p>
  98. </template>
  99. <template v-slot:item.pwd="{ }">
  100. </template>
  101. <template v-slot:item.actions="{ item }">
  102. <div class="d-flex">
  103. <v-btn
  104. icon
  105. @click="openDialogModify(item)"
  106. >
  107. <v-icon>mdi-pencil</v-icon>
  108. </v-btn>
  109. <v-icon
  110. small
  111. @click="deleteOne(item)"
  112. >
  113. mdi-delete
  114. </v-icon>
  115. </div>
  116. </template>
  117. </v-data-table>
  118. <!--修改對話-->
  119. <v-dialog
  120. v-model="dialogModify"
  121. @click:outside="close"
  122. :retain-focus="false"
  123. max-width="500"
  124. >
  125. <v-card>
  126. <v-card-title>
  127. <span class="headline font-weight-bold">修改</span>
  128. </v-card-title>
  129. <v-card-text>
  130. <v-container>
  131. <v-text-field v-model="modifyItem.id" disabled outlined rounded label="員工編號"/>
  132. <v-text-field v-model="modifyItem.username" outlined rounded label="姓名"/>
  133. <v-select v-model="modifyItem.department" outlined rounded :items="departments" label="部門"/>
  134. <v-text-field v-model="modifyItem.account" disabled outlined rounded label="帳號"/>
  135. <v-text-field v-model="modifyItem.pwd" outlined type='password' rounded label="密碼"/>
  136. <v-select v-model="modifyItem.level" outlined rounded label="權限" :items="levelSelectItem"/>
  137. </v-container>
  138. </v-card-text>
  139. <v-card-actions>
  140. <v-spacer></v-spacer>
  141. <v-btn
  142. color="blue darken-1"
  143. text
  144. @click="close"
  145. >
  146. 取消
  147. </v-btn>
  148. <v-btn
  149. color="blue darken-1"
  150. text
  151. @click="modifyOne"
  152. >
  153. 修改
  154. </v-btn>
  155. </v-card-actions>
  156. </v-card>
  157. </v-dialog>
  158. </div>
  159. </template>
  160. <script>
  161. export default {
  162. name: '',
  163. data() {
  164. return {
  165. fullHeight: 0,
  166. dialogInsert: false,
  167. dialogModify: false,
  168. headers: [{'text': '', 'value': 'actions', fixed: true, sortable: false},
  169. {'text': '員工編號', 'value': 'id'},
  170. {'text': '姓名', 'value': 'username'},
  171. {'text': '部門', 'value': 'department'},
  172. // {'text': '型態', 'value': 'type'},
  173. {'text': '帳號', 'value': 'account'},
  174. // {'text': '密碼', 'value': 'pwd'},
  175. {'text': '權限', 'value': 'level'}],
  176. items: [],
  177. departments: [],
  178. insertItem: {
  179. account: "",
  180. department: "",
  181. level: "",
  182. pwd: "",
  183. username: "",
  184. id: "",
  185. },
  186. modifyItem: {
  187. account: "",
  188. department: "",
  189. level: "",
  190. pwd: "",
  191. username: "",
  192. id: "",
  193. },
  194. progress: false,
  195. levelSelectItem: [{'text': '超級管理員', 'value': '0'},
  196. {'text': '一般管理員', 'value': '1'},
  197. {'text': '一般使用者', 'value': '2'},
  198. {'text': '稽核人員', 'value': '3'}],
  199. }
  200. },
  201. async mounted() {
  202. this.progress = true;
  203. this.getUsers();
  204. // this.getSelectItem();
  205. this.fullHeight = window.innerHeight;
  206. window.onresize = () => {
  207. this.fullHeight = window.innerHeight;
  208. };
  209. this.getDepartments();
  210. },
  211. computed: {},
  212. watch: {},
  213. methods: {
  214. openDialogModify(item) {
  215. console.log(item.department);
  216. this.modifyItem.username = item.username;
  217. this.modifyItem.department = item.department;
  218. this.modifyItem.account = item.account;
  219. this.modifyItem.pwd = item.pwd;
  220. this.modifyItem.level = item.level;
  221. this.modifyItem.id = item.id;
  222. this.dialogModify = true;
  223. },
  224. async getUsers() {
  225. await this.$axios.get(`/account/accounts`)
  226. .then((resp) => {
  227. this.items = [];
  228. this.items = resp.data.data;
  229. this.progress = false;
  230. });
  231. },
  232. async getDepartments() {
  233. await this.$axios.get(`/account/departments`).then((resp) => {
  234. this.departments = resp.data.data;
  235. });
  236. },
  237. checkIdAndAccountRepeat(item, next) {
  238. this.$axios.get(`/account/checkIdAndAccountRepeat?id=${item.id}&&account=${item.account}`).then((resp) => {
  239. if (resp.data.code !== 200) {
  240. alert(resp.data.message);
  241. } else {
  242. if (next === '新增') {
  243. this.insertOne();
  244. } else {
  245. this.modifyOne();
  246. }
  247. }
  248. });
  249. },
  250. insertOne() {
  251. this.$axios.post(`/account/account`, this.insertItem).then(() => {
  252. delete this.insertItem.tablename;
  253. this.getUsers();
  254. this.close();
  255. }
  256. );
  257. },
  258. modifyOne() {
  259. this.$axios.put(`/account/account`, this.modifyItem).then(() => {
  260. this.getUsers();
  261. Object.keys(this.modifyItem).forEach((key) => {
  262. this.modifyItem[key] = '';
  263. });
  264. this.close();
  265. }
  266. );
  267. },
  268. deleteOne(item) {
  269. let yes = confirm('確定刪除');
  270. if (yes) {
  271. this.$axios.delete(`/account/account?id=${item.id}`).then(() => {
  272. this.getUsers();
  273. alert('已刪除');
  274. });
  275. }
  276. },
  277. close() {
  278. this.dialogInsert = false;
  279. this.dialogModify = false;
  280. },
  281. }
  282. }
  283. </script>