index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. //element talbe事件都能传
  14. select: select,
  15. }"
  16. :action-list="[]"
  17. @get-list="getList"
  18. >
  19. <template #phoneNumber="{ item }">
  20. <div>
  21. <span v-for="(x, index) in getTypeData(item, 0)">
  22. {{ x.contactNumber }}
  23. <span v-if="index < getTypeData(item, 0).length - 1">,</span>
  24. </span>
  25. </div>
  26. </template>
  27. <template #email="{ item }">
  28. <div>
  29. <span v-for="(x, index) in getTypeData(item, 1)">
  30. {{ x.contactNumber }}
  31. <span v-if="index < getTypeData(item, 1).length - 1">,</span>
  32. </span>
  33. </div>
  34. </template>
  35. </byTable>
  36. </div>
  37. <el-dialog
  38. :title="modalType == 'add' ? '添加IoT平台' : '编辑'"
  39. v-model="dialogVisible"
  40. width="800"
  41. v-loading="loading"
  42. >
  43. <byForm
  44. :formConfig="formConfig"
  45. :formOption="formOption"
  46. v-model="formData.data"
  47. :rules="rules"
  48. ref="byform"
  49. >
  50. <template #fileSlot>
  51. <div style="width: 100%">
  52. <el-button type="primary" @click="addRow"> 添加 </el-button>
  53. <el-form
  54. ref="tableForm"
  55. :model="formData.data"
  56. :rules="rules"
  57. label-width="0px"
  58. style="margin-top: 15px"
  59. >
  60. <el-table :data="formData.data.internalAddressBookList">
  61. <el-table-column prop="type" label="类型" min-width="150">
  62. <template #default="{ row, $index }">
  63. <el-form-item
  64. :prop="'internalAddressBookList.' + $index + '.type'"
  65. :rules="rules.type"
  66. :inline-message="true"
  67. >
  68. <el-select v-model="row.type" placeholder="请选择">
  69. <el-option
  70. v-for="item in contactInformationType"
  71. :label="item.dictValue"
  72. :value="item.dictKey"
  73. >
  74. </el-option>
  75. </el-select>
  76. </el-form-item>
  77. </template>
  78. </el-table-column>
  79. <el-table-column
  80. prop="contactNumber"
  81. label="联系号码"
  82. min-width="150"
  83. >
  84. <template #default="{ row, $index }">
  85. <el-form-item
  86. :prop="
  87. 'internalAddressBookList.' + $index + '.contactNumber'
  88. "
  89. :rules="rules.contactNumber"
  90. :inline-message="true"
  91. >
  92. <el-input
  93. v-model="row.contactNumber"
  94. placeholder="请输入"
  95. />
  96. </el-form-item>
  97. </template>
  98. </el-table-column>
  99. <el-table-column prop="zip" label="操作" width="100">
  100. <template #default="{ $index }">
  101. <el-button type="primary" link @click="handleRemove($index)"
  102. >删除</el-button
  103. >
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. </el-form>
  108. </div>
  109. </template>
  110. </byForm>
  111. <template #footer>
  112. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  113. <el-button
  114. type="primary"
  115. @click="submitForm('byform')"
  116. size="large"
  117. :loading="submitLoading"
  118. >
  119. 确 定
  120. </el-button>
  121. </template>
  122. </el-dialog>
  123. </div>
  124. </template>
  125. <script setup>
  126. /* eslint-disable vue/no-unused-components */
  127. import { ElMessage, ElMessageBox } from "element-plus";
  128. import byTable from "@/components/byTable/index";
  129. import byForm from "@/components/byForm/index";
  130. import { computed, defineComponent, ref } from "vue";
  131. import useUserStore from "@/store/modules/user";
  132. const loading = ref(false);
  133. const submitLoading = ref(false);
  134. const sourceList = ref({
  135. data: [],
  136. pagination: {
  137. total: 3,
  138. pageNum: 1,
  139. pageSize: 10,
  140. },
  141. });
  142. let dialogVisible = ref(false);
  143. let roomDialogVisible = ref(false);
  144. let modalType = ref("add");
  145. let rules = ref({
  146. type: [{ required: true, message: "请选择类型", trigger: "change" }],
  147. contactNumber: [
  148. { required: true, message: "请输入联系号码", trigger: "blur" },
  149. ],
  150. });
  151. const { proxy } = getCurrentInstance();
  152. const selectConfig = [];
  153. const config = computed(() => {
  154. return [
  155. {
  156. attrs: {
  157. label: "部门",
  158. },
  159. render(row) {
  160. return row.dept.deptName;
  161. },
  162. },
  163. {
  164. attrs: {
  165. label: "工号",
  166. prop: "deptId",
  167. },
  168. },
  169. {
  170. attrs: {
  171. label: "姓名",
  172. prop: "nickName",
  173. },
  174. },
  175. {
  176. attrs: {
  177. type: "slot",
  178. slot: "phoneNumber",
  179. label: "手机号",
  180. },
  181. },
  182. {
  183. attrs: {
  184. type: "slot",
  185. slot: "email",
  186. label: "电子邮箱",
  187. },
  188. },
  189. // {
  190. // attrs: {
  191. // label: "座机号码",
  192. // prop: "productId",
  193. // },
  194. // },
  195. {
  196. attrs: {
  197. label: "操作",
  198. width: "100",
  199. align: "right",
  200. },
  201. // 渲染 el-button,一般用在最后一列。
  202. renderHTML(row) {
  203. return [
  204. {
  205. attrs: {
  206. label: "修改",
  207. type: "primary",
  208. text: true,
  209. },
  210. el: "button",
  211. click() {
  212. getDtl(row);
  213. },
  214. },
  215. ];
  216. },
  217. },
  218. ];
  219. });
  220. let formData = reactive({
  221. data: {
  222. type: "1",
  223. },
  224. treeData: [],
  225. });
  226. const formOption = reactive({
  227. inline: true,
  228. labelWidth: 100,
  229. itemWidth: 100,
  230. rules: [],
  231. });
  232. const byform = ref(null);
  233. const treeData = ref([]);
  234. const formConfig = computed(() => {
  235. return [
  236. {
  237. type: "input",
  238. prop: "deptName",
  239. label: "所属部门",
  240. disabled: true,
  241. },
  242. {
  243. type: "input",
  244. prop: "nickName",
  245. label: "姓名",
  246. disabled: true,
  247. },
  248. {
  249. type: "slot",
  250. slotName: "fileSlot",
  251. label: "联系方式",
  252. },
  253. ];
  254. });
  255. const getList = async (req) => {
  256. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  257. loading.value = true;
  258. proxy
  259. .get("/internalAddressBook/page", sourceList.value.pagination)
  260. .then((message) => {
  261. sourceList.value.data = message.rows;
  262. sourceList.value.pagination.total = message.total;
  263. setTimeout(() => {
  264. loading.value = false;
  265. }, 200);
  266. });
  267. };
  268. const openModal = () => {
  269. dialogVisible.value = true;
  270. modalType.value = "add";
  271. formData.data = {};
  272. };
  273. const submitForm = () => {
  274. byform.value.handleSubmit((valid) => {
  275. submitLoading.value = true;
  276. proxy.post("/internalAddressBook/" + modalType.value, formData.data).then(
  277. (res) => {
  278. ElMessage({
  279. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  280. type: "success",
  281. });
  282. dialogVisible.value = false;
  283. submitLoading.value = false;
  284. getList();
  285. },
  286. (err) => (submitLoading.value = false)
  287. );
  288. });
  289. };
  290. const getDtl = (row) => {
  291. modalType.value = "edit";
  292. proxy
  293. .post("/internalAddressBook/detail", { userId: row.userId })
  294. .then((res) => {
  295. res.forEach((x) => {
  296. x.type = x.type + "";
  297. });
  298. formData.data = {
  299. deptName: row.dept.deptName,
  300. nickName: row.nickName,
  301. internalAddressBookList: res,
  302. userId: row.userId,
  303. };
  304. dialogVisible.value = true;
  305. });
  306. };
  307. const addRow = () => {
  308. formData.data.internalAddressBookList.push({
  309. contactNumber: "",
  310. type: "",
  311. });
  312. };
  313. const handleRemove = (index) => {
  314. formData.data.internalAddressBookList.splice(index, 1);
  315. return ElMessage({
  316. message: "删除成功!",
  317. type: "success",
  318. });
  319. };
  320. const contactInformationType = ref([]);
  321. const getDict = () => {
  322. const tenantId = useUserStore().user.tenantId;
  323. proxy
  324. .post("/dictTenantData/page", {
  325. pageNum: 1,
  326. pageSize: 999,
  327. tenantId: "@福建宏星!#¥%……&*()",
  328. dictCode: "contact_information",
  329. })
  330. .then((res) => {
  331. contactInformationType.value = res.rows;
  332. });
  333. };
  334. const getTypeData = (item, type) => {
  335. return item.internalAddressBookList.filter((x) => x.type === type) || [];
  336. };
  337. getList();
  338. getDict();
  339. </script>
  340. <style lang="scss" scoped>
  341. .tenant {
  342. padding: 20px;
  343. }
  344. </style>