reason.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template> 
  2. <div class="app-container">
  3. <el-card class="operate-container" shadow="never">
  4. <i class="el-icon-tickets"></i>
  5. <span>数据列表</span>
  6. <el-button
  7. size="mini"
  8. @click="handleAdd"
  9. class="btn-add">添加
  10. </el-button>
  11. </el-card>
  12. <div class="table-container">
  13. <el-table ref="returnReasonTable"
  14. :data="list"
  15. style="width: 100%;"
  16. @selection-change="handleSelectionChange"
  17. v-loading="listLoading" border>
  18. <el-table-column type="selection" width="60" align="center"></el-table-column>
  19. <el-table-column label="编号" width="80" align="center">
  20. <template slot-scope="scope">{{scope.row.id}}</template>
  21. </el-table-column>
  22. <el-table-column label="原因类型" align="center">
  23. <template slot-scope="scope">{{scope.row.name}}</template>
  24. </el-table-column>
  25. <el-table-column label="排序" width="100" align="center">
  26. <template slot-scope="scope">{{scope.row.sort }}</template>
  27. </el-table-column>
  28. <el-table-column label="是否可用" align="center">
  29. <template slot-scope="scope">
  30. <el-switch
  31. v-model="scope.row.status"
  32. @change="handleStatusChange(scope.$index,scope.row)"
  33. :active-value="1"
  34. :inactive-value="0">
  35. </el-switch>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="添加时间" width="180" align="center">
  39. <template slot-scope="scope">{{scope.row.createTime | formatCreateTime}}</template>
  40. </el-table-column>
  41. <el-table-column label="操作" width="160" align="center">
  42. <template slot-scope="scope">
  43. <el-button
  44. size="mini"
  45. @click="handleUpdate(scope.$index, scope.row)">编辑</el-button>
  46. <el-button
  47. size="mini"
  48. @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. </div>
  53. <!-- <div class="batch-operate-container">
  54. <el-select
  55. size="small"
  56. v-model="operateType" placeholder="批量操作">
  57. <el-option
  58. v-for="item in operateOptions"
  59. :key="item.value"
  60. :label="item.label"
  61. :value="item.value">
  62. </el-option>
  63. </el-select>
  64. <el-button
  65. style="margin-left: 20px"
  66. class="search-button"
  67. @click="handleBatchOperate"
  68. type="primary"
  69. size="small">
  70. 确定
  71. </el-button>
  72. </div> -->
  73. <div class="pagination-container">
  74. <el-pagination
  75. background
  76. @size-change="handleSizeChange"
  77. @current-change="handleCurrentChange"
  78. layout="total, sizes,prev, pager, next,jumper"
  79. :current-page.sync="listQuery.pageNum"
  80. :page-size="listQuery.pageSize"
  81. :page-sizes="[5,10,15]"
  82. :total="total">
  83. </el-pagination>
  84. </div>
  85. <el-dialog
  86. title="添加退货原因"
  87. :visible.sync="dialogVisible" width="30%">
  88. <el-form :model="returnReason"
  89. ref="reasonForm" label-width="150px">
  90. <el-form-item label="原因类型:">
  91. <el-input v-model="returnReason.name" class="input-width"></el-input>
  92. </el-form-item>
  93. <el-form-item label="排序:">
  94. <el-input v-model="returnReason.sort" class="input-width"></el-input>
  95. </el-form-item>
  96. <el-form-item label="是否启用:">
  97. <el-switch v-model="returnReason.status" :active-value="1" :inactive-value="0"></el-switch>
  98. </el-form-item>
  99. </el-form>
  100. <span slot="footer" class="dialog-footer">
  101. <el-button @click="dialogVisible = false">取 消</el-button>
  102. <el-button type="primary" @click="handleConfirm">确 定</el-button>
  103. </span>
  104. </el-dialog>
  105. </div>
  106. </template>
  107. <script>
  108. import {formatDate} from '@/utils/date';
  109. import {fetchList,deleteReason,updateStatus,addReason,getReasonDetail,updateReason} from '@/api/returnReason';
  110. const defaultListQuery = {
  111. pageNum: 1,
  112. pageSize: 5
  113. };
  114. const defaultReturnReason = {
  115. name:null,
  116. sort:0,
  117. status:1,
  118. createTime:null
  119. };
  120. export default {
  121. name: 'returnReasonList',
  122. data() {
  123. return {
  124. list: null,
  125. total: null,
  126. multipleSelection: [],
  127. listLoading:true,
  128. listQuery:Object.assign({}, defaultListQuery),
  129. operateType:null,
  130. operateOptions: [
  131. {
  132. label: "删除",
  133. value: 1
  134. }
  135. ],
  136. dialogVisible:false,
  137. returnReason:Object.assign({},defaultReturnReason),
  138. operateReasonId:null
  139. }
  140. },
  141. created(){
  142. this.getList();
  143. },
  144. filters:{
  145. formatCreateTime(time) {
  146. let date = new Date(time);
  147. return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
  148. }
  149. },
  150. methods: {
  151. handleAdd() {
  152. this.dialogVisible=true;
  153. this.operateReasonId=null;
  154. this.returnReason=Object.assign({},defaultReturnReason);
  155. },
  156. handleConfirm(){
  157. if(this.operateReasonId==null){
  158. //添加操作
  159. addReason(this.returnReason).then(response=>{
  160. this.dialogVisible=false;
  161. this.operateReasonId=null;
  162. this.$message({
  163. message: '添加成功!',
  164. type: 'success',
  165. duration:1000
  166. });
  167. this.getList();
  168. });
  169. }else{
  170. //编辑操作
  171. updateReason(this.operateReasonId,this.returnReason).then(response=>{
  172. this.dialogVisible=false;
  173. this.operateReasonId=null;
  174. this.$message({
  175. message: '修改成功!',
  176. type: 'success',
  177. duration:1000
  178. });
  179. this.getList();
  180. });
  181. }
  182. },
  183. handleUpdate(index, row){
  184. this.dialogVisible=true;
  185. this.operateReasonId=row.id;
  186. getReasonDetail(row.id).then(response=>{
  187. this.returnReason=response.data;
  188. });
  189. },
  190. handleDelete(index, row){
  191. let ids=[];
  192. ids.push(row.id);
  193. this.deleteReason(ids);
  194. },
  195. handleSelectionChange(val){
  196. this.multipleSelection = val;
  197. },
  198. handleStatusChange(index,row){
  199. let ids=[];
  200. ids.push(row.id);
  201. // let param = new URLSearchParams();
  202. // param.append("status",row.status);
  203. // param.append("ids",ids);
  204. let obj = {
  205. status:row.status,
  206. ids:ids.join(',')
  207. }
  208. updateStatus(obj).then(response=>{
  209. this.$message({
  210. message: '状态修改成功',
  211. type: 'success'
  212. });
  213. });
  214. },
  215. handleBatchOperate(){
  216. if(this.multipleSelection==null||this.multipleSelection.length<1){
  217. this.$message({
  218. message: '请选择要操作的条目',
  219. type: 'warning',
  220. duration: 1000
  221. });
  222. return;
  223. }
  224. if(this.operateType===1){
  225. let ids=[];
  226. for(let i=0;i<this.multipleSelection.length;i++){
  227. ids.push(this.multipleSelection[i].id);
  228. }
  229. this.deleteReason(ids);
  230. }
  231. },
  232. handleSizeChange(val){
  233. this.listQuery.pageNum = 1;
  234. this.listQuery.pageSize = val;
  235. this.getList();
  236. },
  237. handleCurrentChange(val){
  238. this.listQuery.pageNum = val;
  239. this.getList();
  240. },
  241. getList(){
  242. this.listLoading = true;
  243. fetchList(this.listQuery).then(response => {
  244. this.listLoading = false;
  245. this.list = response.data.list;
  246. this.total = response.data.total;
  247. });
  248. },
  249. deleteReason(ids){
  250. this.$confirm('是否要进行该删除操作?', '提示', {
  251. confirmButtonText: '确定',
  252. cancelButtonText: '取消',
  253. type: 'warning'
  254. }).then(() => {
  255. // let params = new URLSearchParams();
  256. // params.append("ids",ids);
  257. let obj = {
  258. ids:ids.join(',')
  259. }
  260. deleteReason(obj).then(response=>{
  261. this.$message({
  262. message: '删除成功!',
  263. type: 'success',
  264. duration: 1000
  265. });
  266. this.listQuery.pageNum=1;
  267. this.getList();
  268. });
  269. })
  270. },
  271. }
  272. }
  273. </script>
  274. <style scoped>
  275. .input-width {
  276. width: 80%;
  277. }
  278. </style>