change.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify";
  8. const _Verify = new TestVerify();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. fprodname: "", //产品名称
  15. fprodnum: "", //产品编码
  16. attinfos: [], //附件列表
  17. fintroduction: "", //产品说明
  18. //ftag: [],产品标签
  19. showSaleprod: "", //标签显示
  20. tagents_productid: 0, //识别产品ID
  21. checked: true, //开关控件
  22. fisonsale: 1, //是否上架
  23. throttle: false, //保存节流阀
  24. errTips: {
  25. fprodname: false,
  26. fprodnum: false,
  27. showSaleprod: false,
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. if (options.data) {
  35. const data = JSON.parse(options.data)
  36. console.log(data)
  37. let attinfos = [];
  38. for (let i = 0; i < data.attinfos.length; i++) {
  39. let arr = {
  40. url: data.attinfos[i].fobsurl,
  41. ownerid: data.attinfos[i].ownerid,
  42. tattachmentid: data.attinfos[i].tattachmentid,
  43. ownertable: data.attinfos[i].ownertable,
  44. fdocument: data.attinfos[i].fdocument
  45. }
  46. attinfos.push(arr)
  47. };
  48. /* 是否上架 */
  49. const checked = (data.fisonsale == 1) ? true : false
  50. let showSaleprod = "";
  51. /* 空标签转换为数组格式
  52. ftag = data.ftag
  53. if (data.ftag == null || data.ftag == '') {
  54. ftag = []
  55. } else {
  56. //字符串数组转换数组
  57. for (var i = 0; i < ftag.length; i++) {
  58. showSaleprod += ftag[i] + ' ';
  59. }
  60. }*/
  61. /* 渲染数据 */
  62. this.setData({
  63. fprodname: data.fprodname, //产品名称
  64. fprodnum: data.fprodnum, //产品编码
  65. attinfos, //附件列表
  66. fintroduction: data.fintroduction, //产品说明
  67. fisonsale: data.fisonsale, //是否上架
  68. //ftag: ftag, 产品标签
  69. tagents_productid: data.tagents_productid, //识别产品ID
  70. showSaleprod, // 显示标签
  71. checked, //是否上架
  72. });
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady: function () {
  79. },
  80. /* 添加图片 */
  81. imageChange(data) {
  82. this.setData({
  83. attinfos: data.detail.fileList
  84. })
  85. },
  86. /* 上架开关 */
  87. switchChange() {
  88. const that = this;
  89. wx.showModal({
  90. title: "提示",
  91. content: (this.data.checked) ? '是否确认下架该产品' : '是否确认上架该产品',
  92. success(res) {
  93. if (res.confirm) {
  94. const checked = !that.data.checked,
  95. fisonsale = (checked) ? 1 : 0;
  96. that.setData({
  97. checked,
  98. fisonsale
  99. });
  100. }
  101. }
  102. })
  103. },
  104. /* 表单验证 */
  105. formVerify() {
  106. let errTips = this.data.errTips,
  107. verify = true;
  108. /* 验证产品名称 */
  109. if (!_Verify.required(this.data.fprodname)) {
  110. errTips.fprodname = true;
  111. verify = false;
  112. }
  113. /* 验证产品编码 */
  114. if (!_Verify.required(this.data.fprodnum)) {
  115. errTips.fprodnum = true;
  116. verify = false;
  117. }
  118. /* 验证附件列表 */
  119. if (!_Verify.required(this.data.attinfos, "请上传产品图片")) {
  120. errTips.fprodnum = true;
  121. }
  122. this.setData({
  123. errTips
  124. })
  125. return verify;
  126. },
  127. /* 提交 */
  128. submit() {
  129. if (!this.formVerify() || this.data.throttle) return;
  130. //请求参数
  131. _Http.basic({
  132. "accesstoken": wx.getStorageSync('userData').token,
  133. "classname": "customer.products.products",
  134. "method": "insertOrModifyProducts",
  135. "content": {
  136. "tagents_productid": this.data.tagents_productid,
  137. "fprodnum": this.data.fprodnum,
  138. "fprodname": this.data.fprodname,
  139. "fintroduction": this.data.fintroduction,
  140. "fisonsale": this.data.fisonsale
  141. }
  142. }).then(res => {
  143. console.log(res)
  144. if (res.msg != "成功") return wx.showToast({
  145. title: res.data,
  146. icon: "none"
  147. });
  148. this.setData({
  149. throttle: true //设置节流阀
  150. });
  151. let content = {
  152. ownerid: res.data[0].tagents_productid,
  153. ownertable: "tagents_product",
  154. tattachmentid: 0
  155. };
  156. this.selectComponent("#UploadFiles").saveTheChanges(content);
  157. wx.showToast({
  158. title: '保存成功',
  159. })
  160. setTimeout(() => {
  161. wx.navigateBack({
  162. delta: 1,
  163. })
  164. }, 500)
  165. })
  166. },
  167. /* 获取焦点 */
  168. inputFocus(e) {
  169. const {
  170. name
  171. } = e.currentTarget.dataset;
  172. let errTips = this.data.errTips;
  173. errTips[name] = false;
  174. /* 经营类目提示框 */
  175. if (name == 'showSaleprod') {
  176. errTips[name] = true;
  177. }
  178. this.setData({
  179. errTips
  180. })
  181. },
  182. /* 失去焦点 */
  183. inputBlur(e) {
  184. const {
  185. name
  186. } = e.currentTarget.dataset;
  187. const {
  188. value
  189. } = e.detail;
  190. let errTips = this.data.errTips;
  191. if (value.trim() == "") errTips[name] = true;
  192. /* 经营类目提示框,字符串转化数组 */
  193. if (name == 'showSaleprod') {
  194. errTips[name] = false;
  195. const ftag = this.data.showSaleprod.split(" ");
  196. this.setData({
  197. ftag
  198. })
  199. };
  200. this.setData({
  201. errTips
  202. })
  203. },
  204. /**
  205. * 生命周期函数--监听页面显示
  206. */
  207. onShow: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面隐藏
  211. */
  212. onHide: function () {
  213. },
  214. /**
  215. * 生命周期函数--监听页面卸载
  216. */
  217. onUnload: function () {},
  218. /**
  219. * 页面相关事件处理函数--监听用户下拉动作
  220. */
  221. onPullDownRefresh: function () {
  222. },
  223. /**
  224. * 页面上拉触底事件的处理函数
  225. */
  226. onReachBottom: function () {
  227. },
  228. /**
  229. * 用户点击右上角分享
  230. */
  231. onShareAppMessage: function () {
  232. }
  233. })