detail.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <view class="page-detail">
  3. <view class="page-center">
  4. <uni-section title="清单名称" type="line"></uni-section>
  5. <text style="padding-left: 20rpx">{{ version.version_name }}</text>
  6. <!-- 表单数据 -->
  7. <template v-if="formList.length > 0">
  8. <uni-section title="表单数据" type="line"></uni-section>
  9. <uni-forms class="form" label-align="right" :labelWidth="100">
  10. <uni-forms-item
  11. v-for="item in formList"
  12. :label="item.name"
  13. name="email"
  14. >
  15. <view class="content">{{ item.value.join(",") }}</view>
  16. </uni-forms-item>
  17. </uni-forms>
  18. </template>
  19. <!-- 附件信息 -->
  20. <template v-if="excelFileList.length > 0">
  21. <uni-section title="附件信息" type="line"></uni-section>
  22. <view class="attachment" v-for="item in excelFileList" :key="item.id">
  23. <!-- {{item.name}} -->
  24. <previewFile :src="item.url" :name="item.name" />
  25. </view>
  26. </template>
  27. <!-- 审批信息 -->
  28. <uni-section title="审批信息" type="line"></uni-section>
  29. <uni-steps
  30. :options="flow.list.FlowNodes"
  31. :active="flow.current"
  32. direction="column"
  33. ></uni-steps>
  34. <!-- 清单详情 -->
  35. <uni-section title="清单详情" type="line"></uni-section>
  36. <view class="excel-detail" @click="toExcelDetail">查看详情</view>
  37. <!-- 审批按钮 -->
  38. <view class="btns" v-if="isAuditor">
  39. <button type="primary" @click="showAuditModal">通过</button>
  40. <button type="warn" @click="showRejectModal">拒绝</button>
  41. </view>
  42. </view>
  43. <!-- 审核通过弹窗 -->
  44. <uni-popup ref="popup" type="dialog">
  45. <uni-popup-dialog
  46. type="info"
  47. mode="base"
  48. title="审批"
  49. content="是否通过审批"
  50. :duration="2000"
  51. :before-close="true"
  52. @close="auditClose"
  53. @confirm="auditConfirm"
  54. ></uni-popup-dialog>
  55. </uni-popup>
  56. <!-- 审批拒绝弹窗 -->
  57. <uni-popup ref="rejectPopup" type="dialog">
  58. <uni-popup-dialog
  59. mode="input"
  60. placeholder="请输入拒绝原因"
  61. :duration="2000"
  62. :before-close="true"
  63. @close="rejectClose"
  64. @confirm="rejectConfirm"
  65. ></uni-popup-dialog>
  66. </uni-popup>
  67. </view>
  68. </template>
  69. <script>
  70. import {
  71. queryAttachment,
  72. queryAuditList,
  73. approve,
  74. queryCheckedVersionDetail,
  75. } from "@/services/bom.js";
  76. import { gerCurrentUser } from "@/services/user.js";
  77. import previewFile from "@/components/preview-file/preview-file.vue";
  78. export default {
  79. components: {
  80. previewFile,
  81. },
  82. computed: {
  83. formList() {
  84. if (!this.version.formStr && !this.version.ding_schema) {
  85. return [];
  86. }
  87. if (this.version.formStr) {
  88. try {
  89. const formStrArray = JSON.parse(this.version.formStr);
  90. const formComponents = [];
  91. if (formStrArray && formStrArray.length) {
  92. formStrArray.forEach((item) => {
  93. formComponents.push(JSON.parse(item));
  94. });
  95. }
  96. const formComponent = formComponents.filter(
  97. (item) => item.template_node_id === this.version.template_node_id
  98. );
  99. console.log(formComponent);
  100. return formComponent[0].formComponentValues || [];
  101. } catch (e) {
  102. return [];
  103. }
  104. }
  105. if (this.version.ding_schema) {
  106. try {
  107. const formStrArray = JSON.parse(this.version.ding_schema);
  108. const formComponents = [];
  109. if (formStrArray && formStrArray.length) {
  110. formStrArray.forEach((item) => {
  111. formComponents.push(JSON.parse(item));
  112. });
  113. }
  114. const formComponent = formComponents.filter(
  115. (item) => item.template_node_id === this.version.template_node_id
  116. );
  117. return (
  118. formComponent[0].formComponentValues.filter(
  119. (item) => !item.id.includes("DIYTable")
  120. ) || []
  121. );
  122. } catch (e) {
  123. return [];
  124. }
  125. }
  126. },
  127. },
  128. data() {
  129. return {
  130. projectId: 580,
  131. templateNodeId: 0,
  132. id: 0,
  133. version: {},
  134. excelFileList: [],
  135. auditMessage: "",
  136. flow: {
  137. active: 0,
  138. active_id: null,
  139. current: 0,
  140. currentNode: {},
  141. list: {
  142. FlowNodes: [],
  143. },
  144. },
  145. isAuditor: false,
  146. isMobile: true,
  147. options: {},
  148. };
  149. },
  150. onLoad(options) {
  151. this.templateNodeId = options.templateNodeId;
  152. this.projectId = Number(options.projectId);
  153. this.id = options.excel_id;
  154. // 如果链接带着token, 则强制替换最新的token
  155. if (options["JWT-TOKEN"]) {
  156. uni.setStorageSync("token", options["JWT-TOKEN"]);
  157. }
  158. this.options = options;
  159. this.checkDeviceType();
  160. this.init();
  161. },
  162. methods: {
  163. checkDeviceType() {
  164. const userAgent = navigator.userAgent.toLowerCase();
  165. const mobileKeywords = ["android", "iphone", "ipad", "ipod", "mobile"];
  166. this.isMobile = mobileKeywords.some((keyword) =>
  167. userAgent.includes(keyword)
  168. );
  169. return this.isMobile;
  170. },
  171. async init() {
  172. var currentUser = await gerCurrentUser();
  173. if (!currentUser) {
  174. return;
  175. }
  176. uni.setStorageSync("user", currentUser);
  177. var version = await queryCheckedVersionDetail(this.id);
  178. if (!this.isMobile) {
  179. // 如果是在电脑上打开,转到PC端的页面去
  180. window.location.href = `http://120.55.44.4:8896/#/bom/home/detail/${version.project_id}/${version.template_id}?excel_id=${this.id}&JWT-TOKEN=${this.options["JWT-TOKEN"]}`;
  181. }
  182. if (version.flow_id) {
  183. this.getFlow(version);
  184. }
  185. this.version = version;
  186. if (version.attachment_id) {
  187. var {
  188. data: { list: excelFileList },
  189. } = await queryAttachment({
  190. excel_id: version.attachment_id,
  191. });
  192. this.excelFileList = excelFileList.map((item) => {
  193. const list = item.url.split("/");
  194. const name = list[list.length - 1];
  195. return {
  196. ...item,
  197. name,
  198. };
  199. });
  200. // console.log(this.excelFileList)
  201. }
  202. },
  203. // 显示通过审批弹窗
  204. async showAuditModal() {
  205. this.$refs.popup.open();
  206. },
  207. // 通过审批
  208. async auditConfirm() {
  209. let flow = this.flow;
  210. let flowNode = flow.currentNode;
  211. var { data: newVersion } = await approve({
  212. id: flow.active_id,
  213. project_id: this.projectId,
  214. audit_status: 3,
  215. flow_id: flowNode.flow_id,
  216. node_id: flowNode.seq,
  217. });
  218. this.version = {
  219. ...this.version,
  220. id: newVersion.id,
  221. };
  222. this.getFlow(this.version);
  223. uni.showToast({
  224. title: "操作成功",
  225. });
  226. this.$refs.popup.close();
  227. },
  228. // 显示拒绝审批弹窗
  229. showRejectModal() {
  230. this.$refs.rejectPopup.open();
  231. },
  232. auditClose() {
  233. this.$refs.popup.close();
  234. },
  235. rejectClose() {
  236. this.$refs.rejectPopup.close();
  237. },
  238. async rejectConfirm(audit_comment) {
  239. const flow = this.flow;
  240. const flowNode = flow.currentNode;
  241. var { data: newVersion } = await approve({
  242. id: flow.active_id,
  243. project_id: this.projectId,
  244. audit_status: 2,
  245. flow_id: flowNode.flow_id,
  246. node_id: flowNode.seq,
  247. audit_comment,
  248. });
  249. uni.showToast({
  250. title: "操作成功",
  251. });
  252. this.version = {
  253. ...this.version,
  254. id: newVersion.id,
  255. };
  256. this.getFlow(this.version);
  257. this.rejectClose();
  258. },
  259. // 查询审批信息
  260. async getFlow(version) {
  261. const { data: auditList } = await queryAuditList({
  262. template_id: version.template_id,
  263. template_node_id: version.template_node_id,
  264. flow_id: version.flow_id,
  265. version_id: version.version_id,
  266. audit_series: version.audit_series,
  267. });
  268. if (auditList.length > 0) {
  269. let item = auditList.find((item) => item.list.id == version.flow_id);
  270. if (!item) return;
  271. // 查询当前节点
  272. let current = item.list.FlowNodes.findIndex(
  273. (node) => node.seq == item.active
  274. );
  275. item.current = current == -1 ? 0 : current;
  276. // 保存当前所处节点
  277. item.currentNode = item.list.FlowNodes[item.current];
  278. item.list.FlowNodes.forEach((item) => {
  279. item.title = item.node;
  280. item.desc = item.AuditRoleInfo
  281. ? `审批人:${item?.AuditRoleInfo.Name || "-"}`
  282. : `审批人:${item?.AuditorUser.CName || "-"}`;
  283. });
  284. this.flow = item;
  285. // 判断是否含有审批权限
  286. this.isAuditor = false;
  287. if (item.active_audit == 1) {
  288. let user = uni.getStorageSync("user");
  289. if (item.currentNode && item.currentNode.auditor == user.ID) {
  290. this.isAuditor = true;
  291. }
  292. }
  293. }
  294. },
  295. toExcelDetail() {
  296. uni.navigateTo({
  297. url: `./excelDetail?templateNodeId=${this.templateNodeId}&versionId=${this.version.version_id}`,
  298. });
  299. },
  300. },
  301. };
  302. </script>
  303. <style lang="less" scoped>
  304. .page-detail {
  305. min-height: 100vh;
  306. padding: 20rpx 30rpx 40rpx;
  307. background: url("~@/static/index/bg.png") no-repeat center;
  308. background-size: cover;
  309. background-attachment: fixed;
  310. .page-center {
  311. padding: 30rpx;
  312. padding-top: 0;
  313. background-color: #fff;
  314. }
  315. }
  316. .btns {
  317. display: flex;
  318. margin-top: 40rpx;
  319. }
  320. .excel-detail {
  321. color: #2f42ca;
  322. text-decoration: underline;
  323. padding-left: 20rpx;
  324. }
  325. .form {
  326. width: 90%;
  327. margin: 0;
  328. box-shadow: 0 0 1 3 rgba(0, 0, 0, 0.1);
  329. .content {
  330. line-height: 44rpx;
  331. padding: 14rpx;
  332. word-break: break-all;
  333. }
  334. }
  335. .attachment {
  336. padding-left: 20rpx;
  337. margin-bottom: 20rpx;
  338. }
  339. </style>