index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <script setup lang="ts" name="ChickenCage">
  2. import apis from "@a"
  3. import dayjs from "dayjs"
  4. import { Vue3NextQrcode } from "vue3-next-qrcode"
  5. const tableRef = ref()
  6. const modalRef = ref()
  7. const coopOptions = ref([])
  8. const cageNumPrefix = computed(() => {
  9. if (!form.value.chickenCoopId) {
  10. return ""
  11. }
  12. const coop = coopOptions.value.find((item: any) => item.value == form.value.chickenCoopId)
  13. return coop?.coopNum
  14. })
  15. const isEdit = ref(false)
  16. apis.breeding.chickenCoopApi.options({ status: 0 }).then((res: any) => {
  17. coopOptions.value = res.data.map((item: any) => {
  18. return {
  19. label: `${item.coopName}(${item.coopNum})`,
  20. coopNum: item.coopNum,
  21. value: item.id
  22. }
  23. })
  24. })
  25. const opts = reactive({
  26. columns: [
  27. { field: "id", name: "鸡笼ID", width: 100, isSort: true, visible: false, tooltip: true },
  28. {
  29. field: "cageNum",
  30. name: "鸡笼编号",
  31. visible: true,
  32. isSort: false,
  33. width: "auto",
  34. tooltip: true
  35. },
  36. {
  37. field: "chickenCoopName",
  38. name: "所属鸡舍",
  39. visible: true,
  40. isSort: false,
  41. width: "auto",
  42. tooltip: true
  43. },
  44. {
  45. field: "manager",
  46. name: "管理员",
  47. visible: false,
  48. isSort: false,
  49. width: "auto",
  50. tooltip: true
  51. },
  52. { field: "status", name: "状态", visible: true, isSort: false, width: 100 },
  53. {
  54. field: "maxCapacity",
  55. name: "最大容量",
  56. visible: true,
  57. isSort: false,
  58. width: "auto",
  59. tooltip: true
  60. },
  61. { field: "remark", name: "备注", visible: true, isSort: false, tooltip: true },
  62. { field: "actions", name: `操作`, width: 150 }
  63. ] as any[],
  64. queryParams: {
  65. cageNo: undefined,
  66. chickenCoopId: undefined,
  67. status: undefined
  68. },
  69. searchFormItems: [
  70. {
  71. field: "cageNo",
  72. label: "鸡笼编号",
  73. class: "w-100",
  74. required: false,
  75. placeholder: "请输入鸡笼编号",
  76. component: "I",
  77. listeners: {
  78. keyup: (e: KeyboardEvent) => {
  79. if (e.code == "Enter") {
  80. handleQuery()
  81. }
  82. }
  83. }
  84. },
  85. {
  86. field: "chickenCoopId",
  87. label: "鸡舍",
  88. class: "w-100",
  89. required: false,
  90. placeholder: "请输入鸡舍",
  91. component: "VS",
  92. data: () => coopOptions.value,
  93. props: {
  94. valueIsNumber: true
  95. }
  96. }
  97. // {
  98. // field: "status",
  99. // label: "状态",
  100. // class: "w-100",
  101. // required: false,
  102. // component: "Dict",
  103. // props: {
  104. // placeholder: "请选择状态",
  105. // dictType: "chicken_cage_status",
  106. // valueIsNumber: 1,
  107. // type: "select"
  108. // }
  109. // }
  110. ] as any,
  111. permission: "breeding:chickenCage",
  112. handleBtns: [],
  113. handleFuns: {
  114. handleCreate,
  115. handleUpdate: () => {
  116. const row = tableRef.value.getSelected()
  117. handleUpdate(row)
  118. },
  119. handleDelete: () => {
  120. const rows = tableRef.value.getSelecteds()
  121. handleDelete(rows)
  122. }
  123. },
  124. customBtns: [],
  125. tableListFun: apis.breeding.chickenCageApi.list,
  126. getEntityFun: apis.breeding.chickenCageApi.get,
  127. deleteEntityFun: apis.breeding.chickenCageApi.del,
  128. exportUrl: apis.breeding.chickenCageApi.exportUrl,
  129. exportName: "ChickenCage",
  130. modalTitle: "鸡笼信息",
  131. formItems: [
  132. {
  133. field: "chickenCoopId",
  134. label: "鸡舍",
  135. class: "w-100",
  136. required: true,
  137. placeholder: "请输入鸡舍",
  138. component: "VS",
  139. data: () => coopOptions.value,
  140. disabled: () => isEdit.value,
  141. props: {
  142. valueIsNumber: true
  143. }
  144. },
  145. {
  146. field: "numSuffix",
  147. label: "鸡笼编号",
  148. class: "w-100",
  149. required: true,
  150. placeholder: "请输入鸡笼编号",
  151. component: "slot"
  152. },
  153. // {
  154. // field: "status",
  155. // label: "状态",
  156. // class: "w-100",
  157. // required: true,
  158. // component: "Dict",
  159. // props: {
  160. // dictType: "chicken_cage_status",
  161. // valueIsNumber: 1
  162. // }
  163. // },
  164. {
  165. field: "maxCapacity",
  166. label: "最大容量",
  167. class: "w-100",
  168. required: true,
  169. placeholder: "请输入最大容量",
  170. component: "I"
  171. },
  172. {
  173. field: "remark",
  174. label: "备注",
  175. class: "w-100",
  176. required: false,
  177. placeholder: "请输入备注",
  178. component: "I",
  179. props: {
  180. type: "textarea",
  181. rows: 5
  182. }
  183. }
  184. ] as any,
  185. resetForm: () => {
  186. form.value = emptyFormData.value
  187. },
  188. labelWidth: "80px",
  189. emptyFormData: {
  190. id: undefined,
  191. chickenCoopId: undefined,
  192. cageNum: undefined,
  193. numSuffix: undefined,
  194. manager: undefined,
  195. status: 0,
  196. maxCapacity: undefined,
  197. remark: undefined
  198. }
  199. })
  200. const { queryParams, emptyFormData } = toRefs(opts)
  201. const form = ref<any>(emptyFormData.value)
  202. /** 搜索按钮操作 */
  203. function handleQuery(query?: any) {
  204. query = query || tableRef.value?.getQueryParams() || queryParams.value
  205. addDateRange(query, query.dateRangeCreateTime)
  206. addDateRange(query, query.dateRangeUpdateTime, "UpdateTime")
  207. tableRef.value?.query(query)
  208. }
  209. /** 重置按钮操作 */
  210. function resetQuery(query?: any) {
  211. query = query || tableRef.value?.getQueryParams() || queryParams.value
  212. query.dateRangeCreateTime = [] as any
  213. addDateRange(query, query.dateRangeCreateTime)
  214. query.dateRangeUpdateTime = [] as any
  215. addDateRange(query, query.dateRangeUpdateTime, "UpdateTime")
  216. //
  217. }
  218. function handleCreate(row: any) {
  219. isEdit.value = false
  220. tableRef.value.defaultHandleFuns.handleCreate()
  221. }
  222. /** 修改按钮操作 */
  223. function handleUpdate(row: any) {
  224. isEdit.value = true
  225. tableRef.value.defaultHandleFuns.handleUpdate("", row)
  226. }
  227. /** 删除按钮操作 */
  228. function handleDelete(rows: any[]) {
  229. tableRef.value.defaultHandleFuns.handleDelete("", rows)
  230. }
  231. /** 提交按钮 */
  232. function submitForm() {
  233. form.value.cageNum = cageNumPrefix.value + "-" + form.value.numSuffix
  234. apis.breeding.chickenCageApi.addOrUpdate(form.value).then(() => {
  235. handleQuery()
  236. })
  237. }
  238. function handleFormEdit(data: any) {
  239. data.numSuffix = data.cageNum.split("-")[1]
  240. }
  241. const qrModalRef = ref()
  242. const qrModalData = ref()
  243. const qrCode = ref({
  244. logo: "/media/logo.png",
  245. size: 300,
  246. // colorDark: "#0095e8",
  247. colorDark: "#000000",
  248. text: ""
  249. })
  250. function handleQrCode(row) {
  251. qrModalData.value = row
  252. qrCode.value.text = `${row.cageNum}`
  253. qrModalRef.value.show()
  254. }
  255. function handleDownloadQr(id: string) {
  256. let myImg = document.querySelector("#" + id+' img') as HTMLImageElement
  257. let url = myImg?.src
  258. let a = document.createElement("a")
  259. a.href = url
  260. a.download = `${qrModalData.value.cageNum}笼号二维码`
  261. a.click()
  262. }
  263. // function handlePrintQr(id: string) {
  264. // const printContent = document.querySelector("#" + id)
  265. // if (!printContent) return
  266. // // 创建打印样式
  267. // const style = document.createElement("style")
  268. // style.innerHTML = `
  269. // @media print {
  270. // body * {
  271. // display: none !important;
  272. // }
  273. // #print-area, #print-area * {
  274. // display: block !important;
  275. // }
  276. // #print-area {
  277. // position: absolute;
  278. // top: 0;
  279. // left: 0;
  280. // width: 100vw;
  281. // height: 600px;
  282. // display: flex !important;
  283. // flex-direction: column;
  284. // align-items: center;
  285. // justify-content: center;
  286. // font-family: Arial, sans-serif;
  287. // }
  288. // }
  289. // `
  290. // document.head.appendChild(style)
  291. // // 创建打印区域
  292. // const printArea = document.createElement("div")
  293. // printArea.id = "print-area"
  294. // // printArea.innerHTML = `
  295. // // <div style="width:100%;display:flex;flex-direction: column;align-items: center;justify-content: center;">${printContent.innerHTML}</div>
  296. // // `
  297. // printArea.innerHTML = printContent.innerHTML
  298. // document.body.appendChild(printArea)
  299. // // 打印
  300. // window.print()
  301. // // 清理
  302. // setTimeout(() => {
  303. // document.head.removeChild(style)
  304. // document.body.removeChild(printArea)
  305. // }, 500)
  306. // }
  307. </script>
  308. <template>
  309. <div class="app-container">
  310. <VbDataTable
  311. ref="tableRef"
  312. keyField="id"
  313. :columns="opts.columns"
  314. :handle-perm="opts.permission"
  315. :handle-btns="opts.handleBtns"
  316. :handle-funs="opts.handleFuns"
  317. :search-form-items="opts.searchFormItems"
  318. :custom-btns="opts.customBtns"
  319. :remote-fun="opts.tableListFun"
  320. :get-entity-fun="opts.getEntityFun"
  321. :delete-entity-fun="opts.deleteEntityFun"
  322. :export-url="opts.exportUrl"
  323. :export-name="opts.exportName"
  324. :modal="modalRef"
  325. :reset-form-fun="opts.resetForm"
  326. v-model:form-data="form"
  327. v-model:query-params="queryParams"
  328. :check-multiple="true"
  329. :reset-search-form-fun="resetQuery"
  330. :custom-search-fun="handleQuery"
  331. @form-edit="handleFormEdit">
  332. <template #status="{ row }">
  333. <DictTag type="chicken_cage_status" :value-is-number="1" :value="row.status"></DictTag>
  334. </template>
  335. <template #actions="{ row }">
  336. <vb-tooltip content="生成二维码" placement="top">
  337. <el-button link type="success" @click="handleQrCode(row)">
  338. <template #icon>
  339. <VbIcon icon-name="scan-barcode" icon-type="duotone" class="fs-3"></VbIcon>
  340. </template>
  341. </el-button>
  342. </vb-tooltip>
  343. <vb-tooltip content="修改" placement="top">
  344. <el-button
  345. link
  346. type="primary"
  347. @click="handleUpdate(row)"
  348. v-hasPermission="'breeding:chickenCage:edit'">
  349. <template #icon>
  350. <VbIcon icon-name="notepad-edit" icon-type="duotone" class="fs-3"></VbIcon>
  351. </template>
  352. </el-button>
  353. </vb-tooltip>
  354. <vb-tooltip content="删除" placement="top">
  355. <el-button
  356. link
  357. type="primary"
  358. @click="handleDelete([row])"
  359. v-hasPermission="'breeding:chickenCage:remove'">
  360. <template #icon>
  361. <VbIcon icon-name="trash-square" icon-type="duotone" class="fs-3"></VbIcon>
  362. </template>
  363. </el-button>
  364. </vb-tooltip>
  365. </template>
  366. </VbDataTable>
  367. <VbModal
  368. v-model:modal="qrModalRef"
  369. title="签到二维码"
  370. :confirm-btn="false"
  371. :close-btn-class="'btn btn-danger'"
  372. append-to-body>
  373. <template #body>
  374. <div
  375. id="qr"
  376. class="w-100 w-100 d-flex flex-column justify-content-center align-items-center">
  377. <span class="fs-5 fw-bold my-5 qr-title">{{ qrModalData?.cageNum }} 笼号二维码</span>
  378. <Vue3NextQrcode
  379. :text="qrCode.text"
  380. :size="qrCode.size"
  381. :color-dark="qrCode.colorDark"
  382. :logo-image="qrCode.logo"
  383. :logo-scale="0.15"
  384. :logo-margin="0"
  385. :logo-corner-radius="20"
  386. :margin="20" />
  387. </div>
  388. <div class="text-center">
  389. <el-button type="primary" class="mx-5 w-150px" @click="handleDownloadQr('qr')">
  390. 保存
  391. </el-button>
  392. <!-- <el-button type="primary" class="mx-5 w-150px" @click="handlePrintQr('qr')">
  393. 打印
  394. </el-button> -->
  395. </div>
  396. </template>
  397. </VbModal>
  398. <VbModal
  399. v-model:modal="modalRef"
  400. :title="opts.modalTitle"
  401. :form-data="form"
  402. :form-items="opts.formItems"
  403. :label-width="opts.labelWidth"
  404. append-to-body
  405. @confirm="submitForm">
  406. <template #numSuffix_form>
  407. <el-input
  408. v-model="form.numSuffix"
  409. :disabled="isEdit"
  410. style="min-width: 650px"
  411. placeholder="输入鸡笼编号">
  412. <template #prepend>{{ cageNumPrefix }}</template>
  413. </el-input>
  414. </template>
  415. </VbModal>
  416. </div>
  417. </template>