count.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <uni-popup class="count-popup" ref="countPopRef" type="center" :is-mask-click="false"
  3. borderRadius="10px 10px 10px 10px" background-color="#fff">
  4. <view class="popup-container">
  5. <view class="pop-title flex-row align-center justify-center">
  6. {{$t('operation.PleaseSet')}}{{$t('workOrder.materialCount')}}
  7. <uni-icons type="closeempty" color="#666" class="pop-close" @click="onclose"></uni-icons>
  8. </view>
  9. <view class="pop-content">
  10. <view class="content-cell flex-row align-center justify-between">
  11. <view class="cell-title">
  12. {{$t('workOrder.materialName')}}:
  13. </view>
  14. <view>
  15. {{materialItem.materialName}}
  16. </view>
  17. </view>
  18. <view class="content-cell flex-row align-center justify-between">
  19. <view class="cell-title">
  20. {{$t('workOrder.remainingInventory')}}:
  21. </view>
  22. <view>
  23. {{materialItem.totalInventoryQuantity}}
  24. </view>
  25. </view>
  26. <view class="content-cell flex-row align-center justify-between">
  27. <view class="cell-title">
  28. {{$t('workOrder.materialCount')}}:
  29. </view>
  30. <view>
  31. <uni-easyinput style="text-align: right" :inputBorder="false" :clearable="true" type="digit"
  32. :styles="{ disableColor: '#fff' }" v-model="materialItem.quantity"
  33. :placeholder="$t('operation.PleaseFillIn')" @change="changeQuantity" />
  34. </view>
  35. </view>
  36. </view>
  37. <button type="primary" class="pop-btn" @click="onsubmit">
  38. {{$t('operation.confirm')}}
  39. </button>
  40. </view>
  41. </uni-popup>
  42. </template>
  43. <script setup>
  44. import {
  45. ref,
  46. getCurrentInstance
  47. } from 'vue'
  48. // 引用全局变量$t
  49. const {
  50. appContext
  51. } = getCurrentInstance();
  52. const t = appContext.config.globalProperties.$t;
  53. const quantityMin = ref(0)
  54. const materialItem = ref({})
  55. const countPopRef = ref(null)
  56. const showCountPop = (iten) => {
  57. materialItem.value = iten
  58. materialItem.value.quantity = 1
  59. countPopRef.value.open()
  60. }
  61. const hideCountPop = () => {
  62. countPopRef.value.close()
  63. }
  64. const onclose = () => {
  65. materialItem.quantity = null
  66. hideCountPop()
  67. }
  68. const changeQuantity = (e) => {
  69. console.log('changeQuantity', e)
  70. if (validateQuantity(e)) {
  71. materialItem.value.quantity = e
  72. }
  73. }
  74. const emit = defineEmits(['count-set', ])
  75. const validateQuantity = (quantity) => {
  76. if (!quantity) {
  77. uni.showToast({
  78. title: t("workOrder.materialCountEmpty"),
  79. icon: 'none'
  80. })
  81. return false
  82. }
  83. if (quantity <= 0) {
  84. uni.showToast({
  85. title: t("workOrder.materialCountMustGreaterThan0"),
  86. icon: 'none'
  87. })
  88. return false
  89. }
  90. return true
  91. }
  92. const onsubmit = () => {
  93. console.log('materialItem.value', materialItem.value)
  94. if (validateQuantity(materialItem.value.quantity)) {
  95. // 提交设置的数量
  96. emit('count-set', Object.assign({}, materialItem.value))
  97. materialItem.value.quantity = null
  98. // hideCountPop()
  99. }
  100. }
  101. defineExpose({
  102. showCountPop,
  103. hideCountPop
  104. })
  105. </script>
  106. <style lang="scss" scoped>
  107. .popup-container {
  108. width: 308px;
  109. min-height: 217px;
  110. background: #FFFFFF;
  111. box-shadow: 0px -2px 10px 0px rgba(0, 0, 0, 0.1);
  112. border-radius: 10px;
  113. box-sizing: border-box;
  114. padding: 20px 30px;
  115. position: relative;
  116. }
  117. .pop-title {
  118. font-weight: bold;
  119. font-size: 16px;
  120. color: #333333;
  121. line-height: 22px;
  122. }
  123. .pop-close {
  124. position: absolute;
  125. right: 10px;
  126. top: 10px;
  127. }
  128. .content-cell {
  129. font-size: 14px;
  130. color: #333333;
  131. font-weight: 500;
  132. min-height: 30px;
  133. border-bottom: 1px dashed #CACCCF;
  134. text-align: right;
  135. &:last-child {
  136. // border-bottom: none;
  137. }
  138. &:first-child {
  139. margin-top: 20px;
  140. }
  141. }
  142. .cell-title {
  143. min-width: max-content;
  144. }
  145. .pop-btn {
  146. margin-top: 20px;
  147. width: 120px;
  148. height: 32px;
  149. line-height: 32px;
  150. font-size: 14px;
  151. }
  152. </style>