index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="pageIndexClass">
  3. <div class="content">
  4. <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" :selectConfig="selectConfig"
  5. highlight-current-row :action-list="[
  6. {
  7. text: '添加模板',
  8. action: () => openModal(),
  9. },
  10. ]" @get-list="getList">
  11. </byTable>
  12. </div>
  13. <el-dialog :title="modalType == 'add' ? '新增' : '编辑'" v-if="dialogVisible" v-model="dialogVisible" width="800" v-loading="loadingOperation">
  14. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  15. <template #templateContent>
  16. <div style="width: 100%">
  17. <Editor :value="formData.data.templateContent" @updateValue="updateContent" />
  18. </div>
  19. </template>
  20. </byForm>
  21. <template #footer>
  22. <el-button @click="dialogVisible = false" size="default">取 消</el-button>
  23. <el-button type="primary" @click="submitForm()" size="default">确 定</el-button>
  24. </template>
  25. </el-dialog>
  26. </div>
  27. </template>
  28. <script setup>
  29. import { ElMessage, ElMessageBox } from "element-plus";
  30. import byTable from "@/components/byTable/index";
  31. import byForm from "@/components/byForm/index";
  32. import { computed, ref } from "vue";
  33. import Editor from "@/components/Editor/index.vue";
  34. const { proxy } = getCurrentInstance();
  35. const loading = ref(false);
  36. const companyList = ref([]);
  37. const typeData = ref([
  38. {
  39. dictKey: 1,
  40. dictValue: "销售合同",
  41. },
  42. {
  43. dictKey: 2,
  44. dictValue: "采购合同",
  45. },
  46. ]);
  47. const sourceList = ref({
  48. data: [],
  49. pagination: {
  50. total: 0,
  51. pageNum: 1,
  52. pageSize: 10,
  53. templateType: "",
  54. keyword: "",
  55. },
  56. });
  57. const selectConfig = computed(() => {
  58. return [
  59. {
  60. label: "模板类型",
  61. prop: "templateType",
  62. data: typeData.value,
  63. },
  64. // {
  65. // label: "公司名称",
  66. // prop: "corporationId",
  67. // data: companyList.value,
  68. // },
  69. ];
  70. });
  71. const config = computed(() => {
  72. return [
  73. {
  74. attrs: {
  75. label: "模板类型",
  76. prop: "templateType",
  77. },
  78. render(val) {
  79. return proxy.dictKeyValue(val, typeData.value);
  80. },
  81. },
  82. {
  83. attrs: {
  84. label: "模板名称",
  85. prop: "templateName",
  86. },
  87. },
  88. // {
  89. // attrs: {
  90. // label: "联系人",
  91. // prop: "contactName",
  92. // },
  93. // },
  94. // {
  95. // attrs: {
  96. // label: "联系电话",
  97. // prop: "contactNumber",
  98. // },
  99. // },
  100. {
  101. attrs: {
  102. label: "操作",
  103. width: "120",
  104. align: "center",
  105. },
  106. renderHTML(row) {
  107. return [
  108. {
  109. attrs: {
  110. label: "修改",
  111. type: "primary",
  112. text: true,
  113. },
  114. el: "button",
  115. click() {
  116. update(row);
  117. },
  118. },
  119. {
  120. attrs: {
  121. label: "删除",
  122. type: "primary",
  123. text: true,
  124. },
  125. el: "button",
  126. click() {
  127. ElMessageBox.confirm(
  128. "此操作将永久删除该数据, 是否继续?",
  129. "提示",
  130. {
  131. confirmButtonText: "确定",
  132. cancelButtonText: "取消",
  133. type: "warning",
  134. }
  135. ).then(() => {
  136. proxy
  137. .post("/contractTemplate/delete", {
  138. id: row.id,
  139. })
  140. .then(() => {
  141. ElMessage({
  142. message: "删除成功",
  143. type: "success",
  144. });
  145. getList();
  146. });
  147. });
  148. },
  149. },
  150. ];
  151. },
  152. },
  153. ];
  154. });
  155. const getDict = () => {
  156. proxy.post("/corporation/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  157. companyList.value = res.rows.map((item) => {
  158. return {
  159. label: item.name,
  160. value: item.id,
  161. };
  162. });
  163. });
  164. };
  165. const getList = async (req) => {
  166. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  167. loading.value = true;
  168. proxy
  169. .post("/contractTemplate/page", sourceList.value.pagination)
  170. .then((res) => {
  171. sourceList.value.data = res.rows;
  172. sourceList.value.pagination.total = res.total;
  173. setTimeout(() => {
  174. loading.value = false;
  175. }, 200);
  176. });
  177. };
  178. // getDict();
  179. getList();
  180. const modalType = ref("add");
  181. const dialogVisible = ref(false);
  182. const loadingOperation = ref(false);
  183. const submit = ref(null);
  184. const formData = reactive({
  185. data: {
  186. countryId: "44",
  187. },
  188. });
  189. const formOption = reactive({
  190. inline: true,
  191. labelWidth: 100,
  192. itemWidth: 100,
  193. rules: [],
  194. });
  195. const formConfig = computed(() => {
  196. return [
  197. {
  198. type: "title1",
  199. title: "基础信息",
  200. },
  201. {
  202. type: "select",
  203. label: "模板类型",
  204. prop: "templateType",
  205. data: typeData.value,
  206. },
  207. {
  208. type: "input",
  209. prop: "templateName",
  210. label: "模板名称",
  211. itemType: "text",
  212. placeholder: "请输入模板名称",
  213. },
  214. // {
  215. // type: "select",
  216. // label: "公司名称",
  217. // prop: "corporationId",
  218. // data: companyList.value,
  219. // },
  220. {
  221. type: "title1",
  222. title: "模板内容",
  223. },
  224. // {
  225. // type: "input",
  226. // prop: "contactName",
  227. // label: "业务联系人",
  228. // itemType: "text",
  229. // placeholder: "请输入联系人",
  230. // itemWidth: 50,
  231. // },
  232. // {
  233. // type: "input",
  234. // prop: "contactNumber",
  235. // label: "",
  236. // itemType: "text",
  237. // placeholder: "请输入联系电话",
  238. // itemWidth: 50,
  239. // },
  240. {
  241. type: "slot",
  242. prop: "templateContent",
  243. slotName: "templateContent",
  244. label: "模板内容",
  245. },
  246. ];
  247. });
  248. let rules = ref({
  249. templateName: [
  250. { required: true, message: "请输入模板名称", trigger: "blur" },
  251. ],
  252. templateType: [
  253. { required: true, message: "请选择模板类型", trigger: "change" },
  254. ],
  255. templateContent: [
  256. { required: true, message: "请输入模板内容", trigger: "blur" },
  257. ],
  258. });
  259. const openModal = () => {
  260. modalType.value = "add";
  261. formData.data = {
  262. templateContent: "",
  263. };
  264. loadingOperation.value = false;
  265. dialogVisible.value = true;
  266. };
  267. const submitForm = () => {
  268. submit.value.handleSubmit(() => {
  269. loadingOperation.value = true;
  270. proxy.post("/contractTemplate/" + modalType.value, formData.data).then(
  271. () => {
  272. ElMessage({
  273. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  274. type: "success",
  275. });
  276. dialogVisible.value = false;
  277. getList();
  278. },
  279. (err) => {
  280. console.log(err);
  281. loadingOperation.value = false;
  282. }
  283. );
  284. });
  285. };
  286. const update = (row) => {
  287. modalType.value = "edit";
  288. loadingOperation.value = true;
  289. proxy.post("/contractTemplate/detail", { id: row.id }).then((res) => {
  290. formData.data = res;
  291. loadingOperation.value = false;
  292. dialogVisible.value = true;
  293. });
  294. };
  295. const updateContent = (val) => {
  296. formData.data.templateContent = val;
  297. };
  298. </script>
  299. <style lang="scss" scoped>
  300. .tenant {
  301. padding: 20px;
  302. }
  303. .ql-editor {
  304. padding: 0px;
  305. }
  306. </style>