detail.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. const _Http = getApp().globalData.http;
  2. let sa_brandid = null,
  3. sys_enterpriseid = null;
  4. import {
  5. fileList
  6. } from "../../utils/FormatTheAttachment";
  7. import currency from "../../utils/currency";
  8. Page({
  9. data: {
  10. hidePrice: wx.getStorageSync('hidePrice'),
  11. badge: getApp().globalData.collectCount,
  12. loading: true,
  13. content: {
  14. sa_itemgroupid: null,
  15. spec: "", //规格
  16. color: "", //颜色
  17. material: "", //材质
  18. cheek: "", //边框
  19. dwidth: 0,
  20. dlength: 0,
  21. },
  22. detail: {
  23. spec: ""
  24. },
  25. cWidth: null, //宽定制方案
  26. cLength: null, //长定制方案
  27. },
  28. onLoad(options) {
  29. let data = JSON.parse(options.params);
  30. sa_brandid = data.sa_brandid;
  31. if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = data.sys_enterpriseid
  32. this.data.content.sa_itemgroupid = data.sa_itemgroupid;
  33. this.setData({
  34. userrole: wx.getStorageSync('userrole')
  35. })
  36. this.getDetail(true);
  37. },
  38. /* 获取详情 */
  39. getDetail(init = false) {
  40. let content = this.data.content;
  41. if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
  42. _Http.basic({
  43. "id": "20221223165503",
  44. content
  45. }).then(res => {
  46. wx.hideLoading();
  47. console.log("商品详情", res)
  48. if (res.msg != '成功') return wx.showToast({
  49. title: res.msg,
  50. icon: "none"
  51. })
  52. if (res.data.item.length == 0) return wx.showToast({
  53. title: '未查询到商品',
  54. icon: "none",
  55. mask: true
  56. })
  57. const item = res.data.item[0];
  58. this.handleFiles(item.attinfos)
  59. const CNY = sum => currency(sum, {
  60. symbol: "¥",
  61. precision: 2
  62. }).format();
  63. item.gradeprice = CNY(item.gradeprice);
  64. item.marketprice = CNY(item.marketprice);
  65. this.setData({
  66. content,
  67. detail: item,
  68. specRows: res.data.specRows,
  69. cheekRows: res.data.cheekRows,
  70. materialRows: res.data.materialRows,
  71. colorRows: res.data.colorRows,
  72. loading: false
  73. });
  74. //是否定制
  75. if (init) {
  76. if (item.iscustomsize == 1) {
  77. let cWidth = null,
  78. cLength = null;
  79. Promise.all([{
  80. "id": "20230707091603",
  81. "version": 1,
  82. "content": {
  83. "sa_sizecustomizedschemeid": item.lengthschemeid
  84. }
  85. }, {
  86. "id": "20230707091603",
  87. "version": 1,
  88. "content": {
  89. "sa_sizecustomizedschemeid": item.widthschemeid
  90. }
  91. }].map(v => _Http.basic(v))).then(s => {
  92. if (s.some(c => c.msg != '成功')) return wx.showToast({
  93. title: '定制方案获取失败',
  94. icon: "none"
  95. })
  96. if (item.lengthschemeid) cLength = s[0].data;
  97. if (item.widthschemeid) cWidth = s[1].data;
  98. this.setData({
  99. cWidth,
  100. cLength,
  101. "content.dwidth": cWidth.min || 0,
  102. "content.dlength": cLength.min || 0,
  103. });
  104. })
  105. } else {
  106. this.setData({
  107. cWidth: null,
  108. cLength: null,
  109. "content.dwidth": 0,
  110. "content.dlength": 0,
  111. });
  112. }
  113. }
  114. })
  115. },
  116. /* 预览媒体 */
  117. viewMedias(e) {
  118. const {
  119. index,
  120. type
  121. } = e.currentTarget.dataset;
  122. wx.previewMedia({
  123. current: index,
  124. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  125. })
  126. },
  127. /* 处理附件 */
  128. handleFiles(arr) {
  129. let files = {
  130. images: [],
  131. viewImages: [],
  132. videos: [],
  133. viewVideos: [],
  134. files: []
  135. },
  136. list = fileList(arr);
  137. list.forEach(v => {
  138. switch (v.fileType) {
  139. case "video":
  140. files.videos.push(v)
  141. files.viewVideos.push({
  142. url: v.url,
  143. type: "video",
  144. poster: v.subfiles[0].url
  145. })
  146. break;
  147. case "image":
  148. files.images.push(v)
  149. files.viewImages.push({
  150. url: v.url,
  151. type: "image"
  152. })
  153. break;
  154. default:
  155. files.files.push(v)
  156. break;
  157. }
  158. });
  159. this.setData({
  160. files
  161. })
  162. },
  163. /* 切换产品 */
  164. changeItemno(e) {
  165. const {
  166. value,
  167. valuename
  168. } = e.currentTarget.dataset,
  169. content = this.data.content;
  170. if (!value.flag) return;
  171. wx.showLoading({
  172. title: '加载中...',
  173. mask: true
  174. })
  175. content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
  176. this.getDetail(valuename == "spec")
  177. },
  178. /* 定制选项 */
  179. customParameter(e) {
  180. let {
  181. value,
  182. valuename
  183. } = e.currentTarget.dataset;
  184. this.data.content[valuename] = value;
  185. this.setData({
  186. content: this.data.content
  187. })
  188. },
  189. /* 定制步进器 */
  190. cahngeStepper(e) {
  191. const name = e.currentTarget.dataset.name,
  192. name2 = name == 'cWidth' ? "dwidth" : "dlength",
  193. content = this.data.content;
  194. if (e.type == 'plus') {
  195. content[name2] += 1
  196. } else if (e.type == 'minus') {
  197. content[name2] -= 1
  198. } else {
  199. const data = this.data[name];
  200. content[name2] = (e.detail.value - 0).toFixed(data.decimalplaces);
  201. }
  202. let item = this.data[name];
  203. if (content[name2] > item.max) content[name2] = item.max;
  204. if (content[name2] < item.min) content[name2] = item.min;
  205. this.setData({
  206. content
  207. })
  208. },
  209. clickBut() {
  210. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  211. title: '请选择加入产品领域',
  212. icon: "none",
  213. duration: 3000
  214. }) : this.handleStorage(0);
  215. },
  216. /* 打开文档 */
  217. openDocument(e) {
  218. const {
  219. item
  220. } = e.currentTarget.dataset;
  221. console.log(item)
  222. wx.showLoading({
  223. title: '加载中...',
  224. mask: true,
  225. })
  226. wx.downloadFile({
  227. url: item.url,
  228. success: function (res) {
  229. const filePath = res.tempFilePath
  230. wx.openDocument({
  231. filePath: filePath,
  232. showMenu: true,
  233. fileType: item.postfix,
  234. success: function (res) {
  235. wx.hideLoading();
  236. console.log('打开文档成功')
  237. },
  238. fail(e) {
  239. console.log(e)
  240. wx.showToast({
  241. title: '打开失败',
  242. icon: "error",
  243. mask: true
  244. })
  245. }
  246. })
  247. },
  248. fail(e) {
  249. console.log(e)
  250. wx.showToast({
  251. title: '打开失败',
  252. icon: "error",
  253. mask: true
  254. })
  255. }
  256. })
  257. },
  258. /* 选择领域 */
  259. storage(e) {
  260. this.handleStorage(e.detail.value)
  261. },
  262. handleStorage(index) {
  263. let detail = this.data.detail,
  264. content = this.data.content;
  265. if (detail.iscustomsize == 1) {
  266. if (detail.widthschemeid != 0 && content.dwidth == 0) return wx.showToast({
  267. title: '请完成定制宽选项',
  268. icon: "none"
  269. })
  270. if (detail.lengthschemeid != 0 && content.dlength == 0) return wx.showToast({
  271. title: '请完成定制长选项',
  272. icon: "none"
  273. })
  274. }
  275. _Http.basic({
  276. "id": 20220924095102,
  277. "content": {
  278. sa_brandid,
  279. "itemid": detail.itemid, //货品id
  280. "qty": detail.orderminqty, //数量
  281. itemno: detail.itemno, //货品编号
  282. tradefield: detail.tradefield[index].tradefield,
  283. width: content.dwidth,
  284. length: content.dlength
  285. },
  286. }).then(res => {
  287. console.log("加入购物车", res)
  288. wx.showToast({
  289. title: res.msg == '成功' ? '加入成功' : res.msg,
  290. icon: "none"
  291. });
  292. if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
  293. badge
  294. }))
  295. })
  296. },
  297. /* 前往购物车 */
  298. toCollect(e) {
  299. getApp().globalData.changeBar({
  300. detail: "Collect"
  301. })
  302. wx.navigateBack();
  303. }
  304. })