detail.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. queryVersionsList,
  72. queryAttachment,
  73. queryAuditList,
  74. approve,
  75. queryVersionDetail,
  76. } from "@/services/bom.js";
  77. import { gerCurrentUser } from "@/services/user.js";
  78. import previewFile from "@/components/preview-file/preview-file.vue";
  79. export default {
  80. components: {
  81. previewFile,
  82. },
  83. data() {
  84. return {
  85. projectId: 580,
  86. templateNodeId: 0,
  87. id: 0,
  88. version: {},
  89. excelFileList: [],
  90. auditMessage: "",
  91. flow: {
  92. active: 0,
  93. active_id: null,
  94. current: 0,
  95. currentNode: {},
  96. list: {
  97. FlowNodes: [],
  98. },
  99. },
  100. isAuditor: false,
  101. isMobile: true,
  102. options: {},
  103. };
  104. },
  105. onLoad(options) {
  106. this.templateNodeId = options.templateNodeId;
  107. this.projectId = Number(options.projectId);
  108. this.id = options.excel_id;
  109. // 如果链接带着token, 则强制替换最新的token
  110. if (options["JWT-TOKEN"]) {
  111. uni.setStorageSync("token", options["JWT-TOKEN"]);
  112. }
  113. this.options = options;
  114. this.checkDeviceType();
  115. this.init();
  116. },
  117. methods: {
  118. checkDeviceType() {
  119. const userAgent = navigator.userAgent.toLowerCase();
  120. const mobileKeywords = ["android", "iphone", "ipad", "ipod", "mobile"];
  121. this.isMobile = mobileKeywords.some((keyword) =>
  122. userAgent.includes(keyword)
  123. );
  124. return this.isMobile;
  125. },
  126. async init() {
  127. var currentUser = await gerCurrentUser();
  128. if (!currentUser) {
  129. return;
  130. }
  131. uni.setStorageSync("user", currentUser);
  132. var version = await queryVersionDetail({
  133. userID: currentUser.ID,
  134. excelID: this.id,
  135. });
  136. if (version === null) {
  137. uni.redirectTo({
  138. url: `/pages/approved/BOM/detail?templateNodeId=${this.templateNodeId}&excel_id=${this.id}&projectId=${this.projectId}`,
  139. });
  140. }
  141. if (!this.isMobile) {
  142. // 如果是在电脑上打开,转到PC端的页面去
  143. 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"]}`;
  144. }
  145. if (version.flow_id) {
  146. this.getFlow(version);
  147. }
  148. this.version = version;
  149. if (version.attachment_id) {
  150. var {
  151. data: { list: excelFileList },
  152. } = await queryAttachment({
  153. excel_id: version.attachment_id,
  154. });
  155. this.excelFileList = excelFileList.map((item) => {
  156. const list = item.url.split("/");
  157. const name = list[list.length - 1];
  158. return {
  159. ...item,
  160. name,
  161. };
  162. });
  163. // console.log(this.excelFileList)
  164. }
  165. },
  166. // 显示通过审批弹窗
  167. async showAuditModal() {
  168. this.$refs.popup.open();
  169. },
  170. // 通过审批
  171. async auditConfirm() {
  172. let flow = this.flow;
  173. let flowNode = flow.currentNode;
  174. var { data: newVersion } = await approve({
  175. id: flow.active_id,
  176. project_id: this.projectId,
  177. audit_status: 3,
  178. flow_id: flowNode.flow_id,
  179. node_id: flowNode.seq,
  180. });
  181. this.version = {
  182. ...this.version,
  183. id: newVersion.id,
  184. };
  185. this.getFlow(this.version);
  186. uni.showToast({
  187. title: "操作成功",
  188. });
  189. this.$refs.popup.close();
  190. },
  191. // 显示拒绝审批弹窗
  192. showRejectModal() {
  193. this.$refs.rejectPopup.open();
  194. },
  195. auditClose() {
  196. this.$refs.popup.close();
  197. },
  198. rejectClose() {
  199. this.$refs.rejectPopup.close();
  200. },
  201. async rejectConfirm(audit_comment) {
  202. const flow = this.flow;
  203. const flowNode = flow.currentNode;
  204. var { data: newVersion } = await approve({
  205. id: flow.active_id,
  206. project_id: this.projectId,
  207. audit_status: 2,
  208. flow_id: flowNode.flow_id,
  209. node_id: flowNode.seq,
  210. audit_comment,
  211. });
  212. uni.showToast({
  213. title: "操作成功",
  214. });
  215. this.version = {
  216. ...this.version,
  217. id: newVersion.id,
  218. };
  219. this.getFlow(this.version);
  220. this.rejectClose();
  221. },
  222. // 查询审批信息
  223. async getFlow(version) {
  224. const { data: auditList } = await queryAuditList({
  225. template_id: version.template_id,
  226. template_node_id: version.template_node_id,
  227. flow_id: version.flow_id,
  228. version_id: version.version_id,
  229. audit_series: version.audit_series,
  230. });
  231. if (auditList.length > 0) {
  232. let item = auditList.find((item) => item.list.id == version.flow_id);
  233. if (!item) return;
  234. // 查询当前节点
  235. let current = item.list.FlowNodes.findIndex(
  236. (node) => node.seq == item.active
  237. );
  238. item.current = current == -1 ? 0 : current;
  239. // 保存当前所处节点
  240. item.currentNode = item.list.FlowNodes[item.current];
  241. item.list.FlowNodes.forEach((item) => {
  242. item.title = item.node;
  243. item.desc = item.AuditRoleInfo
  244. ? `审批人:${item?.AuditRoleInfo.Name || "-"}`
  245. : `审批人:${item?.AuditorUser.CName || "-"}`;
  246. });
  247. this.flow = item;
  248. // 判断是否含有审批权限
  249. this.isAuditor = false;
  250. if (item.active_audit == 1) {
  251. let user = uni.getStorageSync("user");
  252. if (item.currentNode && item.currentNode.auditor == user.ID) {
  253. this.isAuditor = true;
  254. }
  255. }
  256. }
  257. },
  258. toExcelDetail() {
  259. uni.navigateTo({
  260. url: `./excelDetail?templateNodeId=${this.templateNodeId}&versionId=${this.version.version_id}`,
  261. });
  262. },
  263. },
  264. computed: {
  265. formList() {
  266. if (!this.version.formStr) {
  267. return [];
  268. }
  269. try {
  270. const formStrArray = JSON.parse(this.version.formStr);
  271. const formComponents = [];
  272. if (formStrArray && formStrArray.length) {
  273. formStrArray.forEach((item) => {
  274. formComponents.push(JSON.parse(item));
  275. });
  276. }
  277. const formComponent = formComponents.filter(
  278. (item) => item.template_node_id === this.version.template_node_id
  279. );
  280. console.log(formComponent);
  281. return (
  282. formComponent[0].formComponentValues.filter(
  283. (item) => !item.id.includes("DIYTable")
  284. ) || []
  285. );
  286. } catch (e) {
  287. return [];
  288. }
  289. },
  290. },
  291. };
  292. </script>
  293. <style lang="less" scoped>
  294. .page-detail {
  295. min-height: 100vh;
  296. padding: 20rpx 30rpx 40rpx;
  297. background: url("~@/static/index/bg.png") no-repeat center;
  298. background-size: cover;
  299. background-attachment: fixed;
  300. .page-center {
  301. padding: 30rpx;
  302. padding-top: 0;
  303. background-color: #fff;
  304. }
  305. }
  306. .btns {
  307. display: flex;
  308. margin-top: 40rpx;
  309. }
  310. .excel-detail {
  311. color: #2f42ca;
  312. text-decoration: underline;
  313. padding-left: 20rpx;
  314. }
  315. .form {
  316. width: 90%;
  317. margin: 0;
  318. box-shadow: 0 0 1 3 rgba(0, 0, 0, 0.1);
  319. .content {
  320. line-height: 44rpx;
  321. padding: 14rpx;
  322. word-break: break-all;
  323. }
  324. }
  325. .attachment {
  326. padding-left: 20rpx;
  327. margin-bottom: 20rpx;
  328. }
  329. </style>