SafeQualityCheckEdit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <view>
  3. <uni-forms ref="form" labelPosition="left" labelAlign="left" @submit="submitForm">
  4. <view class="uni-form-item uni-column">
  5. <view class="title"><text class="uni-form-item__title">工程名称</text></view>
  6. <view class="uni-input-wrapper">
  7. <input class="uni-input" focus placeholder="请填写工程名称" v-model="projectName" />
  8. </view>
  9. </view>
  10. <view class="uni-form-item uni-column">
  11. <view class="title"><text class="uni-form-item__title">检查日期</text></view>
  12. <view class="uni-input-wrapper" style="justify-content: left;">
  13. <picker mode="date" @change="bindDateChange" v-model="checkDate" style="width: 100%;">
  14. <view class="uni-input">{{checkDate}}</view>
  15. </picker>
  16. </view>
  17. </view>
  18. <view class="uni-form-item uni-column">
  19. <view class="title" style="background-color: #efefef;"><text class="uni-form-item__title">上传文件</text></view>
  20. <view class="content">
  21. <g-upfile ref='gUpfile' :mode="imgList" @chooseFile='chooseFile' @imgDelete='imgDelete' :control='control'
  22. :columnNum="columnNum" :maxCount="maxCount" @limitFileSizeList='limitFileSizeList' @limitFileTypeList='limitFileTypeList' :maxFileSize="2000"></g-upfile>
  23. </view>
  24. </view>
  25. <uni-section :title="detailTitle" type="line">
  26. <button type="default" @click="getRelationItem" size="mini">选择检查项</button>
  27. </uni-section>
  28. <uni-list>
  29. <uni-list-item v-if="itemList" v-for="(item, index) in itemList" :key="index">
  30. <view slot="body" class="slot-box">
  31. <view class="row">
  32. <view class="column-left">检查项目:</view>
  33. <view class="column-right">{{item.checkContent}}</view>
  34. </view>
  35. <view class="row">
  36. <view class="column-left">检查结果:</view>
  37. <view class="column-right">
  38. <textarea focus v-model="item.checkResult" placeholder="请填写" auto-height="true" style="width: 240px;text-align: left;" />
  39. </view>
  40. </view>
  41. <view class="row">
  42. <view class="column-left">操作:</view>
  43. <view class="column-right">
  44. <i class="fa fa-window-close" aria-hidden="true" @click="delRow(index)" style="font-size:20px;cursor: pointer;color: #999;margin-left:15px;" title="删除"></i>
  45. </view>
  46. </view>
  47. </view>
  48. </uni-list-item>
  49. </uni-list>
  50. <view style="margin-bottom: 120px;">
  51. </view>
  52. <view class="uni-btn-v uni-column">
  53. <button type="primary" form-type="submit" style="border-radius: 15px;" >提交</button>
  54. </view>
  55. </uni-forms>
  56. </view>
  57. </template>
  58. <script>
  59. import {GetSafeQualityCheckDTO,UpdateSafeQualityCheck} from "@/common/api/SafeQualityCheckApi.js";
  60. import {Decimal} from 'decimal.js'; //decimal计算
  61. export default {
  62. data() {
  63. return {
  64. projectName:'',
  65. checkDate:this.$util.getDate({
  66. format: true
  67. }),
  68. entity:{}, //主表对象
  69. itemList:[], //检查明细
  70. imageList: [],
  71. checkType:0, //核对质量安全检查项与主表的类型是否一致
  72. detailTitle:'',
  73. type:0, //检查项目类型
  74. countIndex: 5,
  75. count: [1, 2, 3, 4, 5],
  76. title1: 'picker',
  77. array: [],
  78. index: 0,
  79. control: true,
  80. columnNum: 3,
  81. imgList: [],
  82. urlList:[],
  83. maxCount:5
  84. }
  85. },
  86. onLoad(){
  87. //console.info(page.path);
  88. //console.info(this);
  89. this.$util.persistLogin(this);
  90. //console.info(this.$store.state.user);
  91. },
  92. onUnload() {
  93. },
  94. created: function() {
  95. this.getList();
  96. },
  97. updated:function(){
  98. console.info('updated');
  99. //this.auditType();
  100. },
  101. methods: {
  102. /**
  103. * 手动提交
  104. * @param {Object} form
  105. */
  106. submitForm(e) {
  107. console.info('submitForm');
  108. let _this=this;
  109. if(this.projectName==='')
  110. {
  111. uni.showToast({
  112. icon:"none",
  113. title:"请填写工程名称",
  114. duration:3000
  115. });
  116. return;
  117. }
  118. if(this.checkDate==='')
  119. {
  120. uni.showToast({
  121. icon:"none",
  122. title:"请选择检查日期",
  123. duration:3000
  124. });
  125. return;
  126. }
  127. if(this.itemList.length<=0){
  128. uni.showToast({
  129. icon:"none",
  130. title:"请选择质量安全检查项",
  131. duration:3000
  132. });
  133. return;
  134. }
  135. let list=[];
  136. let itemNames=[];
  137. this.itemList.forEach(function(item,index,arr){
  138. if(item.checkResult==null||item.checkResult==''){
  139. itemNames.push(item.checkContent);
  140. return;
  141. }
  142. list.push({checkContent:item.checkContent,checkResult:item.checkResult,dictionaryItemCode:item.dictionaryItemCode,dictionaryNameCode:item.dictionaryNameCode });
  143. });
  144. if(itemNames.length>0){
  145. uni.showToast({
  146. title:itemNames[0]+' 检查结果不能为空',
  147. duration:3000,
  148. icon:"none"
  149. });
  150. return;
  151. }
  152. //vise viseCosts
  153. var data1={checkCode:this.entity.checkCode,projectName:this.projectName,checkDate:this.checkDate };
  154. var data={SafeQualityCheck:data1,ItemList:list};
  155. console.info('data:',data);
  156. //return;
  157. UpdateSafeQualityCheck(data).then((res)=>{
  158. console.info("提交后的response",res);
  159. if(res){
  160. if(res=="-1"){
  161. uni.showToast({
  162. title:'修改失败,记录不存在',
  163. icon:'none',
  164. duration:3000
  165. });
  166. return;
  167. }
  168. if(res=="-2"){
  169. uni.showToast({
  170. title:'非申请状态,不能修改',
  171. icon:'none',
  172. duration:3000
  173. });
  174. return;
  175. }
  176. if(res=="-3"){
  177. uni.showToast({
  178. title:'所选检查项目类型与工程所属项目类型不一致',
  179. icon:'none',
  180. duration:3000
  181. });
  182. return;
  183. }
  184. //上传图片
  185. _this.uploadFileToServe(res) ;
  186. uni.navigateTo({
  187. url:'/pages/template/GetSafeQualityCheckDTOs/GetSafeQualityCheckDTOs'
  188. })
  189. }
  190. else{
  191. uni.showToast({
  192. title:'添加失败,重新操作',
  193. icon:'none',
  194. duration:3000
  195. })
  196. }
  197. });
  198. },
  199. /* 获取质量安全检查主表和明细表的信息*/
  200. getList(){
  201. let _this=this;
  202. let checkcode=_this.$util.getQuery("id");
  203. //console.info('getList',_this.$util.getQuery("id"));
  204. if(!checkcode){
  205. uni.showToast({
  206. title:'参数错误',
  207. icon:'none',
  208. duration:3000
  209. });
  210. return;
  211. }
  212. GetSafeQualityCheckDTO(checkcode).then(res=>{
  213. console.info('GetSafeQualityCheckDTO',res);
  214. _this.projectName=res.entity.projectName;
  215. _this.checkDate=res.entity.checkDate.substring(0,10);
  216. _this.entity=res.entity;
  217. _this.itemList=res.list;
  218. let title='';
  219. if(_this.entity.checkType=='SafeCheck'){
  220. title='安全检查修改';
  221. _this.detailTitle='安全检查项目';
  222. _this.type=1;
  223. }
  224. else if(_this.entity.checkType=='QualityCheck'){
  225. title='质量检查修改';
  226. _this.detailTitle='质量检查项目';
  227. _this.type=0;
  228. }
  229. uni.setNavigationBarTitle({
  230. title:title
  231. });
  232. });
  233. },
  234. auditType(){
  235. if(this.checkType==1){
  236. console.info('jinru1');
  237. uni.showToast({
  238. title:'此修改项是安全检查,不能选择质量检查项',
  239. icon:'none',
  240. duration:3000
  241. });
  242. console.info('jinru1结束');
  243. //this.checkType=0;
  244. }
  245. else if(this.checkType==2){
  246. console.info('jinru2');
  247. uni.showToast({
  248. title:'此修改项是质量检查,不能选择安全检查项',
  249. icon:'none',
  250. duration:3000
  251. });
  252. //this.checkType=0;
  253. }
  254. },
  255. /*
  256. 获取关联项
  257. */
  258. getRelationItem() {
  259. let _this = this;
  260. _this.saveTemp(_this);
  261. //console.info("getRelationItem", _this.$util.getQuery("id"));
  262. let checkCode=_this.$util.getQuery("id");
  263. //创建名字为fire的监听器,监听子页面传值事件
  264. uni.$on('items', function(data) {
  265. console.info("监听getRelationItem子页面的传值", data);
  266. //console.info('监听',_this);
  267. //return;
  268. _this.getTemp(_this);
  269. let itemList=_this.itemList;
  270. let result=[];
  271. if(data) {
  272. //console.info("转换id",_this.$util.getQuery("id"));
  273. //转换
  274. data.forEach(function(item,index,arr){
  275. result.push({checkCode:checkCode,checkContent:item.diName,checkResult:'',dictionaryItemCode:item.diCode,dictionaryNameCode:item.dnCode});
  276. });
  277. console.info("转换",result);
  278. //return;
  279. //let checkType=0;
  280. result.forEach(function(item,index,arr){
  281. item.remark='';
  282. let has=false;
  283. for(var i=0;i<itemList.length;i++){
  284. console.info('itemList[i].dictionaryItemCode',itemList[i].dictionaryItemCode);
  285. console.info('item.dictionaryItemCode',item.dictionaryItemCode);
  286. if(itemList[i].dictionaryItemCode==item.dictionaryItemCode){
  287. has=true;
  288. break;
  289. }
  290. }
  291. if(!has){
  292. if(_this.entity.checkType=='SafeCheck'){
  293. if(item.dictionaryNameCode!='10035'){
  294. _this.checkType=1;
  295. _this.$nextTick(function(){
  296. console.info(_this.checkType);
  297. });
  298. console.info('checkType',_this.checkType);
  299. return;
  300. }
  301. }
  302. else{
  303. if(item.dictionaryNameCode!='10034'){
  304. _this.checkType=2;
  305. _this.$nextTick(function(){
  306. console.info(_this.checkType);
  307. });
  308. console.info('checkType',_this.checkType);
  309. return;
  310. }
  311. }
  312. _this.itemList.push(item);
  313. }
  314. });
  315. console.info("监听后的明细增加",_this.itemList);
  316. }
  317. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  318. uni.$off("items");
  319. });
  320. uni.navigateTo({
  321. url: '/pages/template/SelectCheckProject/SelectCheckProject?type='+_this.type
  322. });
  323. },
  324. delRow: function(index) {
  325. console.info("删除");
  326. console.info(this.itemList[index]);
  327. this.itemList.splice(index, 1);
  328. },
  329. bindPickerChange: function(e) {
  330. //console.log('picker发送选择改变,携带值为:' + e.detail.value);
  331. //console.info(e.detail);
  332. this.index = e.detail.value;
  333. this.viseType=this.array[this.index];
  334. console.info(this.viseType);
  335. },
  336. bindDateChange: function(e) {
  337. let date = e.detail.value;
  338. this.checkDate=date;
  339. console.info('bindDateChange',this.checkDate);
  340. },
  341. /*
  342. 上传后返回的值:
  343. list:上传后图片数组
  344. v:返回当前上传图片的临时路径
  345. */
  346. chooseFile(list, v) {
  347. console.log("上传图片_list:", list)
  348. console.log("上传图片_v:", v);
  349. this.urlList=list;
  350. console.info("urlList",this.urlList);
  351. },
  352. /*
  353. 删除图片:
  354. list:删除返回删除后剩余的图片数组
  355. eq:返回删除的数组
  356. */
  357. imgDelete(list, eq) {
  358. console.log("删除图片_list:", list);
  359. console.log("删除图片_eq:", eq);
  360. this.urlList=list;
  361. console.info("urlList",this.urlList);
  362. },
  363. /*限制文件大小列表*/
  364. limitFileSizeList(list){
  365. console.info('limitFileSizeList:',list);
  366. if(list){
  367. if(list.length>0){
  368. uni.showModal({
  369. title:'警告',
  370. content: list.join()+' 文件大小超过2000KB',
  371. showCancel:false
  372. });
  373. }
  374. }
  375. },
  376. /*限制文件类型列表*/
  377. limitFileTypeList(list,allowFileType){
  378. console.info('limitFileTypeList:',list);
  379. console.info('limitFileTypeList:',allowFileType);
  380. if(list){
  381. if(list.length>0){
  382. uni.showModal({
  383. title:'警告',
  384. content: list.join()+' 文件类型必须是'+allowFileType.join(),
  385. showCancel:false
  386. });
  387. }
  388. }
  389. },
  390. /*
  391. 执行上传服务:
  392. urlList:要上传的图片:数组类型
  393. */
  394. uploadFileToServe(code) {
  395. console.info('uploadFileToServe',code)
  396. let _this=this;
  397. var urlList=_this.urlList;
  398. if (!urlList || urlList.length <= 0) {
  399. return;
  400. };
  401. //console.info(urlList);
  402. for (let i = 0; i < urlList.length; i++) {
  403. uni.uploadFile({
  404. url: '/api/Common/UploadImage',
  405. filePath: urlList[i],
  406. name: 'file',
  407. formData: {
  408. createPerson:_this.$store.state.user.userCode,
  409. masterCode:code,
  410. attachMentType:_this.entity.checkType
  411. },
  412. headers: {
  413. 'Content-Type': 'multipart/form-data; boundary = ' + new Date().getTime()
  414. //这里要把content-type设置为multipard/form-data,同时还要设置boundary
  415. },
  416. success: (uploadFileRes) => {
  417. console.log("图片上传:",uploadFileRes.data);
  418. }
  419. });
  420. }
  421. //return;
  422. },
  423. saveTemp(_this){ //临时存
  424. uni.setStorage({
  425. key:'projectName',
  426. data:_this.projectName
  427. });
  428. uni.setStorage({
  429. key:'checkDate',
  430. data:_this.checkDate
  431. });
  432. uni.setStorage({
  433. key:'itemList',
  434. data:_this.itemList
  435. });
  436. },
  437. getTemp(_this){ //获取缓存,重新给表单赋值
  438. _this.projectName=uni.getStorageSync('projectName');
  439. _this.checkDate=uni.getStorageSync('checkDate');
  440. _this.itemList=uni.getStorageSync('itemList');
  441. }
  442. }
  443. }
  444. </script>
  445. <style scoped>
  446. /* 头条小程序组件内不能引入字体 */
  447. /* #ifdef MP-TOUTIAO */
  448. @font-face {
  449. font-family: uniicons;
  450. font-weight: normal;
  451. font-style: normal;
  452. src: url("~@/static/uni.ttf") format("truetype");
  453. }
  454. /* #endif */
  455. page {
  456. display: flex;
  457. flex-direction: column;
  458. box-sizing: border-box;
  459. background-color: #efeff4;
  460. min-height: 100%;
  461. height: auto;
  462. }
  463. view {
  464. font-size: 14px;
  465. line-height: inherit;
  466. }
  467. .uni-form-item__title {
  468. font-size: 16px;
  469. line-height: 24px;
  470. }
  471. .uni-input-wrapper {
  472. /* #ifndef APP-NVUE */
  473. display: flex;
  474. /* #endif */
  475. padding: 8px 13px;
  476. flex-direction: row;
  477. flex-wrap: nowrap;
  478. background-color: #FFFFFF;
  479. }
  480. .title{
  481. background-color: #efefef;
  482. }
  483. .uni-input {
  484. height: 28px;
  485. line-height: 28px;
  486. font-size: 15px;
  487. padding: 0px;
  488. flex: 1;
  489. background-color: #FFFFFF;
  490. }
  491. .uni-icon {
  492. font-family: uniicons;
  493. font-size: 24px;
  494. font-weight: normal;
  495. font-style: normal;
  496. width: 24px;
  497. height: 24px;
  498. line-height: 24px;
  499. margin-left:15px;
  500. color: #999999;
  501. }
  502. .uni-eye-active {
  503. color: #007AFF;
  504. }
  505. .uni-btn-v{
  506. position: fixed;
  507. bottom: 0;
  508. width:100%;
  509. }
  510. .header-slot-box {
  511. font-size:15px;
  512. margin: 5px 5px;
  513. width:20%;
  514. justify-content: center;
  515. }
  516. .body-slot-box {
  517. font-size:15px;
  518. margin: 5px 5px;
  519. width:40%;
  520. justify-content: center;
  521. }
  522. .footer-slot-box {
  523. font-size:15px;
  524. margin: 5px 5px;
  525. width:40%;
  526. justify-content: center;
  527. }
  528. .uni-textarea textarea{
  529. font-size:15px;
  530. }
  531. .content {
  532. padding: 40rpx;
  533. background-color: #fff;
  534. }
  535. /* 上传控件 */
  536. .uploadControl {
  537. border: 1rpx solid #eee;
  538. border-radius: 10rpx;
  539. width: 130rpx;
  540. display: block;
  541. height: 130rpx;
  542. text-align: center;
  543. line-height: 130rpx;
  544. font-size: 30rpx;
  545. color: #888;
  546. background-color: #eeeeee;
  547. }
  548. .topicon >>> .icon{
  549. border: #4CD964 2upx solid;
  550. }
  551. </style>