change.js 6.3 KB

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