index.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. @extends('layouts.app')
  2. @section('title','需求')
  3. @section('content')
  4. {{-- <nav id="nav2">--}}
  5. {{-- @component('demand.menu')@endcomponent--}}
  6. {{-- @component('demand.search.menu')@endcomponent--}}
  7. {{-- </nav>--}}
  8. <div class="container-fluid d-none" id="list">
  9. <div id="form_div"></div>
  10. @include('demand.search._table')
  11. @include('demand.search._uploadFile')
  12. </div>
  13. @endsection
  14. @section('lastScript')
  15. <script src="{{mix('js/queryForm/queryForm.js')}}"></script>
  16. <script>
  17. let demand_vue = new Vue({
  18. el: '#list',
  19. data: {
  20. demands: {!! $demands->toJson() !!}['data'],
  21. status: [
  22. {name: 0, value: '未处理'}, {name: 1, value: '处理中'}, {name: 2, value: '已处理'},
  23. ],
  24. types: [
  25. {name: 0, value: '需求'}, {name: 1, value: '问题'}
  26. ],
  27. selectTr: null,
  28. uploadError: [],
  29. selectDemand: null,
  30. selectIndex: null,
  31. imgs: [],
  32. },
  33. created() {
  34. let that = this;
  35. this.demands.forEach(function (item, index, self) {
  36. that.initDemand(self[index]);
  37. });
  38. },
  39. mounted() {
  40. this.imgs = Array.from(document.getElementById('list').querySelectorAll('img'));
  41. this.lazy();
  42. if (this.imgs && this.imgs.length > 0) {
  43. window.addEventListener('scroll', this.lazy)
  44. }
  45. $('#list').removeClass('d-none');
  46. let data = [
  47. [
  48. {name: 'created_at_start', type: 'time', tip: '创建开始时间'},
  49. {name: 'created_at_end', type: 'time', tip: '创建结束时间'},
  50. {name: 'type', type: 'select', data: this.types, placeholder: '类型'},
  51. ]
  52. ];
  53. let form = new query({
  54. el: "#form_div",
  55. condition: data,
  56. });
  57. form.init();
  58. },
  59. methods: {
  60. initDemand(demand) {
  61. demand['status'] = this.status[demand['status']]['value'] ?? '';
  62. demand['type'] = this.types[demand['type']]['value'] ?? '';
  63. demand['showAddDiv']= false;
  64. demand['showAddBtn']= false;
  65. if (demand['upload_file']) this.setImgUrl(demand['upload_file']);
  66. if (demand['processes']){
  67. demand['processes'].forEach(function(item,index,self){
  68. self[index]['status'] = false;
  69. });
  70. }
  71. },
  72. setImgUrl(uploadFile) {
  73. let url = '{{url('/storage/')}}';
  74. let urlPath = uploadFile['url'];
  75. let type = uploadFile.type;
  76. uploadFile['url'] = url + urlPath + '-thumbnail.' + type;
  77. uploadFile['bulkyUrl'] = url + urlPath + '-bulky.' + type;
  78. uploadFile['commonUrl'] = url + urlPath + '-common.' + type;
  79. },
  80. /** 完结需求 */
  81. finishDemand(demand,index) {
  82. let url = '{{url('apiLocal/demand/finish')}}';
  83. window.tempTip.setDuration(3000);
  84. window.axios.post(url, {id: demand['id']}).then(res => {
  85. if (res.data.success) {
  86. window.tempTip.showSuccess('需求完结成功');
  87. demand.status = '已处理'
  88. return;
  89. }
  90. window.tempTip.show('需求完结失败' + res.data.data);
  91. }).catch(err => {
  92. window.tempTip.show('需求完结异常' + err);
  93. });
  94. },
  95. /** 删除 */
  96. destroyDemand(demand, index) {
  97. if (!confirm('确定要删除当前需求吗?')) {
  98. return;
  99. }
  100. let url = '{{url('apiLocal/demand/destroy?id=')}}' + demand['id'];
  101. window.axios.delete(url).then(res => {
  102. if (res.data.success) {
  103. window.tempTip.showSuccess('删除成功!');
  104. this.$delete(this.demands,index);
  105. this.imgs = Array.from(document.getElementById('list').querySelectorAll('img'));
  106. this.lazy();
  107. this.$forceUpdate();
  108. return;
  109. }
  110. window.tempTip.show(res.data.data);
  111. }).catch(err => {
  112. window.tempTip.show('删除出现异常' + err);
  113. });
  114. },
  115. /** 添加处理过程 */
  116. addProcess(demand) {
  117. window.tempTip.setDuration(3000);
  118. let url = '{{url('apiLocal/demand/process/store')}}';
  119. let process = $('#addProcess'+demand['id']).val();
  120. let data = {'demand_id': demand['id'], 'explain': process};
  121. if(process === null || process.length === 0){
  122. window.tempTip.show('输入内容');
  123. $('#addProcess'+demand['id']).focus();
  124. return;
  125. }
  126. window.axios.post(url, data).then(res => {
  127. if (res.data.success) {
  128. if(!demand['processes'])demand['processes']= [res.data.data];
  129. else demand['processes'].unshift(res.data.data);
  130. this.$forceUpdate();
  131. window.tempTip.showSuccess('添加处理过程成功');
  132. $('#addProcess'+demand['id']).val();
  133. this.toggleAddDiv(demand,demand['id']);
  134. return;
  135. }
  136. $('#addProcess'+demand['id']).focus();
  137. window.tempTip.show('添加处理过程失败')
  138. }).catch(err => {
  139. $('#addProcess'+demand['id']).focus();
  140. window.tempTip.show('添加处理过程异常:' + err);
  141. });
  142. },
  143. /** 文件上传 */
  144. uploadFile() {
  145. let fileInput = document.querySelector('#upLoadFile-input');
  146. let url = '{{url('apiLocal/demand/uploadFile')}}';
  147. let formData = new FormData();
  148. formData.append('id', this.selectDemand);
  149. let file = fileInput.files[0];
  150. formData.append('file', file);
  151. tempTip.setDuration(9999)
  152. tempTip.setIndex(1051)
  153. tempTip.waitingTip('上传中......');
  154. if(fileInput.files.length === 0){
  155. tempTip.cancelWaitingTip();
  156. this.uploadError = ['请选择上传文件'];
  157. return;
  158. }
  159. let that = this;
  160. window.axios.post(url, formData, {
  161. 'Content-Type': 'multipart/form-data'
  162. }).then(res => {
  163. tempTip.cancelWaitingTip()
  164. tempTip.setDuration(2000)
  165. if (res.data.success) {
  166. this.initDemand(res.data.data);
  167. this.$set(this.demands, this.selectIndex, res.data.data);
  168. $('#uploadFile').modal('hide');
  169. setTimeout(function(){
  170. that.imgs.push(document.getElementById('img_'+res.data.data['id']));
  171. that.lazy();
  172. },1);
  173. window.tempTip.showSuccess('文件上传成功');
  174. this.$forceUpdate();
  175. return;
  176. }
  177. if(res.data.errors)this.uploadError = res.data.errors;
  178. window.tempTip.show('文件上传失败');
  179. }).catch(err => {
  180. tempTip.cancelWaitingTip()
  181. window.tempTip.show('文件上传异常:' + err);
  182. });
  183. },
  184. /** 修改需求描述 */
  185. updateDemand(demand, column, $e) {
  186. let url = '{{url('apiLocal/demand/update')}}';
  187. let data = {'id': demand['id']};
  188. let value = $($e.target).val();
  189. data[column] = value;
  190. window.tempTip.setDuration(3000);
  191. window.axios.post(url, data).then(res => {
  192. if (res.data.success) {
  193. demand[column] = value;
  194. this.$forceUpdate();
  195. window.tempTip.showSuccess('修改需求成功');
  196. return;
  197. }
  198. window.tempTip.show(res.data.data);
  199. }).catch(err => {
  200. window.tempTip.show('修改需求描述异常:' + err);
  201. });
  202. },
  203. /** 问题认领 */
  204. claimDemand(demand, index) {
  205. let url = '{{url('apiLocal/demand/claim')}}';
  206. window.tempTip.setDuration(3000);
  207. window.axios.post(url, {id: demand['id']}).then(res => {
  208. if (res.data.success) {
  209. this.initDemand(res.data.data);
  210. this.$set(this.demands, index, res.data.data);
  211. window.tempTip.showSuccess('认领成功!');
  212. return;
  213. }
  214. if (res.data.errors) window.tempTip.show(res.data.errors);
  215. else window.tempTip.show(res.data.data);
  216. }).catch(err => {
  217. window.tempTip.show('认领出现异常' + err);
  218. });
  219. },
  220. showUploadDiv(demand, index) {
  221. this.selectDemand = demand['id'];
  222. this.selectIndex = index;
  223. this.uploadError = [];
  224. $('#uploadFile').modal('show');
  225. },
  226. lazy() {
  227. //可视区域高度
  228. let height = window.innerHeight;
  229. //滚动区域高度
  230. let scrollHeight = document.documentElement.scrollTop || document.body.scrollTop;
  231. let _this = this;
  232. this.imgs.forEach(function (img, i) {
  233. if ((height + scrollHeight) > $('#' + img.getAttribute('id')).offset().top && img.getAttribute('data-src')) {
  234. let temp = new Image();
  235. temp.src = img.getAttribute('data-src');
  236. temp.onload = function () {
  237. img.src = img.getAttribute('data-src');
  238. _this.$delete(_this.imgs, i);
  239. }
  240. }
  241. });
  242. },
  243. removeCommonImg(id) {
  244. $('#' + id).remove();
  245. },
  246. commonImg(id, demand,index) {
  247. if (!demand['upload_file']) return;
  248. let bulkyUrl = demand['upload_file']['bulkyUrl'];
  249. let commonUrl = demand['upload_file']['commonUrl'];
  250. $('#' + id).after(
  251. "<div id=\"imgBulky_" + demand['id'] + "\" style='position: absolute;padding-top: 2px;z-index: 99'>" +
  252. "<div style='position:absolute'>" +
  253. "<div >" +
  254. "<a target='_blank' href='" + bulkyUrl + "'>" +
  255. "<img src='" + commonUrl + "'" + "style='position: relative;left:-50px;' >" +
  256. "</a>" +
  257. "</div>" +
  258. "<button type='button' class='btn btn-sm btn-danger' onclick='demand_vue.btnDeleteImg(this,"+index+")' value='" + id + "' style='position: relative;float: right;margin-right: 51px;margin-top: -30px;' >删除</button>" +
  259. "</div>" +
  260. "</div>");
  261. },
  262. btnDeleteImg(e,index) {
  263. let idStr = $(e).val()
  264. let id = idStr.substr(idStr.indexOf('_') + 1)
  265. if (!confirm('确定要删除所选图片吗?')) return;
  266. this.destroyImg(id,index);
  267. },
  268. destroyImg(id,index) {
  269. let url = '{{url('apiLocal/demand/destroyFile/?id=')}}'+id;
  270. window.tempTip.setDuration(3000);
  271. window.axios.delete(url).then(res=>{
  272. if(res.data.success){
  273. window.tempTip.showSuccess('附件删除成功!');
  274. this.$delete(this.demands[index],['upload_file']);
  275. this.$forceUpdate();
  276. return ;
  277. }
  278. window.tempTip.show('附件删除异常:'+res.data.data);
  279. }).catch(err=>{
  280. window.tempTip.show(err);
  281. });
  282. },
  283. toggleAddDiv(demand,id){
  284. let div = $('#addDiv_'+id);
  285. if(demand['showAddDiv']){
  286. div.addClass('d-none');
  287. }else{
  288. div.removeClass('d-none');
  289. }
  290. demand['showAddDiv'] = !demand['showAddDiv'];
  291. },
  292. toggleDelBtn(demandId,process){
  293. let btn = $('#demand-'+demandId+'process-'+process['id']);
  294. if(process['status']){
  295. btn.addClass('d-none');
  296. }else{
  297. btn.removeClass('d-none');
  298. }
  299. process['status'] = !process['status'];
  300. },
  301. showAddBtn(demand){
  302. if(demand['showAddBtn']){
  303. $("#addBtn_"+demand.id).addClass('d-none');
  304. }else{
  305. $("#addBtn_"+demand.id).removeClass('d-none');
  306. }
  307. demand['showAddBtn'] = !demand['showAddBtn'];
  308. },
  309. deleteProcess(demand,process,process_i,index){
  310. if (!confirm('确定要删除当前描述吗?')) {
  311. return;
  312. }
  313. let url = '{{url('apiLocal/demand/process/destroy/?id=')}}'+ process['id'];
  314. window.tempTip.setDuration(3000);
  315. window.axios.delete(url).then(res=>{
  316. if(res.data.success){
  317. this.$delete(this.demands[index]['processes'],process_i);
  318. demand.processes.slice(process_i,0);
  319. window.tempTip.showSuccess('描述删除成功!');
  320. this.$forceUpdate();
  321. return;
  322. }
  323. window.tempTip.show('描述删除失败!'+res.data.data ? res.data.data : '' );
  324. }).catch(err=>{
  325. window.tempTip.show(err);
  326. });
  327. }
  328. }
  329. });
  330. </script>
  331. @endsection