completionTasks.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <!-- 补全客户信息 -->
  3. <view>
  4. <u-navbar title="补全客户信息" autoBack placeholder></u-navbar>
  5. <view class="card_form">
  6. <x-form ref="customer" :list="list" :model="model" :rules="rules" @confirm="confirm"
  7. @clientele="clientele"></x-form>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import {
  13. urbanArea
  14. } from '@/static/js/districtCode.js'
  15. export default {
  16. data() {
  17. return {
  18. areaData: urbanArea(), //原始数据
  19. list: [{
  20. field: 'name',
  21. label: '姓名',
  22. placeholder: '请输入姓名',
  23. type: 'input',
  24. required: true,
  25. }, {
  26. field: 'principalPhone',
  27. label: '电话',
  28. placeholder: '请输入电话',
  29. type: 'input',
  30. required: true,
  31. }, {
  32. field: 'type',
  33. label: '类型',
  34. placeholder: '请选择类型',
  35. type: 'radio',
  36. options: [{
  37. label: '商户',
  38. value: 0,
  39. },
  40. {
  41. label: '私人',
  42. value: 1,
  43. }
  44. ],
  45. required: true,
  46. }, {
  47. field: 'region',
  48. label: '所在城市/地区',
  49. placeholder: '请选择所在城市/地区',
  50. type: 'cascader',
  51. required: true,
  52. }, {
  53. field: 'address',
  54. label: '地址',
  55. placeholder: '请输入详细地址',
  56. type: 'input',
  57. required: true,
  58. }, {
  59. field: 'addressImg',
  60. label: '现场图片',
  61. placeholder: '请上传现场图片',
  62. type: 'upload',
  63. required: true,
  64. }, {
  65. field: 'remark',
  66. label: '备注',
  67. placeholder: '请输入备注',
  68. type: 'textarea',
  69. }],
  70. model: {
  71. name: '',
  72. principalPhone: '',
  73. address: '',
  74. addressImg: '',
  75. city: '',
  76. area: '',
  77. region: '',
  78. lat: null,
  79. lng: null,
  80. remark: '',
  81. type: 1,
  82. },
  83. rules: {
  84. 'name': {
  85. type: 'string',
  86. required: true,
  87. message: '请输入姓名',
  88. trigger: ['blur', 'change']
  89. },
  90. 'principalPhone': {
  91. type: 'string',
  92. required: true,
  93. message: '请输入号码',
  94. trigger: ['blur', 'change']
  95. },
  96. 'type': {
  97. type: 'number',
  98. required: true,
  99. message: '请选择客户类型',
  100. trigger: ['blur', 'change']
  101. },
  102. 'region': {
  103. type: 'string',
  104. required: true,
  105. message: '请选择所在城市/地区',
  106. trigger: ['blur', 'change']
  107. },
  108. 'address': {
  109. type: 'string',
  110. required: true,
  111. message: '请输入详细地址',
  112. trigger: ['blur', 'change']
  113. },
  114. 'addressImg': {
  115. required: true,
  116. message: '请上传现场图片',
  117. trigger: ['blur', 'change']
  118. },
  119. remark: {
  120. required: false,
  121. }
  122. },
  123. regionCode: [],
  124. customerId: '',
  125. }
  126. },
  127. onLoad(e) {
  128. this.customerId = e.customerId
  129. this.getCustomerList(e.customerId)
  130. },
  131. methods: {
  132. getCustomerList(customerId) {
  133. this.$api.get('/api/customer/' + customerId).then(res => {
  134. if (res.code == 200) {
  135. const param = res.data
  136. let arrImg = []
  137. if (res.data.addressImg) {
  138. arrImg = res.data.addressImg.split(',')
  139. }
  140. let arrimage = []
  141. arrImg.forEach(item => {
  142. var arr = {
  143. thumb: this.$baseUrl + item,
  144. url: item,
  145. }
  146. arrimage.push(arr)
  147. })
  148. this.$refs.customer.fileList1 = arrimage
  149. this.model.name = param.principalName
  150. this.model.principalPhone = param.principalPhone
  151. this.model.address = param.address
  152. this.model.addressImg = res.data.addressImg
  153. this.model.city = param.city
  154. this.model.area = param.area
  155. this.model.type = param.type
  156. this.model.lng = param.lng
  157. this.model.lat = param.lng
  158. this.model.remark = param.remark
  159. this.model.hr = param.city + '/' + param.area
  160. var city = this.cityScreening(param.city, this.areaData)
  161. var area = this.cityScreening(param.area, this.areaData)
  162. this.model.region = city + '/' + area
  163. }
  164. })
  165. },
  166. // 补全客户信息
  167. clientele() {
  168. const param = {
  169. id: this.customerId,
  170. ...this.model
  171. }
  172. delete param.hr
  173. this.$api.put('/api/customer', param).then(res => {
  174. if (res.code == 200) {
  175. uni.$u.toast('操作成功')
  176. setTimeout(() => {
  177. uni.$emit('refresh');
  178. uni.navigateBack({
  179. delta: 1
  180. });
  181. }, 1500)
  182. }
  183. })
  184. },
  185. // 城市筛选
  186. cityScreening(value, list) {
  187. function getChildById(parentArray, id) {
  188. for (let i = 0; i < parentArray.length; i++) {
  189. if (parentArray[i].value === id) { // 如果当前元素的ID与目标ID相等,则返回该元素
  190. return parentArray[i];
  191. } else if (parentArray[i].children && Array.isArray(parentArray[i]
  192. .children)) { // 判断当前元素是否有子节点且类型为数组
  193. const result = getChildById(parentArray[i].children, id); // 对子节点进行递归调用
  194. if (result !== null) { // 若子节点存在结果,则返回该结果
  195. return result;
  196. }
  197. }
  198. }
  199. return null; // 没有找到符合条件的元素时返回null
  200. }
  201. var name = getChildById(list, value)
  202. if (name != null) {
  203. return name.label
  204. }
  205. },
  206. confirm(value) {
  207. this.regionCode = value.value
  208. this.model.city = this.regionCode[0].value
  209. this.model.area = this.regionCode[1].value
  210. this.model.region = value.value[0].label + '/' + value.value[1].label
  211. },
  212. // 获取经纬度
  213. longitude() {
  214. uni.getLocation(({
  215. type: "gcj02",
  216. altitude: true,
  217. isHighAccuracy: true,
  218. geocode: true,
  219. success: function(res) {
  220. console.log('getLocation---', res);
  221. var jw_json = {
  222. jingdu: parseFloat(res.longitude).toFixed(6),
  223. weidu: parseFloat(res.latitude).toFixed(6),
  224. address: res.address.district + res.address.poiName + res.address.street +
  225. res
  226. .address.streetNum
  227. };
  228. uni.setStorageSync('jw_json', jw_json);
  229. },
  230. fail: function(error) {
  231. console.log(error)
  232. this.toast(JSON.stringify(error));
  233. },
  234. }));
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss">
  240. .card_form {
  241. margin: 10rpx 40rpx;
  242. }
  243. </style>