index.vue 12 KB

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