index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
  4. <el-form-item label="国产型号" prop="componentModel">
  5. <el-select v-model="queryParams.id" filterable placeholder="请输入元器件编号">
  6. <el-option
  7. v-for="item in componentInfo"
  8. :value="item.componentModel">
  9. </el-option>
  10. </el-select>
  11. </el-form-item>
  12. <el-form-item label="应用设备" prop="usedBy">
  13. <el-input
  14. v-model="queryParams.usedBy"
  15. placeholder="请输入应用设备"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="使用日期" prop="usedDate">
  21. <el-date-picker clearable
  22. v-model="queryParams.usedDate"
  23. type="date"
  24. value-format="yyyy-MM-dd"
  25. placeholder="请选择使用日期">
  26. </el-date-picker>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" style="margin-right: 20px">搜索</el-button>
  30. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  31. </el-form-item>
  32. </el-form>
  33. <el-row :gutter="10" class="mb8">
  34. <el-col :span="1.5">
  35. <el-button
  36. type="primary"
  37. plain
  38. icon="el-icon-plus"
  39. size="mini"
  40. @click="handleAdd"
  41. v-hasPermi="['biz:record:add']"
  42. >新增</el-button>
  43. </el-col>
  44. <!-- <el-col :span="1.5">-->
  45. <!-- <el-button-->
  46. <!-- type="success"-->
  47. <!-- plain-->
  48. <!-- icon="el-icon-edit"-->
  49. <!-- size="mini"-->
  50. <!-- :disabled="single"-->
  51. <!-- @click="handleUpdate"-->
  52. <!-- v-hasPermi="['biz:record:edit']"-->
  53. <!-- >修改</el-button>-->
  54. <!-- </el-col>-->
  55. <el-col :span="1.5">
  56. <el-button
  57. type="danger"
  58. plain
  59. icon="el-icon-delete"
  60. size="mini"
  61. :disabled="multiple"
  62. @click="handleDelete"
  63. v-hasPermi="['biz:record:remove']"
  64. >删除</el-button>
  65. </el-col>
  66. <el-col :span="1.5">
  67. <el-button
  68. type="info"
  69. icon="el-icon-upload2"
  70. size="mini"
  71. @click="handleImport"
  72. v-hasPermi="['biz:record:import']"
  73. >导入</el-button>
  74. </el-col>
  75. <el-col :span="1.5">
  76. <el-button
  77. type="warning"
  78. plain
  79. icon="el-icon-download"
  80. size="mini"
  81. @click="handleExport"
  82. v-hasPermi="['biz:record:export']"
  83. >导出</el-button>
  84. </el-col>
  85. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  86. </el-row>
  87. <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange" >
  88. <el-table-column type="selection" width="55" align="center" />
  89. <!-- <el-table-column label="编号" align="center" prop="id" />-->
  90. <el-table-column label="国产型号" align="center" prop="componentModel" />
  91. <el-table-column label="应用设备" align="center" prop="usedBy" :show-overflow-tooltip='true' />
  92. <el-table-column label="使用日期" align="center" prop="usedDate" width="180">
  93. <template slot-scope="scope">
  94. <span>{{ parseTime(scope.row.usedDate, '{y}-{m}-{d}') }}</span>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  98. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
  99. <template slot-scope="scope">
  100. <el-button
  101. size="mini"
  102. type="text"
  103. icon="el-icon-edit"
  104. @click="handleUpdate(scope.row)"
  105. v-hasPermi="['biz:record:edit']"
  106. >修改</el-button>
  107. <el-button
  108. size="mini"
  109. type="text"
  110. icon="el-icon-delete"
  111. @click="handleDelete(scope.row)"
  112. v-hasPermi="['biz:record:remove']"
  113. >删除</el-button>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <pagination
  118. v-show="total>0"
  119. :total="total"
  120. :page.sync="queryParams.pageNum"
  121. :limit.sync="queryParams.pageSize"
  122. @pagination="getList"
  123. />
  124. <!-- 元器件记录详情导入对话框 -->
  125. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
  126. <el-upload
  127. ref="upload"
  128. :limit="1"
  129. accept=".xlsx, .xls"
  130. :headers="upload.headers"
  131. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  132. :disabled="upload.isUploading"
  133. :on-progress="handleFileUploadProgress"
  134. :on-success="handleFileSuccess"
  135. :auto-upload="false"
  136. drag
  137. >
  138. <i class="el-icon-upload"></i>
  139. <div class="el-upload__text">
  140. 将文件拖到此处,或
  141. <em>点击上传</em>
  142. </div>
  143. <div class="el-upload__tip" slot="tip">
  144. <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的数据
  145. <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
  146. </div>
  147. <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  148. </el-upload>
  149. <div slot="footer" class="dialog-footer">
  150. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  151. <el-button @click="upload.open = false">取 消</el-button>
  152. </div>
  153. </el-dialog>
  154. <!-- 添加或修改元器件使用经历对话框 -->
  155. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  156. <el-form style="border:1px solid #C0C0C0;padding: 5px;margin: auto" ref="form" :model="form" :rules="rules" label-width="120px">
  157. <el-form-item label="国产型号" prop="componentModel">
  158. <el-select v-model="queryParams.id" filterable placeholder="请输入元器件编号">
  159. <el-option
  160. v-for="item in componentInfo"
  161. :value="item.componentModel">
  162. </el-option>
  163. </el-select>
  164. </el-form-item>
  165. <el-form-item label="应用设备" prop="usedBy">
  166. <el-input v-model="form.usedBy" placeholder="请输入应用设备" />
  167. </el-form-item>
  168. <el-form-item label="使用日期" prop="usedDate">
  169. <el-date-picker clearable
  170. v-model="form.usedDate"
  171. type="date"
  172. value-format="yyyy-MM-dd"
  173. placeholder="请选择使用日期">
  174. </el-date-picker>
  175. </el-form-item>
  176. <el-form-item label="备注" prop="remark">
  177. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  178. </el-form-item>
  179. </el-form>
  180. <div slot="footer" class="dialog-footer">
  181. <el-button type="primary" @click="submitForm">确 定</el-button>
  182. <el-button @click="cancel">取 消</el-button>
  183. </div>
  184. </el-dialog>
  185. </div>
  186. </template>
  187. <script>
  188. import { listRecord, getRecord, delRecord, addRecord, updateRecord,getall } from "@/api/biz/record";
  189. import { getToken } from "@/utils/auth";
  190. export default {
  191. name: "Record",
  192. data() {
  193. return {
  194. componentInfo:null,
  195. // 遮罩层
  196. loading: true,
  197. // 选中数组
  198. ids: [],
  199. // 非单个禁用
  200. single: true,
  201. // 非多个禁用
  202. multiple: true,
  203. // 显示搜索条件
  204. showSearch: true,
  205. // 总条数
  206. total: 0,
  207. // 元器件使用经历表格数据
  208. recordList: [],
  209. // 弹出层标题
  210. title: "",
  211. // 是否显示弹出层
  212. open: false,
  213. // 查询参数
  214. queryParams: {
  215. pageNum: 1,
  216. pageSize: 10,
  217. componentId: null,
  218. usedBy: null,
  219. usedDate: null,
  220. },
  221. // 表单参数
  222. form: {},
  223. // 表单校验
  224. rules: {
  225. },
  226. // 导入参数
  227. upload: {
  228. // 是否显示弹出层(导入)
  229. open: false,
  230. // 弹出层标题(导入)
  231. title: "",
  232. // 是否禁用上传
  233. isUploading: false,
  234. // 是否更新已经存在的用户数据
  235. updateSupport: 0,
  236. // 设置上传的请求头部
  237. headers: { Authorization: "Bearer " + getToken() },
  238. // 上传的地址
  239. url: process.env.VUE_APP_BASE_API + "/biz/record/importData"
  240. },
  241. };
  242. },
  243. async created() {
  244. try {
  245. this.componentInfo = await getall();
  246. console.log(this.componentInfo);
  247. } catch (error) {
  248. console.error("Error fetching component info:", error);
  249. }
  250. this.getList();
  251. },
  252. methods: {
  253. /** 查询元器件使用经历列表 */
  254. getList() {
  255. this.loading = true;
  256. // getall().then(res=>{
  257. // for(let one of res){
  258. // this.componentInfo.push(one.id)
  259. //
  260. // }
  261. // })
  262. listRecord(this.queryParams).then(response => {
  263. this.recordList = response.rows;
  264. this.total = response.total;
  265. this.loading = false;
  266. });
  267. },
  268. // 取消按钮
  269. cancel() {
  270. this.open = false;
  271. this.reset();
  272. },
  273. // 表单重置
  274. reset() {
  275. this.form = {
  276. id: null,
  277. componentId: null,
  278. usedBy: null,
  279. usedDate: null,
  280. createBy: null,
  281. createTime: null,
  282. updateBy: null,
  283. updateTime: null,
  284. remark: null
  285. };
  286. this.resetForm("form");
  287. },
  288. /** 搜索按钮操作 */
  289. handleQuery() {
  290. this.queryParams.pageNum = 1;
  291. this.getList();
  292. },
  293. /** 重置按钮操作 */
  294. resetQuery() {
  295. this.resetForm("queryForm");
  296. this.handleQuery();
  297. },
  298. // 多选框选中数据
  299. handleSelectionChange(selection) {
  300. this.ids = selection.map(item => item.id)
  301. this.single = selection.length!==1
  302. this.multiple = !selection.length
  303. },
  304. /** 新增按钮操作 */
  305. handleAdd() {
  306. this.reset();
  307. this.open = true;
  308. this.title = "添加元器件使用经历";
  309. },
  310. /** 修改按钮操作 */
  311. handleUpdate(row) {
  312. this.reset();
  313. const id = row.id || this.ids
  314. getRecord(id).then(response => {
  315. this.form = response.data;
  316. this.open = true;
  317. this.title = "修改元器件使用经历";
  318. });
  319. },
  320. /** 提交按钮 */
  321. submitForm() {
  322. this.$refs["form"].validate(valid => {
  323. if (valid) {
  324. if (this.form.id != null) {
  325. updateRecord(this.form).then(response => {
  326. this.$modal.msgSuccess("修改成功");
  327. this.open = false;
  328. this.getList();
  329. });
  330. } else {
  331. addRecord(this.form).then(response => {
  332. this.$modal.msgSuccess("新增成功");
  333. this.open = false;
  334. this.getList();
  335. });
  336. }
  337. }
  338. });
  339. },
  340. /** 删除按钮操作 */
  341. handleDelete(row) {
  342. const ids = row.id || this.ids;
  343. this.$modal.confirm('是否确认删除元器件使用经历编号为"' + ids + '"的数据项?').then(function() {
  344. return delRecord(ids);
  345. }).then(() => {
  346. this.getList();
  347. this.$modal.msgSuccess("删除成功");
  348. }).catch(() => {});
  349. },
  350. /** 导出按钮操作 */
  351. handleExport() {
  352. this.download('biz/record/export', {
  353. ...this.queryParams
  354. }, `record_${new Date().getTime()}.xlsx`)
  355. },
  356. /** 导入按钮操作 */
  357. handleImport() {
  358. this.upload.title = "元器件记录导入";
  359. this.upload.open = true;
  360. },
  361. /** 下载模板操作 */
  362. importTemplate() {
  363. this.download('biz/record/importTemplate', {
  364. }, `record_template_${new Date().getTime()}.xlsx`)
  365. },
  366. // 文件上传中处理
  367. handleFileUploadProgress(event, file, fileList) {
  368. this.upload.isUploading = true;
  369. },
  370. // 文件上传成功处理
  371. handleFileSuccess(response, file, fileList) {
  372. this.upload.open = false;
  373. this.upload.isUploading = false;
  374. this.$refs.upload.clearFiles();
  375. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  376. this.getList();
  377. },
  378. // 提交上传文件
  379. submitFileForm() {
  380. this.$refs.upload.submit();
  381. }
  382. }
  383. };
  384. </script>
  385. <style>
  386. .el-checkbox__inner {
  387. border-color: #8492a6 !important;
  388. }
  389. .app-container {
  390. min-height: 100vh;
  391. background: radial-gradient(circle at 10% 20%, #3A71A8 0%, rgb(239, 249, 249) 90%);
  392. }
  393. </style>