SafeQualityCheckAdd.vue 14 KB

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