detail.js 8.9 KB

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