index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div class="marketing app-container">
  3. <div class="search">
  4. <div>
  5. <el-input
  6. v-model="query.key"
  7. size="small"
  8. placeholder="请输入ID或活动名称"
  9. clearable
  10. class="item-width-200 "
  11. ></el-input>
  12. <el-button
  13. class="ml10"
  14. type="primary"
  15. size="small"
  16. icon="el-icon-search"
  17. @click="handleSearch"
  18. >
  19. 搜索
  20. </el-button>
  21. </div>
  22. <el-button class="add-btn" type="primary" size="small" v-if="btnAuthObj.addActivity" @click="handleAdd"
  23. >添加</el-button
  24. >
  25. </div>
  26. <el-table
  27. :data="tableData"
  28. tooltip-effect="dark"
  29. border
  30. v-loading="loading"
  31. style="width: 100%"
  32. >
  33. <el-table-column
  34. align="center"
  35. label="活动ID"
  36. prop="activityId"
  37. show-overflow-tooltip
  38. >
  39. </el-table-column>
  40. <el-table-column
  41. align="center"
  42. label="活动金额"
  43. prop="activityMoney"
  44. show-overflow-tooltip
  45. >
  46. </el-table-column>
  47. <el-table-column
  48. align="center"
  49. label="剩余金额"
  50. prop="residueMoney"
  51. show-overflow-tooltip
  52. >
  53. </el-table-column>
  54. <el-table-column
  55. align="center"
  56. label="活动内容"
  57. prop="activityContent"
  58. show-overflow-tooltip
  59. >
  60. </el-table-column>
  61. <el-table-column
  62. align="center"
  63. label="创建时间"
  64. prop="createTime"
  65. show-overflow-tooltip
  66. >
  67. </el-table-column>
  68. <el-table-column align="center" label="操作">
  69. <template slot-scope="scope">
  70. <el-button type="text" size="small" v-if="btnAuthObj.editActivity" @click="handleEdit(scope.row)"
  71. >编辑</el-button
  72. >
  73. <el-button type="text" size="small" v-if="btnAuthObj.delActivity" @click="handleDel(scope.row.id)"
  74. >删除</el-button
  75. >
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <div class="page-box">
  80. <el-pagination
  81. @size-change="handleSizeChange"
  82. @current-change="handleCurrentChange"
  83. background
  84. :current-page="query.currentPage"
  85. :page-sizes="[10, 20, 30, 40]"
  86. :page-size="query.pageSize"
  87. layout="total, sizes, prev, pager, next, jumper"
  88. :total="total"
  89. >
  90. </el-pagination>
  91. </div>
  92. <el-dialog :title="title" width="550px" :visible.sync="dialogFormVisible">
  93. <el-form label-width="130px" :model="setQuery"
  94. ref="setQuery"
  95. :rules="rules">
  96. <el-form-item label="活动ID" prop="activityId">
  97. <el-input
  98. v-model="setQuery.activityId"
  99. class="item-width-300"
  100. ></el-input>
  101. </el-form-item>
  102. <el-form-item label="活动金额" prop="activityMoney">
  103. <el-input
  104. v-model.number="setQuery.activityMoney"
  105. class="item-width-300"
  106. ></el-input>
  107. </el-form-item>
  108. <el-form-item label="活动有效期" prop="startTime">
  109. <el-date-picker
  110. v-model="date"
  111. size="small"
  112. class="item-width-350 ml10"
  113. value-format="yyyy-MM-dd hh:mm:ss"
  114. type="datetimerange"
  115. range-separator="至"
  116. start-placeholder="开始日期"
  117. end-placeholder="结束日期">
  118. </el-date-picker>
  119. </el-form-item>
  120. <el-form-item label="活动内容" prop="activityContent">
  121. <el-input
  122. v-model.number="setQuery.activityContent"
  123. class="item-width-300"
  124. ></el-input>
  125. </el-form-item>
  126. </el-form>
  127. <div slot="footer" class="dialog-footer">
  128. <el-button @click="dialogFormVisible = false">取 消</el-button>
  129. <el-button type="primary" :loading="btnLoading" @click="save">确 定</el-button>
  130. </div>
  131. </el-dialog>
  132. </div>
  133. </template>
  134. <script>
  135. import { debounce } from "@/utils/index";
  136. import { activityXiaojuList,delActivityXiaoju,addOrUpdateActivityXiaoju } from "@/api/marketing";
  137. export default {
  138. name: "marketing",
  139. data() {
  140. return {
  141. date:'',
  142. title:'',
  143. tableData: [],
  144. loading: false,
  145. btnLoading: false,
  146. dialogFormVisible: false,
  147. query: {
  148. key:'',
  149. currentPage: 1,
  150. pageSize: 10,
  151. },
  152. total: 0,
  153. setQuery:{
  154. "activityContent": "",
  155. "activityId": "",
  156. "activityMoney": 0,
  157. "endTime": "",
  158. "id": 0,
  159. "startTime": ""
  160. },
  161. rules:{
  162. activityId: [{ required: true, message: "请输入活动ID", trigger: "blur" }],
  163. activityMoney: [{ required: true, message: "请输入活动金额", trigger: "blur" }],
  164. startTime: [{ required: true, message: "请选择活动时间", trigger: "change" }],
  165. }
  166. };
  167. },
  168. watch: {
  169. date(val){
  170. if(val){
  171. this.setQuery.startTime = val[0]
  172. this.setQuery.endTime = val[1]
  173. }else{
  174. this.setQuery.startTime = ''
  175. this.setQuery.endTime = ''
  176. }
  177. },
  178. },
  179. methods: {
  180. handleSearch(){
  181. this.query.currentPage = 1;
  182. this.getList();
  183. },
  184. handleEdit(row){
  185. this.title = '编辑'
  186. this.dialogFormVisible = true
  187. this.setQuery = {
  188. "activityContent": row.activityContent,
  189. "activityId": row.activityId,
  190. "activityMoney": row.activityMoney,
  191. "endTime": row.endTime,
  192. "startTime": row.startTime,
  193. "id":row.id
  194. }
  195. this.date = [row.startTime, row.endTime]
  196. },
  197. handleAdd() {
  198. this.title = '添加'
  199. this.dialogFormVisible = true
  200. this.setQuery = {
  201. "activityContent": "",
  202. "activityId": "",
  203. "activityMoney": 0,
  204. "endTime": "",
  205. "startTime": ""
  206. }
  207. this.date = []
  208. },
  209. // 删除
  210. handleDel(id) {
  211. this.$confirm(`此操作将删除该数据, 是否继续?`, '提示', {
  212. confirmButtonText: '确定',
  213. cancelButtonText: '取消',
  214. type: 'warning'
  215. }).then(() => {
  216. delActivityXiaoju({id}).then(res=>{
  217. if(res.state == 'Success'){
  218. this.$notify({
  219. title: '成功',
  220. message: '操作成功',
  221. type: 'success'
  222. });
  223. this.getList()
  224. }
  225. })
  226. })
  227. },
  228. handleSizeChange(val) {
  229. this.query.currentPage = 1;
  230. this.query.pageSize = val;
  231. this.getList();
  232. },
  233. handleCurrentChange(val) {
  234. this.query.currentPage = val;
  235. this.getList();
  236. },
  237. search() {
  238. this.query.currentPage = 1;
  239. this.getList();
  240. },
  241. getList() {
  242. this.loading = true
  243. activityXiaojuList(this.query).then((res) => {
  244. this.loading = false
  245. if (res.state == "Success") {
  246. this.tableData = res.content.records;
  247. this.total = res.content.total
  248. }
  249. });
  250. },
  251. save(){
  252. this.$refs.setQuery.validate((v) => {
  253. if (v) {
  254. this.btnLoading = true
  255. addOrUpdateActivityXiaoju(this.setQuery).then(res=>{
  256. this.btnLoading = false
  257. if(res.state == 'Success'){
  258. this.dialogFormVisible = false
  259. this.$notify({
  260. title: '成功',
  261. message: '操作成功',
  262. type: 'success'
  263. });
  264. this.query.currentPage = 1
  265. this.getList();
  266. }
  267. })
  268. }
  269. });
  270. }
  271. },
  272. created() {
  273. this.getList();
  274. },
  275. };
  276. </script>
  277. <style lang="scss" >
  278. .marketing {
  279. }
  280. </style>