questions.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. import { Component, OnInit, ViewChild, ElementRef } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import setSeconds from "date-fns/setSeconds";
  5. import setMinutes from "date-fns/setMinutes";
  6. import setHours from "date-fns/setHours";
  7. import { MainService } from "../../services/main.service";
  8. import { ToolService } from "../../services/tool.service";
  9. import { NzMessageService } from "ng-zorro-antd";
  10. @Component({
  11. selector: "app-questions",
  12. templateUrl: "./questions.component.html",
  13. styleUrls: ["./questions.component.less"],
  14. })
  15. export class QuestionsComponent implements OnInit {
  16. @ViewChild("inputElement", { static: false }) inputElement: ElementRef;
  17. constructor(
  18. private message: NzMessageService,
  19. private fb: FormBuilder,
  20. private mainService: MainService,
  21. private route: ActivatedRoute,
  22. private router: Router,
  23. private tool: ToolService
  24. ) {
  25. this.route.queryParams.subscribe((res) => {
  26. this.queryParamsId = res.id;
  27. this.queryParamsToken = res.token;
  28. this.queryParamsName = res.title;
  29. });
  30. }
  31. searchCriteria = {
  32. //搜索条件
  33. name: "",
  34. workModel: null,
  35. };
  36. allWorkModel = [
  37. { id: 1, name: "自由抢单" },
  38. { id: 2, name: "指定分组" },
  39. { id: 3, name: "科室绑定人员" },
  40. { id: 4, name: "科室绑定分组" },
  41. ];
  42. quickCombinationModel;
  43. requireGroup = false;
  44. requireDept = false;
  45. queryParamsId = ""; //方案id
  46. queryParamsToken = ""; //方案token
  47. queryParamsName = ""; //方案名称
  48. userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
  49. listOfData: any[] = []; //表格数据
  50. pageIndex: number = 1; //表格当前页码
  51. pageSize: number = 10; //表格每页展示条数
  52. listLength: number = 10; //表格总数据量
  53. tableHeight: number; //表格动态高
  54. modal: boolean = false; //新增/编辑模态框
  55. personModal: boolean = false; //定时启用设置日期模态框
  56. groupsModal: boolean = false; //定时启用设置日期模态框
  57. add: boolean; //true:新增;false:编辑
  58. validateForm: FormGroup; //新增/编辑表单
  59. validateDateForm: FormGroup; //定时启动设置日期表单
  60. validatePersonForm: FormGroup; //
  61. validateGroupForm: FormGroup; //
  62. coopId: number; //当前操作列id
  63. timeDefaultValue = setHours(setMinutes(setSeconds(new Date(), 0), 0), 0);
  64. btnLoading: boolean = false; //提交按钮loading状态
  65. currentHospital; //当前院区
  66. promptContent: string; //操作提示框提示信息
  67. ifSuccess: boolean; //操作成功/失败
  68. promptInfo: string; //操作结果提示信息
  69. promptModalShow: boolean; //操作提示框是否展示
  70. showLoading = false; //操作是否显示loading
  71. classList = []; //班次列表
  72. maskFlag: any = false;
  73. qItems: any = []; //10个选项
  74. // -----------------------
  75. ngOnInit() {
  76. this.getOneQuestionnaireManagement();
  77. Array(10).fill('').forEach((v, i)=>{
  78. this.qItems.push({id:i+1, value:''});
  79. })
  80. console.log(this.qItems)
  81. this.currentHospital = this.tool.getCurrentHospital();
  82. this.initForm();
  83. this.getList(1);
  84. this.getAnswerModes();
  85. }
  86. // 获取问卷数据
  87. getOneQuestionnaireManagement(){
  88. this.mainService.getFetchData('api', "questionnaireManagement", this.queryParamsId).subscribe(res=>{
  89. if(res.status == 200){
  90. this.queryParamsToken = res.data.token;
  91. this.queryParamsName = res.data.title;
  92. }
  93. })
  94. }
  95. // 重置
  96. reset() {
  97. this.searchCriteria = {
  98. //搜索条件
  99. name: "",
  100. workModel: null,
  101. };
  102. this.getList(1);
  103. }
  104. // 表格数据
  105. loading1 = false;
  106. getList(type) {
  107. if (type == 1) {
  108. this.pageIndex = 1;
  109. }
  110. let data = {
  111. questionnaireInfo: {
  112. managementId: this.queryParamsId,
  113. },
  114. idx: this.pageIndex - 1,
  115. sum: this.pageSize,
  116. };
  117. this.loading1 = true;
  118. this.mainService
  119. .getFetchDataList("api", "questionnaireInfo", data)
  120. .subscribe((data) => {
  121. this.loading1 = false;
  122. if (data.status == 200) {
  123. this.listOfData = data.list;
  124. this.listLength = data.totalNum;
  125. }
  126. });
  127. }
  128. // 新增/编辑弹框
  129. addModal() {
  130. this.add = true; //新增
  131. this.modal = true;
  132. this.initForm();
  133. }
  134. //关闭新增/编辑弹框
  135. hideAddModal() {
  136. this.modal = false;
  137. this.copyFlag = false;
  138. this.initForm();
  139. }
  140. // 修改排序号
  141. onChange(value: string): void {
  142. if (value !== "") {
  143. let oValue = parseInt(value);
  144. this.inputElement.nativeElement.value = isNaN(oValue)?'':(oValue?oValue:'');
  145. }
  146. }
  147. // 获取字典数据-答题方式
  148. answerModes: any[] = [];
  149. answerModesRadioValue;
  150. getAnswerModes() {
  151. this.mainService.getDictionary("list", "answer_mode").subscribe((data) => {
  152. this.answerModes = data;
  153. this.answerModesRadioValue = data.find((v) => v.value == 1).id;
  154. });
  155. }
  156. // 初始化新增form表单
  157. initForm() {
  158. this.quickCombinationModel = "";
  159. this.validateForm = this.fb.group({
  160. describe: [null, [Validators.required]],
  161. orders: [null, [Validators.required]],
  162. answerMode: [null, [Validators.required]],
  163. });
  164. }
  165. // 初始化新增form表单
  166. initPersonForm() {
  167. this.validatePersonForm = this.fb.group({
  168. quickCombinationPerson: [null, [Validators.required]],
  169. });
  170. }
  171. // 初始化新增form表单
  172. initGroupsForm() {
  173. this.validateGroupForm = this.fb.group({
  174. quickCombinationGroups: [null, [Validators.required]],
  175. });
  176. }
  177. // 新增/编辑表单提交
  178. submitForm(): void {
  179. for (const i in this.validateForm.controls) {
  180. this.validateForm.controls[i].markAsDirty();
  181. this.validateForm.controls[i].updateValueAndValidity();
  182. }
  183. console.log(this.validateForm);
  184. this.btnLoading = true;
  185. if (this.validateForm.invalid) {
  186. this.btnLoading = false;
  187. return;
  188. }
  189. let data:any = {};
  190. if(this.add){
  191. data = {
  192. questionnaireInfo: {
  193. hosId: this.currentHospital.id,
  194. managementId: this.queryParamsId,
  195. describe: this.validateForm.value.describe,
  196. orders: this.validateForm.value.orders,
  197. answerMode: {id: this.validateForm.value.answerMode},
  198. }
  199. };
  200. if(this.validateForm.value.answerMode == this.answerModesRadioValue){
  201. this.qItems.forEach((v, i)=>{
  202. data.questionnaireInfo['option' + (i + 1)] = v.value;
  203. })
  204. }
  205. }else{
  206. data = {
  207. questionnaireInfo: {
  208. describe: this.validateForm.value.describe,
  209. orders: this.validateForm.value.orders,
  210. answerMode: {id: this.validateForm.value.answerMode},
  211. }
  212. };
  213. if(this.validateForm.value.answerMode == this.answerModesRadioValue){
  214. this.qItems.forEach((v, i)=>{
  215. data.questionnaireInfo['option' + (i + 1)] = v.value;
  216. })
  217. }else{
  218. Array(10).fill('').forEach((v, i)=>{
  219. data.questionnaireInfo['option' + (i + 1)] = v
  220. })
  221. }
  222. data.questionnaireInfo = Object.assign(this.info,data.questionnaireInfo);
  223. console.log(data);
  224. }
  225. this.mainService
  226. .coopTypeConfig(
  227. this.add || (!this.add && this.copyFlag) ? "addData" : "updData",
  228. "questionnaireInfo",
  229. data
  230. )
  231. .subscribe((result) => {
  232. this.btnLoading = false;
  233. if (result.status == 200) {
  234. console.log(this.copyFlag);
  235. if (this.add) {
  236. this.showPromptModal("新增", true, "");
  237. this.listLength++;
  238. } else if (this.copyFlag) {
  239. this.showPromptModal("复制", true, "");
  240. this.listLength++;
  241. } else if (!this.copyFlag) {
  242. //编辑
  243. this.showPromptModal("编辑", true, "");
  244. }
  245. } else {
  246. let msg = "";
  247. if (this.add) {
  248. msg = "新增";
  249. } else if (!this.copyFlag) {
  250. msg = "修改";
  251. } else if (this.copyFlag) {
  252. msg = "复制";
  253. }
  254. this.showPromptModal(msg, false, result.msg);
  255. }
  256. this.hideAddModal();
  257. this.initForm();
  258. });
  259. }
  260. // 复制
  261. copyFlag = false;
  262. copy(e, data) {
  263. e.stopPropagation();
  264. console.log(data);
  265. this.add = false;
  266. this.copyFlag = true;
  267. this.coopId = data.id;
  268. this.info = data;
  269. }
  270. // 编辑
  271. info; //编辑时候保存的信息
  272. edit(e, data) {
  273. e.stopPropagation();
  274. console.log(data);
  275. this.add = false;
  276. this.coopId = data.id;
  277. this.info = data;
  278. this.validateForm.controls.describe.setValue(data.describe); //问卷描述
  279. this.validateForm.controls.orders.setValue(data.orders); //排序号
  280. this.validateForm.controls.answerMode.setValue(data.answerMode?data.answerMode.id.toString():''); //答题方式
  281. if(data.answerMode && data.answerMode.id){
  282. this.qItems.forEach((v, i)=>{
  283. v.value = data['option'+ (i+1)]
  284. })
  285. }
  286. this.modal = true;
  287. }
  288. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  289. // promptModalUrl = '';
  290. showPromptModal(con, success, promptInfo?, loading?) {
  291. this.promptModalShow = false;
  292. this.promptContent = con;
  293. this.ifSuccess = success;
  294. this.promptInfo = promptInfo;
  295. if (loading !== undefined) {
  296. this.showLoading = loading;
  297. } else {
  298. this.showLoading = false;
  299. this.getList(0);
  300. }
  301. // this.promptModalUrl = url;
  302. setTimeout(() => {
  303. this.promptModalShow = true;
  304. }, 100);
  305. }
  306. // 选中表格中快捷建单
  307. isAllDisplayDataChecked = false; //当前页是否全选
  308. mapOfCheckedId = {};
  309. checkedDepIds = []; //已选中快捷建单id
  310. refreshStatus(): void {
  311. this.isAllDisplayDataChecked = this.listOfData.every(
  312. (item) => this.mapOfCheckedId[item.id]
  313. );
  314. let arr = [];
  315. for (var k in this.mapOfCheckedId) {
  316. if (this.mapOfCheckedId[k]) {
  317. arr.push(Number(k));
  318. }
  319. }
  320. this.checkedDepIds = arr;
  321. console.log(this.checkedDepIds, this.isAllDisplayDataChecked);
  322. }
  323. // 整行选中或不选中
  324. selectedListData(id) {
  325. this.mapOfCheckedId[id] = !this.mapOfCheckedId[id];
  326. this.refreshStatus();
  327. }
  328. // 全选
  329. checkAll(value: boolean): void {
  330. this.listOfData.forEach((item) => (this.mapOfCheckedId[item.id] = value));
  331. this.refreshStatus();
  332. }
  333. // 删除轮巡计划
  334. delModal: boolean = false; //删除模态框
  335. tipsMsg1: string; //提示框信息
  336. tipsMsg2: string; //操作后信息
  337. confirmDelType: string; //确认的类型(启用/停用,删除)
  338. confirmDelIsSwitch: boolean; //启用/停用
  339. showDelModal(
  340. e,
  341. id: any,
  342. tipsMsg1: string,
  343. tipsMsg2: string,
  344. type: string,
  345. isSwitch?: boolean
  346. ) {
  347. e.stopPropagation();
  348. this.confirmDelIsSwitch = isSwitch;
  349. this.confirmDelType = type;
  350. this.delModal = true;
  351. this.coopId = id;
  352. this.tipsMsg1 = tipsMsg1;
  353. this.tipsMsg2 = tipsMsg2;
  354. }
  355. // 隐藏删除框
  356. hideDelModal() {
  357. this.delModal = false;
  358. }
  359. // 确认删除
  360. confirmDel() {
  361. this.btnLoading = true;
  362. if (this.confirmDelType === "del") {
  363. //删除
  364. let arrData = [];
  365. if (Array.isArray(this.coopId)) {
  366. arrData = this.coopId;
  367. } else {
  368. arrData = [this.coopId];
  369. }
  370. this.mainService
  371. .coopTypeConfig("rmvData", "questionnaireInfo", arrData)
  372. .subscribe((data) => {
  373. this.btnLoading = false;
  374. this.delModal = false;
  375. if (data.status == 200) {
  376. if (
  377. this.listOfData.length == 1 &&
  378. this.pageIndex == Math.ceil(this.listLength / this.pageSize)
  379. ) {
  380. this.listLength--;
  381. if (this.listLength === 0) {
  382. this.pageIndex = 1;
  383. } else {
  384. this.pageIndex = Math.ceil(this.listLength / this.pageSize);
  385. }
  386. }
  387. this.showPromptModal(this.tipsMsg2, true, "");
  388. this.isAllDisplayDataChecked = false;
  389. this.checkedDepIds = [];
  390. this.mapOfCheckedId = {};
  391. } else {
  392. this.showPromptModal(this.tipsMsg2, false, data.msg);
  393. }
  394. });
  395. }
  396. }
  397. // ----------返回拦截------------
  398. tipModal = false;
  399. // tipMsg1 = '是否确定离开该界面,如果未点击生效,数据可能会遗失?';
  400. // 隐藏模态框
  401. hideTipModal() {
  402. // this.tipModal = false;
  403. }
  404. // 返回
  405. goToWorkAssignment() {
  406. // this.tipModal = true;
  407. this.router.navigateByUrl(`/main/questionnaireManagement`);
  408. }
  409. // 模态框确认
  410. confirmTip() {
  411. // this.tipModal = false;
  412. // this.router.navigateByUrl(`/main/workAssignment`);
  413. }
  414. }