customerInformationAdd.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. var util = require('../../utils/util.js')
  2. const app = getApp();
  3. Page({
  4. data: {
  5. groupNameList: [
  6. // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
  7. ],
  8. groupIndex:'',
  9. grouprId:'',
  10. customeStatusName: [
  11. // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
  12. ],
  13. customeStatusIndex:'',
  14. customeStatusId:'',
  15. rangeNameList: [
  16. // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
  17. ],
  18. rangeIndex:'',
  19. rangeId:'',
  20. provinceList: [
  21. {id: "北京市", name: "北京市"}, {id: "天津市", name: "天津市"}, {id: "河北省", name: "河北省"}, {id: "山西省", name: "山西省"}, {id: "内蒙古自治区", name: "内蒙古自治区"}, {id: "辽宁省", name: "辽宁省"}, {id: "吉林省", name: "吉林省"}, {id: "黑龙江省", name: "黑龙江省"}, {id: "上海市", name: "上海市"}, {id: "江苏省", name: "江苏省"}, {id: "浙江省", name: "浙江省"}, {id: "安徽省", name: "安徽省"}, {id: "福建省", name: "福建省"}, {id: "江西省", name: "江西省"}, {id: "山东省", name: "山东省"}, {id: "河南省", name: "河南省"}, {id: "湖北省", name: "湖北省"}, {id: "湖南省", name: "湖南省"}, {id: "广东省", name: "广东省"}, {id: "广西壮族自治区", name: "广西壮族自治区"}, {id: "海南省", name: "海南省"}, {id: "四川省", name: "四川省"}, {id: "贵州省", name: "贵州省"}, {id: "云南省", name: "云南省"}, {id: "重庆市", name: "重庆市"}, {id: "西藏自治区", name: "西藏自治区"}, {id: "陕西省", name: "陕西省"}, {id: "甘肃省", name: "甘肃省"}, {id: "青海省", name: "青海省"}, {id: "宁夏回族自治区", name: "宁夏回族自治区"}, {id: "新疆维吾尔自治区", name: "新疆维吾尔自治区"}, {id: "香港特别行政区", name: "香港特别行政区"}, {id: "澳门特别行政区", name: "澳门特别行政区"}, {id: "台湾省", name: "台湾省"}
  22. ],
  23. provinceIndex:'',
  24. province:'',
  25. directorNameList: [
  26. // {id: 56, name: "苗舒怡"},{id: 57, name: "颛孙洋洋"},{id: 58, name: "李涛"}
  27. ],
  28. directorIndex:'',
  29. directorId:'',
  30. rules: {
  31. customerName: [{ required: true, message: '客户必填', trigger: 'blur' }],
  32. groupName: [{ required: true, message: '客户集团必填', trigger: 'blur' }],
  33. customeStatusName: [{ required: true, message: '客户状态必填', trigger: 'blur' }],
  34. scode: [{ required: true, message: '必填', trigger: 'blur' }],
  35. directorName: [{ required: true, message: '负责人必填', trigger: 'blur' }]
  36. },
  37. // 新增/编辑
  38. create: {
  39. dialogStatus: '',
  40. temp: {
  41. customerId: '', customerName: '', groupId: '', groupName: '', customeStatusId: '', customeStatusName: '', rangeId: '', rangeName: '', province: '', address: '',scode: '', directorId: '',directorName: '',createrName: '', createrId: '', createtime: util.getToday(), remark: '', content: '',
  42. receiverChoose: 'true'
  43. },
  44. }
  45. },
  46. onLoad: function (options) {
  47. // 表单初始化
  48. wx.lin.initValidateForm(this)
  49. console.log(app.globalData.g_lgName)
  50. this.setData({
  51. ['create.temp.createrId']: app.globalData.g_createrId,
  52. ['create.temp.createrName']: app.globalData.g_lgName
  53. })
  54. // 客户集团下拉
  55. util.getDataByName({ name: 'getDictListSelect1', parammaps: { "pid": "54" } }, this.getPickerList2)
  56. // 客户区域下拉
  57. util.getDataByName({ name: 'getDictListSelect2', parammaps: { "pid": "53" } }, this.getPickerList3)
  58. // 客户状态下拉
  59. util.getDataByName({ name: 'getDictListSelect3', parammaps: { "pid": "52" } }, this.getPickerList4)
  60. // 负责人下拉
  61. util.getDataByName({ name: 'getEmployeesSelect', parammaps: {} }, this.getPickerList5)
  62. },
  63. getPickerList2: function (res) {
  64. console.log('客户集团下拉数据======>', res.data.list)
  65. this.setData({
  66. groupNameList: res.data.list
  67. })
  68. },
  69. getPickerList3: function (res) {
  70. console.log('客户区域下拉数据======>', res.data.list)
  71. this.setData({
  72. rangeNameList: res.data.list
  73. })
  74. },
  75. getPickerList4: function (res) {
  76. console.log('客户状态下拉数据======>', res.data.list)
  77. this.setData({
  78. customeStatusList: res.data.list
  79. })
  80. },
  81. getPickerList5: function (res) {
  82. console.log('负责人下拉数据======>', res.data.list)
  83. this.setData({
  84. directorNameList: res.data.list
  85. })
  86. },
  87. //下拉框:客户集团
  88. change_group:function(e){
  89. var that = this
  90. console.log('change_group的选项', e.detail.value)
  91. var newId = this.data.groupNameList[e.detail.value]['id']
  92. this.setData({
  93. groupIndex: e.detail.value,
  94. groupId: newId,
  95. ['create.temp.groupId']: newId,
  96. })
  97. },
  98. //下拉框:客户状态
  99. change_customeStatus:function(e){
  100. var that = this
  101. console.log('change_customeStatus的选项', e.detail.value)
  102. var newId = this.data.customeStatusList[e.detail.value]['id']
  103. this.setData({
  104. customeStatusIndex: e.detail.value,
  105. customeStatusId: newId,
  106. ['create.temp.customeStatusId']: newId,
  107. })
  108. },
  109. //下拉框:客户区域
  110. change_range:function(e){
  111. var that = this
  112. console.log('change_range的选项', e.detail.value)
  113. var newId = this.data.rangeNameList[e.detail.value]['id']
  114. this.setData({
  115. rangeIndex: e.detail.value,
  116. rangeId: newId,
  117. ['create.temp.rangeId']: newId,
  118. })
  119. },
  120. //下拉框:客户省份
  121. change_province:function(e){
  122. var that = this
  123. console.log('change_province的选项', e.detail.value)
  124. var newId = this.data.provinceList[e.detail.value]['id']
  125. this.setData({
  126. provinceIndex: e.detail.value,
  127. province: newId,
  128. ['create.temp.province']: newId,
  129. })
  130. },
  131. //下拉框:负责人
  132. change_director:function(e){
  133. var that = this
  134. console.log('change_director的选项', e.detail.value)
  135. var newId = this.data.directorNameList[e.detail.value]['id']
  136. this.setData({
  137. directorIndex: e.detail.value,
  138. directorId: newId,
  139. ['create.temp.directorId']: newId,
  140. })
  141. },
  142. //保存
  143. submit:function(e){
  144. var detail_value = e.detail.values
  145. var detail_errors = e.detail.errors
  146. var detail_errors = e.detail.errors
  147. console.log("detail_value",detail_value)
  148. console.log("create.temp",this.data.create.temp)
  149. var that = this
  150. const submit_data = Object.assign({}, this.data.create.temp, detail_value)
  151. console.log("保存发送:",submit_data)
  152. var send_data = {
  153. "name": 'insertCustomerApp',
  154. "parammaps":submit_data
  155. }
  156. //
  157. //验证必填项是否为空
  158. if(submit_data.customerName == ""){
  159. wx.showToast({title: '客户名称必填',icon: 'none',duration: 2000})
  160. } else if(submit_data.groupId == ""){
  161. wx.showToast({title: '客户集团必填',icon: 'none',duration: 2000})
  162. } else if(submit_data.customeStatusId == ""){
  163. wx.showToast({title: '客户状态必填',icon: 'none',duration: 2000})
  164. } else if(submit_data.directorId == ""){
  165. wx.showToast({title: '负责人必填',icon: 'none',duration: 2000})
  166. } else if(submit_data.scode.length != 18){
  167. wx.showToast({title: '社会统一代码必须18位!',icon: 'none',duration: 2000})
  168. } else {
  169. var send_data_check = {
  170. "name":"checkCustomerByName",
  171. "parammaps":{"customerName":submit_data.customerName,"type":"add","id":""}
  172. }
  173. //验证名字是否重复
  174. util.getDataByName(send_data_check, function(res){
  175. console.log(res)
  176. var num = res.data.list[0].num
  177. console.log("num",num)
  178. if(num == 0){
  179. console.log("可以保持")
  180. util.postDataByName(send_data, that.getListSuccess)
  181. }else{
  182. console.log("名字重复!")
  183. wx.showModal({
  184. title: '提示',
  185. content: '客户名称不可重复!',
  186. success (res) {
  187. if (res.confirm) {
  188. console.log('用户点击确定')
  189. } else if (res.cancel) {
  190. console.log('用户点击取消')
  191. }
  192. }
  193. })
  194. }
  195. })
  196. }
  197. },
  198. getListSuccess: function (res) {
  199. console.log('table数据======>', res)
  200. if (res.msg !== 'fail') {
  201. wx.showToast({
  202. title: '保存成功',
  203. icon: 'success',
  204. duration: 2000,
  205. success: function(){
  206. wx.reLaunch({ url:"../customerInformation/customerInformation"})
  207. }
  208. })
  209. } else {
  210. wx.showModal({
  211. title: '保存失败',
  212. content: res.data,
  213. success (res) {
  214. if (res.confirm) {
  215. console.log('用户点击确定')
  216. } else if (res.cancel) {
  217. console.log('用户点击取消')
  218. }
  219. }
  220. })
  221. }
  222. },
  223. onReady: function () {
  224. },
  225. onShow: function () {
  226. },
  227. onHide: function () {
  228. },
  229. onUnload: function () {
  230. },
  231. /**
  232. * 页面相关事件处理函数--监听用户下拉动作
  233. */
  234. onPullDownRefresh: function () {
  235. },
  236. /**
  237. * 页面上拉触底事件的处理函数
  238. */
  239. onReachBottom: function () {
  240. },
  241. onShareAppMessage: function () {
  242. }
  243. })