index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <script>
  2. import {dicts} from "./dicts";
  3. import useColumns from "./columns";
  4. import {LIST, mbDownload, failDownload,oaBack} from "@/api/business/purchase/apply";
  5. // 导入的token
  6. import {getToken} from "@/utils/auth";
  7. export default {
  8. name: "PuchaseApply",
  9. dicts: dicts,
  10. components: {
  11. SeeButton: () => import("./see/index.vue"),
  12. AddButton: () => import("./add/index.vue"),
  13. CopyButton: () => import("./copy/index.vue"),
  14. EditButton: () => import("./edit/index.vue"),
  15. DeleButton: () => import("./delete/index.vue"),
  16. SubmButton: () => import("./submit/index.vue"),
  17. ElSuperTable: () => import("@/components/super-table/index.vue"),
  18. ElSuperSearch: () => import("@/components/super-search/index.vue"),
  19. },
  20. data() {
  21. const {TableColumns, SearchColumns} = useColumns();
  22. const page = this.$init.page();
  23. const params = this.$init.params(SearchColumns);
  24. return {
  25. // 导入参数
  26. upload: {
  27. // 是否显示弹出层(导入)
  28. open: false,
  29. // 弹出层标题(导入)
  30. title: "数据导入",
  31. // 是否禁用上传
  32. isUploading: false,
  33. // 是否更新已经存在的用户数据
  34. updateSupport: 1,
  35. // 设置上传的请求头部
  36. headers: {Authorization: "Bearer " + getToken()},
  37. // 上传的地址
  38. url: process.env.VUE_APP_BASE_API + "/pu/priceApply/import"
  39. },
  40. size: "mini",
  41. loading: false,
  42. params: params,
  43. page: page,
  44. tableData: [],
  45. selectData: [],
  46. SearchColumns: SearchColumns,
  47. TableColumns: TableColumns,
  48. };
  49. },
  50. computed: {},
  51. created() {
  52. this.params.priceCode = this.$route.query.billCode
  53. this.useQuery(this.params, this.page);
  54. },
  55. methods: {
  56. //
  57. async fetchList(prop, page) {
  58. try {
  59. this.loading = true;
  60. const {pageNum, pageSize} = page;
  61. const {code, rows, total} = await LIST(
  62. {...prop},
  63. {pageNum, pageSize}
  64. );
  65. if (code === 200) {
  66. this.tableData = rows.map((item, index) => ({
  67. ...item,
  68. $index: (pageNum - 1) * pageSize + index + 1,
  69. }));
  70. this.page.total = total;
  71. }
  72. } catch (err) {
  73. // catch
  74. console.error(err);
  75. } finally {
  76. // finally
  77. this.loading = false;
  78. }
  79. },
  80. // 查 询
  81. useQuery(prop, page) {
  82. this.fetchList(prop, page);
  83. },
  84. // 重 置
  85. useReset() {
  86. this.page = this.$init.page();
  87. this.params = this.$init.params(this.SearchColumns);
  88. this.useQuery(this.params, this.page);
  89. },
  90. // 选 择
  91. useSelect(prop) {
  92. this.selectData = prop;
  93. },
  94. // 明 细
  95. async useSee(prop) {
  96. const {open} = this.$refs.SeeButton;
  97. await open([prop]);
  98. },
  99. // 下载模板
  100. downLoadMb() {
  101. this.$modal.loading("正在下载模板,请稍后...");
  102. mbDownload().then(res => {
  103. this.$modal.closeLoading();
  104. const blob = new Blob([res], {
  105. type: "application/vnd.ms-excel;charset=UTF-8",
  106. });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
  107. const downloadElement = document.createElement("a"); //创建a标签
  108. const href = window.URL.createObjectURL(blob); // 创建下载的链接
  109. downloadElement.href = href; //下载地址
  110. downloadElement.download = '价格申报单导入模板' + this.parseTime(new Date().getTime()) + ".xlsx"; // 下载后文件名
  111. document.body.appendChild(downloadElement);
  112. downloadElement.click(); // 点击下载
  113. document.body.removeChild(downloadElement); // 下载完成移除元素
  114. window.URL.revokeObjectURL(href); // 释放blob对象
  115. }).catch(err => {
  116. this.$modal.closeLoading();
  117. })
  118. },
  119. // 文件上传中处理
  120. handleFileUploadProgress(event, file, fileList) {
  121. this.upload.isUploading = true;
  122. this.$modal.loading("正在导入数据,请稍后...");
  123. },
  124. // 文件上传成功处理
  125. handleFileSuccess(response, file, fileList) {
  126. this.$modal.closeLoading();
  127. this.upload.open = false;
  128. this.upload.isUploading = false;
  129. this.$refs.upload.clearFiles();
  130. if (response.code == 200) {
  131. this.$alert(response.data.msg, "导入结果", {dangerouslyUseHTMLString: true});
  132. // 有失败的再次下载下来
  133. if (response.data.flag) {
  134. this.$modal.loading("正在下载导入失败数据,请稍后...");
  135. failDownload({failDatas: response.data.datas}).then(res => {
  136. this.$modal.closeLoading();
  137. const blob = new Blob([res], {
  138. type: "application/vnd.ms-excel;charset=UTF-8",
  139. });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
  140. const downloadElement = document.createElement("a"); //创建a标签
  141. const href = window.URL.createObjectURL(blob); // 创建下载的链接
  142. downloadElement.href = href; //下载地址
  143. downloadElement.download = '价格申报单导入失败数据' + this.parseTime(new Date().getTime()) + ".xlsx"; // 下载后文件名
  144. document.body.appendChild(downloadElement);
  145. downloadElement.click(); // 点击下载
  146. document.body.removeChild(downloadElement); // 下载完成移除元素
  147. window.URL.revokeObjectURL(href); // 释放blob对象
  148. }).catch(err => {
  149. this.$modal.closeLoading();
  150. })
  151. }
  152. }else{
  153. this.$notify({
  154. message: response.msg,
  155. type: response.code == 200 ? 'success' : 'warning'
  156. });
  157. }
  158. this.useQuery(this.params, this.page);
  159. },
  160. errorFile(err) {
  161. this.$modal.closeLoading();
  162. this.$modal.notifyError("文件已变动,请重新上传");
  163. },
  164. // 提交上传文件
  165. submitFileForm() {
  166. this.$refs.upload.submit();
  167. },
  168. // 导入数据
  169. importMb() {
  170. this.upload.title = "文件导入"
  171. this.upload.open = true
  172. },
  173. // 收回
  174. async reback(row) {
  175. try {
  176. const { msg, code } = await oaBack({
  177. fdTemplateId: process.env.NODE_ENV == "production" ?
  178. '18804bd6335dd3a05fd9a12415fb6e70' : '188095a870d007772057d7d4ffaad3c7',
  179. fdId: row.flowId,
  180. billCode: row.priceCode,
  181. billMaker: row.createBy
  182. });
  183. if (code === 200) {
  184. this.$emit("success");
  185. this.$notify.success(msg);
  186. }
  187. } catch (err) {
  188. console.error(err);
  189. } finally {
  190. }
  191. },
  192. },
  193. };
  194. </script>
  195. <template>
  196. <el-card
  197. v-loading="loading"
  198. :body-style="{
  199. height: '100%',
  200. padding: 0,
  201. display: 'flex',
  202. 'flex-direction': 'column',
  203. }"
  204. >
  205. <el-super-search
  206. v-model="params"
  207. :size="size"
  208. :dict="dict"
  209. :columns="SearchColumns"
  210. @reset="useReset"
  211. @submit="useQuery(params, page)"
  212. ></el-super-search>
  213. <el-row class="my-4" style="text-align: right">
  214. <el-button-group>
  215. <add-button
  216. :size="size"
  217. :dict="dict"
  218. @success="useQuery(params, page)"
  219. ></add-button>
  220. <copy-button
  221. :size="size"
  222. :dict="dict"
  223. :select-data="selectData"
  224. @success="useQuery(params, page)"
  225. >
  226. </copy-button>
  227. </el-button-group>
  228. <el-button-group>
  229. <see-button
  230. v-show="false"
  231. :size="size"
  232. :dict="dict"
  233. :model="params"
  234. :select-data="selectData"
  235. ref="SeeButton"
  236. @success="useQuery(params, page)"
  237. ></see-button>
  238. <edit-button
  239. :size="size"
  240. :dict="dict"
  241. :select-data="selectData"
  242. @success="useQuery(params, page)"
  243. ></edit-button>
  244. <dele-button
  245. :size="size"
  246. :select-data="selectData"
  247. @success="useQuery(params, page)"
  248. ></dele-button>
  249. </el-button-group>
  250. <el-button-group>
  251. <subm-button
  252. :size="size"
  253. :select-data="selectData"
  254. @success="useQuery(params, page)"
  255. ></subm-button>
  256. </el-button-group>
  257. <el-button-group>
  258. <el-button size="mini" @click="downLoadMb">模 板</el-button>
  259. <el-button size="mini" @click="importMb">导 入</el-button>
  260. </el-button-group>
  261. </el-row>
  262. <el-super-table
  263. v-model="tableData"
  264. :size="size"
  265. :dict="dict"
  266. :page="page"
  267. :columns="TableColumns"
  268. index
  269. checkbox
  270. pagination
  271. convenitentOperation
  272. storage-key="PuchaseApplySuperTable1"
  273. @row-dblclick="useSee"
  274. @row-select="useSelect"
  275. @pagination="useQuery(params, page)"
  276. >
  277. <el-table-column
  278. fixed="right"
  279. label="操作"
  280. align="center"
  281. width="100"
  282. >
  283. <template slot-scope="scope">
  284. <el-button type="text" size="mini" v-if="scope.row.status == '1' && scope.row.flowId" @click="reback(scope.row)">收回</el-button>
  285. </template>
  286. </el-table-column>
  287. </el-super-table>
  288. <!-- 文件导入对话框 -->
  289. <el-dialog title="文件导入" :visible.sync="upload.open" width="400px">
  290. <el-upload
  291. ref="upload"
  292. :limit="1"
  293. accept=".xlsx, .xls"
  294. :headers="upload.headers"
  295. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  296. :disabled="upload.isUploading"
  297. :on-progress="handleFileUploadProgress"
  298. :on-success="handleFileSuccess"
  299. :on-error="errorFile"
  300. :auto-upload="false"
  301. drag
  302. >
  303. <i class="el-icon-upload"></i>
  304. <div class="el-upload__text">
  305. 将文件拖到此处,或
  306. <em>点击上传</em>
  307. </div>
  308. <!-- <div class="el-upload__tip" slot="tip">
  309. <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
  310. </div> -->
  311. <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  312. </el-upload>
  313. <div slot="footer">
  314. <el-button size="mini" type="primary" @click="submitFileForm">确 定</el-button>
  315. <el-button size="mini" @click="upload.open = false">取 消</el-button>
  316. </div>
  317. </el-dialog>
  318. </el-card>
  319. </template>
  320. <style scoped lang="scss">
  321. .el-card {
  322. width: calc(100% - 32px);
  323. height: calc(100vh - 32px);
  324. margin: 16px;
  325. padding: 16px;
  326. border-radius: 8px;
  327. }
  328. .el-button-group + .el-button-group {
  329. margin: 0 0 0 8px;
  330. }
  331. </style>