index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <script lang="ts" setup>
  2. import type { VbenFormProps } from '@vben/common-ui';
  3. import type { VxeGridListeners, VxeGridProps } from '#/adapter/vxe-table';
  4. import { ref } from 'vue';
  5. import { Page, useVbenModal } from '@vben/common-ui';
  6. import { MdiDelete, MdiDetail, MdiEdit } from '@vben/icons';
  7. import { useUserStore } from '@vben/stores';
  8. import { ElMessage, ElMessageBox } from 'element-plus';
  9. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  10. import {
  11. deleteProductApi,
  12. editProductApi,
  13. getProductAndScqyListApi,
  14. } from '#/api/product';
  15. import { $t } from '#/locales';
  16. import AddLinkModal from './add-link-modal.vue';
  17. import ProductDetail from './detail.vue';
  18. import ProductForm from './form.vue';
  19. // 获取用户信息
  20. const userStore = useUserStore();
  21. // 新增关联组件ref
  22. const addLinkModalRef = ref<InstanceType<typeof AddLinkModal>>();
  23. const detailModalRef = ref<InstanceType<typeof ProductDetail>>();
  24. const formOptions: VbenFormProps = {
  25. // 默认展开
  26. collapsed: true,
  27. // 控制表单是否显示折叠按钮
  28. showCollapseButton: true,
  29. // 按下回车时是否提交表单
  30. submitOnEnter: true,
  31. schema: [
  32. {
  33. component: 'Input',
  34. fieldName: 'productsname',
  35. label: '产品名称',
  36. componentProps: {
  37. placeholder: $t('ui.placeholder.input'),
  38. clearable: true,
  39. },
  40. },
  41. {
  42. component: 'Input',
  43. fieldName: 'productsmodel',
  44. label: '产品型号',
  45. componentProps: {
  46. placeholder: $t('ui.placeholder.input'),
  47. clearable: true,
  48. },
  49. },
  50. {
  51. component: 'Input',
  52. fieldName: 'productsjjlx',
  53. label: '机具类型',
  54. componentProps: {
  55. placeholder: $t('ui.placeholder.input'),
  56. clearable: true,
  57. },
  58. },
  59. {
  60. component: 'Input',
  61. fieldName: 'scqyinfomc',
  62. label: '生产企业',
  63. componentProps: {
  64. placeholder: $t('ui.placeholder.input'),
  65. clearable: true,
  66. },
  67. },
  68. {
  69. component: 'Input',
  70. fieldName: 'productscategory',
  71. label: '产品类别',
  72. componentProps: {
  73. placeholder: $t('ui.placeholder.input'),
  74. clearable: true,
  75. },
  76. },
  77. ],
  78. wrapperClass: 'grid-cols-1 md:grid-cols-3 lg:grid-cols-5',
  79. };
  80. const gridOptions: VxeGridProps<any> = {
  81. toolbarConfig: {
  82. custom: true,
  83. export: true,
  84. // import: true,
  85. refresh: true,
  86. zoom: true,
  87. },
  88. height: 'auto',
  89. exportConfig: {},
  90. pagerConfig: {},
  91. rowConfig: {
  92. isHover: true,
  93. },
  94. stripe: true,
  95. proxyConfig: {
  96. response: {
  97. result: 'Data',
  98. total: 'Total',
  99. },
  100. ajax: {
  101. query: async ({ page }, formValues) => {
  102. // 构建查询参数
  103. const queryParams: any = {
  104. pageindex: page.currentPage,
  105. rows: page.pageSize,
  106. ...formValues,
  107. };
  108. // 如果是经销商且不是管理员,添加经销商筛选条件
  109. if (userStore.isDLSNotAdmin) {
  110. queryParams.productsmerchantid =
  111. userStore.userInfo?.workeruserid || '';
  112. }
  113. return await getProductAndScqyListApi(queryParams);
  114. },
  115. },
  116. },
  117. columns: [
  118. { title: '序号', type: 'seq', width: 50 },
  119. { title: '产品名称', field: 'productsname', sortable: true, width: 240 },
  120. { title: '产品型号', field: 'productsmodel', sortable: true, width: 220 },
  121. { title: '机具类型', field: 'productsjjlx', sortable: true, width: 120 },
  122. {
  123. title: '产品类别',
  124. field: 'productscategory',
  125. sortable: true,
  126. width: 120,
  127. },
  128. { title: '生产企业', field: 'scqyinfomc', sortable: true, width: 220 },
  129. // { title: '产品sn号', field: 'productssn' },
  130. // { title: '品目', field: 'productspm', sortable: true, width: 120 },
  131. // { title: '一级分类', field: 'productsfl1', sortable: true, width: 120 },
  132. // { title: '二级分类', field: 'productsfl2', sortable: true, width: 120 },
  133. // { title: '分档名称', field: 'productsfdmc', sortable: true, width: 120 },
  134. // { title: '分档编号', field: 'productsfdbh', sortable: true, width: 120 },
  135. {
  136. title: '产品原价',
  137. field: 'productsprice',
  138. formatter: formatMoney,
  139. sortable: true,
  140. width: 120,
  141. },
  142. {
  143. title: '中央补贴金额',
  144. field: 'productszybt',
  145. formatter: formatMoney,
  146. sortable: true,
  147. width: 120,
  148. },
  149. {
  150. title: '特殊县中央补贴金额',
  151. field: 'productstsxzybt',
  152. formatter: formatMoney,
  153. width: 170,
  154. sortable: true,
  155. },
  156. { title: '创建时间', field: 'productsdate', width: 180 },
  157. {
  158. title: '操作',
  159. field: 'action',
  160. fixed: 'right',
  161. slots: { default: 'action' },
  162. width: 150,
  163. },
  164. ],
  165. };
  166. const gridEvents: VxeGridListeners<any> = {
  167. cellDblclick: ({ row }) => {
  168. handleDetail(row);
  169. },
  170. };
  171. const [Grid, gridApi] = useVbenVxeGrid({
  172. gridEvents,
  173. gridOptions,
  174. formOptions,
  175. });
  176. const [Modal, modalApi] = useVbenModal({
  177. fullscreenButton: false,
  178. closeOnClickModal: false,
  179. closeOnPressEscape: false,
  180. connectedComponent: ProductForm,
  181. });
  182. /* 创建 */
  183. function handleCreate() {
  184. modalApi.setState({ showCancelButton: true });
  185. modalApi.setData({ formType: 'create' }).open();
  186. }
  187. /* 编辑 */
  188. function handleEdit(row: any) {
  189. modalApi.setState({ showCancelButton: true });
  190. modalApi.setData({ formType: 'edit', row }).open();
  191. }
  192. /* 详情 */
  193. function handleDetail(row: any) {
  194. detailModalRef.value?.openDetailModal(row);
  195. }
  196. function formatMoney(row: any) {
  197. return row.cellValue ? row.cellValue.toFixed(2) : '0.00';
  198. }
  199. function handleFinish() {
  200. gridApi.reload();
  201. }
  202. /* 删除 */
  203. async function handleDelete(row: any) {
  204. try {
  205. await ElMessageBox.confirm('确认要删除该产品吗?', '提示', {
  206. confirmButtonText: '确定',
  207. cancelButtonText: '取消',
  208. type: 'warning',
  209. });
  210. await deleteProductApi({ 'productsid.value': row.productsid });
  211. ElMessage.success('删除成功');
  212. gridApi.reload();
  213. } catch (error) {
  214. console.error(error);
  215. }
  216. }
  217. /* 移除关联 */
  218. async function handleRemoveLink(row: any) {
  219. try {
  220. await ElMessageBox.confirm(
  221. '确认要移除关联吗?移除后,小程序商城中,客户将无法购买该产品,请谨慎操作',
  222. '提示',
  223. {
  224. confirmButtonText: '确定',
  225. cancelButtonText: '取消',
  226. type: 'warning',
  227. },
  228. );
  229. const productsmerchantidArr = row.productsmerchantid.split(',');
  230. const productsmerchantid = productsmerchantidArr.filter(
  231. (item: any) => item !== userStore.userInfo?.workeruserid,
  232. );
  233. const newProductsmerchantid = productsmerchantid.join(',');
  234. await editProductApi({
  235. 'productsid.value': row.productsid,
  236. productsmerchantid: newProductsmerchantid || '',
  237. } as any);
  238. ElMessage.success('取消关联成功');
  239. gridApi.reload();
  240. } catch {}
  241. }
  242. /* 新增关联 */
  243. function handleAddLink() {
  244. addLinkModalRef.value?.open();
  245. }
  246. /* 新增关联完成回调 */
  247. function handleAddLinkFinish() {
  248. gridApi.reload();
  249. }
  250. </script>
  251. <template>
  252. <Page auto-content-height>
  253. <Grid table-title="产品列表">
  254. <template #toolbar-tools>
  255. <!--区别: 新增- 新增产品, 新增关联-新增产品和渠道商关联 -->
  256. <el-button
  257. type="primary"
  258. @click="handleCreate"
  259. v-if="!userStore.isDLSNotAdmin"
  260. >
  261. 新增
  262. </el-button>
  263. <el-button
  264. type="primary"
  265. @click="handleAddLink"
  266. v-if="userStore.isDLSNotAdmin"
  267. >
  268. 新增关联
  269. </el-button>
  270. </template>
  271. <template #action="{ row }">
  272. <el-tooltip
  273. class="box-item"
  274. effect="dark"
  275. content="详情"
  276. placement="top"
  277. >
  278. <el-button
  279. round
  280. @click="() => handleDetail(row)"
  281. :icon="MdiDetail"
  282. class="!p-2"
  283. />
  284. </el-tooltip>
  285. <el-tooltip
  286. v-if="!userStore.isDLSNotAdmin"
  287. class="box-item"
  288. effect="dark"
  289. content="编辑"
  290. placement="top"
  291. >
  292. <el-button
  293. round
  294. @click="() => handleEdit(row)"
  295. :icon="MdiEdit"
  296. class="!p-2"
  297. />
  298. </el-tooltip>
  299. <el-tooltip
  300. class="box-item"
  301. effect="dark"
  302. content="删除"
  303. placement="top"
  304. v-if="!userStore.isDLSNotAdmin"
  305. >
  306. <el-button
  307. round
  308. @click="() => handleDelete(row)"
  309. :icon="MdiDelete"
  310. class="!p-2"
  311. />
  312. </el-tooltip>
  313. <el-tooltip
  314. class="box-item"
  315. effect="dark"
  316. content="移除关联"
  317. placement="top"
  318. v-if="userStore.isDLSNotAdmin"
  319. >
  320. <el-button
  321. round
  322. @click="() => handleRemoveLink(row)"
  323. :icon="MdiDelete"
  324. class="!p-2"
  325. />
  326. </el-tooltip>
  327. </template>
  328. </Grid>
  329. <Modal @finish="handleFinish" />
  330. <!-- 新增关联弹窗组件 -->
  331. <AddLinkModal ref="addLinkModalRef" @finish="handleAddLinkFinish" />
  332. <!-- 详情弹窗组件 -->
  333. <ProductDetail ref="detailModalRef" />
  334. </Page>
  335. </template>