turnBack.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div class="application-dialog-container">
  3. <el-dialog
  4. :title="state.dialog.title"
  5. @close="onCancel"
  6. :close-on-click-modal="false"
  7. v-model="state.dialog.isShowDialog"
  8. width="90%"
  9. >
  10. <el-form
  11. ref="expertDialogFormRef"
  12. :model="state.form"
  13. :rules="rules"
  14. size="default"
  15. label-width="140px"
  16. label-position="top"
  17. >
  18. <el-row
  19. class="mb20"
  20. :gutter="20"
  21. >
  22. <el-col :span="24">
  23. <el-form-item label="是否转回">
  24. <el-radio-group
  25. :disabled="state.dialog.type === 'view'"
  26. v-model="isReturn"
  27. >
  28. <el-radio
  29. :label="1"
  30. size="large"
  31. >
  32. </el-radio>
  33. <el-radio
  34. :label="0"
  35. size="large"
  36. >
  37. </el-radio>
  38. </el-radio-group>
  39. </el-form-item>
  40. </el-col>
  41. </el-row>
  42. <!-- <el-row class="mb20">
  43. <el-col :span="24">
  44. <el-form-item
  45. label="品种品系"
  46. prop="categoryId"
  47. >
  48. <el-select
  49. v-model="state.form.categoryId"
  50. placeholder="请选择"
  51. >
  52. <el-option
  53. v-for="item in animalTypeList"
  54. :key="item.id"
  55. :label="item.name"
  56. :value="item.id"
  57. />
  58. </el-select>
  59. </el-form-item>
  60. </el-col>
  61. </el-row> -->
  62. <el-row v-if="isReturn === 1">
  63. <el-col :span="24">
  64. <el-form-item
  65. label="转回日期"
  66. prop="returnDate"
  67. >
  68. <el-date-picker
  69. v-model="state.form.returnDate"
  70. type="date"
  71. placeholder="请选择时间"
  72. clearable
  73. value-format="YYYY-MM-DD"
  74. style="width: 100%"
  75. />
  76. </el-form-item>
  77. </el-col>
  78. </el-row>
  79. <el-row
  80. class="mb20"
  81. v-if="isReturn === 0"
  82. >
  83. <el-col :span="24">
  84. <el-form-item
  85. label="未返回动物情况说明"
  86. prop="notReturnReason"
  87. >
  88. <el-input
  89. v-model="state.form.notReturnReason"
  90. placeholder="请输入"
  91. />
  92. </el-form-item>
  93. </el-col>
  94. </el-row>
  95. <el-row v-if="isReturn === 1">
  96. <el-col :span="24">
  97. <el-form-item
  98. label="运输方式"
  99. prop="returnTransport"
  100. >
  101. <el-input
  102. v-model="state.form.returnTransport"
  103. placeholder="请输入"
  104. />
  105. </el-form-item>
  106. </el-col>
  107. </el-row>
  108. <el-row
  109. class="mb20"
  110. v-if="isReturn === 1"
  111. >
  112. <el-col :span="24">
  113. <el-form-item
  114. label="雄性"
  115. prop="returnMaleNumber"
  116. >
  117. <el-input-number
  118. style="width: 100%"
  119. placeholder="雄性数量"
  120. v-model="state.form.returnMaleNumber"
  121. :min="0"
  122. />
  123. </el-form-item>
  124. </el-col>
  125. </el-row>
  126. <el-row v-if="isReturn === 1">
  127. <el-col :span="24">
  128. <el-form-item
  129. label="雌性"
  130. prop="returnFemaleNumber"
  131. >
  132. <el-input-number
  133. style="width: 100%"
  134. placeholder="雌性数量"
  135. v-model="state.form.returnFemaleNumber"
  136. :min="0"
  137. />
  138. </el-form-item>
  139. </el-col>
  140. </el-row>
  141. <el-row
  142. class="mb20"
  143. :gutter="20"
  144. >
  145. <el-col :span="12">
  146. <el-form-item
  147. label="门禁卡是否归还"
  148. prop="accessCardReturn"
  149. >
  150. <el-radio-group v-model="state.form.accessCardReturn">
  151. <el-radio :label="1">是</el-radio>
  152. <el-radio :label="0">否</el-radio>
  153. </el-radio-group>
  154. </el-form-item>
  155. </el-col>
  156. </el-row>
  157. </el-form>
  158. <template #footer>
  159. <span class="dialog-footer">
  160. <el-button
  161. type="info"
  162. @click="onCancel"
  163. size="default"
  164. >
  165. 取 消
  166. </el-button>
  167. <el-button
  168. color="#2c78ff"
  169. @click="onSubmit()"
  170. size="default"
  171. >
  172. 提交
  173. </el-button>
  174. </span>
  175. </template>
  176. </el-dialog>
  177. </div>
  178. </template>
  179. <script setup lang="ts">
  180. import { reactive, ref } from 'vue'
  181. import to from 'await-to-js'
  182. import { ElMessage } from 'element-plus'
  183. import type { FormRules, FormInstance } from 'element-plus'
  184. import { usePlatAnimalCageApplicationApi } from '/@/api/platform/animal'
  185. import { TurnBackPayload, TakeawayList } from '/@/constants/pageConstants'
  186. import { filterFields } from '/@/utils/func'
  187. const emit = defineEmits(['refresh'])
  188. const platAnimalCageApplicationApi = usePlatAnimalCageApplicationApi()
  189. const expertDialogFormRef = ref<FormInstance>()
  190. const animalTypeList = ref<{ id: string; name: string }[]>([])
  191. const isReturn = ref<number>(1)
  192. const rules = reactive<FormRules<TurnBackPayload>>({
  193. // categoryId: [{ required: true, message: '请选择动物种类', trigger: 'blur' }],
  194. returnDate: [{ required: true, message: '请选择转出日期', trigger: 'blur' }],
  195. notReturnReason: [{ required: true, message: '请输入未返回动物情况说明', trigger: 'blur' }],
  196. })
  197. const defaultFormFields: TurnBackPayload = {
  198. takeawayId: 0,
  199. // categoryId: null,
  200. returnDate: '',
  201. returnTransport: '',
  202. accessCardReturn: 1,
  203. returnFemaleNumber: 0,
  204. returnMaleNumber: 0,
  205. notReturnReason: '',
  206. takeawayType: '10',
  207. }
  208. const state = reactive<{
  209. form: TurnBackPayload
  210. dialog: { isShowDialog: boolean; type: string; title: string; submitTxt: string }
  211. }>({
  212. form: defaultFormFields,
  213. dialog: {
  214. isShowDialog: false,
  215. type: '',
  216. title: '',
  217. submitTxt: '',
  218. },
  219. })
  220. const getDicts = async () => {
  221. const [_, res]: ToResponse = await to(platAnimalCageApplicationApi.getAnimalTypeList({}))
  222. if (res) {
  223. animalTypeList.value = res.data
  224. }
  225. }
  226. const openDialog = async (sourceData: TakeawayList) => {
  227. await getDicts()
  228. state.dialog.title = '登记转回'
  229. state.form.takeawayId = sourceData.id
  230. // state.form.categoryId = animalTypeList.value[0].id
  231. state.dialog.isShowDialog = true
  232. }
  233. const closeDialog = () => {
  234. expertDialogFormRef.value.resetFields()
  235. state.form = defaultFormFields
  236. state.dialog.isShowDialog = false
  237. }
  238. const onCancel = () => {
  239. closeDialog()
  240. }
  241. const onSubmit = async () => {
  242. expertDialogFormRef.value.validate(async (valid: boolean) => {
  243. if (!valid) return
  244. if (isReturn.value === 1) {
  245. if (!state.form.returnMaleNumber && !state.form.returnFemaleNumber) {
  246. ElMessage.error('请添加雄性或雌性数量!')
  247. return
  248. }
  249. }
  250. const post = platAnimalCageApplicationApi.createPlatAnimalTakeawayReback
  251. const [err]: ToResponse = await to(post(filterFields(state.form)))
  252. if (err) return
  253. ElMessage.success('操作成功')
  254. closeDialog()
  255. emit('refresh')
  256. })
  257. }
  258. defineExpose({
  259. openDialog,
  260. })
  261. </script>
  262. <style lang="scss" scoped>
  263. .application-dialog-container {
  264. .el-select {
  265. width: 100%;
  266. }
  267. }
  268. h4 {
  269. font-size: 18px;
  270. }
  271. ul {
  272. padding-left: 20px;
  273. }
  274. .text {
  275. p {
  276. text-indent: 2em;
  277. }
  278. }
  279. .el-upload + .el-button {
  280. vertical-align: top;
  281. }
  282. :deep(.el-checkbox) {
  283. white-space: pre-wrap;
  284. }
  285. </style>