index.vue 8.1 KB

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