add.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='添加巡检记录'></cus-header>
  4. <div class="boxs">
  5. <div class="box">
  6. <div class="box_item">
  7. <div class="left">项目订单号</div>
  8. <div class="right select" @tap="handleSelect(1)">
  9. <text>{{orderNoText}}</text>
  10. <image :src="imgBase+'operation/arrow_right.png'" mode="widthFix"></image>
  11. </div>
  12. </div>
  13. <div class="box_item">
  14. <div class="left">巡检地点</div>
  15. <div class="right select" @tap="handleSelect(2)">
  16. <text>{{placeText}}</text>
  17. <image :src="imgBase+'operation/arrow_right.png'" mode="widthFix"></image>
  18. </div>
  19. </div>
  20. <div class="box_item">
  21. <div class="left">巡检任务</div>
  22. <div class="right">
  23. <input type="text" placeholder="请输入巡检任务" placeholder-class="inp_ph" v-model="dto.inspectionTask">
  24. </div>
  25. </div>
  26. <div class="box_item">
  27. <div class="left">巡检负责人</div>
  28. <div class="right">
  29. <input type="text" placeholder="请输入巡检负责人" placeholder-class="inp_ph" v-model="dto.inspector">
  30. </div>
  31. </div>
  32. <div class="box_item">
  33. <div class="left">巡检时间</div>
  34. <div class="right select" @tap="handleSelect(3)">
  35. <text>{{dateText}}</text>
  36. <image :src="imgBase+'operation/arrow_right.png'" mode="widthFix"></image>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="box">
  41. <div class="box_item">
  42. <div class="left">巡检结果</div>
  43. <div class="right">
  44. <u-radio-group v-model="dto.status" :size="30" :iconSize="30">
  45. <u-radio :labelSize="30" :label="0" :name="0">正常</u-radio>
  46. <u-radio :labelSize="30" :label="1" :name="1">有异常</u-radio>
  47. </u-radio-group>
  48. </div>
  49. </div>
  50. <div class="box_item2">
  51. <div class="top">备注</div>
  52. <div class="bottom">
  53. <u--textarea v-model="dto.remark" placeholder="请输入备注" placeholder-class="inp_ph2" border="none" height="110"></u--textarea>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="box">
  58. <div class="box_item2">
  59. <div class="top">巡检打卡</div>
  60. <div class="bottom" style="padding-top: 24rpx;">
  61. <u-upload width="180" height="180"
  62. :fileList="fileList"
  63. @afterRead="afterRead"
  64. @delete="deletePic"
  65. :maxCount="1"
  66. ></u-upload>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="bottom_btn">
  72. <div class="btn" @tap="submit">提交</div>
  73. </div>
  74. <u-picker :itemHeight="88" :show="show1" :columns="columns1" keyName="orderNo" title="项目订单号"
  75. @cancel="show1=false" @confirm="e=>confirm(e,1)" :immediateChange="true"></u-picker>
  76. <u-picker :itemHeight="88" :show="show2" :columns="columns2" keyName="customerName" title="巡检地点"
  77. @cancel="show2=false" @confirm="e=>confirm(e,2)" :immediateChange="true"></u-picker>
  78. <u-datetime-picker :itemHeight="88" :show="show3" v-model="dto.startDate" mode="date" title="巡检时间"
  79. @cancel="show3=false" @confirm="e=>confirm(e,3)" :immediateChange="true" :minDate="minDate" :maxDate="maxDate"></u-datetime-picker>
  80. </view>
  81. </template>
  82. <script>
  83. const baseApi = require('@/http/baseApi.js')
  84. export default {
  85. data(){
  86. return {
  87. dto:{
  88. orderId:'',
  89. inspectionSite:'',
  90. inspectionTask:'',
  91. inspector:'',
  92. startDate:'',
  93. status:0,
  94. remark:'',
  95. inspectionFile:''
  96. },
  97. fileList:[],
  98. orderNoText:'请选择项目订单号',
  99. placeText:'请选择巡检地点',
  100. dateText:'请选择巡检时间',
  101. show1:false,
  102. show2:false,
  103. show3:false,
  104. columns1:[],
  105. columns2:[],
  106. minDate:'',
  107. maxDate:'',
  108. rules:[
  109. {key:'orderId',tip:'请选择项目订单号'},
  110. {key:'inspectionSite',tip:'请选择巡检地点'},
  111. {key:'inspectionTask',tip:'请输入巡检任务'},
  112. {key:'inspector',tip:'请输入巡检负责人'},
  113. {key:'startDate',tip:'请选择巡检时间'},
  114. // {key:'status',tip:'请选择巡检结果'},
  115. // {key:'remark',tip:'请输入备注'},
  116. // {key:'inspectionFile',tip:'请选择巡检打卡图片'}
  117. ]
  118. }
  119. },
  120. onLoad() {
  121. let d = new Date();
  122. this.minDate = new Date(d.getFullYear(),d.getMonth(),1).getTime();
  123. this.maxDate = new Date().getTime();
  124. this.getOrderList();
  125. this.getCustomerList();
  126. },
  127. methods:{
  128. getOrderList(){
  129. this.$api.get('/wms/project/getOrderPage',{page:1,limit:-1}).then(res=>{
  130. if(res.data.code===0){
  131. this.columns1 = [res.data.data.list];
  132. }else this.$showToast(res.data.msg)
  133. })
  134. },
  135. getCustomerList(){
  136. this.$api.get('/wms/project/getCustomerList',{page:1,limit:-1}).then(res=>{
  137. if(res.data.code!==0) return this.$showToast(res.data.msg)
  138. let list = res.data.data.map(d=>{return {id:d,customerName:d}})
  139. this.columns2 = [list]
  140. })
  141. },
  142. handleSelect(type){
  143. this['show'+type] = true;
  144. },
  145. confirm(e,type){
  146. if(type==1){
  147. this.orderNoText = e.value[0].orderNo;
  148. this.dto.orderId = e.value[0].id;
  149. this.show1 = false;
  150. }else if(type==2){
  151. this.placeText = e.value[0].customerName;
  152. this.dto.inspectionSite = e.value[0].id;
  153. this.show2 = false;
  154. }else if(type==3){
  155. this.dateText = new Date(e.value).Format('yyyy-MM-dd');
  156. this.dto.startDate = new Date(e.value).Format('yyyy-MM-dd hh:mm:ss');
  157. this.show3 = false;
  158. }
  159. },
  160. // 删除图片
  161. deletePic(event) {
  162. this.fileList.splice(event.index, 1);
  163. },
  164. // 新增图片
  165. async afterRead(event) {
  166. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  167. let lists = [].concat(event.file);
  168. let fileListLen = this.fileList.length;
  169. lists.map((item) => {
  170. this.fileList.push({
  171. ...item,
  172. status: "uploading",
  173. message: "上传中",
  174. });
  175. });
  176. for (let i = 0; i < lists.length; i++) {
  177. const result = await this.uploadFilePromise(lists[i].url);
  178. let item = this.fileList[fileListLen];
  179. this.fileList.splice(
  180. fileListLen,
  181. 1,
  182. Object.assign(item, {
  183. status: "success",
  184. message: "",
  185. url: result,
  186. })
  187. );
  188. fileListLen++;
  189. }
  190. },
  191. uploadFilePromise(url) {
  192. return new Promise((resolve, reject) => {
  193. let a = uni.uploadFile({
  194. url: baseApi.BaseApi + '/uploadFile',
  195. filePath: url,
  196. name: "file",
  197. formData: {
  198. user: "test",
  199. },
  200. success: (res) => {
  201. let data = JSON.parse(res.data);
  202. if(data){
  203. if(data.code!==0) return
  204. setTimeout(() => {
  205. resolve(data.data);
  206. }, 1000);
  207. }
  208. },
  209. });
  210. });
  211. },
  212. submit(){
  213. let idx = this.rules.findIndex(r=>!this.dto[r.key]==true);
  214. if(idx>-1) return this.$showToast(this.rules[idx].tip)
  215. let dto = JSON.parse(JSON.stringify(this.dto))
  216. dto.startDate = new Date(dto.startDate).Format('yyyy-MM-dd hh:mm:ss');
  217. dto.inspectionFile = this.fileList[0].url;
  218. this.$api.post('/wms/order/inspection',dto).then(res=>{
  219. if(res.data.code!==0) return this.$showToast(res.data.msg)
  220. this.$showToast('操作成功')
  221. setTimeout(()=>{
  222. uni.navigateBack()
  223. },1500)
  224. })
  225. }
  226. }
  227. }
  228. </script>
  229. <style>
  230. .inp_ph{
  231. font-family: PingFangSC, PingFang SC;
  232. font-weight: 400;
  233. font-size: 28rpx;
  234. color: #B9C0C8;
  235. line-height: 40rpx;
  236. text-align: right;
  237. }
  238. .inp_ph2{
  239. font-family: PingFangSC, PingFang SC;
  240. font-weight: 400;
  241. font-size: 28rpx;
  242. color: #B9C0C8;
  243. line-height: 40rpx;
  244. text-align: left;
  245. }
  246. </style>
  247. <style scoped lang="less">
  248. ::v-deep .u-radio:last-child{
  249. margin-left: 93rpx !important;
  250. }
  251. ::v-deep .u-upload__button .u-icon__icon{
  252. font-size: 48rpx !important;
  253. }
  254. .page{
  255. padding-bottom: 168rpx;
  256. background: #F4F8FB;
  257. .boxs{
  258. padding: 0 24rpx;
  259. .box{
  260. background: #FFFFFF;
  261. border-radius: 16rpx;
  262. margin-top: 20rpx;
  263. padding: 0 24rpx;
  264. }
  265. }
  266. .box_item{
  267. display: flex;
  268. align-items: center;
  269. justify-content: space-between;
  270. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECEEF5;
  271. padding: 24rpx 0;
  272. .left{
  273. font-family: PingFangSC, PingFang SC;
  274. font-weight: 400;
  275. font-size: 30rpx;
  276. color: #1D2129;
  277. line-height: 42rpx;
  278. }
  279. .right{
  280. input{
  281. font-family: PingFangSC, PingFang SC;
  282. font-weight: 400;
  283. font-size: 28rpx;
  284. color: #4E5969;
  285. line-height: 40rpx;
  286. text-align: right;
  287. }
  288. &.select{
  289. display: flex;
  290. align-items: center;
  291. text{
  292. font-family: PingFangSC, PingFang SC;
  293. font-weight: 400;
  294. font-size: 28rpx;
  295. color: #B9C0C8;
  296. line-height: 40rpx;
  297. }
  298. image{
  299. width: 24rpx;
  300. height: 24rpx;
  301. margin-left: 10rpx;
  302. }
  303. }
  304. }
  305. }
  306. .box_item2{
  307. .top{
  308. font-family: PingFangSC, PingFang SC;
  309. font-weight: 400;
  310. font-size: 30rpx;
  311. color: #1D2129;
  312. line-height: 42rpx;
  313. padding-top: 24rpx;
  314. }
  315. .bottom{
  316. padding-bottom: 24rpx;
  317. input{
  318. font-family: PingFangSC, PingFang SC;
  319. font-weight: 400;
  320. font-size: 28rpx;
  321. color: #4E5969;
  322. line-height: 40rpx;
  323. }
  324. }
  325. }
  326. .bottom_btn{
  327. width: 100%;
  328. height: 148rpx;
  329. padding: 20rpx 48rpx;
  330. box-sizing: border-box;
  331. background: #FFFFFF;
  332. position: fixed;
  333. bottom: 0;
  334. left: 0;
  335. z-index: 9;
  336. .btn{
  337. width: 100%;
  338. height: 88rpx;
  339. background: #2E69EB;
  340. border-radius: 16rpx;
  341. font-family: PingFang-SC, PingFang-SC;
  342. font-weight: bold;
  343. font-size: 32rpx;
  344. color: #FFFFFF;
  345. line-height: 88rpx;
  346. text-align: center;
  347. }
  348. }
  349. }
  350. </style>