sheet.vue 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. <!--
  2. * @Author : yuanrunwei
  3. * @Date : 2021-12-04 14:23:58
  4. * @LastEditors: daiqisheng
  5. * @LastEditTime: 2022-05-10 11:24:05
  6. * @FilePath : \spfm-market-front\src\pages\main\performance\components\sheet.vue
  7. -->
  8. <template>
  9. <div class="sheet-container">
  10. <div class="flex-justify-align-end margin-bottom-20">
  11. <span
  12. class="margin-right-10 font-size-16"
  13. v-if="['template'].includes(attribute)"
  14. ><span class="sheet-container-require">*</span>模板类型:</span
  15. >
  16. <el-input
  17. v-if="['template'].includes(attribute)"
  18. v-model="templateType"
  19. :disabled="type === 'view' || (type === 'edit' && attribute === 'file')"
  20. ></el-input>
  21. <el-button
  22. type="primary"
  23. @click="handleVisible"
  24. v-if="['template'].includes(attribute)"
  25. >权限设置</el-button
  26. >
  27. <el-button type="primary" @click="handleDownload">导出</el-button>
  28. <el-button type="primary" @click="handleFullscreen()">全屏显示</el-button>
  29. <el-button
  30. type="primary"
  31. @click="handleSupervise('confirm')"
  32. v-if="['template'].includes(attribute)"
  33. >督办</el-button
  34. >
  35. <template v-if="['edit'].includes(type)">
  36. <el-upload
  37. v-if="!id"
  38. class="margin-right-10 margin-left-10"
  39. action
  40. :on-change="handleChange"
  41. :show-file-list="false"
  42. >
  43. <el-button type="primary">上传</el-button>
  44. </el-upload>
  45. <el-button
  46. v-if="!status || status === '2'"
  47. type="primary"
  48. @click="handleSave('2')"
  49. :disabled="handleForbid()"
  50. >暂存</el-button
  51. >
  52. <el-button
  53. v-if="
  54. status === '2' ||
  55. status === '3' ||
  56. (status === '0' && superviseFlag === '1')
  57. "
  58. type="primary"
  59. @click="handleResave"
  60. :disabled="handleForbid()"
  61. >保存</el-button
  62. >
  63. <el-button
  64. v-if="addFlag === '0'"
  65. type="primary"
  66. @click="handleSave('0')"
  67. :disabled="handleForbid()"
  68. ><span>{{ id ? "提交" : "新增" }}</span
  69. ><span>{{
  70. handleForbid() ? `(请先设置权限)` : ""
  71. }}</span></el-button
  72. >
  73. </template>
  74. </div>
  75. <div id="luckysheet" class="sheet-container-block"></div>
  76. <!-- 设置权限的 -->
  77. <simple-dialog
  78. title="权限设置"
  79. :visible="visible"
  80. :modal="false"
  81. width="1400px"
  82. @confirm="handleAuth"
  83. @cancel="handleVisible"
  84. >
  85. <el-form ref="form" :model="form" label-width="80px">
  86. <el-radio-group
  87. v-model="form.permission_type"
  88. :disabled="type !== 'edit'"
  89. >
  90. <el-form-item>
  91. <el-radio :label="0"><span>无特殊权限</span></el-radio>
  92. <div>
  93. <span class="form-content">负责人</span>
  94. <el-select
  95. v-model="form.person"
  96. multiple
  97. placeholder="请选择负责人"
  98. :disabled="type !== 'edit'"
  99. >
  100. <el-option
  101. v-for="({ label, value }, index) in charge_list"
  102. :key="index"
  103. :label="label"
  104. :value="value"
  105. ></el-option>
  106. </el-select>
  107. </div>
  108. </el-form-item>
  109. <el-form-item>
  110. <el-radio :label="1"><span>特殊权限:</span></el-radio>
  111. <el-form-item
  112. label="负责人"
  113. prop="charge"
  114. v-for="(item, index) in form.charge"
  115. :key="index"
  116. :rules="{
  117. required: true,
  118. message: '负责人不能为空',
  119. trigger: 'blur',
  120. }"
  121. >
  122. <div class="flex">
  123. <el-select
  124. class="margin-bottom-20 margin-right-10"
  125. placeholder="请选择负责人"
  126. v-model="item.person"
  127. filterable
  128. :disabled="type !== 'edit'"
  129. >
  130. <el-option
  131. v-for="({ label, value }, index) in charge_list"
  132. :key="index"
  133. :label="label"
  134. :value="value"
  135. ></el-option>
  136. </el-select>
  137. <div class="form-select">
  138. <span class="form-content">可编辑行:从</span>
  139. <el-input
  140. v-model="item.row_start"
  141. @input="(params) => handleInput(index, 'row_start', params)"
  142. :disabled="type !== 'edit'"
  143. />
  144. <span class="form-content">到</span>
  145. <el-input
  146. v-model="item.row_end"
  147. @input="(params) => handleInput(index, 'row_end', params)"
  148. :disabled="type !== 'edit'"
  149. />
  150. </div>
  151. <div class="form-select">
  152. <span class="form-content">可编辑列:从</span>
  153. <el-input
  154. :disabled="type !== 'edit'"
  155. v-model="item.col_start"
  156. />
  157. <!-- @input="(params) => handleInput(index, 'col_start', params)" -->
  158. <span class="form-content">到</span>
  159. <el-input
  160. :disabled="type !== 'edit'"
  161. v-model="item.col_end"
  162. />
  163. </div>
  164. </div>
  165. </el-form-item>
  166. <div>
  167. <el-button
  168. @click.prevent="handleCharge('add')"
  169. :disabled="type !== 'edit'"
  170. >添加</el-button
  171. >
  172. <el-button
  173. v-if="form.charge.length - 1"
  174. @click.prevent="handleCharge('delete')"
  175. :disabled="type !== 'edit'"
  176. >删除</el-button
  177. >
  178. </div>
  179. </el-form-item>
  180. </el-radio-group>
  181. </el-form>
  182. <template v-if="id && status !== '2' && status !== '3'" v-slot:footer
  183. ><div></div
  184. ></template>
  185. </simple-dialog>
  186. <!-- 科室经理提交的 -->
  187. <simpleDialog
  188. title="提交"
  189. :visible="manager_approve"
  190. :modal="false"
  191. @cancel="handleApprove(0)"
  192. >
  193. <el-form :model="approveForm" label-width="120px">
  194. <el-form-item
  195. label="审批意见:"
  196. :rules="{
  197. required: true,
  198. message: '请选择审批意见',
  199. trigger: 'change',
  200. }"
  201. >
  202. <el-select v-model="approveForm.type">
  203. <el-option
  204. v-for="item in approveForm.list"
  205. :key="item.value"
  206. :label="item.label"
  207. :value="item.value"
  208. >
  209. </el-option>
  210. </el-select>
  211. </el-form-item>
  212. <el-form-item
  213. v-if="approveForm.type === '3'"
  214. label="其它审批意见:"
  215. :rules="{
  216. required: true,
  217. message: '请输入审批意见',
  218. trigger: 'blur',
  219. }"
  220. ><el-input v-model="approveForm.comments"
  221. /></el-form-item>
  222. </el-form>
  223. <template v-slot:footer>
  224. <div>
  225. <el-button @click.prevent="handleApprove('1')" type="primary">结束</el-button>
  226. <el-button @click.prevent="handleApprove('4')"
  227. >转副总审批</el-button
  228. >
  229. <el-button @click.prevent="handleApprove('3')"
  230. >转总经理审批</el-button
  231. >
  232. </div>
  233. </template>
  234. </simpleDialog>
  235. <simpleDialog
  236. title="督办"
  237. :visible="supervise"
  238. :modal="false"
  239. @confirm="handleSupervise('confirm')"
  240. @cancel="handleSupervise('cancel')"
  241. >
  242. <span class="margin-left-20"
  243. >注:设置督办后,系统会按照设定的周期自动派发</span
  244. >
  245. <el-form
  246. :rules="superviserules"
  247. :model="superviseForm"
  248. ref="superviseForm"
  249. class="margin-top-20"
  250. label-width="120px"
  251. >
  252. <el-form-item prop="distribute" label="派发周期">
  253. <el-select v-model="superviseForm.distribute" filterable>
  254. <!-- 0.月 1.季度 2.半年 3.年 -->
  255. <el-option
  256. v-for="({ label, value }, index) in [
  257. { label: '月', value: '0' },
  258. { label: '季度', value: '1' },
  259. { label: '半年', value: '2' },
  260. { label: '年', value: '3' },
  261. ]"
  262. :key="index"
  263. :label="label"
  264. :value="value"
  265. ></el-option>
  266. </el-select>
  267. </el-form-item>
  268. <el-form-item prop="write" label="填报日期">
  269. <el-date-picker
  270. v-model="superviseForm.write"
  271. type="date"
  272. @change="handleWrite"
  273. :picker-options="pickWrite"
  274. >
  275. </el-date-picker
  276. ></el-form-item>
  277. <el-form-item prop="endTime" label="截止时间">
  278. <el-date-picker
  279. v-model="superviseForm.endTime"
  280. @change="handleEnd"
  281. type="datetime"
  282. :unlink-panels="true"
  283. :picker-options="pickOptions"
  284. >
  285. </el-date-picker
  286. ></el-form-item>
  287. </el-form>
  288. <template v-if="id && type === 'view'" v-slot:footer
  289. ><div></div
  290. ></template>
  291. </simpleDialog>
  292. </div>
  293. </template>
  294. <script>
  295. import luckyexcel from "luckyexcel";
  296. import { exportExcel } from "../common/export";
  297. import simpleDialog from "./dialog.vue";
  298. export default {
  299. components: {
  300. simpleDialog,
  301. },
  302. props: {
  303. type: {
  304. type: String,
  305. default: "view", // view 查看 edit 编辑
  306. },
  307. attribute: {
  308. type: String,
  309. default: "template", // template 模板 order 工单 file 文件
  310. },
  311. id: {
  312. default: null,
  313. },
  314. // 接收人
  315. receiver: {
  316. type: String,
  317. default: "",
  318. },
  319. // 模板状态按钮判断
  320. status: { type: String, default: "" },
  321. },
  322. data() {
  323. return {
  324. form: {
  325. charge: [
  326. {
  327. person: [],
  328. col_start: "",
  329. col_end: "",
  330. row_start: "",
  331. row_end: "",
  332. },
  333. ],
  334. array: [],
  335. type: null,
  336. permission_type: null,
  337. col_start: "",
  338. col_end: "",
  339. row_start: "",
  340. row_end: "",
  341. },
  342. approveForm: {
  343. type: "",
  344. comments: "",
  345. list: [
  346. {
  347. label: "同意",
  348. value: "同意",
  349. },
  350. {
  351. label: "不同意",
  352. value: "不同意",
  353. },
  354. {
  355. label: "其他",
  356. value: "3",
  357. },
  358. ],
  359. },
  360. superviserules: {
  361. distribute: [
  362. { required: true, message: "请选择派发周期", trigger: "change" },
  363. ],
  364. write: [
  365. { required: true, message: "请选择填报周期", trigger: "change" },
  366. ],
  367. endTime: [
  368. { required: true, message: "请选择截止时间", trigger: "change" },
  369. ],
  370. },
  371. superviseForm: {
  372. distribute: "", // 派单周期
  373. write: "", // 填写周期
  374. endTime: "", // 截止时间
  375. },
  376. originSuperviseForm: {},
  377. pickOptions: {
  378. disabledDate(time) {
  379. return time.getTime() < new Date().getTime() - 8.64e7;
  380. },
  381. },
  382. pickWrite: {
  383. disabledDate(time) {
  384. return time.getTime() < new Date().getTime() - 8.64e7;
  385. },
  386. },
  387. // 可提交标志
  388. addFlag: "0",
  389. // 督办标志
  390. superviseFlag: null,
  391. rowList: [],
  392. isDisable: true,
  393. issued_id: null,
  394. template_id: null,
  395. visible: false,
  396. templateType: "",
  397. // 督办
  398. supervise: false,
  399. manager_approve: false,
  400. row_list: [],
  401. column_list: [],
  402. charge_list: [],
  403. type_options: [
  404. {
  405. value: 1,
  406. label: "按行",
  407. },
  408. // {
  409. // value: 2,
  410. // label: "按列",
  411. // },
  412. ],
  413. };
  414. },
  415. methods: {
  416. handleInit() {
  417. if (this.id) {
  418. this.handleQuery();
  419. } else {
  420. this.handleCreate();
  421. }
  422. },
  423. // 填报日期
  424. handleWrite(value) {
  425. if (value) {
  426. let range =
  427. new Date().getTime() > value.getTime()
  428. ? new Date().getTime()
  429. : value.getTime();
  430. this.pickOptions = {
  431. disabledDate(time) {
  432. return time.getTime() < range;
  433. },
  434. };
  435. } else {
  436. this.pickOptions = {
  437. disabledDate(time) {
  438. return time.getTime() < new Date().getTime() - 864000;
  439. },
  440. };
  441. }
  442. },
  443. handleEnd(value) {
  444. if (value) {
  445. this.pickWrite = {
  446. disabledDate(time) {
  447. return time.getTime() > value.getTime();
  448. },
  449. };
  450. let write = new Date(this.superviseForm.write).getTime();
  451. if (this.superviseForm.write && value.getTime() < write) {
  452. this.superviseForm.endTime = "";
  453. }
  454. } else {
  455. this.pickWrite = {
  456. disabledDate(time) {
  457. return time.getTime() - 864000 < new Date().getTime();
  458. },
  459. };
  460. }
  461. },
  462. // // 权限选择
  463. // handleRadio(e){
  464. // console.log(e,'e');
  465. // },
  466. handleAllow({ row, column }) {
  467. let public_permisson =
  468. (!this.form.permission_type ||
  469. this.status === "2" ||
  470. this.status === "3") &&
  471. this.type === "edit";
  472. let editable =
  473. this.row_list.includes(row) && this.column_list.includes(column);
  474. // let totalBoolean = (public_permisson || editable) && this.id;
  475. let totalBoolean = public_permisson || editable;
  476. return totalBoolean;
  477. },
  478. async handleQuery() {
  479. let url = "";
  480. let params = {};
  481. switch (this.attribute) {
  482. case "template":
  483. url = "/market/CMKFileTemplate/QueryCMKFileTemplateById";
  484. params = {
  485. templateId: this.id,
  486. };
  487. break;
  488. case "order":
  489. url = "/market/CMKIssued/CMKQueryIssuedById";
  490. params = {
  491. id: this.id,
  492. };
  493. break;
  494. case "file":
  495. url = "/market/CMKIssued/CMKIssuedProcessByUser";
  496. params = {
  497. id: this.id,
  498. receiverId: this.receiver,
  499. };
  500. break;
  501. }
  502. const {
  503. data: {
  504. templateContent,
  505. templateName,
  506. issuedId,
  507. templateId,
  508. list,
  509. superviseFlag,
  510. templateType,
  511. addFlag,
  512. distributeEndTime,
  513. distributeTime,
  514. distributeType,
  515. },
  516. } = await this.$http({
  517. url,
  518. method: "post",
  519. headers: {
  520. "Content-Type": "application/json",
  521. },
  522. data: params,
  523. });
  524. this.superviseFlag = superviseFlag;
  525. if (superviseFlag === "1") {
  526. this.superviseForm = {
  527. distribute: distributeType, // 派单周期
  528. write: distributeTime, // 填写周期
  529. endTime: distributeEndTime, // 截止时间
  530. };
  531. }
  532. console.log(this.superviseForm, "this.superviseForm");
  533. this.templateType = templateType;
  534. this.template_id = templateId;
  535. this.issued_id = issuedId;
  536. this.addFlag = addFlag;
  537. console.log(JSON.parse(templateContent), "123123");
  538. if (list && list.length) {
  539. const { type } = list[0];
  540. if (type === "1") {
  541. // 公共权限
  542. // const { allowEditingColumns, rowNum } = list[0];
  543. this.form = {
  544. permission_type: Number(type) - 1,
  545. person: list.map((el) => {
  546. return `${el.principalMent}-${el.principalId},${el.principalName}`;
  547. }),
  548. charge: [
  549. {
  550. person: "",
  551. col_start: "",
  552. col_end: "",
  553. row_start: "",
  554. row_end: "",
  555. },
  556. ],
  557. };
  558. } else {
  559. // 特殊权限
  560. this.form = {
  561. permission_type: Number(type) - 1,
  562. col_start: "",
  563. col_end: "",
  564. row_start: "",
  565. row_end: "",
  566. charge: list.map((el) => ({
  567. person: `${el.principalMent}-${el.principalId},${el.principalName}`,
  568. col_start: el.allowEditingColumns.split(",")[0],
  569. col_end:
  570. el.allowEditingColumns.split(",")[
  571. el.allowEditingColumns.split(",").length - 1
  572. ],
  573. row_start: el.rowNum.split(",")[0],
  574. row_end: el.rowNum.split(",")[el.rowNum.split(",").length - 1],
  575. })),
  576. };
  577. }
  578. this.row_list =
  579. this.type === "edit" && list[0].rowNum
  580. ? list[0].rowNum
  581. .split(",")
  582. .map((element) => JSON.parse(element) - 1)
  583. : [];
  584. if (this.type === "edit" && list[0].allowEditingColumns) {
  585. // this.column_list = list[0].allowEditingColumns
  586. // .split(",")
  587. // .map((element) => JSON.parse(element) - 1);
  588. this.column_list =
  589. list[0].allowEditingColumnsFlag === "1"
  590. ? list[0].allowEditingColumnsShuzi
  591. .split(",")
  592. .map((element) => JSON.parse(element) - 1)
  593. : list[0].allowEditingColumns
  594. .split(",")
  595. .map((element) => JSON.parse(element) - 1);
  596. } else {
  597. this.column_list = [];
  598. }
  599. // this.formateNumber(list[0].allowEditingColumns);
  600. }
  601. this.handleCreate({
  602. json: templateContent ? JSON.parse(templateContent) : {},
  603. name: templateName,
  604. type: "json",
  605. });
  606. },
  607. handleSupervise(data) {
  608. if (data === "cancel") {
  609. this.supervise = false;
  610. this.superviseForm = {
  611. ...this.originSuperviseForm,
  612. };
  613. return;
  614. }
  615. if (this.supervise === false) {
  616. this.supervise = true;
  617. this.originSuperviseForm = {
  618. ...this.superviseForm,
  619. };
  620. } else {
  621. let filled =
  622. Object.keys(this.superviseForm).length === 3 &&
  623. Object.values(this.superviseForm).filter((el) => el !== "").length ===
  624. 3;
  625. if (filled) {
  626. let time = new Date().getTime();
  627. let endTime = new Date(this.superviseForm.endTime).getTime();
  628. if (time > endTime) {
  629. this.$message.error("截止时间不能小于当前时间");
  630. return;
  631. }
  632. this.superviseForm = {
  633. ...this.superviseForm,
  634. endTime: this.$formatDate(
  635. this.superviseForm.endTime,
  636. "YYYY-MM-DD HH:mm:ss"
  637. ), // 督办设置的截止时间
  638. write: this.$formatDate(this.superviseForm.write, "YYYY-MM-DD"), // 派发时间–或者叫—填报时间
  639. };
  640. this.supervise = false;
  641. } else {
  642. this.$message.error("请填写完整必要的信息");
  643. }
  644. }
  645. },
  646. handleForbid() {
  647. // const object = {};
  648. const { permission_type } = this.form;
  649. if (permission_type === 0) {
  650. // 公共权限 暂时不用可编辑行和列
  651. const { person } = this.form;
  652. if (person.length) {
  653. return false;
  654. }
  655. return true;
  656. } else if (permission_type === 1) {
  657. // 特殊权限
  658. let flag = 1;
  659. const { charge } = this.form;
  660. charge.forEach((el) => {
  661. if (
  662. Object.values(el).filter((v) => {
  663. return v !== "";
  664. }).length === 5
  665. ) {
  666. flag = flag * 1;
  667. } else {
  668. flag = flag * 0;
  669. }
  670. });
  671. return !flag;
  672. } else {
  673. return true;
  674. }
  675. },
  676. async handleCreate({ file, json, type, name } = {}) {
  677. let that = this;
  678. const options = {
  679. container: "luckysheet",
  680. lang: "zh",
  681. showsheetbar: false,
  682. hook: {
  683. cellEditBefore: function ([
  684. { row_focus: row, column_focus: column },
  685. ]) {
  686. if (!that.handleAllow({ row, column })) {
  687. that.$message.error("您没有编辑权限");
  688. }
  689. },
  690. // cellUpdated: function (row, column) {
  691. // that.rowList.push(row);
  692. // },
  693. cellUpdateBefore: function (row, column) {
  694. console.log(row, column);
  695. if (!that.handleAllow({ row, column })) {
  696. return false;
  697. }
  698. },
  699. cellRenderAfter: function (cell, position) {
  700. const { r: row, c: column } = position;
  701. console.log();
  702. if (cell) {
  703. if (!that.handleAllow({ row, column })) {
  704. cell.bg = "#d5d5d5";
  705. } else {
  706. cell.bg = "#ffffff";
  707. }
  708. }
  709. },
  710. rangePasteBefore: function ([
  711. { row_focus: row, column_focus: column },
  712. ]) {
  713. if (!that.handleAllow({ row, column })) {
  714. that.$message.error("您没有编辑权限");
  715. return false;
  716. }
  717. },
  718. updated: function ({ range }) {
  719. const middle = range.map((el) => {
  720. return that.paramsArr(el.row[0], el.row[1]);
  721. });
  722. let changedList = middle.join(",").split(",");
  723. that.rowList.push(...changedList);
  724. },
  725. },
  726. };
  727. switch (type) {
  728. case "file":
  729. if (file) {
  730. await new Promise((resolve) => {
  731. luckyexcel.transformExcelToLucky(file, (export_json) => {
  732. options.data = [
  733. ...export_json.sheets.map((element) => ({
  734. ...element,
  735. zoomRatio: 0.75,
  736. })),
  737. ];
  738. options.title = export_json.info.name;
  739. resolve();
  740. });
  741. });
  742. }
  743. break;
  744. case "json":
  745. if (json) {
  746. options.data = [
  747. {
  748. ...json,
  749. zoomRatio: 0.75,
  750. },
  751. ];
  752. options.title = name;
  753. }
  754. break;
  755. }
  756. window.luckysheet.create(options);
  757. let clock = setInterval(() => {
  758. if (window.luckysheet) {
  759. window.luckysheet.refresh();
  760. clearInterval(clock);
  761. }
  762. }, 1000);
  763. },
  764. async handleChange(response) {
  765. this.handleCreate({ file: response.raw, type: "file" });
  766. },
  767. handleDownload() {
  768. exportExcel(
  769. window.luckysheet.getAllSheets(),
  770. window.luckysheet.getWorkbookName()
  771. );
  772. },
  773. async handleAddAuth({ id }) {
  774. // const object = {};
  775. const { permission_type } = this.form;
  776. console.log(id, permission_type);
  777. let reqdata = {
  778. templateId: id,
  779. type: permission_type ? 2 : 1,
  780. };
  781. if (!permission_type) {
  782. // 公共权限
  783. const { person } = this.form;
  784. const principalId = [];
  785. const principalName = [];
  786. const principalMent = [];
  787. person.forEach((el) => {
  788. principalMent.push(el.split(",")[0].split("-")[0]);
  789. principalId.push(el.split(",")[0].split("-")[1]);
  790. principalName.push(el.split(",")[1]);
  791. });
  792. reqdata.principalId = principalId.join(",");
  793. reqdata.principalName = principalName.join(",");
  794. reqdata.principalMent = principalMent.join(",");
  795. } else {
  796. const { charge } = this.form;
  797. // 特殊权限
  798. reqdata.specialAuth = charge.map((el) =>
  799. JSON.stringify({
  800. allowEditingColumns: `${el.col_start},${el.col_end}`,
  801. rowNum: `${el.row_start},${el.row_end}`,
  802. principalMent: el.person.split(",")[0].split("-")[0],
  803. principalId: el.person.split(",")[0].split("-")[1],
  804. principalName: el.person.split(",")[1],
  805. })
  806. );
  807. }
  808. const {
  809. data: { result, desc },
  810. } = await this.$http({
  811. url: this.id
  812. ? "/market/CMKFileTemplateAuthority/CMKFileTemplateAuthorityUpdate"
  813. : "/market/CMKFileTemplateAuthority/CMKFileTemplateAuthorityAdd",
  814. method: "post",
  815. headers: {
  816. "Content-Type": "application/json",
  817. },
  818. data: reqdata,
  819. });
  820. if (result) {
  821. this.$message.error(desc);
  822. } else {
  823. this.$message.success(desc);
  824. }
  825. return result;
  826. },
  827. async handleSave(type) {
  828. let edit_url = "";
  829. switch (this.attribute) {
  830. case "template":
  831. edit_url = "";
  832. break;
  833. case "order":
  834. edit_url = "";
  835. break;
  836. case "file":
  837. edit_url = "/market/CMKIssued/CMKIssuedSubmit";
  838. break;
  839. }
  840. const sheet_name = window.luckysheet.getSheet().name;
  841. const data = window.luckysheet.getSheet(sheet_name);
  842. const workbook_name = window.luckysheet.getWorkbookName();
  843. if (!this.id) {
  844. // 新增时添加权限
  845. let value = {};
  846. if (!this.templateType) {
  847. this.$message.error("请输入模板类型");
  848. return;
  849. }
  850. if (
  851. Object.values(this.superviseForm).filter((el) => el !== "").length ===
  852. 3
  853. ) {
  854. value = {
  855. distributeEndTime: this.superviseForm.endTime, // 督办设置的截止时间
  856. distributeTime: this.superviseForm.write, // 派发时间–或者叫—填报时间
  857. distributeType: this.superviseForm.distribute, //派发周期类型 派发周期类型 0.月 1.季度 2.半年 3.年
  858. superviseFlag: 1, //督办标识 0.不是 1.是
  859. templateType: this.templateType, //模板类型
  860. templateContent: JSON.stringify(data), //文件内容
  861. templateName: workbook_name, //模板名称
  862. templateUrl: "", //文件链接
  863. status: type,
  864. };
  865. } else {
  866. value = {
  867. superviseFlag: 0, //督办标识 0.不是 1.是
  868. templateType: this.templateType, //模板类型
  869. templateContent: JSON.stringify(data), //文件内容
  870. templateName: workbook_name, //模板名称
  871. templateUrl: "", //文件链接
  872. status: type,
  873. };
  874. }
  875. const {
  876. data: { body },
  877. } = await this.$http({
  878. url: "/market/CMKFileTemplate/CMKFileTemplateAdd", // 新增
  879. method: "post",
  880. headers: {
  881. "Content-Type": "application/json",
  882. },
  883. data: value,
  884. });
  885. await this.handleAddAuth({ id: body });
  886. this.$emit("save");
  887. } else {
  888. // 职位
  889. let duty = JSON.parse(sessionStorage.userInfo).duty;
  890. if (duty === "7" && type === "0") {
  891. this.manager_approve = true;
  892. } else {
  893. if (type === "2") {
  894. // 暂存
  895. let value = {};
  896. if (!this.templateType) {
  897. this.$message.error("请输入模板类型");
  898. return;
  899. }
  900. if (
  901. Object.values(this.superviseForm).filter((el) => el !== "")
  902. .length === 3
  903. ) {
  904. value = {
  905. templateId: this.id,
  906. distributeEndTime: this.superviseForm.endTime, // 督办设置的截止时间
  907. distributeTime: this.superviseForm.write, // 派发时间–或者叫—填报时间
  908. distributeType: this.superviseForm.distribute, //派发周期类型 派发周期类型 0.月 1.季度 2.半年 3.年
  909. superviseFlag: 1, //督办标识 0.不是 1.是
  910. templateType: this.templateType, //模板类型
  911. templateContent: JSON.stringify(data), //文件内容
  912. templateName: workbook_name, //模板名称
  913. templateUrl: "", //文件链接
  914. status: type,
  915. };
  916. } else {
  917. value = {
  918. templateId: this.id,
  919. superviseFlag: 0, //督办标识 0.不是 1.是
  920. templateType: this.templateType, //模板类型
  921. templateContent: JSON.stringify(data), //文件内容
  922. templateName: workbook_name, //模板名称
  923. templateUrl: "", //文件链接
  924. status: type,
  925. };
  926. }
  927. await this.$http({
  928. url: "/market/CMKFileTemplate/UptateCMKFileTemplateById", //
  929. method: "post",
  930. headers: {
  931. "Content-Type": "application/json",
  932. },
  933. data: value,
  934. });
  935. this.$emit("save");
  936. return;
  937. }
  938. // 员工提交
  939. this.rowList.shift();
  940. let reqdata = {
  941. rowIndex: [...new Set(this.rowList)]
  942. .sort(function (a, b) {
  943. return a - b;
  944. })
  945. .join(","),
  946. rowContent: [...new Set(this.rowList)]
  947. .sort(function (a, b) {
  948. return a - b;
  949. })
  950. .map((el) => {
  951. return data.data[el];
  952. }),
  953. };
  954. await this.$http({
  955. url: edit_url, //提交
  956. method: "post",
  957. headers: {
  958. "Content-Type": "application/json",
  959. },
  960. data: {
  961. id: this.template_id,
  962. templateContent: JSON.stringify(data),
  963. templateName: workbook_name,
  964. issuedId: this.issued_id,
  965. rowJson: JSON.stringify(reqdata),
  966. },
  967. });
  968. this.$emit("save");
  969. }
  970. }
  971. },
  972. // 判断数组是否有值
  973. confirmArrayData(data) {
  974. if (data instanceof Array) {
  975. let flag = 0;
  976. if (data.length) {
  977. data.forEach((el) => {
  978. if (el instanceof Object) {
  979. flag = flag + 1;
  980. }
  981. });
  982. if (flag) {
  983. return true;
  984. } else {
  985. return false;
  986. }
  987. } else {
  988. return false;
  989. }
  990. } else {
  991. return false;
  992. }
  993. },
  994. async handleAuth() {
  995. this.$refs["form"].validate((valid) => {
  996. if (valid) {
  997. if (this.handleForbid()) {
  998. this.$message.error("请完善可编辑信息");
  999. return false;
  1000. }
  1001. if (this.id) {
  1002. this.handleAddAuth({ id: this.id });
  1003. }
  1004. this.handleVisible();
  1005. }
  1006. });
  1007. },
  1008. // 通用方法用于转化全局
  1009. paramsArr(start, end) {
  1010. const arr = [];
  1011. console.log(start, end);
  1012. for (let i = Number(start); i <= Number(end); i++) {
  1013. arr.push(i);
  1014. }
  1015. return arr.join(",");
  1016. },
  1017. filterName(id, arr) {
  1018. return arr.filter((el) => el.secLeaderLogin === id)[0].secLeaderName;
  1019. },
  1020. handleCharge(type) {
  1021. switch (type) {
  1022. case "add":
  1023. this.form.charge.push({
  1024. person: "",
  1025. });
  1026. this.handleForbid();
  1027. break;
  1028. case "delete":
  1029. this.form.charge.pop();
  1030. this.handleForbid();
  1031. break;
  1032. }
  1033. },
  1034. handleVisible() {
  1035. this.visible = !this.visible;
  1036. },
  1037. handleInput(index, name, value) {
  1038. let reg = /^[0-9]*$/;
  1039. if (!reg.test(value)) {
  1040. this.form.charge[index][name] = this.form.charge[index][name].substr(
  1041. 0,
  1042. this.form.charge[index][name].length - 1
  1043. );
  1044. this.$message.error("该处只能填写数字");
  1045. }
  1046. },
  1047. async handleApprove(type) {
  1048. if (type) {
  1049. if (this.approveForm.type) {
  1050. if (this.approveForm.type === "3" && !this.approveForm.comments) {
  1051. this.$message.error("请输入其他审批意见");
  1052. return;
  1053. }
  1054. } else {
  1055. this.$message.error("请选择审批意见");
  1056. return;
  1057. }
  1058. const sheet_name = window.luckysheet.getSheet().name;
  1059. const data = window.luckysheet.getSheet(sheet_name);
  1060. const workbook_name = window.luckysheet.getWorkbookName();
  1061. // 经理提交
  1062. this.rowList.shift();
  1063. let reqdata = {
  1064. rowIndex: [...new Set(this.rowList)]
  1065. .sort(function (a, b) {
  1066. return a - b;
  1067. })
  1068. .join(","),
  1069. rowContent: [...new Set(this.rowList)]
  1070. .sort(function (a, b) {
  1071. return a - b;
  1072. })
  1073. .map((el) => {
  1074. return data.data[el];
  1075. }),
  1076. };
  1077. await this.$http({
  1078. url: "/market/CMKIssued/CMKIssuedSubmit", // 提交
  1079. method: "post",
  1080. headers: {
  1081. "Content-Type": "application/json",
  1082. },
  1083. data: {
  1084. id: this.template_id,
  1085. templateContent: JSON.stringify(data),
  1086. templateName: workbook_name,
  1087. issuedId: this.issued_id,
  1088. rowJson: JSON.stringify(reqdata),
  1089. },
  1090. });
  1091. let params = {
  1092. id: this.issued_id,
  1093. reviewOpinion:
  1094. this.approveForm.type === "3"
  1095. ? this.approveForm.comments
  1096. : this.approveForm.type,
  1097. };
  1098. switch (type) {
  1099. case "1":
  1100. params = {
  1101. ...params,
  1102. operateName: "结束",
  1103. status: 3,
  1104. };
  1105. break;
  1106. case "4":
  1107. params = {
  1108. ...params,
  1109. operateName: "转副总审批",
  1110. reviewType: 2,
  1111. };
  1112. break;
  1113. case "3":
  1114. params = {
  1115. ...params,
  1116. operateName: "转总经理审批",
  1117. reviewType: 3,
  1118. };
  1119. break;
  1120. }
  1121. await this.$http({
  1122. url: "/market/CMKIssued/CMKIssuedCheck", // 审批
  1123. method: "post",
  1124. headers: {
  1125. "Content-Type": "application/json",
  1126. },
  1127. data: params,
  1128. });
  1129. this.$message({
  1130. type: "success",
  1131. message: "审批成功",
  1132. });
  1133. this.manager_approve = false;
  1134. this.$emit("save");
  1135. } else {
  1136. this.manager_approve = false;
  1137. }
  1138. },
  1139. handleFullscreen() {
  1140. const element = document.body;
  1141. const is_fullscreen =
  1142. document.fullScreen ||
  1143. document.mozFullScreen ||
  1144. document.webkitIsFullScreen;
  1145. if (!is_fullscreen) {
  1146. //进入全屏,多重短路表达式
  1147. (element.requestFullscreen && element.requestFullscreen()) ||
  1148. (element.mozRequestFullScreen && element.mozRequestFullScreen()) ||
  1149. (element.webkitRequestFullscreen &&
  1150. element.webkitRequestFullscreen()) ||
  1151. (element.msRequestFullscreen && element.msRequestFullscreen());
  1152. } else {
  1153. //退出全屏,三目运算符
  1154. document.exitFullscreen
  1155. ? document.exitFullscreen()
  1156. : document.mozCancelFullScreen
  1157. ? document.mozCancelFullScreen()
  1158. : document.webkitExitFullscreen
  1159. ? document.webkitExitFullscreen()
  1160. : "";
  1161. }
  1162. },
  1163. handleResave() {
  1164. const sheet_name = window.luckysheet.getSheet().name;
  1165. const data = window.luckysheet.getSheet(sheet_name);
  1166. const workbook_name = window.luckysheet.getWorkbookName();
  1167. let value = {};
  1168. if (!this.templateType) {
  1169. this.$message.error("请输入模板类型");
  1170. return;
  1171. }
  1172. if (
  1173. Object.values(this.superviseForm).filter((el) => el !== "").length === 3
  1174. ) {
  1175. value = {
  1176. templateId: this.id,
  1177. distributeEndTime: this.superviseForm.endTime, // 督办设置的截止时间
  1178. distributeTime: this.superviseForm.write, // 派发时间–或者叫—填报时间
  1179. distributeType: this.superviseForm.distribute, //派发周期类型 派发周期类型 0.月 1.季度 2.半年 3.年
  1180. superviseFlag: 1, //督办标识 0.不是 1.是
  1181. templateType: this.templateType, //模板类型
  1182. templateContent: JSON.stringify(data), //文件内容
  1183. templateName: workbook_name, //模板名称
  1184. templateUrl: "", //文件链接
  1185. status: "0",
  1186. };
  1187. } else {
  1188. value = {
  1189. templateId: this.id,
  1190. superviseFlag: 0, //督办标识 0.不是 1.是
  1191. templateType: this.templateType, //模板类型
  1192. templateContent: JSON.stringify(data), //文件内容
  1193. templateName: workbook_name, //模板名称
  1194. templateUrl: "", //文件链接
  1195. status: "0",
  1196. };
  1197. }
  1198. this.$http({
  1199. url: "/market/CMKFileTemplate/UptateCMKFileTemplateById",
  1200. method: "post",
  1201. headers: {
  1202. "Content-Type": "application/json",
  1203. },
  1204. data: value,
  1205. }).then(() => {
  1206. this.$message({
  1207. type: "success",
  1208. message: "保存成功",
  1209. });
  1210. this.$emit("save");
  1211. });
  1212. },
  1213. handleChargeList() {
  1214. this.$http({
  1215. url: "/market/techcentergj/queryLeaderList",
  1216. method: "post",
  1217. headers: {
  1218. "Content-Type": "application/json",
  1219. },
  1220. data: {},
  1221. }).then((response) => {
  1222. this.charge_list = response.data.map((element) => ({
  1223. label: `${element.ou} ${element.secLeaderName}`,
  1224. value: `${element.ou}-${element.secLeaderLogin},${element.secLeaderName}`,
  1225. }));
  1226. });
  1227. },
  1228. },
  1229. mounted() {
  1230. console.log(this.attribute, "attribute");
  1231. console.log(this.type, "type");
  1232. this.handleInit();
  1233. this.handleChargeList();
  1234. },
  1235. destroyed() {
  1236. window.luckysheet.destroy();
  1237. },
  1238. };
  1239. </script>
  1240. <style lang="scss" scope>
  1241. .sheet-container {
  1242. position: fixed;
  1243. width: calc(100% - 40px);
  1244. height: 100%;
  1245. &-block {
  1246. overflow: hidden;
  1247. position: absolute;
  1248. width: 100%;
  1249. height: 75%;
  1250. }
  1251. &-require {
  1252. color: red;
  1253. }
  1254. .el-input {
  1255. width: 200px;
  1256. margin-right: 10px;
  1257. }
  1258. }
  1259. .form {
  1260. &-input {
  1261. margin-top: 5px;
  1262. .el-input {
  1263. width: 150px;
  1264. .el-input__inner {
  1265. height: 30px !important;
  1266. line-height: 30px !important;
  1267. }
  1268. }
  1269. }
  1270. &-content {
  1271. margin: 0px 10px;
  1272. }
  1273. &-select {
  1274. .el-input {
  1275. width: 100px;
  1276. .el-input__inner {
  1277. height: 30px !important;
  1278. line-height: 30px !important;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. </style>