my.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <drawer-tabs-container>
  3. <div class="report-my">
  4. <!-- 按钮 -->
  5. <Button :loading="loadIng > 0" type="primary" icon="md-add" @click="[addDrawerId=0,addDrawerShow=true]">新建汇报</Button>
  6. <!-- 列表 -->
  7. <Table class="tableFill" ref="tableRef" :columns="columns" :data="lists" :loading="loadIng > 0" :no-data-text="noDataText" stripe></Table>
  8. <!-- 分页 -->
  9. <Page class="pageBox" :total="listTotal" :current="listPage" :disabled="loadIng > 0" @on-change="setPage" @on-page-size-change="setPageSize" :page-size-opts="[10,20,30,50,100]" placement="top" show-elevator show-sizer show-total transfer></Page>
  10. </div>
  11. <Drawer v-model="addDrawerShow" width="70%">
  12. <report-add :canload="addDrawerShow" :id="addDrawerId" @on-success="addDrawerSuccess"></report-add>
  13. </Drawer>
  14. </drawer-tabs-container>
  15. </template>
  16. <style lang="scss" scoped>
  17. .report-my {
  18. padding: 0 12px;
  19. .tableFill {
  20. margin: 12px 0 20px;
  21. }
  22. }
  23. </style>
  24. <script>
  25. import DrawerTabsContainer from "../DrawerTabsContainer";
  26. import ReportAdd from "./add";
  27. /**
  28. * 我的汇报
  29. */
  30. export default {
  31. name: 'ReportMy',
  32. components: {ReportAdd, DrawerTabsContainer},
  33. props: {
  34. canload: {
  35. type: Boolean,
  36. default: true
  37. },
  38. },
  39. data () {
  40. return {
  41. loadYet: false,
  42. loadIng: 0,
  43. columns: [],
  44. lists: [],
  45. listPage: 1,
  46. listTotal: 0,
  47. noDataText: "数据加载中.....",
  48. addDrawerId: 0,
  49. addDrawerShow: false,
  50. }
  51. },
  52. created() {
  53. this.columns = [{
  54. "title": "标题",
  55. "key": 'title',
  56. "minWidth": 120,
  57. }, {
  58. "title": "创建日期",
  59. "width": 160,
  60. "align": 'center',
  61. render: (h, params) => {
  62. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  63. }
  64. }, {
  65. "title": "类型",
  66. "key": 'type',
  67. "width": 80,
  68. "align": 'center',
  69. }, {
  70. "title": "状态",
  71. "key": 'status',
  72. "width": 80,
  73. "align": 'center',
  74. }, {
  75. "title": "操作",
  76. "key": 'action',
  77. "width": 140,
  78. "align": 'center',
  79. render: (h, params) => {
  80. let arr = [];
  81. arr.push(h('a', {
  82. style: {padding: '0 2px', fontSize: '12px'},
  83. on: {
  84. click: () => {
  85. }
  86. }
  87. }, '查看'));
  88. arr.push(h('a', {
  89. style: {padding: '0 2px', fontSize: '12px'},
  90. on: {
  91. click: () => {
  92. this.addDrawerId = params.row.id;
  93. this.addDrawerShow = true
  94. }
  95. }
  96. }, '编辑'));
  97. if (params.row.status == '未发送') {
  98. arr.push(h('a', {
  99. style: {padding: '0 2px', fontSize: '12px'},
  100. on: {
  101. click: () => {
  102. this.deleteReport(params.row);
  103. }
  104. }
  105. }, '删除'));
  106. arr.push(h('a', {
  107. style: {padding: '0 2px', fontSize: '12px'},
  108. on: {
  109. click: () => {
  110. this.sendReport(params.row);
  111. }
  112. }
  113. }, '发送'));
  114. }
  115. return h('div', arr);
  116. }
  117. }];
  118. },
  119. mounted() {
  120. if (this.canload) {
  121. this.loadYet = true;
  122. this.getLists(true);
  123. }
  124. },
  125. watch: {
  126. canload(val) {
  127. if (val && !this.loadYet) {
  128. this.loadYet = true;
  129. this.getLists(true);
  130. }
  131. }
  132. },
  133. methods: {
  134. setPage(page) {
  135. this.listPage = page;
  136. this.getLists();
  137. },
  138. setPageSize(size) {
  139. if (Math.max($A.runNum(this.listPageSize), 10) != size) {
  140. this.listPageSize = size;
  141. this.getLists();
  142. }
  143. },
  144. getLists(resetLoad) {
  145. if (resetLoad === true) {
  146. this.listPage = 1;
  147. }
  148. this.loadIng++;
  149. this.noDataText = "数据加载中.....";
  150. $A.aAjax({
  151. url: 'report/my',
  152. data: {
  153. page: Math.max(this.listPage, 1),
  154. pagesize: Math.max($A.runNum(this.listPageSize), 10),
  155. },
  156. complete: () => {
  157. this.loadIng--;
  158. },
  159. error: () => {
  160. this.noDataText = "数据加载失败!";
  161. },
  162. success: (res) => {
  163. if (res.ret === 1) {
  164. this.lists = res.data.lists;
  165. this.listTotal = res.data.total;
  166. this.noDataText = "没有相关的数据";
  167. } else {
  168. this.lists = [];
  169. this.listTotal = 0;
  170. this.noDataText = res.msg;
  171. }
  172. }
  173. });
  174. },
  175. addDrawerSuccess() {
  176. this.addDrawerShow = false;
  177. this.getLists(true);
  178. },
  179. sendReport(row) {
  180. this.$Modal.confirm({
  181. title: '发送汇报',
  182. content: '你确定要发送汇报吗?',
  183. loading: true,
  184. onOk: () => {
  185. $A.aAjax({
  186. url: 'report/template?act=send&id=' + row.id + '&type=' + row.type,
  187. error: () => {
  188. this.$Modal.remove();
  189. alert(this.$L('网络繁忙,请稍后再试!'));
  190. },
  191. success: (res) => {
  192. this.$Modal.remove();
  193. this.$set(row, 'status', '已发送');
  194. setTimeout(() => {
  195. if (res.ret === 1) {
  196. this.$Message.success(res.msg);
  197. } else {
  198. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  199. }
  200. }, 350);
  201. }
  202. });
  203. }
  204. });
  205. },
  206. deleteReport(row) {
  207. this.$Modal.confirm({
  208. title: '删除汇报',
  209. content: '你确定要删除汇报吗?',
  210. loading: true,
  211. onOk: () => {
  212. $A.aAjax({
  213. url: 'report/template?act=delete&id=' + row.id + '&type=' + row.type,
  214. error: () => {
  215. this.$Modal.remove();
  216. alert(this.$L('网络繁忙,请稍后再试!'));
  217. },
  218. success: (res) => {
  219. this.$Modal.remove();
  220. this.lists.some((item, index) => {
  221. if (item.id == row.id) {
  222. this.lists.splice(index, 1);
  223. return true;
  224. }
  225. })
  226. setTimeout(() => {
  227. if (res.ret === 1) {
  228. this.$Message.success(res.msg);
  229. } else {
  230. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  231. }
  232. }, 350);
  233. }
  234. });
  235. }
  236. });
  237. }
  238. }
  239. }
  240. </script>