detail.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. const _Http = getApp().globalData.http;
  2. let sa_brandid = null,
  3. sys_enterpriseid = null;
  4. import {
  5. getLabelList
  6. } from "../../utils/customItemType";
  7. import {
  8. fileList
  9. } from "../../utils/FormatTheAttachment";
  10. import currency from "../../utils/currency";
  11. Page({
  12. data: {
  13. itemCount: 0,
  14. selectCount: 0,
  15. labelList: getLabelList(),
  16. hidePrice: wx.getStorageSync('hidePrice'),
  17. badge: getApp().globalData.collectCount,
  18. favoriteCount: getApp().globalData.favoriteCount,
  19. loading: true,
  20. content: {
  21. sa_itemgroupid: null,
  22. spec: "", //规格
  23. color: "", //颜色
  24. material: "", //材质
  25. cheek: "" //边框
  26. },
  27. detail: {
  28. spec: ""
  29. },
  30. privacyFieldC: [],
  31. isShowFavorites: false,
  32. UniqueLine: false
  33. },
  34. onLoad(options) {
  35. let data = JSON.parse(options.params);
  36. sa_brandid = data.sa_brandid;
  37. if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = data.sys_enterpriseid
  38. this.data.content.sa_itemgroupid = data.sa_itemgroupid;
  39. this.setData({
  40. userrole: wx.getStorageSync('userrole'),
  41. isShowFavorites: wx.getStorageSync('auth').wfavorites ? true : false
  42. })
  43. try {
  44. let privacyFieldC = wx.getStorageSync('auth').wmarket.forms.wmarket.formcols.map(v => v.title);
  45. this.setData({
  46. privacyFieldC
  47. })
  48. console.log("privacyFieldC", privacyFieldC)
  49. } catch (error) {
  50. }
  51. },
  52. /* 获取详情 */
  53. getDetail(init = false, getCustom = true) {
  54. let content = this.data.content;
  55. if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
  56. if (this.data.UniqueLine)['spec', 'cheek', 'material', 'color'].forEach(key => content[key] = '')
  57. _Http.basic({
  58. "id": "20221223165503",
  59. content
  60. }).then(res => {
  61. wx.hideLoading();
  62. console.log("商品详情", res)
  63. if (res.msg != '成功') return wx.showToast({
  64. title: res.msg,
  65. icon: "none"
  66. })
  67. if (res.data.item.length == 0) return wx.showToast({
  68. title: '未查询到商品',
  69. icon: "none",
  70. mask: true
  71. })
  72. const item = res.data.item[0];
  73. this.handleFiles(item.attinfos)
  74. const CNY = sum => currency(sum, {
  75. symbol: "¥",
  76. precision: 2
  77. }).format();
  78. item.gradeprice = CNY(item.gradeprice);
  79. item.marketprice = CNY(item.marketprice);
  80. item.qty = item.orderaddqty;
  81. let ros = {
  82. specRows: res.data.specRows.reverse(),
  83. cheekRows: res.data.cheekRows,
  84. materialRows: res.data.materialRows,
  85. colorRows: res.data.colorRows,
  86. };
  87. let obj = {},
  88. auto = true,
  89. UniqueLine = true;
  90. ['spec', 'cheek', 'material', 'color'].forEach(key => obj[key] = ros[key + 'Rows'].filter(v => v.flag))
  91. for (const key in obj) {
  92. if (obj[key].length > 1) {
  93. auto = false
  94. UniqueLine = false;
  95. }
  96. }
  97. if (auto) {
  98. for (const key in obj) {
  99. if (obj[key].length) content[key] = obj[key][0].parm;
  100. }
  101. }
  102. this.setData({
  103. content,
  104. detail: item,
  105. ...ros,
  106. loading: false,
  107. itemCount: ['specRows', 'cheekRows', 'materialRows', 'colorRows'].filter(v => res.data[v].length).length,
  108. selectCount: ['cheek', 'color', 'material', 'spec'].filter(v => content[v].length).length,
  109. UniqueLine
  110. });
  111. //是否定制
  112. if (getCustom && item.iscustomsize == 1) this.selectComponent("#customMade").init(item);
  113. })
  114. },
  115. /* 预览媒体 */
  116. viewMedias(e) {
  117. const {
  118. index,
  119. type
  120. } = e.currentTarget.dataset;
  121. wx.previewMedia({
  122. current: index,
  123. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  124. })
  125. },
  126. /* 处理附件 */
  127. handleFiles(arr) {
  128. let files = {
  129. images: [],
  130. viewImages: [],
  131. videos: [],
  132. viewVideos: [],
  133. files: []
  134. },
  135. list = fileList(arr);
  136. list.forEach(v => {
  137. switch (v.fileType) {
  138. case "video":
  139. files.videos.push(v)
  140. files.viewVideos.push({
  141. url: v.url,
  142. type: "video",
  143. poster: v.subfiles[0].url
  144. })
  145. break;
  146. case "image":
  147. files.images.push(v)
  148. files.viewImages.push({
  149. url: v.url,
  150. type: "image"
  151. })
  152. break;
  153. default:
  154. files.files.push(v)
  155. break;
  156. }
  157. });
  158. this.setData({
  159. files
  160. })
  161. },
  162. /* 切换产品 */
  163. changeItemno(e) {
  164. const {
  165. value,
  166. valuename
  167. } = e.currentTarget.dataset,
  168. content = this.data.content;
  169. if (!value.flag) return;
  170. wx.showLoading({
  171. title: '加载中...',
  172. mask: true
  173. })
  174. // UniqueLine
  175. content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
  176. this.setData({
  177. selectCount: ['cheek', 'color', 'material', 'spec'].filter(v => content[v].length).length
  178. })
  179. this.getDetail(valuename == "spec")
  180. },
  181. /* 打开文档 */
  182. openDocument(e) {
  183. const {
  184. item
  185. } = e.currentTarget.dataset;
  186. console.log(item)
  187. wx.showLoading({
  188. title: '加载中...',
  189. mask: true,
  190. })
  191. wx.downloadFile({
  192. url: item.url,
  193. success: function (res) {
  194. const filePath = res.tempFilePath
  195. wx.openDocument({
  196. filePath: filePath,
  197. showMenu: true,
  198. fileType: item.postfix,
  199. success: function (res) {
  200. wx.hideLoading();
  201. console.log('打开文档成功')
  202. },
  203. fail(e) {
  204. console.log(e)
  205. wx.showToast({
  206. title: '打开失败',
  207. icon: "error",
  208. mask: true
  209. })
  210. }
  211. })
  212. },
  213. fail(e) {
  214. console.log(e)
  215. wx.showToast({
  216. title: '打开失败',
  217. icon: "error",
  218. mask: true
  219. })
  220. }
  221. })
  222. },
  223. clickBut(e) {
  224. if (this.data.itemCount != this.data.selectCount) return wx.showToast({
  225. title: '请完成产品选项在进行操作',
  226. icon: "none"
  227. })
  228. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  229. title: '请选择加入产品领域',
  230. icon: "none",
  231. duration: 3000
  232. }) : this[e.target.id](0);
  233. },
  234. /* 选择领域 */
  235. storage(e) {
  236. this.addToShoppingCart(e.detail.value)
  237. },
  238. /* 加入购物车 */
  239. addToShoppingCart(index) {
  240. let detail = this.data.detail,
  241. custom = {
  242. length: 0,
  243. width: 0
  244. };
  245. //是否为定制项
  246. if (detail.iscustomsize == 1) custom = this.selectComponent("#customMade").getResult(true);
  247. if (typeof custom == "boolean") return;
  248. let content = Object.assign(this.data.content, {
  249. sa_brandid,
  250. itemid: detail.itemid, //货品id
  251. qty: detail.qty, //数量
  252. itemno: detail.itemno, //货品编号
  253. tradefield: detail.tradefield[index].tradefield,
  254. }, custom);
  255. _Http.basic({
  256. "id": 20220924095102,
  257. content,
  258. }).then(res => {
  259. console.log("加入购物车", res)
  260. wx.showToast({
  261. title: res.msg == '成功' ? '加入成功' : res.msg,
  262. icon: "none"
  263. });
  264. if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
  265. badge
  266. }))
  267. })
  268. },
  269. /* 加入收藏夹 */
  270. addToFavorites() {
  271. let detail = this.data.detail,
  272. iscollection = detail.iscollection == 1 ? false : true,
  273. custom = {
  274. width: 0,
  275. length: 0,
  276. },
  277. favorites = {};
  278. //是否为定制项
  279. if (detail.iscustomsize == 1) custom = this.selectComponent("#customMade").getResult(true);
  280. for (const key in custom) {
  281. favorites['favorites' + key] = custom[key]
  282. }
  283. if (typeof custom == "boolean") return;
  284. _Http.basic({
  285. "id": 20231121143403,
  286. "content": {
  287. "itemid": this.data.detail.itemid, //货品id
  288. "qty": detail.qty, //数量
  289. ...custom,
  290. iscollection,
  291. ...favorites
  292. },
  293. }).then(res => {
  294. console.log(iscollection + "收藏夹", res)
  295. wx.showToast({
  296. title: res.msg == '成功' ? iscollection ? '收藏成功' : "已取消收藏" : res.msg,
  297. icon: "none"
  298. });
  299. if (res.msg == '成功') {
  300. getApp().globalData.getFavoriteCount().then(num => {
  301. this.setData({
  302. favoriteCount: num
  303. })
  304. })
  305. this.setData({
  306. "detail.iscollection": iscollection ? 1 : 0
  307. })
  308. }
  309. })
  310. },
  311. /* 立即下单 */
  312. placeAnOrder(index) {
  313. let detail = this.data.detail,
  314. content = {
  315. "type": "标准订单",
  316. tradefield: detail.tradefield[index].tradefield
  317. },
  318. custom = {
  319. length: 0,
  320. width: 0
  321. }
  322. //是否为定制项
  323. if (detail.iscustomsize == 1) custom = this.selectComponent("#customMade").getResult(true);
  324. console.log("custom", custom)
  325. if (typeof custom == "boolean") return;
  326. content.items = [Object.assign({
  327. sa_orderitemsid: 0,
  328. sa_brandid,
  329. itemid: detail.itemid, //货品id
  330. qty: detail.qty, //数量
  331. itemno: detail.itemno, //货品编号
  332. }, custom)];
  333. _Http.basic({
  334. "id": 20221128183202,
  335. content,
  336. }).then(res => {
  337. console.log("创建订单", res)
  338. wx.showModal({
  339. title: '提示',
  340. content: res.msg == '成功' ? '订单创建成功!是否立即查看' : res.msg,
  341. showCancel: res.msg == '成功',
  342. complete: ({
  343. confirm
  344. }) => {
  345. if (res.msg == '成功' && confirm) wx.navigateTo({
  346. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  347. })
  348. }
  349. })
  350. })
  351. },
  352. /* 前往购物车 */
  353. toCollect(e) {
  354. getApp().globalData.changeBar({
  355. detail: "Collect"
  356. })
  357. wx.navigateBack();
  358. },
  359. onShow() {
  360. this.setData({
  361. favoriteCount: getApp().globalData.favoriteCount,
  362. badge: getApp().globalData.collectCount,
  363. })
  364. this.getDetail(true, this.data.loading);
  365. },
  366. /* 步进器输入框失去焦点 */
  367. inputBlur(e) {
  368. let item = this.data.detail;
  369. let qty = 0;
  370. if (item.orderminqty > e.detail.value) {
  371. wx.showToast({
  372. title: '输入数量低于最低起订量!',
  373. icon: "none"
  374. })
  375. qty = item.orderminqty;
  376. } else if (item.orderminqty < e.detail.value) {
  377. var currencyRounding = value => currency(value, {
  378. increment: item.orderaddqty
  379. });
  380. qty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
  381. } else {
  382. qty = e.detail.value;
  383. }
  384. this.setData({
  385. "detail.qty": 0
  386. });
  387. this.setData({
  388. "detail.qty": qty
  389. });
  390. },
  391. stepperChange(e) {
  392. let item = this.data.detail;
  393. if (e.type == 'plus') {
  394. item.qty += (item.orderaddqty) - 0 || 1
  395. } else {
  396. item.qty -= item.orderaddqty || 1
  397. }
  398. this.setData({
  399. detail: item
  400. })
  401. },
  402. })