template.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. const mapTemplateToTable = {
  2. '所属平台ID': 'platform_id',
  3. '供应商公司编码': 'supplierNo',
  4. '销售方公司编码': 'companyNo',
  5. '购买方公司编码': 'customerNo',
  6. // '一级品类ID': 'cat_id1',
  7. // '二级品类ID': 'cat_id2',
  8. '三级品类ID': 'cat_id',
  9. '商品单位ID': 'good_unit',
  10. '商品名称': 'good_name',
  11. '销售单价': 'sale_price',
  12. '数量': 'good_num',
  13. '销售总额': 'sale_total',
  14. '税率': 'good_tax',
  15. '采购单价': 'cgd_price',
  16. '采购总额': 'cgd_total',
  17. '采购毛利率': 'cgd_tax',
  18. '平台订单号': 'poCode',
  19. '收货人': 'contactor',
  20. '联系电话': 'mobile',
  21. '联系地址': 'addr',
  22. '发货时间': 'sendtime'
  23. }
  24. // '单据号': 'workCode',
  25. export const getTableProperty = (key) => mapTemplateToTable[key]
  26. export const getTableLabel = (field) => {
  27. const keys = Object.keys(mapTemplateToTable)
  28. for (const key of keys) {
  29. if (mapTemplateToTable[key] === field) {
  30. return key
  31. }
  32. }
  33. }
  34. export const PROPERTYS = {
  35. COMPANY_NO: getTableProperty('销售方公司编码'),
  36. CUSTOMER_NO: getTableProperty('购买方公司编码'),
  37. SUPPLIER_NO: getTableProperty('供应商公司编码'),
  38. PLATFORM: getTableProperty('所属平台ID'),
  39. CATEGORY: getTableProperty('三级品类ID'),
  40. GOOD_NAME: getTableProperty('商品名称'),
  41. GOOD_UNIT: getTableProperty('商品单位ID'),
  42. GOOD_NUM: getTableProperty('数量'),
  43. GOOD_PRICE: getTableProperty('销售单价'),
  44. TAX: getTableProperty('税率'),
  45. CGD_PRICE: getTableProperty('采购单价'),
  46. CGD_TAX: getTableProperty('采购毛利率'),
  47. SALE_TOTAL: getTableProperty('销售总额'),
  48. CONTACTOR: getTableProperty('收货人'),
  49. MOBILE: getTableProperty('联系电话'),
  50. ADDR: getTableProperty('联系地址'),
  51. SEND_TIME: getTableProperty('发货时间'),
  52. PO_CODE: getTableProperty('平台订单号'),
  53. CGD_TOTAL: getTableProperty('采购总额'),
  54. WORK_CODE: getTableProperty('单据号')
  55. }
  56. // export const template = [
  57. // {
  58. // '所属平台ID': '58',
  59. // '供应商公司编码': 'QS2206011407522117',
  60. // '销售方公司编码': 'GS2302231323386950',
  61. // '购买方公司编码': 'KH2203271822232121',
  62. // '一级品类ID': '871',
  63. // '二级品类ID': '871',
  64. // '三级品类ID': '871',
  65. // '商品单位ID': '7',
  66. // '商品名称': '测试商品名称',
  67. // '销售单价': '32',
  68. // '数量': '100',
  69. // '销售总额': '3200',
  70. // '税率': '13',
  71. // '采购单价': '30.00',
  72. // '采购总额': '3000',
  73. // '采购毛利率': '6',
  74. // '平台订单号': 'PO206020230400240002',
  75. // '收货人': '张三',
  76. // '联系电话': '19955554444',
  77. // '联系地址': 'xx市xx区xx街道',
  78. // '发货时间': '2023-4-9 8:00:00'
  79. // }
  80. // ]
  81. export const template = Array(1).fill(1).map(() => ({
  82. '所属平台ID': '58',
  83. '供应商公司编码': 'QS2206011407522117',
  84. '销售方公司编码': 'GS2302231323386950',
  85. '购买方公司编码': 'KH2203271822232121',
  86. // '一级品类ID': '871',
  87. // '二级品类ID': '871',
  88. '三级品类ID': '871',
  89. '商品单位ID': '7',
  90. '商品名称': '测试商品名称',
  91. '销售单价': '32',
  92. '数量': '100',
  93. '销售总额': '3200',
  94. '税率': '13',
  95. '采购单价': '30.00',
  96. '采购总额': '3000',
  97. '采购毛利率': '6',
  98. '平台订单号': 'PO206020230400240002',
  99. '收货人': '张三',
  100. '联系电话': '19955554444',
  101. '联系地址': 'xx市xx区xx街道',
  102. '发货时间': '2023-4-9 8:00:00'
  103. }))
  104. export const columns = [
  105. {
  106. type: 'index',
  107. label: '序号',
  108. width: '80px'
  109. },
  110. {
  111. prop: PROPERTYS.PLATFORM,
  112. label: '所属平台ID',
  113. width: '110px',
  114. required: true
  115. },
  116. {
  117. prop: PROPERTYS.SUPPLIER_NO,
  118. label: '供应商公司编码',
  119. width: '120px',
  120. required: true
  121. },
  122. {
  123. prop: PROPERTYS.COMPANY_NO,
  124. label: '销售方公司编码',
  125. width: '156px',
  126. required: true
  127. },
  128. {
  129. prop: PROPERTYS.CUSTOMER_NO,
  130. label: '购买方公司编码',
  131. width: '180px',
  132. required: true
  133. },
  134. // {
  135. // prop: getTableProperty('一级品类ID'),
  136. // label: '一级品类ID',
  137. // width: '150px',
  138. // required: true
  139. // },
  140. // {
  141. // prop: getTableProperty('二级品类ID'),
  142. // label: '二级品类ID',
  143. // width: '150px',
  144. // required: true
  145. // },
  146. {
  147. prop: getTableProperty('三级品类ID'),
  148. label: '三级品类ID',
  149. width: '150px',
  150. required: true
  151. },
  152. {
  153. prop: PROPERTYS.GOOD_UNIT,
  154. label: '商品单位ID',
  155. width: '150px',
  156. required: true
  157. },
  158. {
  159. prop: PROPERTYS.GOOD_NAME,
  160. label: '商品名称',
  161. width: '150px',
  162. required: true
  163. },
  164. {
  165. prop: PROPERTYS.GOOD_PRICE,
  166. label: '销售单价',
  167. 'width': '150px',
  168. required: true
  169. },
  170. {
  171. prop: PROPERTYS.GOOD_NUM,
  172. label: '数量',
  173. width: '140px',
  174. required: true
  175. },
  176. {
  177. prop: PROPERTYS.SALE_TOTAL,
  178. label: '销售总额',
  179. 'width': '150px'
  180. },
  181. {
  182. prop: PROPERTYS.TAX,
  183. label: '税率',
  184. width: '150px',
  185. required: true
  186. },
  187. {
  188. prop: PROPERTYS.CGD_PRICE,
  189. label: '采购单价',
  190. 'width': '150px',
  191. required: true
  192. },
  193. {
  194. prop: PROPERTYS.CGD_TOTAL,
  195. label: '采购总额',
  196. 'width': '150px',
  197. required: true
  198. },
  199. {
  200. prop: getTableProperty('采购毛利率'),
  201. label: '采购毛利率',
  202. 'width': '150px'
  203. },
  204. {
  205. prop: PROPERTYS.PO_CODE,
  206. label: '平台订单号',
  207. 'width': '150px',
  208. required: true
  209. },
  210. {
  211. prop: PROPERTYS.CONTACTOR,
  212. label: '收货人',
  213. 'width': '150px',
  214. required: true
  215. },
  216. // {
  217. // prop: PROPERTYS.WORK_CODE,
  218. // label: '单据号',
  219. // 'width': '150px'
  220. // },
  221. {
  222. prop: PROPERTYS.MOBILE,
  223. label: '联系电话',
  224. 'width': '150px',
  225. required: true
  226. },
  227. {
  228. prop: PROPERTYS.ADDR,
  229. label: '联系地址',
  230. 'width': '150px',
  231. required: true
  232. },
  233. {
  234. prop: PROPERTYS.SEND_TIME,
  235. label: '发货时间',
  236. 'width': '150px',
  237. required: true
  238. }
  239. ]
  240. export function createErrorMessage(messages) {
  241. const rows = Object.keys(messages)
  242. return [rows[0]].reduce((prev, row, index) => {
  243. console.log(messages[row])
  244. const suffix = index === rows.length - 1 ? '</ul>' : ''
  245. const content = prev + `
  246. <li>
  247. <strong style="font-weight:700">第${row}行</strong>,${messages[row][0]}
  248. </li>
  249. `
  250. return content + suffix
  251. }, '<ul>')
  252. }
  253. export const createFieldVerification = (message) => ({
  254. notValidRows: [],
  255. isValid: true,
  256. message
  257. })
  258. export const requsetFields = [
  259. PROPERTYS.TAX,
  260. PROPERTYS.ADDR,
  261. PROPERTYS.MOBILE,
  262. PROPERTYS.PO_CODE,
  263. PROPERTYS.PLATFORM,
  264. PROPERTYS.CATEGORY,
  265. PROPERTYS.GOOD_NAME,
  266. PROPERTYS.GOOD_UNIT,
  267. PROPERTYS.GOOD_NUM,
  268. PROPERTYS.CGD_PRICE,
  269. PROPERTYS.CONTACTOR,
  270. PROPERTYS.SEND_TIME,
  271. PROPERTYS.WORK_CODE,
  272. PROPERTYS.GOOD_PRICE,
  273. PROPERTYS.COMPANY_NO,
  274. PROPERTYS.SUPPLIER_NO,
  275. PROPERTYS.CUSTOMER_NO,
  276. PROPERTYS.CGD_TAX,
  277. PROPERTYS.SALE_TOTAL,
  278. PROPERTYS.CGD_TOTAL
  279. ]
  280. // 税率、数量、销售单价、采购单价
  281. export const requiredFields = [
  282. PROPERTYS.TAX,
  283. PROPERTYS.ADDR,
  284. PROPERTYS.MOBILE,
  285. PROPERTYS.PO_CODE,
  286. PROPERTYS.PLATFORM,
  287. PROPERTYS.CATEGORY,
  288. PROPERTYS.GOOD_NAME,
  289. PROPERTYS.GOOD_UNIT,
  290. PROPERTYS.GOOD_NUM,
  291. PROPERTYS.CONTACTOR,
  292. PROPERTYS.SEND_TIME,
  293. PROPERTYS.COMPANY_NO,
  294. PROPERTYS.SUPPLIER_NO,
  295. PROPERTYS.CUSTOMER_NO,
  296. PROPERTYS.CGD_TOTAL,
  297. PROPERTYS.SALE_TOTAL,
  298. PROPERTYS.CGD_TAX
  299. ]
  300. export const numberFields = [
  301. PROPERTYS.CGD_TOTAL,
  302. PROPERTYS.SALE_TOTAL,
  303. PROPERTYS.GOOD_PRICE,
  304. PROPERTYS.CGD_PRICE,
  305. PROPERTYS.CGD_TAX
  306. ]
  307. export const intNumberFields = [
  308. PROPERTYS.CATEGORY,
  309. PROPERTYS.GOOD_UNIT,
  310. PROPERTYS.GOOD_NUM,
  311. PROPERTYS.TAX
  312. ]
  313. export const helper = {
  314. fields: function(sourceObject) {
  315. return Object.keys(sourceObject)
  316. },
  317. values: function(sourceObject, fields, index = 0) {
  318. return fields.map(field => {
  319. return sourceObject[field][index]
  320. })
  321. },
  322. write: function(sourceObject, fields) {
  323. return fields.reduce((prev, currentKey) => ({
  324. ...prev,
  325. [currentKey]: sourceObject[currentKey]
  326. }), {})
  327. }
  328. }