index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. const _Http = getApp().globalData.http,
  2. file = require("../../utils/FormatTheAttachment");
  3. import currency from "../../utils/currency";
  4. import {
  5. getCustomText
  6. } from "../../utils/customItemType";
  7. Page({
  8. data: {
  9. loading: true,
  10. params: {}, //请求体
  11. result: [], //返回结果
  12. radio: false, //是否为单选
  13. idname: "itemid", //idkey
  14. showName: "itemname",
  15. privacyFieldC: [],
  16. cardno: null
  17. },
  18. onLoad(options) {
  19. if (options.params) {
  20. let params = JSON.parse(options.params);
  21. if (!params.content.pageNumber || !params.content.pageTotal) {
  22. params.content.pageNumber = 1;
  23. params.content.pageTotal = 1;
  24. }
  25. this.setData({
  26. params,
  27. copyParams: JSON.parse(JSON.stringify(params))
  28. });
  29. };
  30. if (_Http.cardno) {
  31. let cardno = _Http.cardno;
  32. this.setData({
  33. params: {
  34. "id": 2025080511204503,
  35. "content": {
  36. "itemid": cardno.itemid,
  37. "sa_orderid": _Http.sa_orderid,
  38. pageNumber: 1,
  39. pageTotal: 1,
  40. pageSize: 20,
  41. },
  42. },
  43. cardno
  44. })
  45. }
  46. this.setData({
  47. radio: options.radio ? true : false,
  48. idname: options.idname || this.data.idname,
  49. showName: options.showName || this.data.showName,
  50. newPrice: options.newprice || "price", //红色价格
  51. });
  52. try {
  53. let privacyFieldC = wx.getStorageSync('auth').worderform.forms.add.formcols.map(v => v.title);
  54. this.setData({
  55. privacyFieldC
  56. })
  57. console.log("privacyFieldC", privacyFieldC)
  58. } catch (error) {
  59. console.error(error)
  60. }
  61. this.getList();
  62. },
  63. getList(init = false) {
  64. //init 用于初始化分页
  65. if (init.detail != undefined) init = init.detail;
  66. let params = this.data.params;
  67. if (init) params.content.pageNumber = 1
  68. if (params.content.pageNumber > params.content.pageTotal) return;
  69. _Http.basic(params).then(res => {
  70. console.log("选择产品列表", res)
  71. this.selectComponent('#ListBox').RefreshToComplete();
  72. if (res.msg != '成功') return wx.showToast({
  73. title: res.msg,
  74. icon: "none"
  75. })
  76. if (res.pageNumber == 1 && res.data.length == 0 && params.id == '2025080511204503') {
  77. this.setData({
  78. params: this.data.copyParams
  79. })
  80. this.getList(true)
  81. return;
  82. }
  83. const CNY = num => currency(num, {
  84. symbol: "¥",
  85. precision: 2
  86. }).format();
  87. let newPrice = this.data.newPrice;
  88. res.data = res.data.map(value => {
  89. if (value.cover) {
  90. value.cover = _Http.getImageUrl(value.cover)
  91. } else {
  92. if (value.attinfos.length != 0) {
  93. value.attinfos = file.fileList(value.attinfos)
  94. let image = value.attinfos.find(v => v.fileType == "image");
  95. value.cover = image ? _Http.getSpecifiedImage(image) : "";
  96. }
  97. }
  98. if (newPrice) value.newPrice = CNY(value[newPrice] || 0);
  99. value.brandName = value.brand.map(name => name.brandname)
  100. value.tradefields = value.tradefield.map(name => name.tradefield)
  101. value.qty = value.orderminqty || 1;
  102. value.width = 0;
  103. value.length = 0;
  104. if (value.iscustomsize) value.customText = getCustomText(value);
  105. return value;
  106. })
  107. this.setData({
  108. 'params.content.pageNumber': res.pageNumber + 1,
  109. 'params.content.pageTotal': res.pageTotal,
  110. 'params.content.total': res.total,
  111. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  112. loading: false
  113. })
  114. })
  115. },
  116. customization(e) {
  117. let {
  118. item
  119. } = e.target.dataset;
  120. item.pitchOn = false;
  121. this.bindChangeFun()
  122. if (item) this.selectComponent("#Custom").onClick(item)
  123. },
  124. bindChangeFun() {
  125. getApp().globalData.customizedProduct = (item, custom) => {
  126. return new Promise((resolve) => {
  127. item = Object.assign(item, custom)
  128. item.customText = getCustomText(item);
  129. let index = this.data.list.findIndex(v => v[this.data.idname] == item[this.data.idname]);
  130. if (index != -1) this.data.list[index] = item;
  131. if (item.pitchOn) this.data.result.push(item[this.data.idname])
  132. this.setData({
  133. list: this.data.list,
  134. result: this.data.result
  135. })
  136. resolve(true)
  137. })
  138. }
  139. },
  140. /* 选中 */
  141. changeResult(e) {
  142. let {
  143. id,
  144. item
  145. } = e.currentTarget.dataset, result = this.data.result;
  146. if (this.data.radio) {
  147. result = [id];
  148. } else {
  149. let isAdd = result.some(v => v == id);
  150. if (!isAdd) {
  151. if (item.iscustomsize == 1) {
  152. if ((item.widthschemeid && item.width == 0) || (item.lengthschemeid && item.length == 0)) {
  153. item.pitchOn = true;
  154. this.bindChangeFun()
  155. if (item) this.selectComponent("#Custom").onClick(item)
  156. } else {
  157. result.push(id)
  158. }
  159. } else {
  160. result.push(id)
  161. }
  162. } else {
  163. result = result.filter(v => v != id)
  164. }
  165. }
  166. this.setData({
  167. result
  168. });
  169. if (this.data.radio) this.submit();
  170. },
  171. /* 提交 */
  172. submit() {
  173. let result = this.data.result,
  174. obj = this.data.radio ? {
  175. id: result,
  176. item: this.data.list.find(value => value[this.data.idname] == result),
  177. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  178. } : {
  179. result,
  180. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  181. value: [result.map(v => {
  182. let data = this.data.list.find(value => value[this.data.idname] == v);
  183. return data ? data[this.data.showName] : ""
  184. }), result]
  185. }
  186. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  187. },
  188. /* 预览图片 */
  189. viewImage(e) {
  190. const {
  191. file
  192. } = e.currentTarget.dataset;
  193. if (file.length) wx.previewMedia({
  194. sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
  195. return {
  196. url: v.url,
  197. type: v.fileType
  198. }
  199. }),
  200. current: 0,
  201. showmenu: true
  202. })
  203. },
  204. /* 开始搜索 */
  205. startSearch({
  206. detail
  207. }) {
  208. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  209. if (detail == condition) return;
  210. this.setData({
  211. 'content.where.condition': detail,
  212. 'params.content.where.condition': detail
  213. });
  214. this.getList(true);
  215. },
  216. /* 取消搜索 */
  217. onClear() {
  218. this.setData({
  219. 'content.where.condition': "",
  220. 'params.content.where.condition': ""
  221. });
  222. this.getList(true);
  223. },
  224. onReady() {
  225. this.selectComponent("#ListBox").setHeight(".total", this);
  226. },
  227. /* 步进器输入框失去焦点 */
  228. inputBlur(e) {
  229. const {
  230. index
  231. } = e.currentTarget.dataset;
  232. let item = this.data.list[index];
  233. let qty = 0;
  234. if (item.orderminqty > e.detail.value) {
  235. wx.showToast({
  236. title: '输入数量低于最低起订量!',
  237. icon: "none"
  238. })
  239. qty = item.orderminqty;
  240. } else if (item.orderminqty < e.detail.value) {
  241. var currencyRounding = value => currency(value, {
  242. increment: item.orderaddqty
  243. });
  244. qty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
  245. } else {
  246. qty = e.detail.value;
  247. }
  248. this.setData({
  249. [`list[${index}].qty`]: 0
  250. });
  251. this.setData({
  252. [`list[${index}].qty`]: qty
  253. });
  254. },
  255. stepperChange(e) {
  256. const {
  257. index
  258. } = e.currentTarget.dataset;
  259. let item = this.data.list[index];
  260. if (e.type == 'plus') {
  261. item.qty += (item.orderaddqty) - 0
  262. } else {
  263. item.qty -= item.orderaddqty
  264. }
  265. this.setData({
  266. [`list[${index}]`]: item
  267. })
  268. },
  269. onUnload() {
  270. getApp().globalData.handleSelect = null;
  271. }
  272. })