index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div class="tenant">
  3. <div class="content">
  4. <byTable
  5. :source="sourceList.data"
  6. :pagination="sourceList.pagination"
  7. :config="config"
  8. :loading="loading"
  9. :selectConfig="selectConfig"
  10. highlight-current-row
  11. :action-list="[
  12. {
  13. text: '添加模板',
  14. action: () => openModal(),
  15. },
  16. ]"
  17. @get-list="getList">
  18. </byTable>
  19. </div>
  20. <el-dialog :title="modalType == 'add' ? '新增' : '编辑'" v-if="dialogVisible" v-model="dialogVisible" width="800" v-loading="loadingOperation">
  21. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  22. <template #allAddress>
  23. <el-row :gutter="10" style="width: 100%">
  24. <el-col :span="8">
  25. <el-form-item prop="countryId">
  26. <el-select v-model="formData.data.countryId" placeholder="国家" @change="(val) => getCityData(val, '20', true)">
  27. <el-option v-for="item in countryData" :label="item.chineseName" :value="item.id"> </el-option>
  28. </el-select>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="8">
  32. <el-form-item prop="provinceId">
  33. <el-select v-model="formData.data.provinceId" placeholder="省/洲" @change="(val) => getCityData(val, '30', true)">
  34. <el-option v-for="item in provinceData" :label="item.name" :value="item.id"> </el-option>
  35. </el-select>
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="8">
  39. <el-form-item prop="cityId">
  40. <el-select v-model="formData.data.cityId" placeholder="城市">
  41. <el-option v-for="item in cityData" :label="item.name" :value="item.id"> </el-option>
  42. </el-select>
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. <el-row style="margin-top: 20px; width: 100%">
  47. <el-col :span="24">
  48. <el-form-item prop="address">
  49. <el-input v-model="formData.data.address" type="textarea"> </el-input>
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. </template>
  54. <template #allAddressEnglish>
  55. <el-row :gutter="10" style="width: 100%">
  56. <el-col :span="8">
  57. <el-form-item prop="countryEnStr">
  58. <el-input v-model="formData.data.countryEnStr" placeholder="请输入国家 (英文)" />
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="8">
  62. <el-form-item prop="provinceEnStr">
  63. <el-input v-model="formData.data.provinceEnStr" placeholder="请输入省/洲 (英文)" />
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="8">
  67. <el-form-item prop="cityEnStr">
  68. <el-input v-model="formData.data.cityEnStr" placeholder="请输入城市 (英文)" />
  69. </el-form-item>
  70. </el-col>
  71. </el-row>
  72. <el-row style="margin-top: 20px; width: 100%">
  73. <el-col :span="24">
  74. <el-form-item prop="addressEn">
  75. <el-input v-model="formData.data.addressEn" type="textarea"> </el-input>
  76. </el-form-item>
  77. </el-col>
  78. </el-row>
  79. </template>
  80. <template #templateContent>
  81. <div style="width: 100%">
  82. <Editor :value="formData.data.templateContent" @updateValue="updateContent"/>
  83. </div>
  84. </template>
  85. </byForm>
  86. <template #footer>
  87. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  88. <el-button type="primary" @click="submitForm()" size="large">确 定</el-button>
  89. </template>
  90. </el-dialog>
  91. </div>
  92. </template>
  93. <script setup>
  94. import { ElMessage, ElMessageBox } from "element-plus";
  95. import byTable from "@/components/byTable/index";
  96. import byForm from "@/components/byForm/index";
  97. import { computed, ref } from "vue";
  98. import Editor from "@/components/Editor/index.vue";
  99. const { proxy } = getCurrentInstance();
  100. const loading = ref(false);
  101. const companyList = ref({});
  102. const sourceList = ref({
  103. data: [],
  104. pagination: {
  105. total: 0,
  106. pageNum: 1,
  107. pageSize: 10,
  108. corporationId: "",
  109. keyword: "",
  110. },
  111. });
  112. const selectConfig = computed(() => {
  113. return [
  114. {
  115. label: "公司名称",
  116. prop: "corporationId",
  117. data: companyList.value,
  118. },
  119. ];
  120. });
  121. const config = computed(() => {
  122. return [
  123. {
  124. attrs: {
  125. label: "公司名称",
  126. prop: "corporationName",
  127. },
  128. },
  129. {
  130. attrs: {
  131. label: "模板名称",
  132. prop: "templateName",
  133. },
  134. },
  135. {
  136. attrs: {
  137. label: "联系人",
  138. prop: "contactName",
  139. },
  140. },
  141. {
  142. attrs: {
  143. label: "联系电话",
  144. prop: "contactNumber",
  145. },
  146. },
  147. {
  148. attrs: {
  149. label: "操作",
  150. width: "120",
  151. align: "center",
  152. },
  153. renderHTML(row) {
  154. return [
  155. {
  156. attrs: {
  157. label: "修改",
  158. type: "primary",
  159. text: true,
  160. },
  161. el: "button",
  162. click() {
  163. update(row);
  164. },
  165. },
  166. {
  167. attrs: {
  168. label: "删除",
  169. type: "primary",
  170. text: true,
  171. },
  172. el: "button",
  173. click() {
  174. ElMessageBox.confirm("此操作将永久删除该数据, 是否继续?", "提示", {
  175. confirmButtonText: "确定",
  176. cancelButtonText: "取消",
  177. type: "warning",
  178. }).then(() => {
  179. proxy
  180. .post("/contractTemplate/delete", {
  181. id: row.id,
  182. })
  183. .then(() => {
  184. ElMessage({
  185. message: "删除成功",
  186. type: "success",
  187. });
  188. getList();
  189. });
  190. });
  191. },
  192. },
  193. ];
  194. },
  195. },
  196. ];
  197. });
  198. const getDict = () => {
  199. proxy.post("/corporation/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  200. companyList.value = res.rows.map((item) => {
  201. return {
  202. label: item.name,
  203. value: item.id,
  204. };
  205. });
  206. });
  207. };
  208. const getList = async (req) => {
  209. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  210. loading.value = true;
  211. proxy.post("/contractTemplate/page", sourceList.value.pagination).then((res) => {
  212. sourceList.value.data = res.rows;
  213. sourceList.value.pagination.total = res.total;
  214. setTimeout(() => {
  215. loading.value = false;
  216. }, 200);
  217. });
  218. };
  219. getDict();
  220. getList();
  221. const modalType = ref("add");
  222. const dialogVisible = ref(false);
  223. const loadingOperation = ref(false);
  224. const submit = ref(null);
  225. const formData = reactive({
  226. data: {
  227. countryId: "China",
  228. },
  229. });
  230. const formOption = reactive({
  231. inline: true,
  232. labelWidth: 100,
  233. itemWidth: 100,
  234. rules: [],
  235. });
  236. const formConfig = computed(() => {
  237. return [
  238. {
  239. label: "基础信息",
  240. },
  241. {
  242. type: "input",
  243. prop: "templateName",
  244. label: "模板名称",
  245. itemType: "text",
  246. placeholder: "请输入模板名称",
  247. },
  248. {
  249. type: "select",
  250. label: "公司名称",
  251. prop: "corporationId",
  252. data: companyList.value,
  253. },
  254. {
  255. label: "联系信息",
  256. },
  257. {
  258. type: "input",
  259. prop: "contactName",
  260. label: "业务联系人",
  261. itemType: "text",
  262. placeholder: "请输入联系人",
  263. itemWidth: 30,
  264. },
  265. {
  266. type: "input",
  267. prop: "contactNumber",
  268. label: " ",
  269. itemType: "text",
  270. placeholder: "请输入联系电话",
  271. itemWidth: 70,
  272. },
  273. {
  274. type: "input",
  275. prop: "corporationNumber",
  276. label: "公司电话",
  277. itemType: "text",
  278. placeholder: "请输入公司电话",
  279. },
  280. {
  281. type: "slot",
  282. slotName: "allAddress",
  283. label: "公司地址",
  284. },
  285. {
  286. type: "slot",
  287. slotName: "allAddressEnglish",
  288. label: "公司地址 (英文)",
  289. },
  290. {
  291. type: "slot",
  292. slotName: "templateContent",
  293. label: "合同模板",
  294. },
  295. ];
  296. });
  297. let rules = ref({
  298. templateName: [{ required: true, message: "请输入模板名称", trigger: "blur" }],
  299. corporationId: [{ required: true, message: "请选择公司", trigger: "change" }],
  300. countryId: [{ required: true, message: "请选择国家", trigger: "change" }],
  301. provinceId: [{ required: true, message: "请选择省/州", trigger: "change" }],
  302. countryEnStr: [{ required: true, message: "请输入国家 (英文)", trigger: "blur" }],
  303. provinceEnStr: [{ required: true, message: "请输入省/洲 (英文)", trigger: "blur" }],
  304. // cityId: [{ required: true, message: "请选择城市", trigger: "change" }],
  305. });
  306. const countryData = ref([]);
  307. const provinceData = ref([]);
  308. const cityData = ref([]);
  309. const getCityData = (id, type, isChange) => {
  310. proxy.post("/areaInfo/list", { parentId: id }).then((res) => {
  311. if (type === "20") {
  312. provinceData.value = res;
  313. if (isChange) {
  314. formData.data.provinceId = "";
  315. formData.data.cityId = "";
  316. }
  317. } else if (type === "30") {
  318. cityData.value = res;
  319. if (isChange) {
  320. formData.data.cityId = "";
  321. }
  322. } else {
  323. countryData.value = res;
  324. }
  325. });
  326. };
  327. getCityData("0");
  328. const openModal = () => {
  329. modalType.value = "add";
  330. formData.data = {
  331. templateContent: "",
  332. countryId: "China",
  333. };
  334. getCityData(formData.data.countryId, "20");
  335. loadingOperation.value = false;
  336. dialogVisible.value = true;
  337. };
  338. const submitForm = () => {
  339. submit.value.handleSubmit(() => {
  340. loadingOperation.value = true;
  341. proxy.post("/contractTemplate/" + modalType.value, formData.data).then(
  342. () => {
  343. ElMessage({
  344. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  345. type: "success",
  346. });
  347. dialogVisible.value = false;
  348. getList();
  349. },
  350. (err) => {
  351. console.log(err);
  352. loadingOperation.value = false;
  353. }
  354. );
  355. });
  356. };
  357. const update = (row) => {
  358. modalType.value = "edit";
  359. loadingOperation.value = true;
  360. proxy.post("/contractTemplate/detail", { id: row.id }).then((res) => {
  361. formData.data = res;
  362. getCityData(formData.data.countryId, "20");
  363. getCityData(formData.data.provinceId, "30");
  364. loadingOperation.value = false;
  365. dialogVisible.value = true;
  366. });
  367. };
  368. const updateContent = (val) => {
  369. formData.data.templateContent = val
  370. }
  371. </script>
  372. <style lang="scss" scoped>
  373. .tenant {
  374. padding: 20px;
  375. }
  376. </style>