detail.vue 9.0 KB

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