index.js 6.7 KB

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