detail.js 9.1 KB

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