goodsList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <section>
  3. <section v-loading="loading"
  4. element-loading-text="拼命加载中……"
  5. class="bg-white">
  6. <div class="table-filter-wrapper mar-l-10">
  7. <ph-form @searchBtn="searchBtn"
  8. @resetSearchBtn="resetSearchBtn"
  9. @addHandle="addHandle"
  10. :searchForm="searchForm">
  11. </ph-form>
  12. </div>
  13. <div class="table-wrapper pad-t-5 bor-t-1">
  14. <ph-table :tableData="tableData"
  15. @editHandle="editHandle"
  16. @singleDeleteHandle="singleDeleteHandle"
  17. @selectionChangeHandle="selectionChangeHandle">
  18. </ph-table>
  19. <el-row class="mar-t-10">
  20. <el-col :span='4'>
  21. <el-button @click="batchDeleteHandle()"
  22. :disabled="isBatchDeleteDisabled"
  23. size="small">批量删除
  24. </el-button>
  25. </el-col>
  26. <el-col :span='20'>
  27. <ph-pagination @sendPaginations="sendPaginationsHandle"
  28. :paginations="paginationParams"
  29. class="mar-r-20 text-right">
  30. </ph-pagination>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. </section>
  35. <!--新增、编辑-->
  36. <added-editor-dialog :dialogForm="dialogForm"
  37. :submitLoading="submitLoading"
  38. :dialogVisible.sync="addedEditorDialog"
  39. @getCancel="handleCancel"
  40. @submitHandle="submitAddedEditorForm">
  41. </added-editor-dialog>
  42. </section>
  43. </template>
  44. <script>
  45. import Form from './Form'
  46. import Table from './Table'
  47. import Pagination from '@/components/Pagination'
  48. import AddedEditorDialog from './components/AddedEditorDialog'
  49. export default {
  50. name: 'goodsList',
  51. components: {
  52. 'ph-pagination': Pagination,
  53. 'added-editor-dialog': AddedEditorDialog,
  54. 'ph-form': Form,
  55. 'ph-table': Table
  56. },
  57. data () {
  58. return {
  59. loading: false,//loading
  60. submitLoading: false,//弹窗提交loading
  61. paginationParams: this.$config.paginationParams,//列表分页
  62. handleType: '',//判断弹窗提交是新增还是编辑
  63. checkedIds: [],//checkbox被选中的子项
  64. isBatchDeleteDisabled: false,//是否可以批量删除
  65. //table数据
  66. tableData: [{
  67. name: '小米手机',
  68. code: 'XMSJ',
  69. time: 1573625941000
  70. }, {
  71. name: '华为手机',
  72. code: 'HWSJ',
  73. time: 1573009362000
  74. }, {
  75. name: '红米手机',
  76. code: 'HMSJ',
  77. time: 1573193112000
  78. }, {
  79. name: '荣耀手机',
  80. code: 'RYSJ',
  81. time: 1573610740000
  82. }],
  83. //弹窗
  84. addedEditorDialog: false,
  85. dialogForm: {
  86. name: '',
  87. code: ''
  88. },
  89. //搜索
  90. searchForm: {
  91. name: '',
  92. code: ''
  93. }
  94. }
  95. },
  96. created () {
  97. //请求列表
  98. //this.getList()
  99. },
  100. methods: {
  101. /*
  102. *functionName: successList
  103. * params: params Object
  104. * params: id String
  105. * desc:封装初始化获取列表和搜索 共用
  106. */
  107. async successList (params) {
  108. return this.$message.error("请配置接口!");
  109. this.loading = true//loading
  110. let res = await this.$api.systemModule.goodsManage.getList(params)
  111. let data = res.data.data
  112. if (res.data.retcode === this.$config.RET_CODE.SUCCESS_CODE) {
  113. this.loading = false
  114. if (data.rows.length > 0) {
  115. this.isBatchDeleteDisabled = false//启用批量删除
  116. this.tableData = data.rows//存储到tableData
  117. this.paginationParams.pageSize = data.pageSize//每页的数量
  118. this.paginationParams.size = data.size//当前页的数量
  119. this.paginationParams.total = data.total//总条数
  120. this.paginationParams.pages = data.pages//总页码数
  121. } else {
  122. this.tableData = []
  123. this.paginationParams.total = 0
  124. this.isBatchDeleteDisabled = true//禁用批量删除
  125. }
  126. } else {
  127. this.$message({
  128. type: 'error',
  129. message: res.data.retmsg
  130. })
  131. }
  132. },
  133. /*
  134. *functionName: getList
  135. * params: params Object
  136. * params: aliveFlag String
  137. * params: pageNo Number
  138. * params: pageSize Number
  139. * desc:获取表格数据
  140. */
  141. getList () {
  142. return this.$message.error("请配置接口!");
  143. let params = {
  144. pageNo: this.paginationParams.pageNo,//页码
  145. pageSize: this.paginationParams.pageSize//每页条数
  146. }
  147. //列表成功请求
  148. this.successList(params)
  149. },
  150. /*
  151. *functionName: searchBtn
  152. * params: searchData Object
  153. * desc:查询
  154. */
  155. searchBtn (searchData) {
  156. let params = {
  157. pageNo: this.paginationParams.pageNo,//页码
  158. pageSize: this.paginationParams.pageSize,//每页条数
  159. name: searchData && searchData.name ? searchData.name : null,
  160. }
  161. //列表成功请求
  162. this.successList(params)
  163. },
  164. /*
  165. *functionName: sendPaginationsHandle
  166. * params: params Object
  167. * desc:接收分页参数
  168. */
  169. sendPaginationsHandle () {
  170. if (this.searchForm.name !== '' || this.searchForm.code !== '') {
  171. let params = {
  172. pageNo: this.paginationParams.pageNo,//页码
  173. pageSize: this.paginationParams.pageSize,//每页条数
  174. name: this.searchForm && this.searchForm.name !== '' ? this.searchForm.name : null,
  175. }
  176. //发送请求
  177. this.successList(params)
  178. } else {
  179. this.getList()
  180. }
  181. },
  182. /*
  183. *functionName: resetSearchBtn
  184. * desc:重置搜索查询
  185. */
  186. resetSearchBtn () {
  187. this.searchForm = {}
  188. this.paginationParams.pageNo = 1
  189. this.getList()
  190. },
  191. /*
  192. *functionName: addHandle
  193. * desc:弹出新增
  194. */
  195. addHandle () {
  196. this.handleType = 'add'//判断为新增
  197. this.addedEditorDialog = true//显示弹窗
  198. //设置传给后台的数据
  199. this.dialogForm = {
  200. name: '',
  201. code: ''
  202. }
  203. },
  204. /*
  205. *functionName: selectionChangeHandle
  206. * params: checkedData Object
  207. * desc:表格全选
  208. */
  209. selectionChangeHandle (checkedData) {
  210. //checkedData是选中的数组,遍历后的数据为数组,如[1,2,3],追加到checkedIds作为传给后台的参数
  211. checkedData.forEach(item => {
  212. this.checkedIds.push(item.id)
  213. })
  214. },
  215. /*
  216. *functionName: editHandle
  217. * params: params Number
  218. * desc:弹出修改
  219. */
  220. editHandle (index, row) {
  221. this.handleType = 'edit'//判断为编辑
  222. this.addedEditorDialog = true//显示弹窗
  223. this.dialogForm = {
  224. name: row.name,
  225. code: row.code,
  226. id: row.id
  227. }
  228. //请求接口
  229. let params = row.id
  230. return this.$message.error("请配置接口!");
  231. this.$api.systemModule.goodsManage.getDataById(params)
  232. .then(res => {
  233. if (res.data.retcode === this.$config.RET_CODE.SUCCESS_CODE) {
  234. let data = res.data.data
  235. //设置传给后台的数据
  236. this.dialogForm = {
  237. name: data.name,
  238. code: data.code,
  239. id: data.id
  240. }
  241. } else {
  242. this.$message({
  243. type: 'error',
  244. message: res.data.retmsg
  245. })
  246. }
  247. }).catch(err => {
  248. console.log(err)
  249. })
  250. },
  251. /*
  252. *functionName: deleteHandle
  253. * params: params Object
  254. * desc:删除共用方法
  255. */
  256. deleteHandle (tipsText, params, cancelTips) {
  257. //提示框
  258. this.$confirm(tipsText, '提示', {
  259. confirmButtonText: '确定',
  260. cancelButtonText: '取消',
  261. type: 'warning',
  262. center: true
  263. }).then(() => {
  264. return this.$message.error("请配置接口!");
  265. //请求删除账号接口
  266. this.$api.systemModule.goodsManage.batchEdit(params)
  267. .then(res => {
  268. if (res.data.retcode === this.$config.RET_CODE.SUCCESS_CODE) {
  269. this.$message({
  270. type: 'success',
  271. message: res.data.retmsg
  272. })
  273. this.getList()
  274. } else {
  275. this.$message({
  276. type: 'error',
  277. message: res.data.retmsg
  278. })
  279. }
  280. }).catch(err => {
  281. console.log(err)
  282. })
  283. }).catch(() => {
  284. this.$message({
  285. type: 'info',
  286. message: cancelTips
  287. })
  288. })
  289. },
  290. /*
  291. *functionName: singleDeleteHandle
  292. * params: params Object
  293. * desc:单个删除
  294. */
  295. singleDeleteHandle (index, row) {
  296. let arr = []
  297. arr.push(row.id)
  298. let params = {
  299. ids: [row.id]//数组
  300. }
  301. this.deleteHandle('确定删除当前拍品信息?', params, '取消删除')
  302. },
  303. /*
  304. *functionName: batchDeleteHandle
  305. * params: params Array
  306. * desc:批量删除
  307. */
  308. batchDeleteHandle () {
  309. if (this.checkedIds.length > 0) {
  310. let params = {
  311. ids: this.checkedIds//数组
  312. }
  313. this.deleteHandle('确定批量删除当前拍品信息?', params, '取消删除')
  314. } else {
  315. this.$message({
  316. type: 'error',
  317. message: '请选择拍品'
  318. })
  319. }
  320. },
  321. /*
  322. *functionName: handleCancel
  323. * desc:点击弹框下的取消
  324. */
  325. handleCancel () {
  326. this.addedEditorDialog = false
  327. },
  328. /*
  329. *functionName: submitAddedEditorForm
  330. * params: params Array
  331. * desc:新增、修改弹窗提交
  332. */
  333. submitAddedEditorForm () {
  334. return this.$message.error("请配置接口!");
  335. this.submitLoading = true
  336. let params = this.dialogForm
  337. if (this.handleType === 'add') {
  338. //添加
  339. this.$api.systemModule.goodsManage.add(params)
  340. .then(res => {
  341. if (res.data.retcode === this.$config.RET_CODE.SUCCESS_CODE) {
  342. this.submitLoading = false
  343. this.$message({
  344. message: res.data.retmsg,
  345. type: "success"
  346. })
  347. this.getList()
  348. this.addedEditorDialog = false//隐藏弹窗
  349. } else {
  350. //账号已存在或者其他异常
  351. this.$message({
  352. message: res.data.retmsg,
  353. type: "error"
  354. })
  355. this.submitLoading = false
  356. }
  357. }).catch(err => {
  358. console.log(err)
  359. this.addedEditorDialog = false//隐藏弹窗
  360. this.submitLoading = false
  361. })
  362. } else if (this.handleType === 'edit') {
  363. return this.$message.error("请配置接口!");
  364. //编辑
  365. this.$api.systemModule.goodsManage.edit(params)
  366. .then(res => {
  367. if (res.data.retcode === this.$config.RET_CODE.SUCCESS_CODE) {
  368. this.submitLoading = false
  369. this.$message({
  370. type: "success",
  371. message: res.data.retmsg
  372. })
  373. this.getList()//再次请求列表
  374. this.addedEditorDialog = false//隐藏弹窗
  375. } else {
  376. //其他异常
  377. this.$message({
  378. type: "error",
  379. message: res.data.retmsg
  380. })
  381. this.submitLoading = false
  382. }
  383. }).catch(err => {
  384. //隐藏弹窗
  385. console.log(err)
  386. this.addedEditorDialog = false
  387. this.submitLoading = false
  388. })
  389. }
  390. }
  391. }
  392. }
  393. </script>