add.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <uni-popup class="materials-popup" ref="materialAddPopRef" type="bottom" :is-mask-click="false"
  3. borderRadius="10px 10px 0 0 " background-color="#fff">
  4. <uni-row class="head-row align-center">
  5. <uni-col :span="6" class="head-cancel align-center justify-start" @click="oncancel">
  6. {{$t('operation.cancel')}}
  7. </uni-col>
  8. <uni-col :span="12" class="head-title justify-center">
  9. {{$t('workOrder.addMaterial')}}
  10. </uni-col>
  11. <uni-col :span="6" class="head-add align-center justify-end" @click="onConfirm(materialAddFormRef)">
  12. {{$t('operation.confirm')}}
  13. </uni-col>
  14. </uni-row>
  15. <view class="material-add-section">
  16. <uni-forms ref="materialAddFormRef" labelWidth="140px" :modelValue="addInfo" :rules="formRules">
  17. <!-- 物料主数据 -->
  18. <uni-forms-item class="form-item" :label="$t('workOrder.masterData')" name="name" :required="true">
  19. <uni-easyinput style="text-align: right" :inputBorder="false" :clearable="false"
  20. :styles="{disableColor:'#fff'}" :placeholder="$t('operation.PleaseSelect')"
  21. v-model="addInfo.name" @focus="onMasterDataShow" />
  22. </uni-forms-item>
  23. <!-- 物料编码 -->
  24. <uni-forms-item class="form-item" :label="$t('workOrder.materialCode')" name="code" :required="true">
  25. <uni-easyinput style="text-align: right" :inputBorder="false" :clearable="false" :disabled="true"
  26. :styles="{disableColor:'#fff'}" v-model="addInfo.code"
  27. :placeholder="''" />
  28. </uni-forms-item>
  29. <!-- 物料名称 -->
  30. <uni-forms-item class="form-item" :label="$t('workOrder.materialName')" name="name" :required="true">
  31. <uni-easyinput style="text-align: right" :inputBorder="false" :clearable="false" :disabled="true"
  32. :styles="{disableColor:'#fff'}" v-model="addInfo.name"
  33. :placeholder="''" />
  34. </uni-forms-item>
  35. <!-- 单位 -->
  36. <uni-forms-item class="form-item" :label="$t('workOrder.unit')" name="unit" :required="false">
  37. <uni-easyinput style="text-align: right" :inputBorder="false" :clearable="false" :disabled="true"
  38. :styles="{disableColor:'#fff'}" v-model="addInfo.unit"
  39. :placeholder="''" />
  40. </uni-forms-item>
  41. <!-- 消耗数量 -->
  42. <uni-forms-item class="form-item" :label="$t('workOrder.consumptionQuantity')" name="quantity"
  43. :required="true">
  44. <uni-easyinput style="text-align: right" :inputBorder="false" :clearable="false"
  45. :styles="{disableColor:'#fff'}" type="digit" v-model="addInfo.quantity"
  46. :placeholder="$t('operation.PleaseFillIn')" />
  47. </uni-forms-item>
  48. <!-- 单价(元) -->
  49. <uni-forms-item class="form-item" :label="$t('workOrder.unitPrice')" name="unitPrice" :required="true">
  50. <uni-easyinput style="text-align: right" :inputBorder="false" :clearable="false" type="digit"
  51. :styles="{disableColor:'#fff'}" v-model="addInfo.unitPrice"
  52. :placeholder="$t('operation.PleaseFillIn')" />
  53. </uni-forms-item>
  54. <!-- 备注 -->
  55. <uni-forms-item class="form-item" :label="$t('operation.remark')" :required="false" name="remark">
  56. <uni-easyinput style="text-align: right" type="textarea" :autoHeight="true" :inputBorder="false"
  57. :clearable="false" :styles="{disableColor:'#fff'}" v-model="addInfo.remark"
  58. :placeholder="$t('operation.PleaseFillIn')" />
  59. </uni-forms-item>
  60. </uni-forms>
  61. </view>
  62. </uni-popup>
  63. <master-data ref="masterDataRef" @master-data-submit="onMasterDataSet"></master-data>
  64. </template>
  65. <script setup>
  66. import dayjs from 'dayjs'
  67. import {
  68. computed,
  69. ref,
  70. reactive,
  71. watch,
  72. onMounted,
  73. } from 'vue'
  74. import {
  75. useI18n
  76. } from 'vue-i18n'
  77. import {
  78. getDeptId,
  79. } from "@/utils/auth"
  80. import {
  81. getMaterialListData
  82. } from '@/api/material'
  83. import {
  84. devicePage,
  85. } from '@/api/device';
  86. import masterData from './master-data'
  87. const {
  88. t,
  89. locale
  90. } = useI18n({
  91. useScope: 'global'
  92. })
  93. // 接收父组件传递的参数
  94. const props = defineProps({})
  95. const addInfo = ref({
  96. // code: '',
  97. // name: '',
  98. // unit: '',
  99. // quantity: '',
  100. // unitPrice: '',
  101. // remark: '',
  102. })
  103. const materialAddFormRef = ref(null)
  104. const formRules = ref({
  105. name: {
  106. rules: [{
  107. required: true,
  108. errorMessage: t('operation.PleaseFillIn'),
  109. }, ]
  110. },
  111. quantity: {
  112. rules: [{
  113. required: true,
  114. errorMessage: t('operation.PleaseFillIn'),
  115. }, ]
  116. },
  117. unitPrice: {
  118. rules: [{
  119. required: true,
  120. errorMessage: t('operation.PleaseFillIn'),
  121. }, ]
  122. },
  123. })
  124. const oncancel = () => {
  125. addInfo.value = {}
  126. close()
  127. }
  128. const onConfirm = async (formEl) => {
  129. if (!formEl) return
  130. await formEl.validate().then(res => {
  131. console.log('onConfirm res-', res)
  132. addInfo.value.chooseKey = `${addInfo.value.id}_${addInfo.value.code}_${addInfo.value.unitPrice}` // 手动拼接chooseKey
  133. emit('add-set', addInfo.value)
  134. oncancel()
  135. }).catch(err => {
  136. console.error('onConfirm err-', err)
  137. })
  138. }
  139. const masterDataRef = ref(null)
  140. const onMasterDataShow = () => {
  141. masterDataRef.value.open()
  142. }
  143. const onMasterDataSet = (item) => {
  144. console.log('onMasterDataSet-', item)
  145. addInfo.value = {
  146. ...addInfo.value,
  147. ...item,
  148. }
  149. }
  150. onMounted(() => {})
  151. const materialAddPopRef = ref(null)
  152. // 打开弹窗
  153. const open = () => {
  154. materialAddPopRef.value.open()
  155. }
  156. // 关闭弹窗
  157. const close = () => {
  158. materialAddPopRef.value.close()
  159. }
  160. const emit = defineEmits(['add-set'])
  161. // 提供外部方法
  162. const expose = {
  163. open,
  164. }
  165. defineExpose(expose)
  166. </script>
  167. <style lang="scss" scoped>
  168. @import "@/style/work-order-detail.scss";
  169. .materials-popup {
  170. width: 100%;
  171. height: 100%;
  172. min-height: 411px;
  173. background-color: #fff;
  174. padding: 20px;
  175. }
  176. :deep(.uni-popup__wrapper) {
  177. padding: 20px;
  178. }
  179. .head-row {
  180. margin-bottom: 20px;
  181. font-size: 16px;
  182. line-height: 21px;
  183. color: #A3A3A3;
  184. height: 40px;
  185. border-bottom: 1px dashed #CACCCF;
  186. }
  187. .head-title {
  188. color: #333333;
  189. font-weight: bold;
  190. }
  191. .head-add {
  192. color: #004098;
  193. }
  194. </style>