index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <div>
  3. <basic-container>
  4. <avue-crud
  5. :option="option"
  6. :search.sync="search"
  7. v-model="form"
  8. :table-loading="loading"
  9. :data="dataList"
  10. ref="crud"
  11. :key="key"
  12. @on-load="onLoad"
  13. @selection-change="selectionChange"
  14. :before-open="beforeOpen"
  15. @row-update="rowUpdate"
  16. @search-change="searchChange"
  17. @refresh-change="refreshChange"
  18. @resetColumn="resetColumnTwo('crud','option','optionList',249)"
  19. @saveColumn="saveColumnTwo('crud','option','optionList',249)"
  20. :page.sync="page">
  21. <template slot-scope="{type,size,row,$index}" slot="menu">
  22. <el-button icon="el-icon-edit" :size="size" :type="type" @click="$refs.crud.rowEdit(row,index)">编辑
  23. </el-button>
  24. <el-button icon="el-icon-view" :size="size" :type="type" @click="check(row)">
  25. {{ row.upperFrame == 0 ? '上架' : '下架' }}
  26. </el-button>
  27. </template>
  28. <template slot-scope="{type,size,row,$index}" slot="menuLeft">
  29. <el-button class="el-icon-document-copy" :disabled="selectionList.length === 0" type="primary" size="small"
  30. @click="change(row,'up')">批量上架
  31. </el-button>
  32. <el-button class="el-icon-document-copy" :disabled="selectionList.length === 0" type="danger" size="small"
  33. @click="change(row,'down')">批量下架
  34. </el-button>
  35. <el-button class="el-icon-document-copy" :disabled="selectionList.length === 0" type="warning" size="small"
  36. @click="dialogVisible = true">
  37. 批量标签
  38. </el-button>
  39. </template>
  40. </avue-crud>
  41. </basic-container>
  42. <el-dialog
  43. title="批量标签"
  44. :visible.sync="dialogVisible"
  45. v-if="dialogVisible"
  46. append-to-body
  47. :close-on-click-modal="false"
  48. :before-close="(done)=>{
  49. this.dialogVisible = false
  50. done()
  51. }"
  52. width="40%">
  53. <span>
  54. <avue-form :option="optionTwo" v-model="formTwo"></avue-form>
  55. </span>
  56. <span slot="footer" class="dialog-footer">
  57. <el-button @click="dialogVisible = false">取 消</el-button>
  58. <el-button type="primary" @click="change(formTwo,'label')">确 定</el-button>
  59. </span>
  60. </el-dialog>
  61. </div>
  62. </template>
  63. <script>
  64. import {getList, submit} from "@/api/productLaunch/index.js";
  65. export default {
  66. name: "index",
  67. data() {
  68. return {
  69. loading: false,
  70. dialogVisible: false,
  71. search: {},
  72. form: {},
  73. formTwo: {},
  74. dataList: [],
  75. selectionList: [],
  76. optionTwo: {
  77. menuBtn:false,
  78. column: [
  79. {
  80. label: '标签',
  81. prop: 'label',
  82. width: 170,
  83. multiple: true,
  84. tags: true,
  85. filterable: true,
  86. type: 'select',
  87. span: 24,
  88. dicUrl: "/api/blade-system/dict-biz/dictionary?code=lable",
  89. props: {
  90. label: "dictValue",
  91. value: "dictKey"
  92. }
  93. }
  94. ]
  95. },
  96. page: {
  97. pageSize: 20,
  98. currentPage: 1,
  99. total: 0,
  100. pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  101. },
  102. key: 0,
  103. option: {},
  104. optionList: {
  105. viewBtn: false,
  106. editBtn: false,
  107. delBtn: false,
  108. addBtn: false,
  109. index: true,
  110. span: 8,
  111. border: true,
  112. selection: true,
  113. height: "auto",
  114. searchMenuPosition: "right",
  115. align: "center",
  116. menuWidth: 140,
  117. searchSpan: 8,
  118. searchIcon: true,
  119. searchIndex: 2,
  120. highlightCurrentRow: true,
  121. dialogWidth: "70%",
  122. column: [{
  123. label: '名称',
  124. prop: 'goods',
  125. overHidden: true,
  126. disabled: true,
  127. search: true,
  128. }, {
  129. label: '库存',
  130. prop: 'balance',
  131. overHidden: true,
  132. disabled: true,
  133. }, {
  134. label: '库存单价',
  135. prop: 'stockPrice',
  136. disabled: true,
  137. overHidden: true,
  138. }, {
  139. label: '商城价格',
  140. prop: 'salesPrice',
  141. type: 'number',
  142. controls: false,
  143. }, {
  144. label: '标签',
  145. prop: 'label',
  146. searchProp: 'labels',
  147. multiple: true,
  148. tags: true,
  149. filterable: true,
  150. type: 'select',
  151. span: 16,
  152. dicUrl: "/api/blade-system/dict-biz/dictionary?code=lable",
  153. props: {
  154. label: "dictValue",
  155. value: "dictKey"
  156. }
  157. }, {
  158. label: '标签',
  159. prop: 'label',
  160. filterable: true,
  161. display:false,
  162. search: true,
  163. hide:true,
  164. showColumn:false,
  165. type: 'select',
  166. span: 16,
  167. dicUrl: "/api/blade-system/dict-biz/dictionary?code=lable",
  168. props: {
  169. label: "dictValue",
  170. value: "dictKey"
  171. }
  172. }]
  173. }
  174. }
  175. },
  176. async created() {
  177. this.option = await this.getColumnData(this.getColumnName(249), this.optionList);
  178. this.key++
  179. let i = 0;
  180. this.option.column.forEach(item => {
  181. if (item.search) i++
  182. })
  183. if (i % 3 !== 0) {
  184. const num = 3 - Number(i % 3)
  185. this.option.searchMenuSpan = num * 8;
  186. this.option.searchMenuPosition = "right";
  187. }
  188. },
  189. methods: {
  190. //刷新
  191. refreshChange() {
  192. this.onLoad(this.page, this.search)
  193. },
  194. searchChange(params, done) {
  195. done();
  196. this.onLoad(this.page, params)
  197. },
  198. selectionChange(list) {
  199. this.selectionList = list
  200. },
  201. //打开表单前
  202. beforeOpen(done, type) {
  203. if (this.form.label.includes('特价')) {
  204. this.$set(this.findObject(this.option.column, "salesPrice"), "disabled", false)
  205. } else {
  206. this.$set(this.findObject(this.option.column, "salesPrice"), "disabled", true)
  207. }
  208. done();
  209. },
  210. //编辑确定
  211. rowUpdate(form, index, done, loading) {
  212. submit({
  213. ...form,
  214. label: form.label.join(","),
  215. ids: form.goodsId,
  216. specialOffer: form.salesPrice,
  217. }).then(res => {
  218. this.onLoad(this.page, this.search)
  219. done()
  220. }).catch(() => {
  221. loading()
  222. })
  223. },
  224. check(row) {
  225. submit({
  226. ...row,
  227. label: row.label.join(","),
  228. ids: row.goodsId,
  229. upperFrame: row.upperFrame == 0 ? 1 : 0,
  230. specialOffer: row.salesPrice,
  231. }).then(res => {
  232. this.onLoad(this.page, this.search)
  233. })
  234. },
  235. change(row, type) {
  236. let data = []
  237. for (let item of this.selectionList) {
  238. data.push(item.goodsId)
  239. }
  240. if (type === "up") {
  241. this.$confirm('是否确认全部上架?', '提示', {
  242. confirmButtonText: '确定',
  243. cancelButtonText: '取消',
  244. type: 'warning'
  245. }).then(() => {
  246. submit({
  247. upperFrame: 1,
  248. ids: data.join(",")
  249. }).then(res => {
  250. this.onLoad(this.page, this.search)
  251. })
  252. }).catch(() => {
  253. });
  254. } else if (type === "down") {
  255. this.$confirm('是否确认全部下架?', '提示', {
  256. confirmButtonText: '确定',
  257. cancelButtonText: '取消',
  258. type: 'warning'
  259. }).then(() => {
  260. submit({
  261. upperFrame: 0,
  262. ids: data.join(",")
  263. }).then(res => {
  264. this.onLoad(this.page, this.search)
  265. })
  266. }).catch(() => {
  267. });
  268. }else if (type === "label"){
  269. this.$confirm('是否确认全部修改?', '提示', {
  270. confirmButtonText: '确定',
  271. cancelButtonText: '取消',
  272. type: 'warning'
  273. }).then(() => {
  274. submit({
  275. label: row.label.join(","),
  276. ids: data.join(",")
  277. }).then(res => {
  278. this.onLoad(this.page, this.search)
  279. this.dialogVisible = false
  280. })
  281. }).catch(() => {
  282. });
  283. }
  284. },
  285. onLoad(page, params = {}) {
  286. params = {
  287. ...params,
  288. current: page.currentPage,
  289. size: page.pageSize,
  290. ...Object.assign(params, this.search)
  291. }
  292. this.loading = true
  293. getList(params).then(res => {
  294. this.dataList = res.data.data.records
  295. this.page.total = res.data.data.total
  296. this.loading = false
  297. }).finally(() => {
  298. this.loading = false
  299. })
  300. },
  301. //自定义列保存
  302. async saveColumnTwo(ref, option, optionBack, code) {
  303. /**
  304. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  305. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  306. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  307. */
  308. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  309. if (inSave) {
  310. this.$message.success("保存成功");
  311. //关闭窗口
  312. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  313. }
  314. },
  315. //自定义列重置
  316. async resetColumnTwo(ref, option, optionBack, code) {
  317. this[option] = this[optionBack];
  318. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  319. if (inSave) {
  320. this.$message.success("重置成功");
  321. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  322. }
  323. }
  324. }
  325. }
  326. </script>
  327. <style scoped>
  328. </style>