anomaly.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <view class="anomaly-container">
  3. <!-- 内容区域 -->
  4. <scroll-view scroll-y class="anomaly-scroll">
  5. <!-- 异常类型 -->
  6. <view class="ano-card">
  7. <view class="ano-section-title">
  8. <view class="ano-title-bar"></view>
  9. <text class="ano-title-text">异常类型</text>
  10. </view>
  11. <view class="ano-type-row" @click="openTypeSheet">
  12. <text class="ano-type-val" :class="{ 'placeholder': !selectedType }">
  13. {{ selectedType || '请选择异常类型' }}
  14. </text>
  15. <image class="ano-right-arrow" src="/static/icons/right_arrow_orange.svg"></image>
  16. </view>
  17. </view>
  18. <!-- 异常描述 -->
  19. <view class="ano-card">
  20. <view class="ano-section-title">
  21. <view class="ano-title-bar"></view>
  22. <text class="ano-title-text">异常描述</text>
  23. </view>
  24. <textarea
  25. class="ano-textarea"
  26. v-model="anomalyDesc"
  27. placeholder="请详细描述现场异常情况..."
  28. placeholder-style="color:#ccc; font-size:28rpx;"
  29. maxlength="500"
  30. ></textarea>
  31. </view>
  32. <!-- 现场照片 -->
  33. <view class="ano-card">
  34. <view class="ano-section-title">
  35. <view class="ano-title-bar"></view>
  36. <text class="ano-title-text">现场照片 (必填,最多5张)</text>
  37. </view>
  38. <view class="ano-photo-grid">
  39. <!-- 已上传图片 -->
  40. <view class="ano-photo-item" v-for="(img, idx) in photoList" :key="idx">
  41. <image class="ano-photo-preview" :src="img.url || img.localPath || img" mode="aspectFill"></image>
  42. <view class="ano-photo-del" @click="removePhoto(idx)">×</view>
  43. </view>
  44. <!-- 添加按钮 -->
  45. <view class="ano-photo-add" @click="choosePhoto" v-if="photoList.length < 5">
  46. <image class="ano-add-icon" src="/static/icons/camera_grey.svg"></image>
  47. <text class="ano-add-text">上传</text>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 底部留空供按钮 -->
  52. <view style="height: 160rpx;"></view>
  53. </scroll-view>
  54. <!-- 底部提交按钮 -->
  55. <view class="ano-footer">
  56. <button class="ano-submit-btn" @click="submitAnomaly">提交上报</button>
  57. </view>
  58. <!-- 异常类型选择器 -->
  59. <view class="ano-sheet-mask" v-if="showTypeSheet" @click="closeTypeSheet">
  60. <view class="ano-sheet" @click.stop>
  61. <text class="ano-sheet-title">选择异常类型</text>
  62. <scroll-view scroll-y class="ano-sheet-list">
  63. <view
  64. class="ano-sheet-item"
  65. v-for="(type, idx) in anomalyTypes"
  66. :key="idx"
  67. @click="selectType(type)"
  68. >
  69. <text :class="['ano-sheet-item-text', { 'selected': selectedTypeValue === type.value }]">{{ type.label }}</text>
  70. <image
  71. v-if="selectedTypeValue === type.value"
  72. class="ano-check-icon"
  73. src="/static/icons/right_arrow_orange.svg"
  74. ></image>
  75. </view>
  76. </scroll-view>
  77. <view class="ano-sheet-cancel" @click="closeTypeSheet">取消</view>
  78. </view>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. import { getDictDataByType } from '@/api/system/dict/index'
  84. import { uploadFile, uploadAnamaly } from '@/api/fulfiller'
  85. export default {
  86. data() {
  87. return {
  88. orderId: '',
  89. // 已选异常类型(dictValue)
  90. selectedTypeValue: '',
  91. // 已选异常类型标签(dictLabel,用于显示)
  92. selectedTypeLabel: '',
  93. // 异常描述
  94. anomalyDesc: '',
  95. // 照片列表(含 url 和 ossId)
  96. photoList: [],
  97. // 是否显示类型选择器
  98. showTypeSheet: false,
  99. // 异常类型字典列表(从后端获取)
  100. anomalyTypes: []
  101. };
  102. },
  103. onLoad(options) {
  104. if (options.orderId) {
  105. this.orderId = options.orderId
  106. }
  107. this.loadAnomalyTypes()
  108. },
  109. computed: {
  110. // 当前选中的类型显示文本
  111. selectedType() {
  112. return this.selectedTypeLabel || ''
  113. }
  114. },
  115. methods: {
  116. /**
  117. * 加载异常类型字典数据
  118. */
  119. async loadAnomalyTypes() {
  120. try {
  121. const res = await getDictDataByType('flf_anamaly_type')
  122. if (res.data && Array.isArray(res.data)) {
  123. this.anomalyTypes = res.data.map(item => ({
  124. label: item.dictLabel,
  125. value: item.dictValue,
  126. dictCode: item.dictCode
  127. }))
  128. console.log('异常类型字典:', this.anomalyTypes)
  129. }
  130. } catch (err) {
  131. console.error('获取异常类型字典失败:', err)
  132. }
  133. },
  134. // 打开类型选择器
  135. openTypeSheet() {
  136. this.showTypeSheet = true;
  137. },
  138. // 关闭类型选择器
  139. closeTypeSheet() {
  140. this.showTypeSheet = false;
  141. },
  142. // 选择异常类型
  143. selectType(type) {
  144. this.selectedTypeValue = type.value;
  145. this.selectedTypeLabel = type.label;
  146. this.closeTypeSheet();
  147. },
  148. // 选择照片并上传
  149. choosePhoto() {
  150. uni.chooseImage({
  151. count: 5 - this.photoList.length,
  152. sizeType: ['compressed'],
  153. sourceType: ['album', 'camera'],
  154. success: async (res) => {
  155. uni.showLoading({ title: '上传中...' });
  156. try {
  157. for (const filePath of res.tempFilePaths) {
  158. const uploadRes = await uploadFile(filePath);
  159. if (uploadRes.code === 200) {
  160. this.photoList.push({
  161. url: uploadRes.data.url,
  162. ossId: uploadRes.data.ossId,
  163. localPath: filePath
  164. });
  165. }
  166. }
  167. uni.hideLoading();
  168. } catch (err) {
  169. uni.hideLoading();
  170. console.error('上传失败:', err);
  171. uni.showToast({ title: '上传失败', icon: 'none' });
  172. }
  173. }
  174. });
  175. },
  176. // 删除照片
  177. removePhoto(idx) {
  178. this.photoList.splice(idx, 1);
  179. },
  180. // 提交上报
  181. async submitAnomaly() {
  182. if (!this.selectedTypeValue) {
  183. uni.showToast({ title: '请选择异常类型', icon: 'none' });
  184. return;
  185. }
  186. if (this.photoList.length === 0) {
  187. uni.showToast({ title: '请上传现场照片', icon: 'none' });
  188. return;
  189. }
  190. const data = {
  191. orderId: this.orderId,
  192. type: this.selectedTypeValue,
  193. content: this.anomalyDesc,
  194. photos: this.photoList.map(p => p.ossId)
  195. }
  196. try {
  197. uni.showLoading({ title: '提交中...' });
  198. await uploadAnamaly(data);
  199. uni.hideLoading();
  200. uni.showToast({ title: '上报成功', icon: 'success' });
  201. setTimeout(() => {
  202. uni.navigateBack();
  203. }, 1500);
  204. } catch (err) {
  205. uni.hideLoading();
  206. console.error('异常上报失败:', err);
  207. uni.showToast({ title: '提交失败,请重试', icon: 'none' });
  208. }
  209. }
  210. }
  211. };
  212. </script>
  213. <style>
  214. /* 页面背景 */
  215. .anomaly-container {
  216. min-height: 100vh;
  217. background-color: #F7F8FA;
  218. display: flex;
  219. flex-direction: column;
  220. }
  221. .anomaly-scroll {
  222. flex: 1;
  223. padding: 20rpx 30rpx 0;
  224. box-sizing: border-box;
  225. }
  226. /* 内容卡片 */
  227. .ano-card {
  228. background-color: #fff;
  229. border-radius: 16rpx;
  230. padding: 30rpx;
  231. margin-bottom: 20rpx;
  232. }
  233. /* 节标题 */
  234. .ano-section-title {
  235. display: flex;
  236. align-items: center;
  237. margin-bottom: 20rpx;
  238. }
  239. .ano-title-bar {
  240. width: 6rpx;
  241. height: 30rpx;
  242. background-color: #FF9800;
  243. border-radius: 3rpx;
  244. margin-right: 12rpx;
  245. }
  246. .ano-title-text {
  247. font-size: 30rpx;
  248. font-weight: bold;
  249. color: #333;
  250. }
  251. /* 异常类型行 */
  252. .ano-type-row {
  253. display: flex;
  254. align-items: center;
  255. justify-content: space-between;
  256. padding: 10rpx 0;
  257. }
  258. .ano-type-val {
  259. font-size: 28rpx;
  260. color: #333;
  261. flex: 1;
  262. }
  263. .ano-type-val.placeholder {
  264. color: #ccc;
  265. }
  266. .ano-right-arrow {
  267. width: 20rpx;
  268. height: 20rpx;
  269. }
  270. /* 描述文本框 */
  271. .ano-textarea {
  272. width: 100%;
  273. min-height: 200rpx;
  274. font-size: 28rpx;
  275. color: #333;
  276. line-height: 1.6;
  277. background-color: #FAFAFA;
  278. border-radius: 10rpx;
  279. padding: 20rpx;
  280. box-sizing: border-box;
  281. }
  282. /* 照片网格 */
  283. .ano-photo-grid {
  284. display: flex;
  285. flex-wrap: wrap;
  286. gap: 16rpx;
  287. }
  288. .ano-photo-item {
  289. width: 150rpx;
  290. height: 150rpx;
  291. border-radius: 12rpx;
  292. position: relative;
  293. overflow: hidden;
  294. }
  295. .ano-photo-preview {
  296. width: 100%;
  297. height: 100%;
  298. }
  299. .ano-photo-del {
  300. position: absolute;
  301. top: 4rpx;
  302. right: 4rpx;
  303. width: 36rpx;
  304. height: 36rpx;
  305. line-height: 32rpx;
  306. text-align: center;
  307. background-color: rgba(0, 0, 0, 0.5);
  308. color: #fff;
  309. border-radius: 50%;
  310. font-size: 28rpx;
  311. }
  312. .ano-photo-add {
  313. width: 150rpx;
  314. height: 150rpx;
  315. border: 2rpx dashed #E0E0E0;
  316. border-radius: 12rpx;
  317. background-color: #FAFAFA;
  318. display: flex;
  319. flex-direction: column;
  320. justify-content: center;
  321. align-items: center;
  322. }
  323. .ano-add-icon {
  324. width: 50rpx;
  325. height: 50rpx;
  326. margin-bottom: 10rpx;
  327. opacity: 0.5;
  328. }
  329. .ano-add-text {
  330. font-size: 24rpx;
  331. color: #999;
  332. }
  333. /* 底部提交 */
  334. .ano-footer {
  335. position: fixed;
  336. bottom: 0;
  337. left: 0;
  338. width: 100%;
  339. background-color: #FF9800;
  340. padding: 20rpx 40rpx;
  341. padding-bottom: constant(safe-area-inset-bottom);
  342. padding-bottom: env(safe-area-inset-bottom);
  343. box-sizing: border-box;
  344. }
  345. .ano-submit-btn {
  346. width: 100%;
  347. height: 90rpx;
  348. line-height: 90rpx;
  349. background: linear-gradient(90deg, #FF9800 0%, #FF5722 100%);
  350. color: #fff;
  351. font-size: 32rpx;
  352. font-weight: bold;
  353. border-radius: 45rpx;
  354. border: none;
  355. }
  356. .ano-submit-btn::after {
  357. border: none;
  358. }
  359. /* 异常类型选择器 */
  360. .ano-sheet-mask {
  361. position: fixed;
  362. top: 0;
  363. left: 0;
  364. width: 100%;
  365. height: 100%;
  366. background-color: rgba(0, 0, 0, 0.5);
  367. z-index: 999;
  368. display: flex;
  369. align-items: flex-end;
  370. }
  371. .ano-sheet {
  372. width: 100%;
  373. background-color: #fff;
  374. border-radius: 24rpx 24rpx 0 0;
  375. padding-bottom: constant(safe-area-inset-bottom);
  376. padding-bottom: env(safe-area-inset-bottom);
  377. }
  378. .ano-sheet-title {
  379. display: block;
  380. text-align: center;
  381. font-size: 28rpx;
  382. color: #999;
  383. padding: 30rpx 0 20rpx;
  384. border-bottom: 1px solid #f5f5f5;
  385. }
  386. .ano-sheet-list {
  387. max-height: 60vh;
  388. }
  389. .ano-sheet-item {
  390. display: flex;
  391. align-items: center;
  392. justify-content: space-between;
  393. padding: 30rpx 40rpx;
  394. border-bottom: 1px solid #f9f9f9;
  395. }
  396. .ano-sheet-item-text {
  397. font-size: 32rpx;
  398. color: #333;
  399. }
  400. .ano-sheet-item-text.selected {
  401. color: #FF9800;
  402. font-weight: bold;
  403. }
  404. .ano-check-icon {
  405. width: 20rpx;
  406. height: 20rpx;
  407. }
  408. .ano-sheet-cancel {
  409. text-align: center;
  410. font-size: 32rpx;
  411. color: #999;
  412. padding: 30rpx 0;
  413. border-top: 16rpx solid #F7F8FA;
  414. }
  415. </style>