| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- @auth
- <script>
- new Vue({
- el: "#demand-div",
- data: {
- types: [{name:'0',value:'需求'},{name:'1',value:'问题'}],
- addDemand: {},
- authorities: [],
- authoritiesFilter: [],
- demandErrors: {}
- },
- created() {
- this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
- this.getAuthority();
- },
- mounted() {
- },
- methods: {
- /** 筛选 */
- filterAuth($e) {
- let value = $($e.target).val();
- let authorities = JSON.parse(JSON.stringify(this.authorities));
- if (value === null) {
- this.authoritiesFilter = authorities;
- return;
- }
- this.authoritiesFilter = authorities.filter(function (item) {
- return item['name'].includes(value);
- });
- if(this.authoritiesFilter.length > 0)
- this.addDemand.authority_id = this.authoritiesFilter[0]['id'];
- },
- /** 创建 */
- showAddDemand() {
- this.addDemand = {};
- this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
- $('#add-demand-auth-filter').val('');
- $('#add-demand').modal('show')
- if(this.authoritiesFilter.length === 0){
- if(this.authorities.length !==0)this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
- else this.getAuthority();
- }
- },
- /** 创建 */
- createDemand() {
- let url = '{{url('apiLocal/demand/store')}}';
- window.tempTip.setIndex(1999);
- window.tempTip.setDuration(3000);
- let formData = new FormData();
- let file = document.querySelector('#add-demand-file-create').files[0];
- if(this.addDemand['authority_id'])formData.append('authority_id', this.addDemand['authority_id']);
- if(this.addDemand['type'])formData.append('type', this.addDemand['type']);
- if(this.addDemand['description'])formData.append('description', this.addDemand['description']);
- if(file)formData.append('file', file);
- window.axios.post(url, formData, {
- 'Content-Type': 'multipart/form-data'
- }).then(res => {
- if (res.data.success) {
- window.tempTip.showSuccess('问题提交成功');
- $('#add-demand').modal('hide')
- return;
- }
- if(res.data.errors) this.demandErrors = res.data.errors;
- else window.tempTip.show('问题提交失败');
- }).catch(err => {
- window.tempTip.show(err);
- });
- },
- getAuthority(){
- let url = '{{url('apiLocal/authority/get')}}';
- window.axios.get(url).then(res=>{
- if(res.data.success){
- this.authorities = res.data.data;
- this.authoritiesFilter = res.data.data;
- this.$forceUpdate();
- }
- }).catch(err=>{
- window.tempTip.show(err);
- });
- },
- }
- });
- </script>
- @endauth
|