anomaly.vue 12 KB

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