detail.js 5.5 KB

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