index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. fisadministrator: (wx.getStorageSync('userData').fisadministrator == 1) ? true : false, //是否主账号
  15. butText: "保存", //按钮文字
  16. disabled: false, //禁用
  17. popups: false, //弹出层控制
  18. /* */
  19. fbrand: "", //品牌名称
  20. attinfos: [], // 图片列表
  21. isLogo: [], //用于判断是否上传logo
  22. saleprodclass: [], //经营类目
  23. showSaleprodclass: "", //显示经营类目
  24. fcontact: "", //联系人
  25. fphonenumber: "", //联系方式
  26. fagentname: "", //商户名称
  27. fintroduction: "", //商户介绍
  28. faddress: "", //地址
  29. fdutyparagraph: "", //统一社会代码
  30. requestType: "普通修改", //请求类型
  31. /* */
  32. errTips: {
  33. fbrand: false,
  34. attinfos: false,
  35. saleprodclass: false,
  36. fcontact: false,
  37. fphonenumber: false,
  38. fagentname: false,
  39. fintroduction: false,
  40. faddress: false,
  41. }
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. _Http.basic({
  48. "accesstoken": wx.getStorageSync('userData').token,
  49. "classname": "customer.tagents.tagents",
  50. "method": "query_enterpriseAgentsMain",
  51. "content": {}
  52. }).then(res => {
  53. console.log(res)
  54. const data = res.data[0];
  55. let butText = '保存',
  56. disabled = false;
  57. if (data.ftype == '个人' && data.fisauthenticating == 1) {
  58. wx.showToast({
  59. title: '商户信息审核中',
  60. icon: "none",
  61. duration: 5000,
  62. })
  63. butText = "审核中";
  64. disabled = true;
  65. this.returnData(data)
  66. } else if (data.ftype == '个人' && data.fisauthenticating == 0) {
  67. butText = "立即认证";
  68. this.setData({
  69. requestType: "商户认证"
  70. })
  71. } else {
  72. this.returnData(data)
  73. };
  74. this.setData({
  75. butText,
  76. disabled
  77. })
  78. })
  79. },
  80. /* 选择类目回调 */
  81. saleprodChange(arr) {
  82. let {
  83. detail
  84. } = arr, showSaleprodclass = "";
  85. console.log(arr)
  86. for (let i = 0; i < detail.length; i++) {
  87. showSaleprodclass += (detail[i] + ',');
  88. };
  89. this.setData({
  90. popups: false,
  91. saleprodclass: detail,
  92. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1)
  93. })
  94. },
  95. /* 返回数据 */
  96. returnData(data) {
  97. console.log(data)
  98. let imageData = [];
  99. if (data.attinfos.length >= 1) {
  100. imageData = [{
  101. url: data.attinfos[0].fobsurl,
  102. ownerid: data.attinfos[0].ownerid,
  103. tattachmentid: data.attinfos[0].tattachmentid
  104. }];
  105. }
  106. this.saleprodChange({
  107. detali: data.saleprodclass
  108. })
  109. this.setData({
  110. fbrand: data.fbrand,
  111. saleprodclass: data.saleprodclass,
  112. fcontact: data.fcontact,
  113. fphonenumber: data.fphonenumber,
  114. fintroduction: data.fintroduction,
  115. fagentname: data.fagentname,
  116. faddress: data.faddress,
  117. fdutyparagraph: data.fdutyparagraph,
  118. attinfos: imageData,
  119. isLogo: imageData
  120. })
  121. },
  122. /* 提交数据 */
  123. submit() {
  124. if (!this.formVerify()) return wx.showToast({
  125. title: '请检查表单内容',
  126. icon: "error"
  127. });
  128. /* 验证附件列表 */
  129. if (!_Verify.required(this.data.isLogo, "请上传品牌logo")) return;
  130. /* 发送请求 */
  131. _Http.basic({
  132. "accesstoken": wx.getStorageSync('userData').token,
  133. "classname": "customer.tagents.tagents",
  134. "method": "modify_enterpriseAgent",
  135. "content": {
  136. "ftype": this.data.requestType,
  137. "data": [{
  138. "fbrand": this.data.fbrand,
  139. "saleprodclass": this.data.saleprodclass,
  140. "fcontact": this.data.fcontact,
  141. "fphonenumber": this.data.fphonenumber,
  142. "fagentname": this.data.fagentname,
  143. "fintroduction": this.data.fintroduction,
  144. "faddress": this.data.faddress,
  145. "fdutyparagraph": this.data.fdutyparagraph,
  146. }]
  147. }
  148. }).then(res => {
  149. if (res.data == '成功') {
  150. wx.showToast({
  151. title: '提交成功',
  152. });
  153. wx.navigateBack({
  154. delta: 1,
  155. })
  156. }
  157. })
  158. },
  159. /* 表单验证 */
  160. formVerify() {
  161. let errTips = this.data.errTips,
  162. verify = true;
  163. /* 验证品牌名 */
  164. if (!_Verify.required(this.data.fbrand)) {
  165. errTips.fbrand = true;
  166. verify = false;
  167. }
  168. /* 验证经营类目 */
  169. if (!_Verify.required(this.data.saleprodclass)) {
  170. errTips.saleprodclass = true;
  171. verify = false;
  172. }
  173. /* 验证联系人 */
  174. if (!_Verify.required(this.data.fcontact)) {
  175. errTips.fcontact = true;
  176. verify = false;
  177. }
  178. /* 验证联系方式 */
  179. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  180. errTips.fphonenumber = true;
  181. verify = false;
  182. }
  183. /* 验证商户名称 */
  184. if (!_Verify.required(this.data.fagentname)) {
  185. errTips.fagentname = true;
  186. verify = false;
  187. }
  188. /* 验证商户介绍 */
  189. if (!_Verify.required(this.data.fintroduction)) {
  190. errTips.fintroduction = true;
  191. verify = false;
  192. }
  193. /* 验证地址 */
  194. if (!_Verify.required(this.data.faddress)) {
  195. errTips.faddress = true;
  196. verify = false;
  197. }
  198. this.setData({
  199. errTips
  200. })
  201. return verify;
  202. },
  203. /* 弹出层 */
  204. showPop() {
  205. this.setData({
  206. popups: !this.data.popups
  207. })
  208. },
  209. /* 获取焦点 */
  210. inputFocus(e) {
  211. const {
  212. name
  213. } = e.currentTarget.dataset;
  214. let errTips = this.data.errTips;
  215. errTips[name] = false;
  216. this.setData({
  217. errTips
  218. })
  219. },
  220. /* 失去焦点 */
  221. inputBlur(e) {
  222. const {
  223. name
  224. } = e.currentTarget.dataset;
  225. const {
  226. value
  227. } = e.detail;
  228. /* 联系方式验证 */
  229. if (name == 'fphonenumber') {
  230. _Verify.phoneNumber(this.data.fphonenumber, true)
  231. }
  232. if (value.trim() == "") {
  233. let errTips = this.data.errTips;
  234. errTips[name] = true;
  235. this.setData({
  236. errTips
  237. })
  238. }
  239. },
  240. /* 更改logo */
  241. logoChange(data) {
  242. this.setData({
  243. isLogo: data.detail.fileList
  244. })
  245. },
  246. /**
  247. * 生命周期函数--监听页面初次渲染完成
  248. */
  249. onReady: function () {
  250. },
  251. /**
  252. * 生命周期函数--监听页面显示
  253. */
  254. onShow: function () {
  255. },
  256. /**
  257. * 生命周期函数--监听页面隐藏
  258. */
  259. onHide: function () {
  260. },
  261. /**
  262. * 生命周期函数--监听页面卸载
  263. */
  264. onUnload: function () {
  265. },
  266. /**
  267. * 页面相关事件处理函数--监听用户下拉动作
  268. */
  269. onPullDownRefresh: function () {
  270. },
  271. /**
  272. * 页面上拉触底事件的处理函数
  273. */
  274. onReachBottom: function () {
  275. },
  276. /**
  277. * 用户点击右上角分享
  278. */
  279. onShareAppMessage: function () {
  280. }
  281. })