index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. isDisabled: false, //是否禁用
  15. butText: "保存", //按钮文字
  16. popups: false, //弹出层控制
  17. /* */
  18. fbrand: "", //品牌名称
  19. attinfos: [], // 图片列表
  20. coverAttinfos: [], //品牌展示图
  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. /* input事件剔除特殊字符 */
  44. eliminate(value) {
  45. const {
  46. name
  47. } = value.target.dataset;
  48. this.setData({
  49. [name]: _Verify.Eliminate(value.detail)
  50. })
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad: function (options) {
  56. // 判断主子账号 是否禁用
  57. this.setData({
  58. isDisabled: (wx.getStorageSync('userData').fisadministrator == 1) ? false : true
  59. });
  60. //判断进入方式
  61. if (options.data == null) {
  62. console.log("注册进入")
  63. this.setData({
  64. requestType: "商户认证"
  65. })
  66. } else if (options.data == 1) {
  67. wx.showToast({
  68. title: '商户信息审核中',
  69. icon: 'none',
  70. duration: 5000
  71. });
  72. this.setData({
  73. requestType: "商户认证",
  74. isDisabled: true
  75. })
  76. } else {
  77. //处理数据
  78. const data = JSON.parse(options.data);
  79. this.returnData(data)
  80. }
  81. },
  82. //跳转富文本
  83. toRichText() {
  84. const that = this;
  85. const fintroduction = encodeURIComponent(this.data.fintroduction);
  86. wx.navigateTo({
  87. url: './editor/editor?fintroduction=' + fintroduction,
  88. events: {
  89. richTextCallBack: function (richText) {
  90. that.setData({
  91. fintroduction: richText.richText
  92. })
  93. }
  94. }
  95. })
  96. },
  97. /* 添加图片 */
  98. imageChange(data) {
  99. this.setData({
  100. attinfos: data.detail.fileList
  101. })
  102. },
  103. coverImageChange(data) {
  104. this.setData({
  105. coverAttinfos: data.detail.fileList
  106. })
  107. },
  108. /* 选择类目回调 */
  109. saleprodChange(arr) {
  110. let detail = arr.detail,
  111. showSaleprodclass = "";
  112. for (let i = 0; i < detail.length; i++) {
  113. showSaleprodclass += (detail[i] + ',');
  114. };
  115. this.setData({
  116. popups: false,
  117. saleprodclass: detail,
  118. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1)
  119. })
  120. },
  121. /* 返回数据 */
  122. returnData(data) {
  123. console.log(data)
  124. var attinfos = [],
  125. coverAttinfos = [];
  126. // 格式化图片
  127. for (let i = 0; i < data.attinfos.length; i++) {
  128. const Data = {
  129. url: data.attinfos[i].fobsurl,
  130. ownerid: data.attinfos[i].ownerid,
  131. tattachmentid: data.attinfos[i].tattachmentid,
  132. ownertable: data.attinfos[i].ownertable,
  133. fdocument: data.attinfos[i].fdocument
  134. };
  135. if (data.attinfos[i].ftype == "brandlogo") {
  136. attinfos.unshift(Data)
  137. } else if (data.attinfos[i].ftype == "brandcover") {
  138. coverAttinfos.unshift(Data)
  139. }
  140. }
  141. //格式化经营类目
  142. if (data.saleprodclass.length >= 1) {
  143. this.saleprodChange({
  144. detail: data.saleprodclass
  145. })
  146. }
  147. //解码富文本
  148. const fintroduction = decodeURIComponent(data.fintroduction);
  149. this.setData({
  150. fbrand: data.fbrand,
  151. saleprodclass: data.saleprodclass,
  152. fcontact: data.fcontact,
  153. fphonenumber: data.fphonenumber,
  154. fagentname: data.fagentname,
  155. faddress: data.faddress,
  156. fdutyparagraph: data.fdutyparagraph,
  157. attinfos,
  158. coverAttinfos,
  159. fintroduction
  160. })
  161. },
  162. /* 提交数据 */
  163. submit() {
  164. if (!this.formVerify()) return wx.showToast({
  165. title: '请检查表单内容',
  166. icon: "error"
  167. });
  168. if (this.data.attinfos.length < 1) return wx.showToast({
  169. title: '请上传品牌LOGO!',
  170. icon: "none"
  171. });
  172. if (this.data.coverAttinfos.length < 1) return wx.showToast({
  173. title: '请上传品牌展示图!',
  174. icon: "none"
  175. });
  176. const that = this;
  177. if (this.data.requestType == '普通修改') {
  178. wx.showModal({
  179. title: '提示',
  180. content: "是否确认修改商户信息",
  181. success: (res => {
  182. if (res.confirm) {
  183. that.requestToSend();
  184. };
  185. })
  186. })
  187. } else {
  188. that.requestToSend();
  189. }
  190. },
  191. /* 发送请求 */
  192. requestToSend() {
  193. _Http.basic({
  194. "accesstoken": wx.getStorageSync('userData').token,
  195. "classname": "customer.tagents.tagents",
  196. "method": "modify_enterpriseAgent",
  197. "content": {
  198. "ftype": this.data.requestType,
  199. "data": [{
  200. "fbrand": this.data.fbrand,
  201. "saleprodclass": this.data.saleprodclass,
  202. "fcontact": this.data.fcontact,
  203. "fphonenumber": this.data.fphonenumber,
  204. "fagentname": this.data.fagentname,
  205. "fintroduction": this.data.fintroduction,
  206. "faddress": this.data.faddress,
  207. "fdutyparagraph": this.data.fdutyparagraph,
  208. }]
  209. }
  210. }).then(res => {
  211. if (res.msg != '成功') return wx.showToast({
  212. title: res.data,
  213. })
  214. wx.showToast({
  215. title: '提交成功',
  216. });
  217. setTimeout(() => {
  218. wx.navigateBack({
  219. delta: 1,
  220. })
  221. }, 500)
  222. })
  223. },
  224. /* 表单验证 */
  225. formVerify() {
  226. let errTips = this.data.errTips,
  227. verify = true;
  228. /* 验证品牌名 */
  229. if (!_Verify.required(this.data.fbrand)) {
  230. errTips.fbrand = true;
  231. verify = false;
  232. }
  233. /* 验证经营类目 */
  234. if (!_Verify.required(this.data.showSaleprodclass)) {
  235. errTips.saleprodclass = true;
  236. verify = false;
  237. }
  238. /* 验证联系人 */
  239. if (!_Verify.required(this.data.fcontact)) {
  240. errTips.fcontact = true;
  241. verify = false;
  242. }
  243. /* 验证联系方式 */
  244. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  245. errTips.fphonenumber = true;
  246. verify = false;
  247. }
  248. /* 验证商户名称 */
  249. if (!_Verify.required(this.data.fagentname)) {
  250. errTips.fagentname = true;
  251. verify = false;
  252. }
  253. /* 验证商户介绍 */
  254. if (!_Verify.required(this.data.fintroduction)) {
  255. errTips.fintroduction = true;
  256. verify = false;
  257. }
  258. /* 验证地址 */
  259. if (!_Verify.required(this.data.faddress)) {
  260. errTips.faddress = true;
  261. verify = false;
  262. }
  263. this.setData({
  264. errTips
  265. })
  266. return verify;
  267. },
  268. /* 弹出层 */
  269. showPop() {
  270. if (this.data.isDisabled) return;
  271. this.setData({
  272. popups: !this.data.popups
  273. })
  274. },
  275. /* 获取焦点 */
  276. inputFocus(e) {
  277. const {
  278. name
  279. } = e.currentTarget.dataset;
  280. let errTips = this.data.errTips;
  281. errTips[name] = false;
  282. this.setData({
  283. errTips
  284. })
  285. },
  286. /* 失去焦点 */
  287. inputBlur(e) {
  288. const {
  289. name
  290. } = e.currentTarget.dataset;
  291. const {
  292. value
  293. } = e.detail;
  294. let errTips = this.data.errTips;
  295. /* 联系方式验证 */
  296. if (name == 'fphonenumber') {
  297. if (!_Verify.phoneNumber(this.data.fphonenumber, true)) errTips[name] = true;
  298. }
  299. if (value.trim() == "") {
  300. errTips[name] = true;
  301. }
  302. this.setData({
  303. errTips
  304. })
  305. },
  306. /**
  307. * 生命周期函数--监听页面初次渲染完成
  308. */
  309. onReady: function () {
  310. },
  311. /**
  312. * 生命周期函数--监听页面显示
  313. */
  314. onShow: function () {
  315. },
  316. /**
  317. * 生命周期函数--监听页面隐藏
  318. */
  319. onHide: function () {
  320. },
  321. /**
  322. * 生命周期函数--监听页面卸载
  323. */
  324. onUnload: function () {
  325. },
  326. /**
  327. * 页面相关事件处理函数--监听用户下拉动作
  328. */
  329. onPullDownRefresh: function () {
  330. },
  331. /**
  332. * 页面上拉触底事件的处理函数
  333. */
  334. onReachBottom: function () {
  335. },
  336. /**
  337. * 用户点击右上角分享
  338. */
  339. onShareAppMessage: function () {
  340. }
  341. })