index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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=label",
  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. if (row.upperFrame == 0){
  226. if (!Number(row.salesPrice)) return this.$message.error("上架失败,商城价格不能为0")
  227. }
  228. submit({
  229. ...row,
  230. label: row.label.join(","),
  231. ids: row.goodsId,
  232. upperFrame: row.upperFrame == 0 ? 1 : 0,
  233. specialOffer: row.salesPrice,
  234. }).then(res => {
  235. this.onLoad(this.page, this.search)
  236. })
  237. },
  238. change(row, type) {
  239. let data = []
  240. for (let item of this.selectionList) {
  241. data.push(item.goodsId)
  242. }
  243. if (type === "up") {
  244. for (let item of this.selectionList) {
  245. if (!Number(item.salesPrice)) return this.$message.error("上架失败,商城价格不能为0")
  246. }
  247. this.$confirm('是否确认全部上架?', '提示', {
  248. confirmButtonText: '确定',
  249. cancelButtonText: '取消',
  250. type: 'warning'
  251. }).then(() => {
  252. submit({
  253. upperFrame: 1,
  254. ids: data.join(",")
  255. }).then(res => {
  256. this.onLoad(this.page, this.search)
  257. })
  258. }).catch(() => {
  259. });
  260. } else if (type === "down") {
  261. this.$confirm('是否确认全部下架?', '提示', {
  262. confirmButtonText: '确定',
  263. cancelButtonText: '取消',
  264. type: 'warning'
  265. }).then(() => {
  266. submit({
  267. upperFrame: 0,
  268. ids: data.join(",")
  269. }).then(res => {
  270. this.onLoad(this.page, this.search)
  271. })
  272. }).catch(() => {
  273. });
  274. }else if (type === "label"){
  275. this.$confirm('是否确认全部修改?', '提示', {
  276. confirmButtonText: '确定',
  277. cancelButtonText: '取消',
  278. type: 'warning'
  279. }).then(() => {
  280. submit({
  281. label: row.label.join(","),
  282. ids: data.join(",")
  283. }).then(res => {
  284. this.onLoad(this.page, this.search)
  285. this.dialogVisible = false
  286. })
  287. }).catch(() => {
  288. });
  289. }
  290. },
  291. onLoad(page, params = {}) {
  292. params = {
  293. ...params,
  294. current: page.currentPage,
  295. size: page.pageSize,
  296. ...Object.assign(params, this.search)
  297. }
  298. this.loading = true
  299. getList(params).then(res => {
  300. this.dataList = res.data.data.records
  301. this.page.total = res.data.data.total
  302. this.loading = false
  303. }).finally(() => {
  304. this.loading = false
  305. })
  306. },
  307. //自定义列保存
  308. async saveColumnTwo(ref, option, optionBack, code) {
  309. /**
  310. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  311. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  312. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  313. */
  314. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  315. if (inSave) {
  316. this.$message.success("保存成功");
  317. //关闭窗口
  318. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  319. }
  320. },
  321. //自定义列重置
  322. async resetColumnTwo(ref, option, optionBack, code) {
  323. this[option] = this[optionBack];
  324. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  325. if (inSave) {
  326. this.$message.success("重置成功");
  327. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  328. }
  329. }
  330. }
  331. }
  332. </script>
  333. <style scoped>
  334. </style>