add.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <uni-popup
  3. class="repairs-popup"
  4. ref="repairAddPopRef"
  5. type="bottom"
  6. :is-mask-click="false"
  7. borderRadius="10px 10px 0 0 "
  8. background-color="#fff"
  9. >
  10. <uni-row class="head-row align-center">
  11. <uni-col
  12. :span="6"
  13. class="head-cancel align-center justify-start"
  14. @click="oncancel"
  15. >
  16. {{ $t("operation.cancel") }}
  17. </uni-col>
  18. <uni-col :span="12" class="head-title justify-center">
  19. {{ $t("operation.add")
  20. }}{{ $t("equipmentMaintenance.maintenanceItems") }}
  21. </uni-col>
  22. <uni-col
  23. :span="6"
  24. class="head-add align-center justify-end"
  25. @click="onConfirm(repairAddFormRef)"
  26. >
  27. {{ $t("operation.confirm") }}
  28. </uni-col>
  29. </uni-row>
  30. <view class="repair-add-section">
  31. <uni-forms
  32. ref="repairAddFormRef"
  33. labelWidth="140px"
  34. :modelValue="addInfo"
  35. :rules="formRules"
  36. >
  37. <!-- 设备编码 -->
  38. <uni-forms-item
  39. class="form-item"
  40. :label="$t('device.deviceCode')"
  41. name="deviceCode"
  42. :required="true"
  43. >
  44. <uni-easyinput
  45. style="text-align: right"
  46. :inputBorder="false"
  47. :clearable="false"
  48. :disabled="true"
  49. :styles="{ disableColor: '#fff' }"
  50. v-model="addInfo.deviceCode"
  51. :placeholder="$t('operation.PleaseFillIn')"
  52. />
  53. </uni-forms-item>
  54. <!-- 设备名称 -->
  55. <uni-forms-item
  56. class="form-item"
  57. :label="$t('device.deviceName')"
  58. name="deviceName"
  59. :required="true"
  60. >
  61. <uni-easyinput
  62. style="text-align: right"
  63. :inputBorder="false"
  64. :clearable="false"
  65. :disabled="true"
  66. :styles="{ disableColor: '#fff' }"
  67. v-model="addInfo.deviceName"
  68. :placeholder="$t('operation.PleaseFillIn')"
  69. />
  70. </uni-forms-item>
  71. <!-- 维修项 -->
  72. <uni-forms-item
  73. class="form-item"
  74. :label="$t('equipmentMaintenance.maintenanceItems')"
  75. name="name"
  76. :required="false"
  77. >
  78. <uni-easyinput
  79. style="text-align: right"
  80. :inputBorder="false"
  81. :clearable="false"
  82. :disabled="false"
  83. :styles="{ disableColor: '#fff' }"
  84. v-model="addInfo.name"
  85. :placeholder="$t('operation.PleaseFillIn')"
  86. />
  87. </uni-forms-item>
  88. </uni-forms>
  89. </view>
  90. </uni-popup>
  91. </template>
  92. <script setup>
  93. import dayjs from "dayjs";
  94. import { computed, ref, reactive, watch, onMounted } from "vue";
  95. import { useI18n } from "vue-i18n";
  96. import { getDeptId } from "@/utils/auth";
  97. const { t, locale } = useI18n({
  98. useScope: "global",
  99. });
  100. // 接收父组件传递的参数
  101. const props = defineProps({});
  102. const allBoms = ref([]);
  103. const addInfo = ref({});
  104. const repairAddFormRef = ref(null);
  105. const formRules = ref({
  106. name: {
  107. rules: [
  108. {
  109. required: true,
  110. errorMessage: t("operation.PleaseFillIn"),
  111. },
  112. ],
  113. },
  114. });
  115. const oncancel = () => {
  116. addInfo.value = {};
  117. close();
  118. };
  119. const onConfirm = async (formEl) => {
  120. if (!formEl) return;
  121. await formEl
  122. .validate()
  123. .then((res) => {
  124. console.log("onConfirm res-", res);
  125. addInfo.value.chooseKey = `${addInfo.value.deviceCode}_${addInfo.value.deviceName}_${addInfo.value.name}`; // 手动拼接chooseKey
  126. // 生成8位随机数字作为bomNodeId
  127. addInfo.value.bomNodeId = Math.floor(Math.random() * 100000000); //.toString();
  128. // 判断addInfo.value.chooseKey是否在allBoms.value中
  129. if (allBoms.value.includes(addInfo.value.chooseKey)) {
  130. uni.showToast({
  131. title:
  132. t("equipmentMaintenance.maintenanceItems") + t("operation.repeat"),
  133. icon: "none",
  134. });
  135. } else {
  136. emit("add-set", addInfo.value);
  137. oncancel();
  138. }
  139. })
  140. .catch((err) => {
  141. console.error("onConfirm err-", err);
  142. });
  143. };
  144. onMounted(() => {});
  145. const repairAddPopRef = ref(null);
  146. // 打开弹窗
  147. const open = (info) => {
  148. const { bom, ...device } = info;
  149. console.log("repair-open", info, bom);
  150. addInfo.value = device;
  151. // 遍历bom,返回deviceCode,deviceName,name拼接成的字符串形成新数组赋值allBoms
  152. allBoms.value = bom.map(
  153. (item) => `${item.deviceCode}_${item.deviceName}_${item.name}`
  154. );
  155. console.log("allBoms.value-", allBoms.value);
  156. repairAddPopRef.value.open();
  157. };
  158. // 关闭弹窗
  159. const close = () => {
  160. repairAddPopRef.value.close();
  161. };
  162. const emit = defineEmits(["add-set"]);
  163. // 提供外部方法
  164. const expose = {
  165. open,
  166. };
  167. defineExpose(expose);
  168. </script>
  169. <style lang="scss" scoped>
  170. @import "@/style/work-order-detail.scss";
  171. .repairs-popup {
  172. width: 100%;
  173. height: 100%;
  174. min-height: 411px;
  175. background-color: #fff;
  176. padding: 20px;
  177. }
  178. :deep(.uni-popup__wrapper) {
  179. padding: 20px;
  180. }
  181. .head-row {
  182. margin-bottom: 20px;
  183. font-size: 16px;
  184. line-height: 21px;
  185. color: #a3a3a3;
  186. height: 40px;
  187. border-bottom: 1px dashed #cacccf;
  188. }
  189. .head-title {
  190. color: #333333;
  191. font-weight: bold;
  192. }
  193. .head-add {
  194. color: #004098;
  195. }
  196. </style>