SafeQualityCheckAdd.vue 12 KB

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