_createjs.blade.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. @auth
  2. <script>
  3. new Vue({
  4. el: "#demand-div",
  5. data: {
  6. types: [{name:'0',value:'需求'},{name:'1',value:'问题'}],
  7. addDemand: {},
  8. authorities: [],
  9. authoritiesFilter: [],
  10. demandErrors: {}
  11. },
  12. created() {
  13. this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
  14. this.getAuthority();
  15. },
  16. mounted() {
  17. },
  18. methods: {
  19. /** 筛选 */
  20. filterAuth($e) {
  21. let value = $($e.target).val();
  22. let authorities = JSON.parse(JSON.stringify(this.authorities));
  23. if (value === null) {
  24. this.authoritiesFilter = authorities;
  25. return;
  26. }
  27. this.authoritiesFilter = authorities.filter(function (item) {
  28. return item['name'].includes(value);
  29. });
  30. if(this.authoritiesFilter.length > 0)
  31. this.addDemand.authority_id = this.authoritiesFilter[0]['id'];
  32. },
  33. /** 创建 */
  34. showAddDemand() {
  35. this.addDemand = {};
  36. this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
  37. $('#add-demand-auth-filter').val('');
  38. $('#add-demand').modal('show')
  39. if(this.authoritiesFilter.length === 0){
  40. if(this.authorities.length !==0)this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
  41. else this.getAuthority();
  42. }
  43. },
  44. /** 创建 */
  45. createDemand() {
  46. let url = '{{url('apiLocal/demand/store')}}';
  47. window.tempTip.setIndex(1999);
  48. window.tempTip.setDuration(3000);
  49. let formData = new FormData();
  50. let file = document.querySelector('#add-demand-file-create').files[0];
  51. if(this.addDemand['authority_id'])formData.append('authority_id', this.addDemand['authority_id']);
  52. if(this.addDemand['type'])formData.append('type', this.addDemand['type']);
  53. if(this.addDemand['description'])formData.append('description', this.addDemand['description']);
  54. if(file)formData.append('file', file);
  55. window.axios.post(url, formData, {
  56. 'Content-Type': 'multipart/form-data'
  57. }).then(res => {
  58. if (res.data.success) {
  59. window.tempTip.showSuccess('问题提交成功');
  60. $('#add-demand').modal('hide')
  61. return;
  62. }
  63. if(res.data.errors) this.demandErrors = res.data.errors;
  64. else window.tempTip.show('问题提交失败');
  65. }).catch(err => {
  66. window.tempTip.show(err);
  67. });
  68. },
  69. getAuthority(){
  70. let url = '{{url('apiLocal/authority/get')}}';
  71. window.axios.get(url).then(res=>{
  72. if(res.data.success){
  73. this.authorities = res.data.data;
  74. this.authoritiesFilter = res.data.data;
  75. this.$forceUpdate();
  76. }
  77. }).catch(err=>{
  78. window.tempTip.show(err);
  79. });
  80. },
  81. }
  82. });
  83. </script>
  84. @endauth