taskExcel.vue 7.7 KB

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