Attribute.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="attribute">
  3. <van-dialog v-model:show="attributeTrueFalseBy"
  4. title="维护货品属性"
  5. show-cancel-button
  6. :beforeClose="beforeClose"
  7. :keyboardEnabled="false"
  8. >
  9. <div>
  10. <van-form>
  11. <van-cell-group inset>
  12. <van-field v-if="attribute.includes('size')"
  13. v-model="length"
  14. name="length"
  15. type="number"
  16. label="长/厘米:"
  17. placeholder="请输入长/厘米"
  18. :label-width="70"
  19. clearable
  20. autocomplete="off"
  21. />
  22. <van-field v-if="attribute.includes('size')"
  23. v-model="width"
  24. name="width"
  25. type="number"
  26. label="宽/厘米:"
  27. placeholder="请输入宽/厘米"
  28. :label-width="70"
  29. clearable
  30. autocomplete="off"
  31. />
  32. <van-field v-if="attribute.includes('size')"
  33. v-model="height"
  34. name="height"
  35. type="number"
  36. label="高/厘米:"
  37. placeholder="请输入高/厘米"
  38. :label-width="70"
  39. clearable
  40. autocomplete="off"
  41. />
  42. <van-field v-if="attribute.includes('metering')"
  43. v-model="weight"
  44. name="weight"
  45. type="number"
  46. label="重量/千克:"
  47. placeholder="请输入重量/千克"
  48. :label-width="70"
  49. clearable
  50. autocomplete="off"
  51. />
  52. <van-field v-if="attribute.includes('carton')"
  53. v-model="packCarton"
  54. name="packCarton"
  55. type="number"
  56. label="每箱件数:"
  57. placeholder="请输入每箱件数"
  58. :label-width="70"
  59. clearable
  60. autocomplete="off"
  61. />
  62. <van-field v-if="attribute.includes('carton') && midPackSpecEnabled"
  63. v-model="midPackSpec"
  64. name="midPackSpec"
  65. type="number"
  66. label="每包件数:"
  67. placeholder="请输入每包件数"
  68. :label-width="70"
  69. clearable
  70. autocomplete="off"
  71. />
  72. </van-cell-group>
  73. </van-form>
  74. </div>
  75. </van-dialog>
  76. </div>
  77. </template>
  78. <script setup>
  79. import { ref } from 'vue'
  80. import { showToast } from 'vant'
  81. const attributeTrueFalseBy = ref(false)
  82. //长/厘米
  83. const length = ref('')
  84. //宽/厘米
  85. const width = ref('')
  86. //高/厘米
  87. const height = ref('')
  88. //每箱件数
  89. const packCarton = ref('')
  90. //重量/千克
  91. const weight = ref('')
  92. const packId=ref('')
  93. const attribute = ref([])
  94. const midPackSpec = ref('')
  95. const midPackSpecEnabled = ref(false)
  96. const show = (item, attributeMap) => {
  97. midPackSpec.value =''
  98. length.value =''
  99. width.value =''
  100. height.value = ''
  101. packCarton.value = attributeMap.packCarton
  102. packId.value =attributeMap.packId
  103. weight.value = ''
  104. attribute.value = item
  105. midPackSpecEnabled.value = attributeMap.midPackSpecEnabled
  106. attributeTrueFalseBy.value = true
  107. }
  108. const emit = defineEmits()
  109. const beforeClose = (action) =>
  110. new Promise(async (resolve) => {
  111. if (action === 'confirm') {
  112. if (['size'].some(val => attribute.value.includes(val))) {
  113. if (!length.value || !width.value || !height.value ) {
  114. showToast('请输入长宽高')
  115. return resolve(false)
  116. }
  117. }
  118. if (['metering'].some(val => attribute.value.includes(val))) {
  119. if (!weight.value) {
  120. showToast('请输入重量')
  121. return resolve(false)
  122. }
  123. }
  124. if (['carton'].some(val => attribute.value.includes(val))) {
  125. if (!packCarton.value) {
  126. showToast('请输入每箱件数')
  127. return resolve(false)
  128. }
  129. if (midPackSpecEnabled.value && !midPackSpec.value) {
  130. showToast('请输入每包件数')
  131. return resolve(false)
  132. }
  133. }
  134. const data = {
  135. height: height.value ? height.value / 100 : undefined,
  136. length: length.value ? length.value / 100 : undefined,
  137. width: width.value ? width.value / 100 : undefined,
  138. packCarton: packCarton.value,
  139. packId: midPackSpecEnabled.value ? '1/' +midPackSpec.value+'/' + packCarton.value : packCarton.value ? '1/' + packCarton.value : 'STANDARD',
  140. weight: weight.value ? weight.value: undefined ,
  141. cube:(height.value && width.value && length.value)? (height.value / 100) * (length.value / 100) * (width.value / 100):undefined,
  142. }
  143. emit('setAttribute', data)
  144. }
  145. resolve(true)
  146. })
  147. defineExpose({ show })
  148. </script>
  149. <style lang="scss" scoped>
  150. </style>