order-create.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
  2. $('.navLayout').find('.navList').eq(0).addClass("on").find('.con').show().find('a').eq(2).addClass("on");
  3. const seeDetail = new Vue({
  4. el: '#seeDetail',
  5. mixins: [cmSysVitaMixins],
  6. data() {
  7. const defaultConfirmParam = {
  8. cartType:3, // 购买类型:(1自主下单, 3协销下单)
  9. orderSource:1, // 订单来源 1WWW 6小程序[采美,星范]
  10. addressId:0, // 收货地址Id
  11. cityId:0, // 收货地址Id
  12. orderInfo:[], // 订单商品数据 // 订单发票信息
  13. addressInfo:{
  14. receiver:'',
  15. mobile:'',
  16. provinceId:'',
  17. cityId:'',
  18. townId:'',
  19. address:''
  20. }, // 订单地址信息
  21. orderInvoice:{ type: 0 }, // 订单发票信息
  22. payInfo:{ // 订单金额数据
  23. orderShouldPayFee: 0, // 订单最终支付金额
  24. clauseId:0 // 条款Id
  25. }
  26. };
  27. return {
  28. isFiexd:false,
  29. shopId:'',
  30. addressForm:{
  31. receiver:'',
  32. mobile:'',
  33. provinceId:'',
  34. cityId:'',
  35. townId:'',
  36. address:''
  37. },
  38. invoiceForm:{
  39. type:0, // 0 不开发票 1 普通发票 2 增值税发票
  40. headingType:0, // 0 个人 1 单位
  41. invoiceTitle:'', // 发票抬头
  42. corporationTaxNum:'',//单位税号
  43. registeredAddress:'',// 注册地址
  44. registeredPhone:'',// 注册电话
  45. openBank:'',// 开户银行
  46. bankAccountNo:''// 银行账号
  47. },
  48. hanldShouldPayFee:0,
  49. prosParams:{
  50. productInfo:[],
  51. shopId:'',
  52. cityId:''
  53. },
  54. confirmParam: defaultConfirmParam, // 提交订单参数
  55. supplier:{},
  56. orderInfoArray:[],
  57. provinceList:[],
  58. cityList:[],
  59. townList:[],
  60. productsArr:[],
  61. isLoading:true,
  62. abnormalProductList:[],// 成本异常商品
  63. goodsDialogVisible:false,
  64. abnormalDialogVisible:false,
  65. productRadio:null,
  66. checkedProductList:[],
  67. total:0,
  68. productsList:[],
  69. listQuery:{
  70. name:'',//商品名称
  71. shopId:'',
  72. pageNum:1,
  73. pageSize:10
  74. },
  75. rules: {
  76. receiver: [{required: true,message: '请填写收货人',trigger: 'blur'}],
  77. mobile: [{required: true,message: '请填写联系方式',trigger: 'blur'}],
  78. provinceId: [{required: true,message: '请选择省份',trigger: 'change'}],
  79. cityId: [{required: true,message: '请选择市',trigger: 'change'}],
  80. townId: [{required: true,message: '请选择区县',trigger: 'change'}],
  81. address: [{required: true,message: '请填写详细地址信息',trigger: 'blur'}],
  82. invoiceTitle: [{required: true,message: '请填写发票抬头',trigger: 'blur'}],
  83. corporationTaxNum: [{required: true,message: '请填写单位税号',trigger: 'blur'}],
  84. registeredAddress: [{required: true,message: '请填写详细地址信息',trigger: 'blur'}],
  85. registeredPhone: [{required: true,message: '请填写注册电话',trigger: 'blur'}],
  86. openBank: [{required: true,message: '请填写开户银行',trigger: 'blur'}],
  87. bankAccountNo: [{required: true,message: '请填写银行账号',trigger: 'blur'}]
  88. },
  89. submitLoading:false,
  90. }
  91. },
  92. filters: {
  93. amountfilters(value) {
  94. if (value) {
  95. return Number(value).toFixed(2)
  96. } else {
  97. return '0.00'
  98. }
  99. },
  100. },
  101. computed: {
  102. disabled() {
  103. return this.productRadio === null
  104. },
  105. checkedConfirmFlag(){
  106. if(this.confirmParam.cityId && this.checkedProductList.length > 0 ){
  107. return true
  108. }
  109. },
  110. },
  111. methods: {
  112. // 计算总运费
  113. handleTotalPostage(supplier){
  114. if(supplier.isColdChina){
  115. if(supplier.handlePostageFlag === 2){
  116. return (supplier.coldChain*100 + supplier.postage*100 - supplier.postage*100)/100
  117. }else{
  118. return (supplier.postage*100 + supplier.coldChain*100)/100
  119. }
  120. }else{
  121. return supplier.postage
  122. }
  123. },
  124. // 勾选冷链费
  125. handleChangeColdChina(flag,supplier){
  126. if(flag){
  127. supplier.totalPrice = Number((supplier.totalPrice*100 + supplier.coldChain*100)/100)
  128. this.attributePallPrice()
  129. console.log('totalPrice',supplier.totalPrice)
  130. }else{
  131. supplier.totalPrice = Number(this.repiceNumSub(supplier.totalPrice,supplier.coldChain))
  132. this.attributePallPrice()
  133. console.log('hanldShouldPayFee',this.hanldShouldPayFee)
  134. }
  135. },
  136. getProvinceOptions(){ // 获取全部省份
  137. const _this = this;
  138. OrderApi.GetAddressSelect({},function(res){
  139. if(res.code === 0 && res.data){
  140. _this.provinceList = res.data;
  141. }else{
  142. CAIMEI.Alert(res.msg,'确定',false);
  143. }
  144. });
  145. },
  146. getCityList(parentId){// 获取地区
  147. const _this = this;
  148. this.cityList = [];
  149. this.townList = [];
  150. this.addressForm.cityId = '';
  151. this.addressForm.townId = '';
  152. OrderApi.GetAddressSelect({ parentId: parentId,type:1 },function(res){
  153. if(res.code === 0 && res.data){
  154. _this.cityList = res.data;
  155. }else{
  156. CAIMEI.Alert(res.msg,'确定',false);
  157. }
  158. });
  159. },
  160. getTownList(cityId){
  161. const _this = this;
  162. this.townList = [];
  163. this.addressForm.townId = '';
  164. this.confirmParam.cityId = this.prosParams.cityId = this.addressForm.cityId
  165. console.log('cityId',cityId)
  166. OrderApi.GetAddressSelect({parentId: cityId,type:2},function(res){
  167. if(res.code === 0 && res.data){
  168. _this.townList = res.data;
  169. }else{
  170. CAIMEI.Alert(res.msg,'确定',false);
  171. }
  172. })
  173. // 切换市区时重新调用确认订单信息
  174. if(this.checkedProductList.length > 0){
  175. this.prosParams.productInfo = this.handleProStringify(this.checkedProductList)
  176. console.log('prosParams',this.prosParams)
  177. this.getSettlement(this.prosParams)
  178. }
  179. },
  180. handleConfirm(){
  181. // 校验收货信息
  182. this.$refs['dataForm'].validate(async valid => {
  183. if (valid) {
  184. if(this.productsArr.length === 0){
  185. this.$alert('请添加商品~', '提示', {
  186. type: 'warning',
  187. confirmButtonText: '确定',
  188. });
  189. }
  190. }
  191. })
  192. // 校验发票
  193. if(this.invoiceForm.type!==0){
  194. this.$refs['invoiceForm'].validate(async valid => {
  195. if (valid) {
  196. if(this.checkedConfirmFlag){
  197. this.initializationParams()
  198. }
  199. }
  200. })
  201. }else {
  202. if(this.checkedConfirmFlag){
  203. this.initializationParams()
  204. }
  205. }
  206. },
  207. //统一处理
  208. initializationParams(){
  209. // 发票信息
  210. if(this.invoiceForm.type!==0){
  211. this.invoiceForm.type = parseInt(this.invoiceForm.type)
  212. this.confirmParam.orderInvoice = this.invoiceForm;
  213. }
  214. //商品信息
  215. this.confirmParam.orderInfo = this.hanldeProcessing()
  216. console.log('orderInfo',this.confirmParam.orderInfo)
  217. this.confirmParam.payInfo.orderShouldPayFee = parseFloat(this.hanldShouldPayFee).toFixed(2);
  218. this.confirmParam.addressInfo = JSON.stringify(this.addressForm)
  219. console.log('addressInfo',this.confirmParam.addressInfo)
  220. this.confirmParam.payInfo = JSON.stringify(this.confirmParam.payInfo)
  221. this.confirmParam.orderInfo = JSON.stringify(this.confirmParam.orderInfo)
  222. this.confirmParam.orderInvoice = JSON.stringify(this.confirmParam.orderInvoice)
  223. console.log('confirmParam',this.confirmParam);
  224. this.handleConfirmOrder(this.confirmParam);
  225. },
  226. // 处理数据格式
  227. hanldeProcessing() {
  228. return this.orderInfoArray.map(el => {
  229. let productInfo = []
  230. el.cartList.forEach(pros => {
  231. productInfo.push({
  232. skuId: pros.skuId,
  233. productNum: pros.number,
  234. presentNum: 0,
  235. productType: pros.giftType,
  236. price: pros.price.toString()
  237. })
  238. })
  239. return {
  240. splitCode: el.splitCode,
  241. shopId: el.shopId,
  242. note: el.note ? el.note : '',
  243. postage: el.isColdChina
  244. ? parseInt(el.postage + el.coldChain).toFixed(2)
  245. : parseInt(el.postage).toFixed(2),
  246. postageFlag: parseInt(el.handlePostageFlag),
  247. isColdChina: el.isColdChina ? 1 : 0,
  248. productInfo: productInfo
  249. }
  250. })
  251. },
  252. handleConfirmOrder(params){
  253. const _this = this;
  254. this.submitLoading = true
  255. setTimeout(()=>{
  256. SupplierApi.shopGenerateOrder(params,function(response){
  257. if(response.code === 0){
  258. const data = response.data
  259. _this.submitLoading = false
  260. _this.$message({
  261. message: '恭喜你,订单提交成功~',
  262. type: 'success'
  263. });
  264. setTimeout(()=>{
  265. _this.submitLoading = false
  266. _this.formatConfirmParam()
  267. window.location.href = '/supplier/order/detail.html?shopOrderId='+data.shopOrderId
  268. },2000)
  269. }else{
  270. setTimeout(()=>{
  271. _this.$message.error(response.msg)
  272. _this.submitLoading = false
  273. _this.formatConfirmParam()
  274. },2000)
  275. }
  276. })
  277. },1000)
  278. },
  279. // 还原提交订单参数格式
  280. formatConfirmParam:function(){
  281. this.confirmParam.payInfo = JSON.parse(this.confirmParam.payInfo);
  282. this.confirmParam.orderInfo = JSON.parse(this.confirmParam.orderInfo);
  283. this.confirmParam.addressInfo = JSON.parse(this.confirmParam.addressInfo);
  284. this.confirmParam.orderInvoice = JSON.parse(this.confirmParam.orderInvoice);
  285. console.log('payInfo',this.confirmParam.payInfo)
  286. },
  287. // 添加商品弹窗显示
  288. handleShowVisible(){
  289. this.getProductList()
  290. this.goodsDialogVisible = true
  291. },
  292. //切换页码
  293. handleCurrentChange(val){
  294. this.listQuery.pageNum = val;
  295. this.getProductList();
  296. },
  297. // 已选择的禁用勾选框
  298. handleSelectable(row) {
  299. const skuIds = this.checkedProductList.map(pros => pros.skuId);
  300. console.log('skuIds',skuIds)
  301. return !skuIds.includes(row.skuId);
  302. },
  303. //取消选择
  304. handleCanle(){
  305. this.productRadio = null
  306. this.goodsDialogVisible = false
  307. },
  308. // 删除确认商品
  309. handleDelete(index){
  310. this.checkedProductList.splice(index, 1)
  311. if(this.checkedProductList.length === 0){
  312. this.productsArr = []
  313. }
  314. if(this.checkedProductList.length > 0){
  315. this.prosParams.productInfo = this.handleProStringify(this.checkedProductList)
  316. this.getSettlement(this.prosParams)
  317. }
  318. },
  319. //修改sku
  320. handleChangeSku(row){
  321. const _this = this
  322. let skus = row.skus
  323. console.log('skus',skus)
  324. skus.forEach((sku)=>{
  325. if(row.skuId === sku.skuId){
  326. if(sku.ladderPriceFlag === 1){
  327. row.price = _this.handeleToFixed(sku.ladderPriceList[0].buyPrice)
  328. row.count = sku.minBuyNumber
  329. row.minBuyNumber = sku.minBuyNumber
  330. row.ladderPriceFlag = sku.ladderPriceFlag
  331. row.ladderPriceList = sku.ladderPriceList
  332. }else{
  333. row.price = _this.handeleToFixed(sku.price)
  334. row.count = sku.minBuyNumber
  335. row.minBuyNumber = sku.minBuyNumber
  336. row.ladderPriceFlag = sku.ladderPriceFlag
  337. row.ladderPriceList = sku.ladderPriceList
  338. }
  339. }
  340. })
  341. },
  342. // 修改数量判断阶梯价
  343. handleChangeNumber(row){
  344. const _this = this
  345. if (row.count < row.minBuyNumber) {
  346. row.count = row.minBuyNumber
  347. if (row.ladderPriceFlag === 1) {
  348. row.ladderPriceList.forEach((item) => {
  349. if (row.count >= item.buyNum) {
  350. row.price = _this.handeleToFixed(item.buyPrice)
  351. }
  352. })
  353. } else {
  354. row.price = _this.handeleToFixed(row.price)
  355. }
  356. } else {
  357. if (row.ladderPriceFlag === 1) {
  358. row.ladderPriceList.forEach((item) => {
  359. if (row.count >= item.buyNum) {
  360. row.price = _this.handeleToFixed(item.buyPrice)
  361. }
  362. })
  363. } else {
  364. row.price = _this.handeleToFixed(row.price)
  365. }
  366. }
  367. },
  368. // 保留小数点后两位数
  369. handeleToFixed(value){
  370. return value.toFixed(2)
  371. },
  372. //确认选择商品
  373. handleAddProConfirm(){
  374. this.checkedProductList = [...this.checkedProductList,...this.productRadio]
  375. this.prosParams.productInfo = this.handleProStringify(this.checkedProductList)
  376. this.getSettlement(this.prosParams)
  377. },
  378. // 统一格式化确认订单商品信息参数
  379. handleProStringify(productInfo){
  380. return JSON.stringify(productInfo.map((pros)=>{
  381. return {
  382. productId:pros.productId,
  383. count:pros.count,
  384. skuId:pros.skuId,
  385. price:pros.price
  386. }
  387. }))
  388. },
  389. // 确认订单信息
  390. getSettlement(params){
  391. const _this = this;
  392. this.orderInfoArray =[]
  393. SupplierApi.getSettlement(params,function(response){
  394. if(response.code === 0){
  395. let data = response.data
  396. if(data.abnormalProductList.length > 0){
  397. _this.abnormalProductList = data.abnormalProductList
  398. _this.abnormalDialogVisible = true
  399. // 根据 checkedProductList 中的 skuId,删除 abnormalProductList 中的相同 skuId 的数据
  400. _this.checkedProductList = _this.checkedProductList.filter(check => !_this.abnormalProductList.map(abnormal => abnormal.skuId).includes(check.skuId));
  401. console.log('checkedProductList',_this.checkedProductList)
  402. }else{
  403. _this.supplier = data.shop
  404. _this.orderInfoArray.push(_this.supplier)
  405. _this.hanldShouldPayFee = data.shop.totalPrice;
  406. _this.supplier.handlePostageFlag = data.shop.postageFlag
  407. _this.productsArr = data.shop.cartList
  408. _this.handleCanle()
  409. }
  410. }else{
  411. _this.$message.error(response.msg)
  412. }
  413. })
  414. },
  415. // 选择商品
  416. handleSelectionChange(row) {
  417. this.productRadio = row
  418. console.log('productRadio', this.productRadio)
  419. },
  420. getProductList(){//我的商品数据初始化
  421. const _this = this;
  422. this.isLoading = true
  423. SupplierApi.getShopProduct(this.listQuery,function(response){
  424. if(response.code === 0){
  425. const data = response.data
  426. _this.productsList = data.results.map((pros)=>{
  427. pros.count = pros.minBuyNumber
  428. pros.price = _this.handeleToFixed(pros.price)
  429. return pros
  430. })
  431. _this.total = data.totalRecord
  432. _this.isLoading = false
  433. }else{
  434. CAIMEI.Alert(response.msg, '确定')
  435. _this.isLoading = false
  436. }
  437. })
  438. },
  439. },
  440. mounted () {
  441. const _this = this;
  442. this.getProvinceOptions();
  443. if(globalUserData){
  444. this.listQuery.shopId = this.confirmParam.shopId = globalUserData.shopId;
  445. this.shopId = this.prosParams.shopId = globalUserData.shopId;
  446. }
  447. if (isPC) {
  448. $(window).scroll(function (event) {
  449. var supportPageOffset = window.pageXOffset !== undefined; // 判断是否支持pageXOffset
  450. var isCSS1Compat = ((document.compatMode || "") === "CSS1Compat"); // 判断渲染模式是不是标准模式
  451. var scrollHeight = supportPageOffset ? window.pageYOffset : isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop;
  452. if (scrollHeight < 100) {
  453. _this.isFiexd = true
  454. } else {
  455. _this.isFiexd = false
  456. }
  457. });
  458. }
  459. },
  460. });