change.js 6.5 KB

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