index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="名称" prop="name">
  5. <el-input v-model="queryParams.name" placeholder="名称" clearable @keyup.enter.native="handleQuery" />
  6. </el-form-item>
  7. <el-form-item label="SNS编号" title="SNS编号" prop="snsId">
  8. <el-input v-model="queryParams.snsId" placeholder="请输入SNS编号" clearable @keyup.enter.native="handleQuery" />
  9. </el-form-item>
  10. <el-form-item>
  11. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  12. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  13. </el-form-item>
  14. </el-form>
  15. <el-row :gutter="10" class="mb8">
  16. <el-col :span="1.5">
  17. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  18. v-hasPermi="['manage:product:add']">新增</el-button>
  19. </el-col>
  20. <el-col :span="1.5">
  21. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
  22. v-hasPermi="['manage:product:export']">导出</el-button>
  23. </el-col>
  24. <el-col :span="1.5">
  25. <el-button type="primary" icon="el-icon-upload2" size="mini" @click="handleImport"
  26. v-hasPermi="['manage:product:import']">导入</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
  30. </el-col>
  31. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  32. </el-row>
  33. <el-table v-if="refreshTable" border v-loading="loading" :data="productList" row-key="id" :default-expand-all="isExpandAll"
  34. :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  35. <el-table-column label="名称" align="center" prop="name" />
  36. <el-table-column label="SNS编号" align="center" prop="snsId" />
  37. <el-table-column label="归属" align="center" prop="parentName" />
  38. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  39. <template slot-scope="scope">
  40. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  41. v-hasPermi="['manage:product:edit']">修改</el-button>
  42. <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)"
  43. v-hasPermi="['manage:product:add']">新增</el-button>
  44. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  45. v-hasPermi="['manage:product:remove']">删除</el-button>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <!-- 添加或修改产品树信息对话框 -->
  50. <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="500px" append-to-body>
  51. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  52. <!-- <el-form-item label="归属" prop="aircraftId" v-if="isAdd">
  53. <el-select v-model="form.aircraftId" placeholder="请选择机号信息" style="width:100%">
  54. <el-option v-for="item in aircraftOptions" :key="item.id" :label="item.name" :value="item.id">
  55. </el-option>
  56. </el-select>user/profile
  57. </el-form-item> -->
  58. <el-form-item label="归属" prop="parentId" v-if="!isParentId">
  59. <treeselect v-model="form.parentId" :options="productOptions" :normalizer="normalizer" placeholder="请选择父ID" />
  60. </el-form-item>
  61. <el-form-item label="名称" prop="name">
  62. <el-input v-model="form.name" placeholder="请输入名称" />
  63. </el-form-item>
  64. <el-form-item label="SNS编号" prop="snsId">
  65. <el-input v-model="form.snsId" placeholder="请输入SNS编号" />
  66. </el-form-item>
  67. </el-form>
  68. <div slot="footer" class="dialog-footer">
  69. <el-button type="primary" @click="submitForm">确 定</el-button>
  70. <el-button @click="cancel">取 消</el-button>
  71. </div>
  72. </el-dialog>
  73. <!-- 产品树导入对话框 -->
  74. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  75. <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
  76. :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
  77. :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
  78. <i class="el-icon-upload"></i>
  79. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  80. <div class="el-upload__tip text-center" slot="tip">
  81. <div class="el-upload__tip" slot="tip">
  82. <el-checkbox v-model="upload.updateSupport" />
  83. 是否更新已经存在的产品树数据
  84. </div>
  85. <span>仅允许导入xls、xlsx格式文件。</span>
  86. <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
  87. @click="importTemplate">下载模板</el-link>
  88. </div>
  89. </el-upload>
  90. <div slot="footer" class="dialog-footer">
  91. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  92. <el-button @click="upload.open = false">取 消</el-button>
  93. </div>
  94. </el-dialog>
  95. </div>
  96. </template>
  97. <script>
  98. import { getToken } from '@/utils/auth'
  99. import {
  100. listProduct,
  101. getProduct,
  102. delProduct,
  103. addProduct,
  104. updateProduct,
  105. aircraftListSelect,
  106. } from '@/api/manage/product'
  107. import Treeselect from '@riophae/vue-treeselect'
  108. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  109. export default {
  110. name: 'Product',
  111. components: {
  112. Treeselect,
  113. },
  114. data() {
  115. return {
  116. // 遮罩层
  117. loading: true,
  118. // 显示搜索条件
  119. showSearch: true,
  120. // 产品树信息表格数据
  121. productList: [],
  122. // 产品树信息树选项
  123. productOptions: [],
  124. // 弹出层标题
  125. title: '',
  126. // 是否显示弹出层
  127. open: false,
  128. // // 是否新增
  129. // isAdd: true,
  130. // 是否展开,默认全部展开
  131. isExpandAll: true,
  132. // // 单机列表
  133. // aircraftOptions: undefined,
  134. // 重新渲染表格状态
  135. refreshTable: true,
  136. // 查询参数
  137. queryParams: {
  138. parentId: null,
  139. name: null,
  140. snsId: null,
  141. },
  142. // 表单参数
  143. form: {},
  144. // 表单校验
  145. rules: {
  146. parentId: [
  147. { required: true, message: '归属不能为空', trigger: 'blur' },
  148. ],
  149. aircraftId: [
  150. { required: true, message: '归属不能为空', trigger: 'blur' },
  151. ],
  152. },
  153. upload: {
  154. title: '',
  155. // 是否显示弹出层
  156. open: false,
  157. // 是否禁用上传
  158. isUploading: false,
  159. // 设置上传的请求头部
  160. headers: { Authorization: 'Bearer ' + getToken() },
  161. // 是否更新已存在数据
  162. updateSupport: 0,
  163. // 上传的地址
  164. url: process.env.VUE_APP_BASE_API + '/manage/product/import',
  165. },
  166. }
  167. },
  168. created() {
  169. this.getList()
  170. },
  171. computed: {
  172. isParentId() {
  173. return this.form.parentId == 0
  174. },
  175. },
  176. methods: {
  177. /** 查询产品树信息列表 */
  178. getList() {
  179. this.loading = true
  180. listProduct(this.queryParams).then(response => {
  181. this.productList = this.handleTree(response.data, 'id', 'parentId')
  182. this.loading = false
  183. })
  184. },
  185. /** 查询单机信息列表 */
  186. // getAircraftList() {
  187. // aircraftListSelect(this.queryParams).then(response => {
  188. // this.aircraftOptions = response.data
  189. // })
  190. // },
  191. /** 转换产品树信息数据结构 */
  192. normalizer(node) {
  193. if (node.children && !node.children.length) {
  194. delete node.children
  195. }
  196. return {
  197. id: node.id,
  198. label: node.name,
  199. children: node.children,
  200. }
  201. },
  202. /** 查询产品树信息下拉树结构 */
  203. getTreeselect() {
  204. listProduct().then(response => {
  205. this.productOptions = []
  206. // const data = { id: 0, name: '顶级节点', children: [], isDisabled: true }
  207. this.productOptions = this.handleTree(response.data, 'id')
  208. // this.productOptions.push(data)
  209. })
  210. },
  211. // 取消按钮
  212. cancel() {
  213. this.open = false
  214. this.reset()
  215. },
  216. // 表单重置
  217. reset() {
  218. this.form = {
  219. id: null,
  220. parentId: null,
  221. parentName: null,
  222. aircraftId: null,
  223. name: null,
  224. snsId: null,
  225. }
  226. this.resetForm('form')
  227. },
  228. /** 搜索按钮操作 */
  229. handleQuery() {
  230. this.getList()
  231. },
  232. /** 重置按钮操作 */
  233. resetQuery() {
  234. this.resetForm('queryForm')
  235. this.handleQuery()
  236. },
  237. /** 新增按钮操作 */
  238. handleAdd(row) {
  239. this.reset()
  240. if (row != null && row.id) {
  241. this.getTreeselect()
  242. // this.isAdd = false
  243. this.form.parentId = row.id
  244. } else {
  245. // this.isAdd = true
  246. this.form.parentId = 0
  247. }
  248. this.open = true
  249. this.title = '添加产品树信息'
  250. },
  251. /** 展开/折叠操作 */
  252. toggleExpandAll() {
  253. this.refreshTable = false
  254. this.isExpandAll = !this.isExpandAll
  255. this.$nextTick(() => {
  256. this.refreshTable = true
  257. })
  258. },
  259. /** 修改按钮操作 */
  260. handleUpdate(row) {
  261. this.reset()
  262. if (row.parentId == 0) {
  263. this.form.aircraftId = row.aircraftId
  264. this.form.name = row.name
  265. this.form.snsId = row.snsId
  266. this.form.parentId = row.parentId
  267. this.form.id = row.id
  268. // this.isAdd = true
  269. this.open = true
  270. return
  271. }
  272. this.getTreeselect()
  273. if (row != null) {
  274. this.form.parentId = row.id
  275. }
  276. getProduct(row.id).then(response => {
  277. this.form = response.data
  278. // this.isAdd = false
  279. this.open = true
  280. this.title = '修改产品树信息'
  281. })
  282. },
  283. /** 提交按钮 */
  284. submitForm() {
  285. this.$refs['form'].validate(valid => {
  286. if (valid) {
  287. if (this.form.id != null) {
  288. updateProduct(this.form).then(response => {
  289. this.$modal.msgSuccess('修改成功')
  290. this.open = false
  291. this.getList()
  292. })
  293. } else {
  294. addProduct(this.form).then(response => {
  295. this.$modal.msgSuccess('新增成功')
  296. this.open = false
  297. this.getList()
  298. })
  299. }
  300. }
  301. })
  302. },
  303. /** 删除按钮操作 */
  304. handleDelete(row) {
  305. this.$modal
  306. .confirm('是否确认删除产品树信息编号为"' + row.id + '"的数据项?')
  307. .then(function () {
  308. return delProduct(row.id)
  309. })
  310. .then(() => {
  311. this.getList()
  312. this.$modal.msgSuccess('删除成功')
  313. })
  314. .catch(() => {})
  315. },
  316. /** 导出按钮操作 */
  317. handleExport() {
  318. this.download(
  319. 'manage/product/export',
  320. {
  321. ...this.queryParams,
  322. },
  323. `product_${new Date().getTime()}.xlsx`
  324. )
  325. },
  326. /** 导入按钮操作 */
  327. handleImport() {
  328. this.upload.title = '产品树导入'
  329. this.upload.open = true
  330. },
  331. submitFileForm() {
  332. this.$refs.upload.submit()
  333. },
  334. uploadClose() {
  335. // 关闭弹窗
  336. this.upload.open = false
  337. // 重置上传状态和文件
  338. this.upload.isUploading = false
  339. this.$refs.upload.clearFiles()
  340. // 重置表单
  341. this.upload.form = {}
  342. // this.resetForm("uploadForm");
  343. },
  344. // 文件上传中处理
  345. handleFileUploadProgress(event, file, fileList) {
  346. this.upload.isUploading = true
  347. },
  348. // 文件上传成功处理
  349. handleFileSuccess(response, file, fileList) {
  350. if (response.code !== 200) {
  351. this.$modal.msgError(response.msg)
  352. return
  353. }
  354. this.upload.open = false
  355. this.upload.isUploading = false
  356. this.$refs.upload.clearFiles()
  357. this.$alert(
  358. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  359. response.msg +
  360. '</div>',
  361. '导入结果',
  362. { dangerouslyUseHTMLString: true }
  363. )
  364. this.getList()
  365. },
  366. /** 下载模板操作 */
  367. importTemplate() {
  368. this.download(
  369. '/manage/product/importTemplate',
  370. {},
  371. `product_template_${new Date().getTime()}.xlsx`
  372. )
  373. },
  374. },
  375. }
  376. </script>