detail.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.reverse(),
  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. date: Date.now() + 1
  85. }
  86. }, {
  87. "id": "20230707091603",
  88. "version": 1,
  89. "content": {
  90. "sa_sizecustomizedschemeid": item.widthschemeid,
  91. date: Date.now() + 2
  92. }
  93. }].map(v => _Http.basic(v))).then(s => {
  94. if (s.some(c => c.msg != '成功')) return wx.showToast({
  95. title: '定制方案获取失败',
  96. icon: "none"
  97. })
  98. if (item.lengthschemeid) cLength = s[0].data;
  99. if (item.widthschemeid) cWidth = s[1].data;
  100. this.setData({
  101. cWidth,
  102. cLength,
  103. "content.dwidth": cWidth.min || 0,
  104. "content.dlength": cLength.min || 0,
  105. });
  106. })
  107. } else {
  108. this.setData({
  109. cWidth: null,
  110. cLength: null,
  111. "content.dwidth": 0,
  112. "content.dlength": 0,
  113. });
  114. }
  115. }
  116. })
  117. },
  118. /* 预览媒体 */
  119. viewMedias(e) {
  120. const {
  121. index,
  122. type
  123. } = e.currentTarget.dataset;
  124. wx.previewMedia({
  125. current: index,
  126. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  127. })
  128. },
  129. /* 处理附件 */
  130. handleFiles(arr) {
  131. let files = {
  132. images: [],
  133. viewImages: [],
  134. videos: [],
  135. viewVideos: [],
  136. files: []
  137. },
  138. list = fileList(arr);
  139. list.forEach(v => {
  140. switch (v.fileType) {
  141. case "video":
  142. files.videos.push(v)
  143. files.viewVideos.push({
  144. url: v.url,
  145. type: "video",
  146. poster: v.subfiles[0].url
  147. })
  148. break;
  149. case "image":
  150. files.images.push(v)
  151. files.viewImages.push({
  152. url: v.url,
  153. type: "image"
  154. })
  155. break;
  156. default:
  157. files.files.push(v)
  158. break;
  159. }
  160. });
  161. this.setData({
  162. files
  163. })
  164. },
  165. /* 切换产品 */
  166. changeItemno(e) {
  167. const {
  168. value,
  169. valuename
  170. } = e.currentTarget.dataset,
  171. content = this.data.content;
  172. if (!value.flag) return;
  173. wx.showLoading({
  174. title: '加载中...',
  175. mask: true
  176. })
  177. content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
  178. this.getDetail(valuename == "spec")
  179. },
  180. /* 定制选项 */
  181. customParameter(e) {
  182. let {
  183. value,
  184. valuename
  185. } = e.currentTarget.dataset;
  186. this.data.content[valuename] = value;
  187. this.setData({
  188. content: this.data.content
  189. })
  190. },
  191. /* 定制步进器 */
  192. cahngeStepper(e) {
  193. const name = e.currentTarget.dataset.name,
  194. name2 = name == 'cWidth' ? "dwidth" : "dlength",
  195. content = this.data.content;
  196. if (e.type == 'plus') {
  197. content[name2] += 1
  198. } else if (e.type == 'minus') {
  199. content[name2] -= 1
  200. } else {
  201. const data = this.data[name];
  202. content[name2] = (e.detail.value - 0).toFixed(data.decimalplaces);
  203. }
  204. let item = this.data[name];
  205. if (content[name2] > item.max) content[name2] = item.max;
  206. if (content[name2] < item.min) content[name2] = item.min;
  207. this.setData({
  208. content
  209. })
  210. },
  211. clickBut() {
  212. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  213. title: '请选择加入产品领域',
  214. icon: "none",
  215. duration: 3000
  216. }) : this.handleStorage(0);
  217. },
  218. /* 打开文档 */
  219. openDocument(e) {
  220. const {
  221. item
  222. } = e.currentTarget.dataset;
  223. console.log(item)
  224. wx.showLoading({
  225. title: '加载中...',
  226. mask: true,
  227. })
  228. wx.downloadFile({
  229. url: item.url,
  230. success: function (res) {
  231. const filePath = res.tempFilePath
  232. wx.openDocument({
  233. filePath: filePath,
  234. showMenu: true,
  235. fileType: item.postfix,
  236. success: function (res) {
  237. wx.hideLoading();
  238. console.log('打开文档成功')
  239. },
  240. fail(e) {
  241. console.log(e)
  242. wx.showToast({
  243. title: '打开失败',
  244. icon: "error",
  245. mask: true
  246. })
  247. }
  248. })
  249. },
  250. fail(e) {
  251. console.log(e)
  252. wx.showToast({
  253. title: '打开失败',
  254. icon: "error",
  255. mask: true
  256. })
  257. }
  258. })
  259. },
  260. /* 选择领域 */
  261. storage(e) {
  262. this.handleStorage(e.detail.value)
  263. },
  264. handleStorage(index) {
  265. let detail = this.data.detail,
  266. content = this.data.content;
  267. if (detail.iscustomsize == 1) {
  268. if (detail.widthschemeid != 0 && content.dwidth == 0) return wx.showToast({
  269. title: '请完成定制宽选项',
  270. icon: "none"
  271. })
  272. if (detail.lengthschemeid != 0 && content.dlength == 0) return wx.showToast({
  273. title: '请完成定制长选项',
  274. icon: "none"
  275. })
  276. }
  277. _Http.basic({
  278. "id": 20220924095102,
  279. "content": {
  280. sa_brandid,
  281. "itemid": detail.itemid, //货品id
  282. "qty": detail.orderminqty, //数量
  283. itemno: detail.itemno, //货品编号
  284. tradefield: detail.tradefield[index].tradefield,
  285. width: content.dwidth,
  286. length: content.dlength
  287. },
  288. }).then(res => {
  289. console.log("加入购物车", res)
  290. wx.showToast({
  291. title: res.msg == '成功' ? '加入成功' : res.msg,
  292. icon: "none"
  293. });
  294. if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
  295. badge
  296. }))
  297. })
  298. },
  299. /* 前往购物车 */
  300. toCollect(e) {
  301. getApp().globalData.changeBar({
  302. detail: "Collect"
  303. })
  304. wx.navigateBack();
  305. }
  306. })