form.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. let obj = this.collectImgList[j]
  172. obj.fileUrl = collectImgList[j].fileUrl
  173. this.collectImgList.splice(j, 1, obj)
  174. }
  175. }
  176. }
  177. for (let i = 0; i < this.faultImgList.length; i++) {
  178. for (let j = 0; j < faultImgList.length; j++) {
  179. if (this.faultImgList[i].fileName == faultImgList[j].fileName) {
  180. let obj = this.faultImgList[j]
  181. obj.fileUrl = faultImgList[j].fileUrl
  182. this.faultImgList.splice(j, 1, obj)
  183. }
  184. }
  185. }
  186. this.faultRemark = data.bugRemark
  187. this.isBaoNei = data.isDefend == 'YES' ? true : false
  188. this.remarkVal = data.detailRemark
  189. this.insideCode = data.insideCode
  190. })
  191. },
  192. // 获取工单详情
  193. async getOrderDetail() {
  194. return new Promise((resolve, reject) => {
  195. this.$api
  196. .post('/pg/order/base/detail', {
  197. orderBaseId: this.oid
  198. })
  199. .then(res => {
  200. this.orderDetail = res.data
  201. })
  202. .finally(res => {
  203. resolve(1)
  204. })
  205. })
  206. },
  207. // 获取采集图片类型列表
  208. async getCollectImgTypeList() {
  209. return new Promise((resolve, reject) => {
  210. this.$api
  211. .post('/changeOrder/sysDict', {
  212. dictType: 'GATHER_IMG'
  213. })
  214. .then(res => {
  215. this.collectImgList = res.data.map(item => {
  216. return {
  217. fileUrl: '',
  218. fileName: item.dictValue,
  219. type: 'INSTALL'
  220. }
  221. })
  222. resolve(1)
  223. })
  224. })
  225. },
  226. // 获取故障图片类型列表
  227. async getFaultImgTypeList() {
  228. return new Promise((resolve, reject) => {
  229. this.$api
  230. .post('/changeOrder/sysDict', {
  231. dictType: 'BUG_IMG'
  232. })
  233. .then(res => {
  234. this.faultImgList = res.data.map(item => {
  235. return {
  236. fileUrl: '',
  237. fileName: item.dictValue,
  238. type: 'BUG'
  239. }
  240. })
  241. resolve(1)
  242. })
  243. })
  244. },
  245. // 上传采集图片
  246. async chooseCollectImg(index) {
  247. if (!this.address) {
  248. // uni.showLoading()
  249. const lo = await this.$getAddress()
  250. this.address = lo.address || ''
  251. if (!this.address) {
  252. this.address = `${this.orderDetail.province}${this.orderDetail.city}${this.orderDetail.area}${this.orderDetail.street}`
  253. }
  254. }
  255. uni.chooseImage({
  256. count: 1,
  257. sizeType: ['compressed'],
  258. sourceType: ['album', 'camera'],
  259. success: async res => {
  260. let data = await uploadImgFull(res.tempFilePaths[0])
  261. this.$api
  262. .post('/changeOrder/submitPic', {
  263. patch: data.url,
  264. positionName: this.address,
  265. productDetailId: this.detail.id
  266. })
  267. .then(res => {
  268. let obj = this.collectImgList[index]
  269. obj.fileUrl = res.data
  270. this.collectImgList.splice(index, 1, obj)
  271. uni.hideLoading()
  272. })
  273. },
  274. fail: err => {
  275. uni.hideLoading()
  276. console.log(err)
  277. }
  278. })
  279. },
  280. // 选择故障图片
  281. async chooseFaultImg(index) {
  282. if (!this.address) {
  283. uni.showLoading()
  284. const lo = await this.$getAddress()
  285. this.address = lo.address || ''
  286. if (!this.address) {
  287. this.address = `${this.orderDetail.province}${this.orderDetail.city}${this.orderDetail.area}${this.orderDetail.street}`
  288. }
  289. }
  290. uni.chooseImage({
  291. count: 1,
  292. sizeType: ['compressed'],
  293. sourceType: ['album', 'camera'],
  294. success: async res => {
  295. let data = await uploadImgFull(res.tempFilePaths[0])
  296. this.$api
  297. .post('/changeOrder/submitPic', {
  298. patch: data.url,
  299. positionName: this.address,
  300. productDetailId: this.detail.id
  301. })
  302. .then(res => {
  303. let obj = this.faultImgList[index]
  304. obj.fileUrl = res.data
  305. this.faultImgList.splice(index, 1, obj)
  306. uni.hideLoading()
  307. })
  308. },
  309. fail: err => {
  310. uni.hideLoading()
  311. console.log(err)
  312. }
  313. })
  314. },
  315. delCollectImg(index) {
  316. let obj = this.collectImgList[index]
  317. obj.fileUrl = ''
  318. this.collectImgList.splice(index, 1, obj)
  319. },
  320. delFaultImg(index) {
  321. let obj = this.faultImgList[index]
  322. obj.fileUrl = ''
  323. this.faultImgList.splice(index, 1, obj)
  324. },
  325. // 预览图片
  326. prevImg(url) {
  327. uni.previewImage({
  328. current: url,
  329. urls: [url]
  330. })
  331. },
  332. // 提交(type: 1=临时保存 2=提交采集 0=本地缓存)
  333. async submitData(type) {
  334. let collectImgList = JSON.parse(JSON.stringify(this.collectImgList)).filter(o => o.fileUrl)
  335. let faultImgList = JSON.parse(JSON.stringify(this.faultImgList)).filter(o => o.fileUrl)
  336. if (type === 2) {
  337. if (collectImgList.length < 1) return this.$toast('请上传采集图片')
  338. if (this.orderDetail.orderType == 'REPAIR') {
  339. if (!this.faultRemark) return this.$toast('请填写故障现象')
  340. if (faultImgList.length < 1) return this.$toast('请上传故障图片')
  341. }
  342. }
  343. let params = {
  344. orderBaseId: this.oid,
  345. id: this.cid,
  346. bugRemark: this.faultRemark,
  347. isDefend: this.isBaoNei ? 'YES' : 'NO',
  348. detailRemark: this.remarkVal,
  349. pgOrderProductDetails: [...collectImgList, ...faultImgList],
  350. status: type == 2 ? 'OK' : 'WAIT_SAVE',
  351. giveAddress: this.address,
  352. insideCode: this.insideCode,
  353. productName: this?.detail?.productName,
  354. smallName: this?.detail?.smallName
  355. }
  356. // 本地缓存
  357. if (type === 0) {
  358. this.setStorage(params)
  359. }
  360. // 临时保存 / 提交采集
  361. else {
  362. this.$api
  363. .postJson('/changeOrder/submit', params)
  364. .then(res => {
  365. if (type === 1) {
  366. // this.setStorage(params);
  367. this.$successToast('保存成功')
  368. } else {
  369. // this.delStorage();
  370. // this.isNeedSave = false;
  371. this.$successToast('提交成功')
  372. }
  373. this.crossPage.$emit('refreshCollectList', type)
  374. setTimeout(() => {
  375. this.$navToPage(
  376. {
  377. delta: 1
  378. },
  379. 'navigateBack'
  380. )
  381. }, 500)
  382. })
  383. .catch(res => {
  384. // this.setStorage(params);
  385. })
  386. }
  387. },
  388. // 记录缓存
  389. setStorage(params) {
  390. let storageList = this.$getStorage('collectDataList') || []
  391. let index = storageList.findIndex(item => item['id'] === this.cid)
  392. // 如果有就替换 没有就添加
  393. if (index !== -1) {
  394. storageList.splice(index, 1, params)
  395. } else {
  396. storageList.push(params)
  397. }
  398. this.$removeStorage('collectDataList')
  399. this.$setStorage('collectDataList', storageList)
  400. },
  401. // 删除缓存
  402. delStorage() {
  403. let storageList = this.$getStorage('collectDataList') || []
  404. let index = storageList.findIndex(item => item['id'] === this.cid)
  405. storageList.splice(index, 1)
  406. this.$removeStorage('collectDataList')
  407. this.$setStorage('collectDataList', storageList)
  408. },
  409. backPage() {
  410. this.$navToPage(
  411. {
  412. delta: 1
  413. },
  414. 'navigateBack'
  415. )
  416. }
  417. }
  418. }
  419. </script>
  420. <style lang="scss" scoped>
  421. .top-container {
  422. background: #ffffff;
  423. padding: 30rpx;
  424. .row {
  425. height: 36rpx;
  426. display: flex;
  427. align-items: center;
  428. margin-top: 20rpx;
  429. &:first-child {
  430. margin-top: 0;
  431. }
  432. .label {
  433. color: $sec-font;
  434. flex-shrink: 0;
  435. font-size: 28rpx;
  436. }
  437. .value {
  438. font-size: 28rpx;
  439. }
  440. }
  441. }
  442. .common-title {
  443. font-weight: 500;
  444. .star {
  445. color: $minor-color;
  446. }
  447. .tips {
  448. color: $assist-color;
  449. font-weight: normal;
  450. margin-left: 12rpx;
  451. font-size: 28rpx;
  452. }
  453. }
  454. .card-container {
  455. background: #ffffff;
  456. padding: 30rpx;
  457. margin-top: 30rpx;
  458. .title {
  459. .star {
  460. color: $minor-color;
  461. }
  462. .tips {
  463. color: $assist-color;
  464. font-weight: normal;
  465. margin-left: 12rpx;
  466. font-size: 28rpx;
  467. }
  468. }
  469. .row {
  470. display: flex;
  471. align-items: center;
  472. justify-content: space-between;
  473. margin-top: 30rpx;
  474. .label {
  475. flex-shrink: 0;
  476. }
  477. .radio {
  478. display: flex;
  479. .item {
  480. width: 176rpx;
  481. height: 64rpx;
  482. background: #f4f5f9;
  483. border-radius: 8rpx;
  484. text-align: center;
  485. line-height: 64rpx;
  486. font-size: 32rpx;
  487. margin-left: 26rpx;
  488. &.active {
  489. background: $theme-color;
  490. color: #ffffff;
  491. }
  492. }
  493. ::v-deep .u-button {
  494. width: 176rpx;
  495. height: 64rpx;
  496. font-size: 32rpx;
  497. border-radius: 8rpx;
  498. }
  499. }
  500. }
  501. ::v-deep .u-textarea {
  502. background: #f4f5f9;
  503. margin-top: 20rpx;
  504. }
  505. .imgs {
  506. display: flex;
  507. flex-wrap: wrap;
  508. .it {
  509. display: flex;
  510. flex-direction: column;
  511. align-items: center;
  512. position: relative;
  513. margin-top: 30rpx;
  514. margin-right: 30rpx;
  515. &:nth-child(3n) {
  516. margin-right: 0;
  517. }
  518. .close {
  519. position: absolute;
  520. right: -20rpx;
  521. top: -20rpx;
  522. z-index: 99;
  523. width: 42rpx;
  524. height: 42rpx;
  525. background: $minor-color;
  526. color: #ffffff;
  527. text-align: center;
  528. line-height: 42rpx;
  529. border-radius: 50%;
  530. font-size: 28rpx;
  531. }
  532. image {
  533. width: 190rpx;
  534. height: 190rpx;
  535. background: #f4f4f7;
  536. border-radius: 20rpx;
  537. overflow: hidden;
  538. }
  539. .empty {
  540. width: 190rpx;
  541. height: 190rpx;
  542. border: 1px dashed #e5e5e5;
  543. display: flex;
  544. align-items: center;
  545. justify-content: center;
  546. flex-direction: column;
  547. position: relative;
  548. border-radius: 20rpx;
  549. overflow: hidden;
  550. .iconfont {
  551. font-size: 52rpx;
  552. color: $sec-font;
  553. }
  554. .text {
  555. margin-top: 12rpx;
  556. font-size: 28rpx;
  557. color: $sec-font;
  558. }
  559. }
  560. .name {
  561. margin-top: 24rpx;
  562. color: $sec-font;
  563. text {
  564. color: $minor-color;
  565. }
  566. }
  567. }
  568. }
  569. }
  570. .code {
  571. display: flex;
  572. align-items: center;
  573. justify-content: space-between;
  574. margin-top: 20rpx;
  575. background: #f4f5f9;
  576. box-sizing: border-box;
  577. padding: 10px;
  578. border-radius: 3px;
  579. .btn {
  580. font-size: 32rpx;
  581. color: $theme-color;
  582. margin-left: 16rpx;
  583. }
  584. }
  585. </style>