index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class="jnpf-relation-form-attr">
  3. <u-input v-model="innerValue" input-align='right' disabled :placeholder="placeholder" />
  4. </view>
  5. </template>
  6. <script>
  7. import {
  8. useBaseStore
  9. } from '@/store/modules/base'
  10. const baseStore = useBaseStore()
  11. export default {
  12. name: 'jnpf-relation-form-attr',
  13. props: {
  14. modelValue: {
  15. type: [String, Number],
  16. default: ''
  17. },
  18. showField: {
  19. type: String,
  20. default: ''
  21. },
  22. relationField: {
  23. type: String,
  24. default: ''
  25. },
  26. type: {
  27. type: String,
  28. default: 'relationFormAttr'
  29. },
  30. isStorage: {
  31. type: Number,
  32. default: 0
  33. },
  34. },
  35. data() {
  36. return {
  37. innerValue: '',
  38. placeholder: ''
  39. }
  40. },
  41. computed: {
  42. relationData() {
  43. return baseStore.relationData
  44. }
  45. },
  46. watch: {
  47. relationData: {
  48. handler(val) {
  49. if (!this.showField || !this.relationField) return
  50. let obj = val[this.relationField] || {}
  51. this.innerValue = obj[this.showField] ? obj[this.showField] : ''
  52. this.$emit('change', this.innerValue)
  53. },
  54. deep: true
  55. },
  56. innerValue(val) {
  57. this.$emit('update:modelValue', val)
  58. }
  59. },
  60. created() {
  61. const placeholder = this.type === 'relationFormAttr' ? this.isStorage ? this.$t(
  62. 'component.jnpf.relationFormAttr.storage') : this.$t('component.jnpf.relationFormAttr.unStorage') :
  63. this.isStorage ? this.$t('component.jnpf.popupAttr.storage') : this.$t(
  64. 'component.jnpf.popupAttr.unStorage')
  65. this.placeholder = placeholder
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .jnpf-relation-form-attr {
  71. width: 100%;
  72. text-align: right;
  73. }
  74. </style>