form.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <template>
  2. <view>
  3. <zj-page-layout :hasFooter="true" :isScroll="false">
  4. <view class="top-container" v-if="detail">
  5. <view class="row" style="margin-bottom: 30rpx">
  6. <view class="label">产品小类:</view>
  7. <view class="value">
  8. <!-- {{detail.smallName || ''}} -->
  9. <u--input placeholder="请输入产品小类" style="height: 30rpx" v-model="detail.smallName"></u--input>
  10. </view>
  11. </view>
  12. <view class="row">
  13. <view class="label">产品机型:</view>
  14. <view class="value">
  15. <!-- {{detail.productName || ''}} -->
  16. <u--input placeholder="请输入产品机型" style="height: 30rpx" v-model="detail.productName"></u--input>
  17. </view>
  18. </view>
  19. <view class="row">
  20. <view class="label">大工师傅:</view>
  21. <view class="value">{{
  22. detail.pgOrderWorkers
  23. .filter(t => t.isMaster == true)
  24. .map(o => o.workerName)
  25. .join(',')
  26. }}</view>
  27. </view>
  28. <view class="row">
  29. <view class="label">小工师傅:</view>
  30. <view class="value">{{
  31. detail.pgOrderWorkers
  32. .filter(t => t.isMaster == false)
  33. .map(o => o.workerName)
  34. .join(',')
  35. }}</view>
  36. </view>
  37. </view>
  38. <view class="card-container">
  39. <view class="common-title"><text class="star">*</text>采集图片<text class="tips">最少1张</text></view>
  40. <view class="imgs">
  41. <view class="it" v-for="(item, index) in collectImgList" :key="index">
  42. <block v-if="item.fileUrl">
  43. <text class="iconfont icon-guanbi1 close" @tap="delCollectImg(index)" v-if="!isView"></text>
  44. <image mode="aspectFill" :src="item.fileUrl" @tap="prevImg(item.fileUrl)"> </image>
  45. </block>
  46. <view class="empty" v-else @tap="isView ? '' : chooseCollectImg(index)">
  47. <text class="iconfont icon-xiangji"></text>
  48. <text class="text">{{ isView ? '暂无图片' : '添加图片' }}</text>
  49. </view>
  50. <view class="name">{{ item.fileName }}</view>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- v-if="orderDetail.orderType == 'REPAIR'" -->
  55. <view class="card-container" v-if="orderDetail.orderType == 'REPAIR'">
  56. <view class="common-title">内机条码</view>
  57. <view class="code">
  58. <u--input placeholder="请输入内机条码" border="none" v-model="insideCode"></u--input>
  59. <view class="btn" @click="getScancode('insideCode')">扫描</view>
  60. </view>
  61. <view class="title mt20"><text class="star">*</text>故障现象</view>
  62. <u--textarea
  63. v-model="faultRemark"
  64. placeholder="请输入故障现象"
  65. fixed
  66. border="none"
  67. :disabled="isView"
  68. ></u--textarea>
  69. <view class="title mt20"><text class="star">*</text>故障图片<text class="tips">最少1张</text></view>
  70. <view class="imgs">
  71. <view class="it" v-for="(item, index) in faultImgList" :key="index">
  72. <block v-if="item.fileUrl">
  73. <text class="iconfont icon-guanbi1 close" @tap="delFaultImg(index)" v-if="!isView"></text>
  74. <image mode="aspectFill" :src="item.fileUrl" @tap="prevImg(item.fileUrl)"> </image>
  75. </block>
  76. <view class="empty" v-else @tap="isView ? '' : chooseFaultImg(index)">
  77. <text class="iconfont icon-xiangji"></text>
  78. <text class="text">{{ isView ? '暂无图片' : '添加图片' }}</text>
  79. </view>
  80. <view class="name">{{ item.fileName }}</view>
  81. </view>
  82. </view>
  83. <view class="row">
  84. <view class="title"><text class="star">*</text>是否保内</view>
  85. <view class="radio">
  86. <view class="item" :class="isBaoNei ? 'active' : ''" @tap="isView ? '' : (isBaoNei = true)">是</view>
  87. <view class="item" :class="!isBaoNei ? 'active' : ''" @tap="isView ? '' : (isBaoNei = false)">否</view>
  88. </view>
  89. </view>
  90. </view>
  91. <view class="card-container">
  92. <view class="common-title">备注</view>
  93. <u--textarea
  94. v-model="remarkVal"
  95. placeholder="请输入备注内容"
  96. fixed
  97. border="none"
  98. :disabled="isView"
  99. ></u--textarea>
  100. </view>
  101. <u-gap height="30"></u-gap>
  102. <template slot="footer">
  103. <view class="footer-btn-group" v-if="!isView">
  104. <u-button text="临时保存" size="large" @click="submitData(1)"></u-button>
  105. <u-button text="提交采集" type="primary" size="large" @click="submitData(2)"></u-button>
  106. </view>
  107. <view class="footer-btn-group" v-else>
  108. <u-button text="返回" size="large" @click="backPage()"></u-button>
  109. </view>
  110. </template>
  111. </zj-page-layout>
  112. </view>
  113. </template>
  114. <script>
  115. import { uploadImgFull, wxScanCode } from '@/common/utils/util.js'
  116. export default {
  117. data() {
  118. return {
  119. oid: null, // 服务单id
  120. cid: null, // 采集id
  121. detail: null,
  122. orderDetail: {},
  123. isView: false, // 是否仅查看
  124. collectImgList: [],
  125. faultImgList: [],
  126. collectImgType: null,
  127. collectImgTypeList: [],
  128. isShowCollectImgTypeDialog: false,
  129. faultImgType: null,
  130. faultImgTypeList: [],
  131. isShowFaultImgTypeDialog: false,
  132. isBaoNei: true,
  133. faultRemark: '',
  134. remarkVal: '', // 采集备注
  135. address: '',
  136. isNeedSave: true,
  137. insideCode: ''
  138. }
  139. },
  140. async onLoad({ oid, cid, isView }) {
  141. this.oid = oid
  142. this.cid = cid
  143. this.isView = isView == 1 ? true : false
  144. await this.getOrderDetail()
  145. await this.getCollectImgTypeList()
  146. if (this.orderDetail.orderType == 'REPAIR') {
  147. await this.getFaultImgTypeList()
  148. }
  149. this.getDetail()
  150. const lo = await this.$getAddress()
  151. this.address = lo.address || ''
  152. },
  153. methods: {
  154. async getScancode(type) {
  155. var codeVal = await wxScanCode()
  156. this[type] = codeVal
  157. },
  158. getDetail() {
  159. this.$api
  160. .post('/changeOrder/productDetail', {
  161. id: this.cid
  162. })
  163. .then(res => {
  164. this.detail = res.data
  165. const data = res.data
  166. let collectImgList = data.pgOrderProductDetails.filter(o => o.type == 'INSTALL')
  167. let faultImgList = data.pgOrderProductDetails.filter(o => o.type == 'BUG')
  168. for (let i = 0; i < this.collectImgList.length; i++) {
  169. for (let j = 0; j < collectImgList.length; j++) {
  170. if (this.collectImgList[i].fileName == collectImgList[j].fileName) {
  171. this.collectImgList[i].fileUrl = collectImgList[j].fileUrl
  172. }
  173. }
  174. }
  175. for (let i = 0; i < this.faultImgList.length; i++) {
  176. for (let j = 0; j < faultImgList.length; j++) {
  177. if (this.faultImgList[i].fileName == faultImgList[j].fileName) {
  178. this.faultImgList[i].fileUrl = faultImgList[j].fileUrl
  179. }
  180. }
  181. }
  182. this.faultRemark = data.bugRemark
  183. this.isBaoNei = data.isDefend == 'YES' ? true : false
  184. this.remarkVal = data.detailRemark
  185. this.insideCode = data.insideCode
  186. })
  187. },
  188. // 获取工单详情
  189. async getOrderDetail() {
  190. return new Promise((resolve, reject) => {
  191. this.$api
  192. .post('/pg/order/base/detail', {
  193. orderBaseId: this.oid
  194. })
  195. .then(res => {
  196. this.orderDetail = res.data
  197. })
  198. .finally(res => {
  199. resolve(1)
  200. })
  201. })
  202. },
  203. // 获取采集图片类型列表
  204. async getCollectImgTypeList() {
  205. return new Promise((resolve, reject) => {
  206. this.$api
  207. .post('/changeOrder/sysDict', {
  208. dictType: 'GATHER_IMG'
  209. })
  210. .then(res => {
  211. this.collectImgList = res.data.map(item => {
  212. return {
  213. fileUrl: '',
  214. fileName: item.dictValue,
  215. type: 'INSTALL'
  216. }
  217. })
  218. resolve(1)
  219. })
  220. })
  221. },
  222. // 获取故障图片类型列表
  223. async getFaultImgTypeList() {
  224. return new Promise((resolve, reject) => {
  225. this.$api
  226. .post('/changeOrder/sysDict', {
  227. dictType: 'BUG_IMG'
  228. })
  229. .then(res => {
  230. this.faultImgList = res.data.map(item => {
  231. return {
  232. fileUrl: '',
  233. fileName: item.dictValue,
  234. type: 'BUG'
  235. }
  236. })
  237. resolve(1)
  238. })
  239. })
  240. },
  241. // 上传采集图片
  242. async chooseCollectImg(index) {
  243. if (!this.address) {
  244. // uni.showLoading()
  245. const lo = await this.$getAddress()
  246. this.address = lo.address || ''
  247. if (!this.address) {
  248. this.address = `${this.orderDetail.province}${this.orderDetail.city}${this.orderDetail.area}${this.orderDetail.street}`
  249. }
  250. // uni.hideLoading()
  251. // return this.$modal({
  252. // content: '请开启位置信息权限后,重新获取位置信息',
  253. // confirmText: '获取位置'
  254. // }).then(async() => {
  255. // const lo = await this.$getAddress();
  256. // this.address = lo.address || '';
  257. // if(!this.address) {
  258. // this.address = `${this.orderDetail.province}${this.orderDetail.city}${this.orderDetail.area}${this.orderDetail.street}`;
  259. // // this.$tips('获取定位失败,请开启位置信息权限');
  260. // }
  261. // }).catch(() => {})
  262. }
  263. uni.chooseImage({
  264. count: 1,
  265. sizeType: ['compressed'],
  266. sourceType: ['album', 'camera'],
  267. success: async res => {
  268. let data = await uploadImgFull(res.tempFilePaths[0])
  269. this.$api
  270. .post('/changeOrder/submitPic', {
  271. patch: data.url,
  272. positionName: this.address,
  273. productDetailId: this.detail.id
  274. })
  275. .then(res => {
  276. this.collectImgList[index].fileUrl = res.data
  277. uni.hideLoading()
  278. })
  279. },
  280. fail: err => {
  281. console.log(err)
  282. }
  283. })
  284. },
  285. // 选择故障图片
  286. async chooseFaultImg(index) {
  287. if (!this.address) {
  288. uni.showLoading()
  289. const lo = await this.$getAddress()
  290. this.address = lo.address || ''
  291. if (!this.address) {
  292. this.address = `${this.orderDetail.province}${this.orderDetail.city}${this.orderDetail.area}${this.orderDetail.street}`
  293. }
  294. uni.hideLoading()
  295. // return this.$modal({
  296. // content: '请开启位置信息权限后,重新获取位置信息',
  297. // confirmText: '获取位置'
  298. // }).then(async() => {
  299. // const lo = await this.$getAddress();
  300. // this.address = lo.address || '';
  301. // if(!this.address) {
  302. // this.address = `${this.orderDetail.province}${this.orderDetail.city}${this.orderDetail.area}${this.orderDetail.street}`;
  303. // // this.$tips('获取定位失败,请开启位置信息权限');
  304. // }
  305. // }).catch(() => {})
  306. }
  307. uni.chooseImage({
  308. count: 1,
  309. sizeType: ['compressed'],
  310. sourceType: ['album', 'camera'],
  311. success: async res => {
  312. let data = await uploadImgFull(res.tempFilePaths[0])
  313. this.$api
  314. .post('/changeOrder/submitPic', {
  315. patch: data.url,
  316. positionName: this.address,
  317. productDetailId: this.detail.id
  318. })
  319. .then(res => {
  320. this.faultImgList[index].fileUrl = res.data
  321. uni.hideLoading()
  322. })
  323. },
  324. fail: err => {
  325. console.log(err)
  326. }
  327. })
  328. },
  329. delCollectImg(index) {
  330. let obj = this.collectImgList[index]
  331. obj.fileUrl = ''
  332. this.$set(this.collectImgList, index, obj)
  333. },
  334. delFaultImg(index) {
  335. let obj = this.faultImgList[index]
  336. obj.fileUrl = ''
  337. this.$set(this.faultImgList, index, obj)
  338. },
  339. // 预览图片
  340. prevImg(url) {
  341. uni.previewImage({
  342. current: url,
  343. urls: [url]
  344. })
  345. },
  346. // 提交(type: 1=临时保存 2=提交采集 0=本地缓存)
  347. async submitData(type) {
  348. let collectImgList = JSON.parse(JSON.stringify(this.collectImgList)).filter(o => o.fileUrl)
  349. let faultImgList = JSON.parse(JSON.stringify(this.faultImgList)).filter(o => o.fileUrl)
  350. if (type === 2) {
  351. if (collectImgList.length < 1) return this.$toast('请上传采集图片')
  352. if (this.orderDetail.orderType == 'REPAIR') {
  353. if (!this.faultRemark) return this.$toast('请填写故障现象')
  354. if (faultImgList.length < 1) return this.$toast('请上传故障图片')
  355. }
  356. }
  357. let params = {
  358. orderBaseId: this.oid,
  359. id: this.cid,
  360. bugRemark: this.faultRemark,
  361. isDefend: this.isBaoNei ? 'YES' : 'NO',
  362. detailRemark: this.remarkVal,
  363. pgOrderProductDetails: [...collectImgList, ...faultImgList],
  364. status: type == 2 ? 'OK' : 'WAIT_SAVE',
  365. giveAddress: this.address,
  366. insideCode: this.insideCode,
  367. productName: this?.detail?.productName,
  368. smallName: this?.detail?.smallName
  369. }
  370. // 本地缓存
  371. if (type === 0) {
  372. this.setStorage(params)
  373. }
  374. // 临时保存 / 提交采集
  375. else {
  376. this.$api
  377. .postJson('/changeOrder/submit', params)
  378. .then(res => {
  379. if (type === 1) {
  380. // this.setStorage(params);
  381. this.$successToast('保存成功')
  382. } else {
  383. // this.delStorage();
  384. // this.isNeedSave = false;
  385. this.$successToast('提交成功')
  386. }
  387. this.crossPage.$emit('refreshCollectList', type)
  388. setTimeout(() => {
  389. this.$navToPage(
  390. {
  391. delta: 1
  392. },
  393. 'navigateBack'
  394. )
  395. }, 500)
  396. })
  397. .catch(res => {
  398. // this.setStorage(params);
  399. })
  400. }
  401. },
  402. // 记录缓存
  403. setStorage(params) {
  404. let storageList = this.$getStorage('collectDataList') || []
  405. let index = storageList.findIndex(item => item['id'] === this.cid)
  406. // 如果有就替换 没有就添加
  407. if (index !== -1) {
  408. storageList.splice(index, 1, params)
  409. } else {
  410. storageList.push(params)
  411. }
  412. this.$removeStorage('collectDataList')
  413. this.$setStorage('collectDataList', storageList)
  414. },
  415. // 删除缓存
  416. delStorage() {
  417. let storageList = this.$getStorage('collectDataList') || []
  418. let index = storageList.findIndex(item => item['id'] === this.cid)
  419. storageList.splice(index, 1)
  420. this.$removeStorage('collectDataList')
  421. this.$setStorage('collectDataList', storageList)
  422. },
  423. backPage() {
  424. this.$navToPage(
  425. {
  426. delta: 1
  427. },
  428. 'navigateBack'
  429. )
  430. }
  431. }
  432. }
  433. </script>
  434. <style lang="scss" scoped>
  435. .top-container {
  436. background: #ffffff;
  437. padding: 30rpx;
  438. .row {
  439. height: 36rpx;
  440. display: flex;
  441. align-items: center;
  442. margin-top: 20rpx;
  443. &:first-child {
  444. margin-top: 0;
  445. }
  446. .label {
  447. color: $sec-font;
  448. flex-shrink: 0;
  449. font-size: 28rpx;
  450. }
  451. .value {
  452. font-size: 28rpx;
  453. }
  454. }
  455. }
  456. .common-title {
  457. font-weight: 500;
  458. .star {
  459. color: $minor-color;
  460. }
  461. .tips {
  462. color: $assist-color;
  463. font-weight: normal;
  464. margin-left: 12rpx;
  465. font-size: 28rpx;
  466. }
  467. }
  468. .card-container {
  469. background: #ffffff;
  470. padding: 30rpx;
  471. margin-top: 30rpx;
  472. .title {
  473. .star {
  474. color: $minor-color;
  475. }
  476. .tips {
  477. color: $assist-color;
  478. font-weight: normal;
  479. margin-left: 12rpx;
  480. font-size: 28rpx;
  481. }
  482. }
  483. .row {
  484. display: flex;
  485. align-items: center;
  486. justify-content: space-between;
  487. margin-top: 30rpx;
  488. .label {
  489. flex-shrink: 0;
  490. }
  491. .radio {
  492. display: flex;
  493. .item {
  494. width: 176rpx;
  495. height: 64rpx;
  496. background: #f4f5f9;
  497. border-radius: 8rpx;
  498. text-align: center;
  499. line-height: 64rpx;
  500. font-size: 32rpx;
  501. margin-left: 26rpx;
  502. &.active {
  503. background: $theme-color;
  504. color: #ffffff;
  505. }
  506. }
  507. ::v-deep .u-button {
  508. width: 176rpx;
  509. height: 64rpx;
  510. font-size: 32rpx;
  511. border-radius: 8rpx;
  512. }
  513. }
  514. }
  515. ::v-deep .u-textarea {
  516. background: #f4f5f9;
  517. margin-top: 20rpx;
  518. }
  519. .imgs {
  520. display: flex;
  521. flex-wrap: wrap;
  522. .it {
  523. display: flex;
  524. flex-direction: column;
  525. align-items: center;
  526. position: relative;
  527. margin-top: 30rpx;
  528. margin-right: 30rpx;
  529. &:nth-child(3n) {
  530. margin-right: 0;
  531. }
  532. .close {
  533. position: absolute;
  534. right: -20rpx;
  535. top: -20rpx;
  536. z-index: 99;
  537. width: 42rpx;
  538. height: 42rpx;
  539. background: $minor-color;
  540. color: #ffffff;
  541. text-align: center;
  542. line-height: 42rpx;
  543. border-radius: 50%;
  544. font-size: 28rpx;
  545. }
  546. image {
  547. width: 190rpx;
  548. height: 190rpx;
  549. background: #f4f4f7;
  550. border-radius: 20rpx;
  551. overflow: hidden;
  552. }
  553. .empty {
  554. width: 190rpx;
  555. height: 190rpx;
  556. border: 1px dashed #e5e5e5;
  557. display: flex;
  558. align-items: center;
  559. justify-content: center;
  560. flex-direction: column;
  561. position: relative;
  562. border-radius: 20rpx;
  563. overflow: hidden;
  564. .iconfont {
  565. font-size: 52rpx;
  566. color: $sec-font;
  567. }
  568. .text {
  569. margin-top: 12rpx;
  570. font-size: 28rpx;
  571. color: $sec-font;
  572. }
  573. }
  574. .name {
  575. margin-top: 24rpx;
  576. color: $sec-font;
  577. text {
  578. color: $minor-color;
  579. }
  580. }
  581. }
  582. }
  583. }
  584. .code {
  585. display: flex;
  586. align-items: center;
  587. justify-content: space-between;
  588. margin-top: 20rpx;
  589. background: #f4f5f9;
  590. box-sizing: border-box;
  591. padding: 10px;
  592. border-radius: 3px;
  593. .btn {
  594. font-size: 32rpx;
  595. color: $theme-color;
  596. margin-left: 16rpx;
  597. }
  598. }
  599. </style>