updateExcel.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="dialogBody">
  3. <div class="exView" :key="excelKey1">
  4. <ExcelView
  5. ref="excelViewRef"
  6. :option="options"
  7. @confirm="confirm"
  8. v-model:data="exceldata"
  9. :checkStatus="true"
  10. :verifications="setting"
  11. />
  12. </div>
  13. <div class="btns" v-if="options.edit !== false">
  14. <el-button class="btn" type="success" @click="submit">确 定 </el-button>
  15. <el-button class="btn" @click="reset">重 置 </el-button>
  16. <el-button class="btn" type="info" @click="cancel">取 消 </el-button>
  17. </div>
  18. <div class="btns" v-else>
  19. <el-button class="btn" type="info" @click="cancel">返 回 </el-button>
  20. </div>
  21. </div>
  22. </template>
  23. <script setup lang="ts">
  24. import { ref } from "vue";
  25. import { useCrud } from "@/hooks/userCrud";
  26. import { setExcelData } from "@/api/excel/index.ts";
  27. import ExcelView from "@/components/ExcelView/index.vue";
  28. import { useDictionaryStore } from "@/store";
  29. const setting = ref([]);
  30. const props = defineProps({
  31. data: {
  32. type: Object,
  33. },
  34. });
  35. const rowData = ref({});
  36. const emits = defineEmits(["update:modelValue", "close", "refresh"]);
  37. const excelKey1 = ref(false);
  38. const submit = async () => {
  39. excelViewRef.value.confirm();
  40. const { data, code } = await setExcelData({
  41. excelData: JSON.stringify(exceldata.value),
  42. excelFormId: rowData.value.excelFormId,
  43. processId: rowData.value.processId,
  44. formType: rowData.value.formType,
  45. formName: rowData.value.formName,
  46. });
  47. if (code == "200") {
  48. ElMessage.success("修改成功!");
  49. cancel();
  50. emits("refresh");
  51. }
  52. };
  53. const reset = () => {
  54. exceldata.value = JSON.parse(rowData.value.excelData);
  55. excelKey1.value = !excelKey1.value;
  56. };
  57. const cancel = () => {
  58. excelKey1.value = !excelKey1.value;
  59. options.value.edit = true;
  60. emits("close");
  61. };
  62. // 存放操作表格相关业务代码
  63. const useAddTemplateHook = () => {
  64. //excelView 组件实例
  65. const excelViewRef = ref(null);
  66. //表格配置项
  67. const options = ref({
  68. //头部操作区域
  69. opreaState: true,
  70. //导入按钮展示
  71. in: true,
  72. //导出按钮展示
  73. out: true,
  74. print: true,
  75. //编辑状态 false:为查看状态
  76. edit: true,
  77. //当前操作表格名称
  78. inName: "",
  79. opreaTitle: false,
  80. });
  81. //双向绑定表格data变量
  82. const exceldata = ref(null);
  83. //控制表格组件展示界面变量(包括表格展示页面和操作页面)
  84. const excelStatus = ref(true);
  85. //获取组件内实时数据赋值到外层
  86. const confirm = (data: any) => {
  87. exceldata.value = data;
  88. };
  89. return {
  90. excelStatus,
  91. options,
  92. confirm,
  93. exceldata,
  94. excelViewRef,
  95. };
  96. };
  97. const { options, confirm, exceldata, excelViewRef } = useAddTemplateHook();
  98. const useFormHook = () => {
  99. //KEY告知组件刷新
  100. const excelKey = ref(1);
  101. //表单data
  102. const formVlaue = reactive({ formType: null, formName: null, state: null });
  103. //表单是否为编辑状态变量
  104. const operaEditStatus = ref(false);
  105. //选中的行id
  106. const selectId = ref(null);
  107. //表单ref实例
  108. const formRef = ref(null);
  109. //表单校验规则
  110. const rules = reactive({
  111. formName: [
  112. {
  113. required: true,
  114. trigger: "blur",
  115. },
  116. ],
  117. formType: [
  118. {
  119. required: true,
  120. trigger: "blur",
  121. },
  122. ],
  123. state: [
  124. {
  125. required: true,
  126. trigger: "blur",
  127. },
  128. ],
  129. });
  130. //新增模版
  131. const submitForm = async (formEl: any) => {
  132. //@ts-ignore;
  133. excelViewRef.value.confirm();
  134. if (exceldata.value == null) return ElMessage.error("请提供表格数据!");
  135. if (!formEl) return;
  136. await formEl.validate(async (valid: any, fields: any) => {
  137. if (valid) {
  138. const { data, code } = await addExcel({
  139. ...formVlaue,
  140. excelData: exceldata.value,
  141. });
  142. if (code == "200") {
  143. ElMessage.success("添加成功!");
  144. resetData();
  145. dataEditList();
  146. editTep(data);
  147. }
  148. }
  149. });
  150. };
  151. //更新行内信息
  152. const updateExForm = async (formEl: any) => {
  153. //@ts-ignore;
  154. excelViewRef.value.saveCellData();
  155. //@ts-ignore;
  156. excelViewRef.value.confirm();
  157. if (exceldata.value == null) return ElMessage.error("请提供表格数据!");
  158. if (!formEl) return;
  159. await formEl.validate(async (valid: any, fields: any) => {
  160. if (valid) {
  161. const { data, code } = await updateExcel({
  162. ...formVlaue,
  163. excelData: exceldata.value,
  164. id: selectId.value,
  165. settings: settings.value,
  166. });
  167. if (code == "200") {
  168. ElMessage.success("修改成功!");
  169. resetData();
  170. dataEditList();
  171. }
  172. }
  173. });
  174. };
  175. //表达数据重置
  176. const resetForm = (formEl: any) => {
  177. if (!formEl) return;
  178. formEl.resetFields();
  179. };
  180. return {
  181. formVlaue,
  182. formRef,
  183. rules,
  184. selectId,
  185. excelKey,
  186. operaEditStatus,
  187. submitForm,
  188. resetForm,
  189. updateExForm,
  190. };
  191. };
  192. const {
  193. formVlaue,
  194. formRef,
  195. rules,
  196. selectId,
  197. excelKey,
  198. operaEditStatus,
  199. submitForm,
  200. resetForm,
  201. updateExForm,
  202. } = useFormHook();
  203. //表格新增 分页
  204. const useAddFormHook = () => {
  205. const formRef1 = ref(null);
  206. const settings = ref([]);
  207. const searchForm = ref({
  208. pageNo: 1,
  209. pageSize: 5,
  210. totalPages: 0,
  211. });
  212. const addForm = ref({
  213. paramName: "",
  214. position: "",
  215. });
  216. const addPage = () => {
  217. searchForm.value.pageNo = searchForm.value.pageNo + 1;
  218. getSettingData();
  219. };
  220. const deletePage = () => {
  221. searchForm.value.pageNo = searchForm.value.pageNo - 1;
  222. getSettingData();
  223. };
  224. const getSettingData = async () => {
  225. const { data } = await getSettingsData({
  226. excelFormId: selectId.value,
  227. ...searchForm.value,
  228. });
  229. settings.value = data.records;
  230. if (settings.value.length == 0 && searchForm.value.pageNo > 1) {
  231. deletePage();
  232. }
  233. searchForm.value.totalPages = data.totalPages;
  234. };
  235. const addSettings = async () => {
  236. const { data, code } = await addSettingsData({
  237. excelFormId: selectId.value,
  238. ...addForm.value,
  239. });
  240. if (code == "200") {
  241. ElMessage.success("添加成功");
  242. resetAddForm();
  243. getSettingData();
  244. }
  245. };
  246. const deleteSettings = async (id: any) => {
  247. const { data, code } = await deleteSettingsData({ id: id });
  248. if (code == "200") {
  249. ElMessage.success("删除成功");
  250. getSettingData();
  251. }
  252. };
  253. const resetAddForm = () => {
  254. addForm.value = {
  255. paramName: "",
  256. position: "",
  257. };
  258. searchForm.value = {
  259. pageNo: 1,
  260. pageSize: 5,
  261. totalPages: 0,
  262. };
  263. settings.value = [];
  264. };
  265. const creatAddForm = async () => {
  266. await formRef1.value.validate(async (valid: any, fields: any) => {
  267. if (valid) {
  268. addSettings();
  269. }
  270. });
  271. };
  272. const addRules = reactive({
  273. paramName: [
  274. {
  275. required: true,
  276. trigger: "blur",
  277. },
  278. ],
  279. position: [
  280. {
  281. required: true,
  282. trigger: "blur",
  283. },
  284. ],
  285. });
  286. return {
  287. formRef1,
  288. addForm,
  289. searchForm,
  290. settings,
  291. addRules,
  292. creatAddForm,
  293. resetAddForm,
  294. getSettingData,
  295. addSettings,
  296. addPage,
  297. deleteSettings,
  298. deletePage,
  299. };
  300. };
  301. const {
  302. formRef1,
  303. addForm,
  304. searchForm,
  305. settings,
  306. addRules,
  307. creatAddForm,
  308. deletePage,
  309. addPage,
  310. resetAddForm,
  311. getSettingData,
  312. deleteSettings,
  313. } = useAddFormHook();
  314. watch(
  315. () => props.data,
  316. () => {
  317. //@ts-ignore
  318. rowData.value = props.data;
  319. exceldata.value = JSON.parse(rowData.value.writeData);
  320. excelKey1.value = !excelKey1.value;
  321. if (rowData.value.lookStatus == true) {
  322. options.value.edit = false;
  323. }
  324. setting.value = rowData.value.settings;
  325. },
  326. { immediate: true }
  327. );
  328. watch(
  329. () => rowData.value,
  330. () => {
  331. if (rowData.value.lookStatus == true) {
  332. options.value.edit = false;
  333. }
  334. },
  335. { immediate: true, deep: true }
  336. );
  337. </script>
  338. <style lang="scss" scoped>
  339. .dialogBody {
  340. width: 1560px;
  341. height: 560px;
  342. display: flex;
  343. .exView {
  344. width: 1330px;
  345. height: 560px;
  346. display: flex;
  347. position: relative;
  348. }
  349. .btns {
  350. width: 200px;
  351. height: 560px;
  352. display: flex;
  353. flex-direction: column;
  354. align-items: center;
  355. padding: 40px 0 0 20px;
  356. .btn {
  357. width: 100%;
  358. margin: 10px;
  359. }
  360. }
  361. }
  362. </style>