detail.vue 8.2 KB

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