index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <script setup lang="tsx">
  2. import { computed, ref } from 'vue';
  3. import { NButton, NImage, NInputNumber, NSelect } from 'naive-ui';
  4. import dayjs from 'dayjs';
  5. import { fetchGetAllStoreList } from '@/service/api/goods/desk-category';
  6. import {
  7. fetchGetAllChannelList,
  8. fetchGetGoodsList,
  9. fetchImportGoods,
  10. fetchSetUpChannels
  11. } from '@/service/api/goods/store-goods';
  12. import { areAllItemsAllFieldsFilled } from '@/utils/zt';
  13. import { useTable } from '@/components/zt/Table/hooks/useTable';
  14. import type { ModalMethods } from '@/components/zt/Modal/types';
  15. import SvgIcon from '@/components/custom/svg-icon.vue';
  16. import { useModal } from '@/components/zt/Modal/hooks/useModal';
  17. type Price = { channelId: number | undefined; channelProdPrice: number; id: number };
  18. const importTemplateRef = ref<ModalMethods>();
  19. const options = ref<Api.goods.Channel[]>([]);
  20. const TypeName = ['企业用户', 'B端用户', 'C端用户'];
  21. const columns: NaiveUI.TableColumn<Api.goods.ShopSku>[] = [
  22. {
  23. type: 'selection',
  24. align: 'center',
  25. width: 48,
  26. fixed: 'left'
  27. },
  28. {
  29. key: 'skuName',
  30. title: '商品信息',
  31. align: 'left',
  32. width: 300,
  33. fixed: 'left',
  34. render: row => {
  35. if (!row.sku) {
  36. return '---';
  37. }
  38. const img = row.sku.pic?.split(',');
  39. return (
  40. <div class={'flex items-center'}>
  41. <NImage src={img[0]} class="h-[80px] min-w-80px w-[80px]" lazy />
  42. <div class={'ml-[10px]'}>
  43. <div class={'text-[16px] font-semibold'}>{row.sku.skuName || '--'}</div>
  44. <div class={'text-gray'}>海博商品ID: {row.sku.hbSkuId || '--'} </div>
  45. <div class={'text-gray'}>商品编码:{row.sku.partyCode || '--'} </div>
  46. <div class={'text-gray'}>SPUID: {row.sku.hbSpuId || '--'} </div>
  47. <div class={'text-gray'}>外部商品编码:{row.sku.skuCode || '--'} </div>
  48. <div class={'text-gray'}>条形码:{row.sku.modelId || '--'} </div>
  49. <div class={'text-gray'}>
  50. 重量/规格/单位:{row.sku.weight || '--'} / {row.sku.weightUnit || '--'} / {row.sku.weightUnit || '--'}
  51. </div>
  52. </div>
  53. </div>
  54. );
  55. }
  56. },
  57. {
  58. key: 'shopName',
  59. title: '门店名称',
  60. align: 'center',
  61. width: 120,
  62. ellipsis: {
  63. tooltip: true
  64. },
  65. render: row => {
  66. const nameList = row.channelProdList?.map(it => it.shopName);
  67. return <div>{nameList?.join(',') || '--'}</div>;
  68. }
  69. },
  70. {
  71. key: 'shopSkuStocks',
  72. title: '线上可售库存',
  73. align: 'center',
  74. width: 120
  75. },
  76. {
  77. key: 'purchasePrice',
  78. title: '进货价(元)',
  79. align: 'center',
  80. width: 120,
  81. render: row => {
  82. if (!row.channelProdList?.length) return '--';
  83. if (row.channelProdList) return <div>{row.channelProdList[0].purchasePrice || '--'}</div>;
  84. return '--';
  85. }
  86. },
  87. {
  88. key: 'deliveryPrice',
  89. title: '出货价/控制价(元)',
  90. align: 'center',
  91. width: 150,
  92. render: row => {
  93. if (!row.channelProdList?.length) return '--';
  94. if (row.channelProdList) return <div>{row.channelProdList[0].deliveryPrice || '--'}</div>;
  95. return '--';
  96. }
  97. },
  98. {
  99. key: 'name',
  100. title: '销售渠道及价格',
  101. align: 'center',
  102. width: 250,
  103. render: row => {
  104. return row.channelProdList?.map(it => {
  105. return (
  106. <div>
  107. {TypeName[Number(it.channelId) - 1]} ({it.channelName || '--'}) : {it.channelProdPrice || '--'}
  108. </div>
  109. );
  110. });
  111. }
  112. }
  113. ];
  114. const PriceColumns: NaiveUI.TableColumn<Price>[] = [
  115. {
  116. title: '销售渠道',
  117. key: 'channelId',
  118. align: 'center',
  119. width: 250,
  120. render: row => {
  121. return (
  122. <NSelect
  123. options={options.value}
  124. labelField="channelName"
  125. valueField="id"
  126. value={row.channelId}
  127. clearable
  128. onUpdate:value={value => {
  129. options.value.map(it => {
  130. if (it.id == row.channelId) {
  131. it.disabled = false;
  132. }
  133. return it;
  134. });
  135. row.channelId = value ? Number(value) : undefined;
  136. }}
  137. onUpdate:show={value => {
  138. options.value.map(it => {
  139. if (it.id == row.channelId) {
  140. if (value) {
  141. it.disabled = false;
  142. }
  143. if (!value) {
  144. it.disabled = true;
  145. }
  146. }
  147. return it;
  148. });
  149. }}
  150. ></NSelect>
  151. );
  152. }
  153. },
  154. {
  155. title: '售价(元)',
  156. key: 'channelProdPrice',
  157. align: 'center',
  158. width: 250,
  159. render: row => {
  160. return (
  161. <NInputNumber
  162. value={row.channelProdPrice}
  163. precision={2}
  164. onUpdate:value={value => {
  165. row.channelProdPrice = Number(value);
  166. }}
  167. min={1}
  168. />
  169. );
  170. }
  171. },
  172. {
  173. title: () => {
  174. return (
  175. <div onClick={() => handleAddPrice()} class={'w-full flex items-center justify-center'}>
  176. <SvgIcon
  177. icon={'proicons:add-square'}
  178. class={'cursor-pointer text-24px'}
  179. style={'color:var(--n-color)'}
  180. ></SvgIcon>
  181. </div>
  182. );
  183. },
  184. key: 'action',
  185. width: 80,
  186. align: 'center',
  187. render: row => {
  188. return (
  189. <div onClick={() => handleDelPrice(row.id)} class={'w-full flex items-center justify-center'}>
  190. <SvgIcon
  191. icon={'proicons:subtract-square'}
  192. class={'cursor-pointer text-24px'}
  193. style={'color:#f5222d'}
  194. ></SvgIcon>
  195. </div>
  196. );
  197. }
  198. }
  199. ];
  200. const PriceData = ref<Price[]>([]);
  201. const selectData = ref<Api.goods.ShopSku>();
  202. const [registerTable, { getTableCheckedRowKeys, refresh, getTableData }] = useTable({
  203. searchFormConfig: {
  204. schemas: [
  205. {
  206. label: '门店名称',
  207. component: 'ApiSelect',
  208. field: 'shopId',
  209. componentProps: {
  210. api: fetchGetAllStoreList,
  211. labelFeild: 'shopName',
  212. valueFeild: 'hbStationId'
  213. }
  214. },
  215. {
  216. label: '商品名称',
  217. component: 'NInput',
  218. field: 'shopId'
  219. }
  220. ],
  221. inline: false,
  222. size: 'small',
  223. labelPlacement: 'left',
  224. isFull: false
  225. },
  226. tableConfig: {
  227. keyField: 'id',
  228. title: '商品列表',
  229. showAddButton: false,
  230. scrollX: 1200
  231. }
  232. });
  233. const [
  234. registerModalPrice,
  235. { openModal: openPriceModal, setSubLoading: setSubModalLoding, closeModal: closePriceModal }
  236. ] = useModal({
  237. title: '设置渠道及价格',
  238. width: 800,
  239. height: 300
  240. });
  241. const isDisabledExport = computed(() => {
  242. return !getTableCheckedRowKeys().length;
  243. });
  244. const tableData = computed(() => {
  245. return getTableData();
  246. });
  247. async function handleSubmitImport(file: File) {
  248. const { error } = await fetchImportGoods({ file });
  249. if (!error) {
  250. importTemplateRef.value?.closeModal();
  251. }
  252. importTemplateRef.value?.setSubLoading(false);
  253. }
  254. function openImportModal() {
  255. importTemplateRef.value?.openModal();
  256. }
  257. function handleModalPrice(row: Api.goods.ShopSku) {
  258. selectData.value = row;
  259. if (row.channelProdList) {
  260. PriceData.value = row.channelProdList?.map(it => {
  261. return {
  262. channelId: Number(it.channelId),
  263. channelProdPrice: Number(it.channelProdPrice),
  264. id: Number(it.id)
  265. };
  266. });
  267. }
  268. openPriceModal();
  269. }
  270. function handleAddPrice() {
  271. if (PriceData.value.length == 3) {
  272. window.$message?.error('最多只能添加3条数据');
  273. return;
  274. }
  275. PriceData.value.push({
  276. channelId: undefined,
  277. channelProdPrice: 1,
  278. id: dayjs().valueOf()
  279. });
  280. }
  281. function handleDelPrice(id: number) {
  282. PriceData.value = PriceData.value.filter(item => item.id != id);
  283. }
  284. async function handleSubmitPrice() {
  285. setSubModalLoding(false);
  286. if (!PriceData.value.length) {
  287. window.$message?.error('最少填写一条数据');
  288. return;
  289. }
  290. if (!areAllItemsAllFieldsFilled(PriceData.value)) {
  291. window.$message?.error('请填写完整数据');
  292. return;
  293. }
  294. setSubModalLoding(true);
  295. const form = {
  296. shopId: selectData.value?.shopId,
  297. skuId: selectData.value?.skuId,
  298. purchasePrice: selectData.value?.channelProdList?.length ? selectData.value.channelProdList[0].purchasePrice : null,
  299. deliveryPrice: selectData.value?.channelProdList?.length ? selectData.value.channelProdList[0].deliveryPrice : null,
  300. setChannelPriceDtoList: PriceData.value.map(item => {
  301. return {
  302. channelId: item.channelId,
  303. channelProdPrice: item.channelProdPrice
  304. };
  305. })
  306. };
  307. const { error } = await fetchSetUpChannels(form);
  308. if (!error) {
  309. closePriceModal();
  310. refresh();
  311. PriceData.value = [];
  312. options.value.map(it => (it.disabled = false));
  313. } else {
  314. setSubModalLoding(false);
  315. }
  316. console.log(PriceData.value, 'asdsad');
  317. }
  318. async function getData() {
  319. const { data, error } = await fetchGetAllChannelList();
  320. if (!error) {
  321. options.value = data;
  322. }
  323. }
  324. getData();
  325. </script>
  326. <template>
  327. <LayoutTable>
  328. <ZTable :columns="columns" :api="fetchGetGoodsList" @register="registerTable">
  329. <template #op="{ row }">
  330. <NButton size="small" ghost type="primary" @click="handleModalPrice(row)">设置渠道及价格</NButton>
  331. </template>
  332. <template #prefix>
  333. <NSpace>
  334. <NButton size="small" @click="openImportModal">导入商品销售渠道及价格</NButton>
  335. <NButton size="small" :disabled="tableData.length == 0">导出全部</NButton>
  336. <NButton size="small" :disabled="isDisabledExport">导出选中数据</NButton>
  337. <NButton size="small">修改记录</NButton>
  338. </NSpace>
  339. </template>
  340. </ZTable>
  341. <ZImportTemplate
  342. ref="importTemplateRef"
  343. url="/platform/channelProd/template/download"
  344. template-text="商品渠道及价格导入模版.xlsx"
  345. modal-text="导入商品销售渠道及价格"
  346. @submit="handleSubmitImport"
  347. ></ZImportTemplate>
  348. <BasicModal @register="registerModalPrice" @ok="handleSubmitPrice">
  349. <NDataTable :columns="PriceColumns" :data="PriceData" :row-key="row => row.id" />
  350. </BasicModal>
  351. </LayoutTable>
  352. </template>
  353. <style scoped></style>