index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <a-row :gutter="10">
  3. <a-col :xs="24" :sm="24" :md="24" :lg="5" :xl="5">
  4. <a-card :bordered="false" :loading="cardLoading" class="left-tree-container">
  5. <a-tree
  6. v-if="treeData.length > 0"
  7. v-model:expandedKeys="defaultExpandedKeys"
  8. :tree-data="treeData"
  9. :field-names="treeFieldNames"
  10. @select="treeSelect"
  11. />
  12. <a-empty v-else :image="Empty.PRESENTED_IMAGE_SIMPLE" />
  13. </a-card>
  14. </a-col>
  15. <a-col :xs="24" :sm="24" :md="24" :lg="19" :xl="19">
  16. <a-card :bordered="false" class="xn-mb10">
  17. <a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form" :model="searchFormState">
  18. <a-row :gutter="24">
  19. <a-col :span="8">
  20. <a-form-item name="searchKey" label="名称关键词">
  21. <a-input v-model:value="searchFormState.searchKey" placeholder="请输入门店名称关键词" />
  22. </a-form-item>
  23. </a-col>
  24. <a-col :span="8">
  25. <a-button type="primary" @click="tableRef.refresh(true)">
  26. <template #icon><SearchOutlined /></template>
  27. 查询
  28. </a-button>
  29. <a-button class="snowy-button-left" @click="reset">
  30. <template #icon><redo-outlined /></template>
  31. 重置
  32. </a-button>
  33. </a-col>
  34. </a-row>
  35. </a-form>
  36. </a-card>
  37. <a-card :bordered="false">
  38. <s-table
  39. ref="tableRef"
  40. :columns="columns"
  41. :data="loadData"
  42. :expand-row-by-click="true"
  43. :alert="options.alert.show"
  44. bordered
  45. :row-key="(record) => record.id"
  46. :tool-config="toolConfig"
  47. :row-selection="options.rowSelection"
  48. >
  49. <template #operator class="table-operator">
  50. <a-space>
  51. <a-button
  52. type="primary"
  53. @click="formRef.onOpen(undefined, searchFormState.parentId)"
  54. v-if="hasPerm('bizOrgAdd')"
  55. >
  56. <template #icon><plus-outlined /></template>
  57. 新增
  58. </a-button>
  59. <xn-batch-button
  60. v-if="hasPerm('bizOrgBatchDelete')"
  61. buttonName="批量删除"
  62. icon="DeleteOutlined"
  63. buttonDanger
  64. :selectedRowKeys="selectedRowKeys"
  65. @batchCallBack="deleteBatchOrg"
  66. />
  67. </a-space>
  68. </template>
  69. <template #bodyCell="{ column, record }">
  70. <template v-if="column.dataIndex === 'category'">
  71. {{ $TOOL.dictTypeData('ORG_CATEGORY', record.category) }}
  72. </template>
  73. <template v-if="column.dataIndex === 'action'">
  74. <a @click="showModal(record)" >二维码</a>
  75. <a-divider type="vertical" />
  76. <a @click="formRef.onOpen(record)" v-if="hasPerm('bizOrgEdit')">编辑</a>
  77. <a-divider type="vertical" v-if="hasPerm(['bizOrgEdit', 'bizOrgDelete'], 'and')" />
  78. <a-popconfirm title="删除此机构与下级机构吗?" @confirm="removeOrg(record)">
  79. <a-button type="link" danger size="small" v-if="hasPerm('bizOrgDelete')">删除</a-button>
  80. </a-popconfirm>
  81. </template>
  82. </template>
  83. </s-table>
  84. </a-card>
  85. </a-col>
  86. </a-row>
  87. <Form ref="formRef" @successful="tableRef.refresh()" />
  88. <a-modal v-model:visible="open" title="二维码">
  89. <div id="qrcode" style="text-align: center; margin: 15px;">
  90. <a-row>
  91. <a-col :span="14">
  92. <br><br>
  93. <p><span>门店名称:</span>{{nowRecord.name}}</p>
  94. <p><span>门店编码:</span>{{ nowRecord.code }}</p>
  95. </a-col>
  96. <a-col :span="8">
  97. <a-image width="206" :src="qrCodeUrl.codeUrl">
  98. <template #default>
  99. <img src="https://www.antdv.com/assets/logo.1ef800a8.svg" class="icon" alt="Icon" />
  100. </template>
  101. </a-image>
  102. </a-col>
  103. </a-row>
  104. </div>
  105. <template #footer>
  106. <a-button @click="closeQrCode">关闭</a-button>
  107. <a-button type="primary" @click="downloadFile">下载</a-button>
  108. </template>
  109. </a-modal>
  110. </template>
  111. <script setup name="bizOrg">
  112. import { Empty } from 'ant-design-vue'
  113. import { isEmpty } from 'lodash-es'
  114. import bizOrgApi from '@/api/biz/bizOrgApi'
  115. import Form from './form.vue'
  116. import QRCode from 'qrcode'
  117. import html2canvas from 'html2canvas'
  118. const columns = [
  119. {
  120. title: '门店名称',
  121. dataIndex: 'name',
  122. width:150
  123. },
  124. {
  125. title: '门店编码',
  126. dataIndex: 'code',
  127. width:120
  128. },
  129. {
  130. title: '门店地址',
  131. dataIndex: 'address',
  132. width:180
  133. },
  134. {
  135. title: '分类',
  136. dataIndex: 'category',
  137. width: 100
  138. },
  139. {
  140. title: '排序',
  141. dataIndex: 'sortCode',
  142. width: 80
  143. }
  144. ]
  145. if (hasPerm(['bizOrgEdit', 'bizOrgDelete'])) {
  146. columns.push({
  147. title: '操作',
  148. dataIndex: 'action',
  149. align: 'center',
  150. width: 180
  151. })
  152. }
  153. const selectedRowKeys = ref([])
  154. // 列表选择配置
  155. const options = {
  156. alert: {
  157. show: false,
  158. clear: () => {
  159. selectedRowKeys.value = ref([])
  160. }
  161. },
  162. rowSelection: {
  163. onChange: (selectedRowKey, selectedRows) => {
  164. selectedRowKeys.value = selectedRowKey
  165. }
  166. }
  167. }
  168. const toolConfig = { refresh: true, height: true, columnSetting: true }
  169. // 定义tableDOM
  170. const tableRef = ref(null)
  171. const formRef = ref()
  172. const searchFormRef = ref()
  173. const searchFormState = ref({})
  174. // 默认展开的节点
  175. const defaultExpandedKeys = ref([])
  176. const treeData = ref([])
  177. // 替换treeNode 中 title,key,children
  178. const treeFieldNames = { children: 'children', title: 'name', key: 'id' }
  179. const cardLoading = ref(true)
  180. // 表格查询 返回 Promise 对象
  181. const loadData = (parameter) => {
  182. loadTreeData()
  183. return bizOrgApi.orgPage(Object.assign(parameter, searchFormState.value)).then((res) => {
  184. return res
  185. })
  186. }
  187. // 重置
  188. const reset = () => {
  189. searchFormRef.value.resetFields()
  190. tableRef.value.refresh(true)
  191. }
  192. // 加载左侧的树
  193. const loadTreeData = () => {
  194. bizOrgApi
  195. .orgTree()
  196. .then((res) => {
  197. cardLoading.value = false
  198. if (res !== null) {
  199. treeData.value = res
  200. if (isEmpty(defaultExpandedKeys.value)) {
  201. // 默认展开2级
  202. treeData.value.forEach((item) => {
  203. // 因为0的顶级
  204. if (item.parentId === '0') {
  205. defaultExpandedKeys.value.push(item.id)
  206. // 取到下级ID
  207. if (item.children) {
  208. item.children.forEach((items) => {
  209. defaultExpandedKeys.value.push(items.id)
  210. })
  211. }
  212. }
  213. })
  214. }
  215. }
  216. })
  217. .finally(() => {
  218. cardLoading.value = false
  219. })
  220. }
  221. // 点击树查询
  222. const treeSelect = (selectedKeys) => {
  223. if (selectedKeys.length > 0) {
  224. searchFormState.value.parentId = selectedKeys.toString()
  225. } else {
  226. delete searchFormState.value.parentId
  227. }
  228. tableRef.value.refresh(true)
  229. }
  230. // 删除
  231. const removeOrg = (record) => {
  232. let params = [
  233. {
  234. id: record.id
  235. }
  236. ]
  237. bizOrgApi.orgDelete(params).then(() => {
  238. tableRef.value.refresh(true)
  239. })
  240. }
  241. // 批量删除
  242. const deleteBatchOrg = (params) => {
  243. bizOrgApi.orgDelete(params).then(() => {
  244. tableRef.value.clearRefreshSelected()
  245. })
  246. }
  247. //二维码
  248. const open = ref(false);
  249. const qrCodeUrl = ref({})
  250. const qrcodeCanvasRef = ref();
  251. const nowRecord = ref({})
  252. const showModal = (record) => {
  253. nowRecord.value = record
  254. open.value = true;
  255. getQrCode(record)
  256. };
  257. const getQrCode = (record) => {
  258. //QRCode.toDataURL("id:"+record.id+"saleCode:"+record.saleCode, {
  259. let param = {
  260. id:record.id,
  261. code:record.code
  262. }
  263. QRCode.toDataURL(JSON.stringify(param), {
  264. errorCorrectionLevel: 'H',
  265. margin: 1,
  266. height: 206,
  267. width: 206,
  268. type: '10',
  269. scal: 177,
  270. color: {
  271. dark: '#000' // 二维码背景颜色
  272. },
  273. rendererOpts: {
  274. quality: 0.9
  275. },
  276. icon:'/public/img/tanglogo.png'
  277. })
  278. .then((url) => {
  279. qrCodeUrl.value.codeUrl = url
  280. })
  281. .catch((err) => {
  282. console.error(err)
  283. })
  284. }
  285. const closeQrCode = () => {
  286. open.value = false;
  287. }
  288. // 下载二维码
  289. const downloadFile = () => {
  290. html2canvas(qrcode, {
  291. logging: false,
  292. allowTaint: true,
  293. scale: window.devicePixelRatio,
  294. scrollY: 0,
  295. scrollX: 0,
  296. useCORS: true,
  297. backgroundColor: '#ffffff'
  298. })
  299. .then(function (canvas) {
  300. const a = window.document.createElement('a')
  301. a.href = canvas.toDataURL('image/png')
  302. a.download = '二维码'
  303. a.click()
  304. this.$message.success('正在进行下载保存')
  305. })
  306. .catch((err) => {
  307. console.log(err)
  308. })
  309. }
  310. </script>
  311. <style scoped>
  312. .ant-form-item {
  313. margin-bottom: 0 !important;
  314. }
  315. .snowy-button-left {
  316. margin-left: 8px;
  317. }
  318. </style>