index.vue 11 KB

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