You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

395 lines
12 KiB

​
3 months ago
​
​
​
​
​
​
​
3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
3 months ago
​
​
​
​
​
​
3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 month ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <template>
  2. <div class="po-order-detail">
  3. <!--
  4. 订单详情动态渲染区(按字段权限 schema 控制)
  5. 规则:
  6. 1) 普通字段固定 1 格(24 栅格中的 4)=> 一行 6 格;
  7. 2) Vendor Name 固定 2 格(8);
  8. 3) Comments 固定全行(24)。
  9. -->
  10. <el-form label-position="top" class="detail-form">
  11. <el-row :gutter="20">
  12. <el-col
  13. v-for="field in displayFields"
  14. :key="getFieldKey(field)"
  15. :span="getFieldSpan(field)">
  16. <el-form-item :label="getFieldLabel(field)">
  17. <el-input :value="getFieldDisplayValue(field)" disabled />
  18. </el-form-item>
  19. </el-col>
  20. </el-row>
  21. </el-form>
  22. </div>
  23. </template>
  24. <script>
  25. import { formatPoOrderTypeLabel } from './poOrderTypeOptions.js'
  26. export default {
  27. name: 'PoOrderDetail',
  28. props: {
  29. detailData: {
  30. type: Object,
  31. default: () => ({})
  32. },
  33. schemaFields: {
  34. type: Array,
  35. default: () => []
  36. },
  37. locale: {
  38. type: String,
  39. default: 'zh'
  40. }
  41. },
  42. data () {
  43. return {
  44. labelMap: {
  45. 'PO No': 'PO No',
  46. 'PO号': 'PO No',
  47. '订单类型': 'Order Type',
  48. '类型': 'Type',
  49. 'Customer': 'Customer',
  50. '客户': 'Customer',
  51. 'Buyer': 'Buyer',
  52. '采购员': 'Buyer',
  53. 'Vendor Name': 'Vendor Name',
  54. '供应商名称': 'Vendor Name',
  55. 'V_Short_Office': 'V_Short_Office',
  56. 'V_Short_NPC': 'V_Short_NPC',
  57. 'Part No': 'Part No',
  58. '产品编码': 'Part No',
  59. 'Item': 'Item',
  60. '项目': 'Item',
  61. 'Category': 'Category',
  62. '品类': 'Category',
  63. 'SKU': 'SKU',
  64. 'Unit Price': 'Unit Price',
  65. '单价': 'Unit Price',
  66. 'PO Qty': 'PO Qty',
  67. '数量': 'PO Qty',
  68. 'PO Value': 'PO Value',
  69. '金额': 'PO Value',
  70. 'ShippedQty': 'ShippedQty',
  71. 'A_Qty': 'A_Qty',
  72. 'A-Value': 'A-Value',
  73. 'Departure Port': 'Departure Port',
  74. '出发港': 'Departure Port',
  75. 'Destination Port': 'Destination Port',
  76. '目的港': 'Destination Port',
  77. 'Method': 'Method',
  78. '运输方式': 'Method',
  79. 'Buyer Release Date': 'Buyer Release Date',
  80. '采购发布日期': 'Buyer Release Date',
  81. 'Planner Release Date': 'Planner Release Date',
  82. '计划发布日期': 'Planner Release Date',
  83. 'Status': 'Status',
  84. '状态': 'Status',
  85. 'PI Confirmed Date': 'PI Confirmed Date',
  86. 'PI确认日期': 'PI Confirmed Date',
  87. 'Original Arrival Date': 'Original Arrival Date',
  88. '原始到货日期': 'Original Arrival Date',
  89. 'Final Confirmed Arrival Date': 'Final Confirmed Arrival Date',
  90. '最终确认到货日期': 'Final Confirmed Arrival Date',
  91. 'PI Confirmed CRD': 'PI Confirmed CRD',
  92. 'Original CRD': 'Original CRD',
  93. 'Inspection Date': 'Inspection Date',
  94. '验货日期': 'Inspection Date',
  95. 'Actual Completion Date': 'Actual Completion Date',
  96. '实际完成日期': 'Actual Completion Date',
  97. 'ETA': 'ETA',
  98. 'Flexport Id': 'Flexport Id',
  99. 'On Board Date': 'On Board Date',
  100. '装船日期': 'On Board Date',
  101. 'Doc Sent': 'Doc Sent',
  102. 'Telex Release': 'Telex Release',
  103. 'Advance Payment': 'Advance Payment',
  104. '预付款': 'Advance Payment',
  105. 'Advanc Paid': 'Advanc Paid',
  106. 'Create Date': 'Create Date',
  107. '创建日期': 'Create Date',
  108. 'M-Planner': 'M-Planner',
  109. '计划员': 'M-Planner',
  110. 'Edit Date': 'Edit Date',
  111. '编辑日期': 'Edit Date',
  112. 'Last Editor': 'Last Editor',
  113. '最后编辑人': 'Last Editor',
  114. 'Remark Delay': 'Remark Delay',
  115. '延迟备注': 'Remark Delay',
  116. 'Comments': 'Comments',
  117. '备注': 'Comments',
  118. 'Inspection Completed Qty': 'Inspection Completed Qty',
  119. '已验货数量': 'Inspection Completed Qty'
  120. }
  121. }
  122. },
  123. computed: {
  124. /**
  125. * 详情页签显示字段(基于权限 schema 动态决定)。
  126. * 处理逻辑:
  127. * 1) 仅保留 visibleFlag=Y 的字段;
  128. * 2) 同一 field_code 去重,防止异常配置导致重复渲染;
  129. * 3) 按 sortNo 升序,保证与列表页/权限配置顺序一致。
  130. * 返回值:用于页面渲染的字段数组(已过滤、去重、排序)。
  131. * 边界处理:schemaFields 非数组时直接返回空数组,避免页面渲染报错。
  132. */
  133. displayFields () {
  134. if (!Array.isArray(this.schemaFields)) {
  135. return []
  136. }
  137. const seen = new Set()
  138. const visible = this.schemaFields.filter(field => {
  139. if (!field) {
  140. return false
  141. }
  142. const visibleFlag = String(field.visibleFlag || 'Y').toUpperCase()
  143. if (visibleFlag !== 'Y') {
  144. return false
  145. }
  146. const key = this.getFieldKey(field)
  147. if (!key || seen.has(key)) {
  148. return false
  149. }
  150. seen.add(key)
  151. return true
  152. })
  153. return visible.sort((a, b) => {
  154. const left = Number(a && a.sortNo)
  155. const right = Number(b && b.sortNo)
  156. const la = Number.isFinite(left) ? left : Number.MAX_SAFE_INTEGER
  157. const rb = Number.isFinite(right) ? right : Number.MAX_SAFE_INTEGER
  158. if (la !== rb) {
  159. return la - rb
  160. }
  161. return this.getFieldKey(a).localeCompare(this.getFieldKey(b))
  162. })
  163. }
  164. },
  165. methods: {
  166. /**
  167. * 生成字段唯一键。
  168. * 优先级:fieldCode > fieldProp > fieldLabel。
  169. * 入参:field(单个字段 schema 对象,允许为空)。
  170. * 返回值:稳定字符串 key;若字段信息缺失则返回空字符串。
  171. * 边界处理:字段为空时走空字符串回退,避免 v-for key 异常。
  172. */
  173. getFieldKey (field) {
  174. const code = this.getFieldCode(field)
  175. if (code) {
  176. return code
  177. }
  178. const prop = this.getFieldProp(field)
  179. if (prop) {
  180. return prop
  181. }
  182. return String((field && field.fieldLabel) || '').trim()
  183. },
  184. /**
  185. * 解析字段编码(snake_case)。
  186. * 入参兼容:
  187. * 1) 后端直接返回 fieldCode;
  188. * 2) 无 fieldCode 时由 fieldProp 反推 snake_case。
  189. * 入参:field(字段 schema 对象)。
  190. * 返回值:字段编码字符串;无法解析时返回空字符串。
  191. * 边界处理:field 为空或关键属性缺失时不抛错,统一回空串。
  192. */
  193. getFieldCode (field) {
  194. if (!field) {
  195. return ''
  196. }
  197. const code = String(field.fieldCode || '').trim()
  198. if (code) {
  199. return code.toLowerCase()
  200. }
  201. const prop = String(field.fieldProp || '').trim()
  202. return prop ? this.camelToSnake(prop) : ''
  203. },
  204. /**
  205. * 解析字段属性(camelCase),用于读取当前行对象值。
  206. * 入参兼容:
  207. * 1) 后端直接返回 fieldProp;
  208. * 2) 无 fieldProp 时由 fieldCode 反推 camelCase。
  209. * 入参:field(字段 schema 对象)。
  210. * 返回值:字段属性名;无法解析时返回空字符串。
  211. * 边界处理:field 为空或编码异常时统一回空串,避免取值报错。
  212. */
  213. getFieldProp (field) {
  214. if (!field) {
  215. return ''
  216. }
  217. const prop = String(field.fieldProp || '').trim()
  218. if (prop) {
  219. return prop
  220. }
  221. const code = String(field.fieldCode || '').trim()
  222. return code ? this.snakeToCamel(code) : ''
  223. },
  224. /**
  225. * 获取展示标签。
  226. * 优先 fieldLabel;若异常缺失则回退字段属性名,避免出现空标签。
  227. * 入参:field(字段 schema 对象)。
  228. * 返回值:展示标签字符串。
  229. * 边界处理:label/prop/code 都缺失时返回空串,不中断渲染流程。
  230. */
  231. getFieldLabel (field) {
  232. const label = String((field && field.fieldLabel) || '').trim()
  233. if (label) {
  234. if (this.locale === 'en' && this.labelMap[label]) {
  235. return this.labelMap[label]
  236. }
  237. return label
  238. }
  239. return this.getFieldProp(field) || this.getFieldCode(field)
  240. },
  241. /**
  242. * 按业务布局规则计算栅格宽度:
  243. * - Vendor Name(supplier_name): 2格 => span=8
  244. * - Comments(remark): 全行 => span=24
  245. * - 其他字段: 1格 => span=4
  246. * 入参:field(字段 schema 对象)。
  247. * 返回值:Element 栅格 span 数值。
  248. * 边界处理:未匹配特殊字段时统一走默认 1 格,保证布局稳定。
  249. */
  250. getFieldSpan (field) {
  251. const code = this.getFieldCode(field)
  252. const label = this.getFieldLabel(field).trim().toLowerCase()
  253. if (code === 'supplier_name' || label === 'vendor name') {
  254. return 8
  255. }
  256. if (code === 'remark' || code === 'comments' || label === 'comments') {
  257. return 24
  258. }
  259. return 4
  260. },
  261. /**
  262. * 读取详情字段原始值。
  263. * 读取顺序:
  264. * 1) detailData[fieldProp]
  265. * 2) detailData[fieldCode](兼容少量 snake_case 回传)
  266. * 3) detailData.extValues[fieldCode/fieldProp](兼容扩展字段)
  267. * 入参:field(字段 schema 对象)。
  268. * 返回值:原始字段值;取不到值时返回空字符串。
  269. * 边界处理:detailData/extValues 为空或结构异常时安全降级为空串。
  270. */
  271. getFieldRawValue (field) {
  272. const row = this.detailData || {}
  273. const prop = this.getFieldProp(field)
  274. const code = this.getFieldCode(field)
  275. if (prop && row[prop] !== undefined && row[prop] !== null) {
  276. return row[prop]
  277. }
  278. if (code && row[code] !== undefined && row[code] !== null) {
  279. return row[code]
  280. }
  281. const extValues = row.extValues && typeof row.extValues === 'object' ? row.extValues : null
  282. if (extValues) {
  283. if (code && extValues[code] !== undefined && extValues[code] !== null) {
  284. return extValues[code]
  285. }
  286. if (prop && extValues[prop] !== undefined && extValues[prop] !== null) {
  287. return extValues[prop]
  288. }
  289. }
  290. return ''
  291. },
  292. /**
  293. * 获取最终显示值。
  294. * 特殊处理:
  295. * 1) order_type/orderType 走统一枚举格式化;
  296. * 2) 其余字段按原值输出,空值统一返回空字符串。
  297. * 入参:field(字段 schema 对象)。
  298. * 返回值:可直接绑定到输入框的展示值。
  299. * 边界处理:空值统一归一为空串,避免界面出现 undefined/null。
  300. */
  301. getFieldDisplayValue (field) {
  302. const raw = this.getFieldRawValue(field)
  303. const code = this.getFieldCode(field)
  304. const prop = this.getFieldProp(field)
  305. // rqrq - 详情仅展示英文,保留 detailData.status 原值供业务使用。
  306. if (code === 'status' || prop === 'status') {
  307. const row = this.detailData || {}
  308. return row.statusDisplay != null ? row.statusDisplay : raw
  309. }
  310. if (raw === null || raw === undefined) {
  311. return ''
  312. }
  313. if (code === 'order_type' || prop === 'orderType') {
  314. return formatPoOrderTypeLabel(raw)
  315. }
  316. return raw
  317. },
  318. /**
  319. * snake_case 转 camelCase。
  320. * 入参:snake(下划线字段名)。
  321. * 返回值:camelCase 字段名;入参为空时原样返回。
  322. */
  323. snakeToCamel (snake) {
  324. if (!snake || !snake.includes('_')) {
  325. return snake
  326. }
  327. return snake.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase())
  328. },
  329. /**
  330. * camelCase 转 snake_case。
  331. * 入参:camel(驼峰字段名)。
  332. * 返回值:snake_case 字段名;入参为空时返回空字符串。
  333. */
  334. camelToSnake (camel) {
  335. if (!camel) {
  336. return ''
  337. }
  338. return camel.replace(/([A-Z])/g, '_$1').toLowerCase()
  339. }
  340. }
  341. }
  342. </script>
  343. <style scoped lang="scss">
  344. .po-order-detail {
  345. width: 100%;
  346. }
  347. .detail-form {
  348. width: 100%;
  349. }
  350. .el-form-item {
  351. margin-bottom: 6px;
  352. }
  353. /deep/ .el-form-item__label {
  354. font-size: 14px;
  355. color: #606266;
  356. line-height: 1.5;
  357. padding-bottom: 6px;
  358. font-weight: normal;
  359. }
  360. /deep/ .el-input__inner {
  361. height: 32px;
  362. line-height: 32px;
  363. font-size: 13px;
  364. border-radius: 4px;
  365. border: 1px solid #dcdfe6;
  366. background-color: #fff;
  367. }
  368. /deep/ .el-input.is-disabled .el-input__inner {
  369. background-color: #f5f7fa;
  370. border-color: #e4e7ed;
  371. color: #c0c4cc;
  372. cursor: not-allowed;
  373. }
  374. /deep/ .el-input__inner:focus {
  375. border-color: #409eff;
  376. outline: none;
  377. }
  378. </style>