index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="pageIndexClass">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" highlight-current-row
  6. :selectConfig="selectConfig" :table-events="{
  7. }" :action-list="[
  8. {
  9. text: '添加设备',
  10. action: () => openModal('add'),
  11. },
  12. ]" @get-list="getList">
  13. <template #slotName="{ item }">
  14. {{ item.createTime }}
  15. </template>
  16. </byTable>
  17. </div>
  18. <el-dialog :title="modalType == 'add' ? '添加设备' : '编辑'" v-model="dialogVisible" width="800">
  19. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform" v-loading="submitLoading">
  20. </byForm>
  21. <template #footer>
  22. <el-button @click="dialogVisible = false" size="default" v-debounce>取 消</el-button>
  23. <el-button type="primary" @click="submitForm('byform')" size="default" v-debounce>
  24. 确 定
  25. </el-button>
  26. </template>
  27. </el-dialog>
  28. </div>
  29. </template>
  30. <script setup>
  31. /* eslint-disable vue/no-unused-components */
  32. import { ElMessage, ElMessageBox } from "element-plus";
  33. import byTable from "@/components/byTable/index";
  34. import byForm from "@/components/byForm/index";
  35. import { computed, defineComponent, ref } from "vue";
  36. const { proxy } = getCurrentInstance();
  37. const loading = ref(false);
  38. const submitLoading = ref(false);
  39. const sourceList = ref({
  40. data: [],
  41. pagination: {
  42. total: 3,
  43. pageNum: 1,
  44. pageSize: 10,
  45. },
  46. });
  47. const treeData = ref([]);
  48. const companyData = ref([]);
  49. const dialogVisible = ref(false);
  50. const roomDialogVisible = ref(false);
  51. const modalType = ref("add");
  52. const rules = ref({
  53. companyId: [{ required: true, message: "请选择归属公司", trigger: "change" }],
  54. deviceCode: [
  55. { required: true, message: "请输入设备编码", trigger: ["blur"] },
  56. ],
  57. deviceName: [
  58. { required: true, message: "请输入设备名称", trigger: ["blur"] },
  59. ],
  60. });
  61. const selectConfig = computed(() => [
  62. {
  63. label: "归属公司",
  64. prop: "companyId",
  65. data: companyData.value,
  66. },
  67. ]);
  68. const config = computed(() => {
  69. return [
  70. {
  71. attrs: {
  72. label: "归属公司",
  73. prop: "companyName",
  74. width: 110,
  75. },
  76. },
  77. {
  78. attrs: {
  79. label: "设备编码",
  80. prop: "deviceCode",
  81. width: 150,
  82. },
  83. },
  84. {
  85. attrs: {
  86. label: "设备名称",
  87. prop: "deviceName",
  88. width: 150,
  89. },
  90. },
  91. {
  92. attrs: {
  93. label: "规格型号",
  94. prop: "deviceSpec",
  95. width: 150,
  96. },
  97. },
  98. {
  99. attrs: {
  100. label: "制造商",
  101. prop: "makerName",
  102. width: 150,
  103. },
  104. },
  105. {
  106. attrs: {
  107. label: "制造商电话",
  108. prop: "makerPhone",
  109. width: 180,
  110. },
  111. },
  112. {
  113. attrs: {
  114. label: "出厂日期",
  115. prop: "deviceDeliveryTime",
  116. width: 110,
  117. },
  118. render(val) {
  119. if (val) {
  120. return val.slice(0, 10);
  121. }
  122. },
  123. },
  124. {
  125. attrs: {
  126. label: "备注",
  127. prop: "remark",
  128. },
  129. },
  130. {
  131. attrs: {
  132. label: "操作",
  133. width: "100",
  134. align: "center",
  135. },
  136. // 渲染 el-button,一般用在最后一列。
  137. renderHTML(row) {
  138. return [
  139. {
  140. attrs: {
  141. label: "删除",
  142. type: "danger",
  143. text: true,
  144. },
  145. el: "button",
  146. click() {
  147. proxy
  148. .msgConfirm()
  149. .then((res) => {
  150. proxy
  151. .post("/tdaDevice/delete", {
  152. id: row.id,
  153. })
  154. .then((res) => {
  155. proxy.msgTip("删除成功", 1);
  156. getList();
  157. });
  158. })
  159. .catch((err) => {});
  160. },
  161. },
  162. ];
  163. },
  164. },
  165. ];
  166. });
  167. const formData = reactive({
  168. data: {},
  169. });
  170. const formOption = reactive({
  171. inline: true,
  172. labelWidth: 100,
  173. itemWidth: 100,
  174. });
  175. const byform = ref(null);
  176. const formConfig = computed(() => [
  177. {
  178. type: "treeSelect",
  179. prop: "companyId",
  180. label: "归属公司",
  181. data: treeData.value,
  182. propsTreeLabel: "deptName",
  183. propsTreeValue: "deptId",
  184. itemWidth: 100,
  185. },
  186. {
  187. type: "input",
  188. prop: "deviceCode",
  189. label: "设备编码",
  190. required: true,
  191. },
  192. {
  193. type: "input",
  194. prop: "deviceName",
  195. label: "设备名称",
  196. required: true,
  197. },
  198. {
  199. type: "input",
  200. prop: "deviceSpec",
  201. label: "规格型号",
  202. required: true,
  203. },
  204. {
  205. type: "input",
  206. prop: "makerName",
  207. label: "制造商",
  208. required: true,
  209. },
  210. {
  211. type: "input",
  212. prop: "makerPhone",
  213. label: "制造商电话",
  214. required: true,
  215. },
  216. {
  217. type: "date",
  218. itemType: "date",
  219. prop: "deviceDeliveryTime",
  220. label: "出厂日期",
  221. required: true,
  222. },
  223. {
  224. type: "input",
  225. itemType: "textarea",
  226. prop: "remark",
  227. label: "备注",
  228. required: true,
  229. },
  230. ]);
  231. const getList = (req) => {
  232. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  233. loading.value = true;
  234. proxy.post("/tdaDevice/page", sourceList.value.pagination).then((res) => {
  235. sourceList.value.data = res.rows;
  236. sourceList.value.pagination.total = res.total;
  237. setTimeout(() => {
  238. loading.value = false;
  239. }, 200);
  240. });
  241. };
  242. const getDict = () => {
  243. proxy
  244. .get("/tenantDept/list", {
  245. pageNum: 1,
  246. pageSize: 9999,
  247. keyword: "",
  248. tenantId: proxy.useUserStore().user.tenantId,
  249. type: 0,
  250. })
  251. .then((res) => {
  252. companyData.value = res.data.map((x) => ({
  253. ...x,
  254. label: x.deptName,
  255. value: x.deptId,
  256. }));
  257. treeData.value = proxy.handleTree(res.data, "deptId");
  258. });
  259. };
  260. getDict();
  261. const openModal = () => {
  262. dialogVisible.value = true;
  263. modalType.value = "add";
  264. formData.data = {};
  265. };
  266. const submitForm = () => {
  267. byform.value.handleSubmit((valid) => {
  268. submitLoading.value = true;
  269. proxy.post("/tdaDevice/" + modalType.value, formData.data).then(
  270. (res) => {
  271. proxy.msgTip(modalType.value == "add" ? "添加成功" : "编辑成功");
  272. dialogVisible.value = false;
  273. submitLoading.value = false;
  274. getList();
  275. },
  276. (err) => (submitLoading.value = false)
  277. );
  278. });
  279. };
  280. const getDtl = (row) => {
  281. modalType.value = "edit";
  282. proxy.post("/tdaDevice/detail", { id: row.id }).then((res) => {
  283. formData.data = res;
  284. console.log(formData);
  285. dialogVisible.value = true;
  286. });
  287. };
  288. getList();
  289. </script>
  290. <style lang="scss" scoped>
  291. .tenant {
  292. padding: 20px;
  293. }
  294. </style>