downing.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <el-button el-button type="primary" icon="Download" @click="showdialog">收发登记表</el-button>
  3. <el-button el-button type="primary" icon="Download" @click="showdialogdialog">运输登记表</el-button>
  4. <el-dialog v-model="dialogFormVisible" title="收发登记表" :append-to-body="true" draggable width="30%">
  5. <el-form :model="initParam" ref="ruleFormRef" :rules="rules">
  6. <el-form-item label="品名" :label-width="formLabelWidth" prop="productId">
  7. <el-select v-model.number="initParam.productId" filterable remote reserve-keyword placeholder="品名"
  8. :remote-method="remoteMethod1" :loading="loading" clearable style="width: 100%;"
  9. @clear="initParam.productId = null" @click="click1">
  10. <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="生产企业" :label-width="formLabelWidth" prop="enterpriseId">
  14. <el-select v-model.number="initParam.enterpriseId" filterable remote reserve-keyword placeholder="生产企业"
  15. :remote-method="remoteMethod2" :loading="loading" clearable style="width: 100%;"
  16. @clear="initParam.enterpriseId = null" @click="click2">
  17. <el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value" />
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="规格" :label-width="formLabelWidth" prop="specId">
  21. <el-select v-model.number="initParam.specId" filterable remote reserve-keyword placeholder="规格"
  22. :remote-method="remoteMethod3" :loading="loading" clearable style="width: 100%;"
  23. @clear="initParam.specId = null" @click="click3">
  24. <el-option v-for="item in options3" :key="item.value" :label="item.label" :value="item.value" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="批号" :label-width="formLabelWidth" prop="batchNumber">
  28. <!-- <el-select v-model="initParam.batchNumber" class="m-2" placeholder="Select" style="width: 100%;">
  29. <el-option v-for="item in options5" :key="item" :label="item" :value="item" />
  30. </el-select> -->
  31. <el-autocomplete v-model="initParam.batchNumber" :fetch-suggestions="querySearch" clearable
  32. class="inputWidth" placeholder="批号" style="width: 100%;"/>
  33. </el-form-item>
  34. </el-form>
  35. <template #footer>
  36. <span class="dialog-footer">
  37. <el-button @click="dialogFormVisible = false">Cancel</el-button>
  38. <el-button type="primary" @click="submitForm(ruleFormRef,'excel')">导出</el-button>
  39. <el-button type="primary" @click="submitForm(ruleFormRef,'pdf')">打印</el-button>
  40. </span>
  41. </template>
  42. </el-dialog>
  43. <el-dialog v-model="dialogFormVisible1" title="运输登记表" :append-to-body="true" draggable width="30%">
  44. <el-form :model="initParamWord" ref="ruleFormRef1" :rules="rules1">
  45. <el-form-item label="出库日期" :label-width="formLabelWidth" prop="date">
  46. <el-date-picker v-model="initParamWord.date" type="date" value-format="YYYY-MM-DD" clearable
  47. style="width: 100%;" />
  48. </el-form-item>
  49. <el-form-item label="收货单位" :label-width="formLabelWidth" prop="receivingUnit">
  50. <!-- <el-select v-model.number="initParamWord.receivingUnit" filterable remote reserve-keyword placeholder="收货单位"
  51. :remote-method="remoteMethod4" :loading="loading" clearable style="width: 100%;"
  52. @clear="initParamWord.receivingUnit = null" @click="click4">
  53. <el-option v-for="item in options4" :key="item.value" :label="item.label" :value="item.value" />
  54. </el-select> -->
  55. <el-autocomplete v-model="initParamWord.receivingUnit" :fetch-suggestions="querySearch1" clearable class="inputWidth"
  56. placeholder="收货单位" style="width: 100%;" />
  57. </el-form-item>
  58. <el-form-item label="品名" :label-width="formLabelWidth">
  59. <el-select v-model.number="initParamWord.productId" filterable remote reserve-keyword placeholder="品名"
  60. :remote-method="remoteMethod1" :loading="loading" clearable style="width: 100%;"
  61. @clear="initParamWord.productId = null" @click="click1">
  62. <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value" />
  63. </el-select>
  64. </el-form-item>
  65. </el-form>
  66. <template #footer>
  67. <span class="dialog-footer">
  68. <el-button @click="dialogFormVisible1 = false">Cancel</el-button>
  69. <el-button type="primary" @click="submitForm1(ruleFormRef1,'word')">导出</el-button>
  70. <el-button type="primary" @click="submitForm1(ruleFormRef1,'pdf')">打印</el-button>
  71. </span>
  72. </template>
  73. </el-dialog>
  74. </template>
  75. <script setup lang="ts">
  76. import { inventoryExcel, transportWord,stockunit } from "@/api";
  77. import { gradeName, enterpriseFun, stockunitFun, specification, LotNumber,shoubat } from "@/plugins/selectData";
  78. import { reactive, ref, onMounted } from 'vue'
  79. import { downPDF, downloadExcelFun } from "@/utils/download";
  80. import type { FormInstance } from 'element-plus'
  81. const dialogFormVisible = ref(false)
  82. const dialogFormVisible1 = ref(false)
  83. const ruleFormRef = ref<FormInstance>()
  84. const ruleFormRef1 = ref<FormInstance>()
  85. const formLabelWidth = '80px'
  86. const loading = ref(false)
  87. interface RuleForm {
  88. batchNumber: any,
  89. enterpriseId?: any,
  90. productId?: any,
  91. specId: any,
  92. type: string
  93. }
  94. const initParam = reactive<RuleForm>({//请求参数
  95. "batchNumber":'',
  96. "enterpriseId": null,
  97. "productId": null,
  98. "specId": null,
  99. "type": ''
  100. })
  101. interface RuleForm1 {
  102. date: any,
  103. receivingUnit?: any,
  104. productId?: any,
  105. type: string
  106. }
  107. const initParamWord = reactive<RuleForm1>({//请求参数
  108. "date": null,
  109. "receivingUnit": '',
  110. "productId": null,
  111. "type": ''
  112. })
  113. onMounted(async () => {
  114. const result1: any = await gradeName()//疫苗名称
  115. const result2: any = await enterpriseFun()//生产企业
  116. const result3: any = await specification()//规格
  117. const result4: any = await stockunitFun(2)//收发货单位
  118. list1.value = findMap(result1 || [], 'obj')
  119. list2.value = findMap(result2 || [], 'obj')
  120. list3.value = findMap(result3 || [], 'obj')
  121. list4.value = findMap(result4 || [], 'map')
  122. })
  123. //函数
  124. const findMap = (arr: any, obj: any) => {
  125. return arr.map((item: any) => {
  126. return { value: obj == 'obj' ? item.id : item, label: obj == 'obj' ? item.name : item }
  127. })
  128. }
  129. interface ListItem {
  130. value: string
  131. label: string
  132. }
  133. const click1 = async () => { options1.value = list1.value }
  134. const click2 = async () => { options2.value = list2.value }
  135. const click3 = async () => { options3.value = list3.value }
  136. const click4 = async () => { options4.value = list4.value }
  137. const list1 = ref<ListItem[]>([])//疫苗名称
  138. const list2 = ref<ListItem[]>([])//生产企业
  139. const list3 = ref<ListItem[]>([])//收发货单位
  140. const list4 = ref<ListItem[]>([])//收发货单位
  141. const options1 = ref<ListItem[]>([])
  142. const options2 = ref<ListItem[]>([])
  143. const options3 = ref<ListItem[]>([])
  144. const options4 = ref<ListItem[]>([])
  145. const remoteMethod1 = async (query: string) => {
  146. if (query) {
  147. loading.value = true
  148. setTimeout(() => {
  149. loading.value = false
  150. options1.value = list1.value.filter((item: any) => {
  151. return item.label.toLowerCase().includes(query.toLowerCase())
  152. })
  153. }, 200)
  154. } else {
  155. options1.value = []
  156. }
  157. }
  158. const remoteMethod2 = async (query: string) => {
  159. if (query) {
  160. loading.value = true
  161. setTimeout(() => {
  162. loading.value = false
  163. options2.value = list2.value.filter((item: any) => {
  164. console.log('第一个', query, item)
  165. return item.label.toLowerCase().includes(query.toLowerCase())
  166. })
  167. }, 200)
  168. } else {
  169. options2.value = []
  170. }
  171. }
  172. const remoteMethod3 = async (query: string) => {
  173. if (query) {
  174. loading.value = true
  175. setTimeout(() => {
  176. loading.value = false
  177. options3.value = list3.value.filter((item: any) => {
  178. return item.label.toLowerCase().includes(query.toLowerCase())
  179. })
  180. }, 200)
  181. } else {
  182. options3.value = []
  183. }
  184. }
  185. const remoteMethod4 = async (query: string) => {
  186. if (query) {
  187. loading.value = true
  188. setTimeout(() => {
  189. loading.value = false
  190. options4.value = list4.value.filter((item: any) => {
  191. return item.label.toLowerCase().includes(query.toLowerCase())
  192. })
  193. }, 200)
  194. } else {
  195. options3.value = []
  196. }
  197. }
  198. //函数
  199. const showdialog = async ()=>{
  200. dialogFormVisible.value = true
  201. const reslut:any = await LotNumber()
  202. console.log('数据1',reslut)
  203. const arrMap = reslut
  204. const arr:any = []
  205. arrMap.forEach((item:any)=>{
  206. arr.push({ value: item, link: item})
  207. })
  208. restaurants.value = arr
  209. console.log('数据2',restaurants.value)
  210. }
  211. interface RestaurantItem {
  212. value: string
  213. link: string
  214. }
  215. const restaurants = ref<RestaurantItem[]>([])
  216. const querySearch = (queryString: string, cb: any) => {
  217. const results = queryString
  218. ? restaurants.value.filter(createFilter(queryString))
  219. : restaurants.value
  220. cb(results)
  221. }
  222. const createFilter = (queryString: string) => {
  223. return (restaurant: RestaurantItem) => {
  224. return (
  225. restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
  226. )
  227. }
  228. }
  229. //显示运输登记
  230. const showdialogdialog = async ()=>{
  231. dialogFormVisible1.value = true
  232. const reslut:any = await shoubat()
  233. console.log('数据1',reslut)
  234. const arrMap = reslut
  235. const arr:any = []
  236. arrMap.forEach((item:any)=>{
  237. arr.push({ value: item, link: item})
  238. })
  239. restaurants1.value = arr
  240. console.log('数据2',restaurants1.value)
  241. }
  242. const restaurants1 = ref<RestaurantItem[]>([])
  243. const querySearch1 = (queryString: string, cb: any) => {
  244. const results = queryString
  245. ? restaurants1.value.filter(createFilter(queryString))
  246. : restaurants1.value
  247. cb(results)
  248. }
  249. const rules = reactive({
  250. batchNumber: [{ required: true, message: '必填项', trigger: 'change' }],
  251. enterpriseId: [{ required: true, message: '必填项', trigger: 'change' }],
  252. productId: [{ required: true, message: '必填项', trigger: 'change' }],
  253. specId: [{ required: true, message: '必填项', trigger: 'change' }],
  254. })
  255. const submitForm = async (formEl: FormInstance | undefined,ty:string) => {
  256. if (!formEl) return
  257. await formEl.validate(async (valid, fields) => {
  258. if (valid) {
  259. initParam.type = ty
  260. const result = await inventoryExcel(initParam)
  261. ty=='excel'?downloadExcelFun(result):downPDF(result)
  262. } else {
  263. console.log('error submit!', fields)
  264. }
  265. })
  266. }
  267. const rules1 = reactive({
  268. date: [{ required: true, message: '必填项', trigger: 'change' }],
  269. receivingUnit: [{ required: true, message: '必填项', trigger: 'change' }],
  270. })
  271. const submitForm1 = async (formEl: FormInstance | undefined,ty:any) => {
  272. if (!formEl) return
  273. await formEl.validate(async (valid, fields) => {
  274. if (valid) {
  275. initParamWord.type = ty
  276. const result:any = await transportWord(initParamWord)
  277. ty=='word'?downloadExcelFun(result):downPDF(result)
  278. } else {
  279. console.log('error submit!', fields)
  280. }
  281. })
  282. }
  283. </script>
  284. <style lang="scss">
  285. /* @import url(); 引入css类 */
  286. .inputWidth {
  287. width: 200px;
  288. }
  289. </style>