AddCustomer.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view class="detail-view">
  3. <u-form label-width="140" :model="add_form" ref="uForm">
  4. <view class="form-model-view">
  5. <u-form-item required label="客户名称" prop="name"><u-input v-model="add_form.name" placeholder="请输入客户真实姓名" /></u-form-item>
  6. <u-form-item required label="登录账号" prop="mobile"><u-input v-model="add_form.mobile" type="number" placeholder="请输入客户手机号" /></u-form-item>
  7. <u-form-item required label="客户类型" prop="type">
  8. <u-input @click="goPage('/pagesT/customer/selCustomerType')" class="dis-input" disabled v-model="type_name" placeholder="请选择" />
  9. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  10. </u-form-item>
  11. <u-form-item label="账号状态" v-if="$accessCheck($Access.CustomerListUpdateCustomerStatus)">
  12. <view class="form-value">
  13. <u-switch style="transform: translateY(14rpx);" v-model="add_form.enableStatus" :active-value="5" :inactive-value="4" size="40"></u-switch>
  14. </view>
  15. </u-form-item>
  16. </view>
  17. <view class="form-model-view">
  18. <u-form-item label="联系人"><u-input v-model="add_form.contact.name" placeholder="请输入联系人" /></u-form-item>
  19. <u-form-item label="联系电话"><u-input v-model="add_form.contact.mobile" type="number" placeholder="请输入联系电话" /></u-form-item>
  20. <u-form-item label="所属区域">
  21. <u-input class="dis-input" @click="openSel('region_show')" v-model="region_name" disabled placeholder="请选择" />
  22. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  23. </u-form-item>
  24. <u-form-item label-position="top" label="详细地址"><u-input v-model="add_form.address" type="textarea" placeholder="请输入" /></u-form-item>
  25. <u-form-item label="所属商铺">
  26. <u-input @click="goPage('/pagesT/shop/selShop')" class="dis-input" v-model="shop_name" disabled placeholder="请选择" />
  27. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  28. </u-form-item>
  29. <u-form-item label="分拣区">
  30. <u-input class="dis-input" disabled @click="goPage('/pagesT/werahouse/selReservoir')" v-model="reservoir_name" placeholder="请选择" />
  31. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  32. </u-form-item>
  33. </view>
  34. <view class="form-model-view">
  35. <u-form-item label="销售部门">
  36. <u-input @click="openSel('show_department')" v-model="department_name" class="dis-input" disabled placeholder="请选择" />
  37. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  38. </u-form-item>
  39. <u-form-item label="业务员">
  40. <u-input
  41. @click="goPage('/pagesT/staff/selStaff?departmentId=' + add_form.departmentId)"
  42. class="dis-input"
  43. disabled
  44. placeholder="请选择"
  45. v-model="add_form.salesManName"
  46. />
  47. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  48. </u-form-item>
  49. </view>
  50. <view class="form-model-view">
  51. <u-form-item label-position="top" label="营业执照">
  52. <upload :images="add_form.extend.license ? [add_form.extend.license] : []" @handleRemove="imgRemove" @uploadSuccess="uploadSuccess" />
  53. </u-form-item>
  54. </view>
  55. <view class="form-model-view">
  56. <u-form-item label="客户生日">
  57. <u-input class="dis-input" disabled @click="openSel('time_show')" v-model="birthday" placeholder="请选择" />
  58. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  59. </u-form-item>
  60. <u-form-item label="备注" label-position="top"><u-input type="textarea" v-model="add_form.remark" /></u-form-item>
  61. </view>
  62. </u-form>
  63. <view class="detail-bottom"><view class="handel-btn" @click="submit">提交</view></view>
  64. <SelDeparment v-model="show_department" @confirm="departmentConfirm" @cancel="departmentCancel" />
  65. <RegionSel v-model="region_show" @confirm="regionConfirm" @cancel="regionCancel" />
  66. <u-picker @confirm="birthdayConfirm" mode="time" v-model="time_show"></u-picker>
  67. </view>
  68. </template>
  69. <script>
  70. import upload from '@/components/qiniu/QiniuUpload.vue';
  71. import SelDeparment from '@/components/SelDepartment.vue';
  72. import RegionSel from '@/components/region/RegionSel.vue';
  73. export default {
  74. components: { upload, SelDeparment, RegionSel },
  75. data() {
  76. return {
  77. region_show: false,
  78. time_show: false,
  79. show_department: false,
  80. shopData: '',
  81. staffData: '',
  82. reservoirData: '',
  83. customerTypeData: '',
  84. reservoir_name: '',
  85. shop_name: '',
  86. type_name: '',
  87. department_name: '',
  88. region_name: '',
  89. birthday: '',
  90. rules: {
  91. name: [
  92. {
  93. required: true,
  94. message: '请输入客户名称',
  95. // 可以单个或者同时写两个触发验证方式
  96. trigger: 'blur,change'
  97. }
  98. ],
  99. mobile: [
  100. {
  101. required: true,
  102. message: '请输入登录账号',
  103. // 可以单个或者同时写两个触发验证方式
  104. trigger: 'blur,change'
  105. }
  106. ]
  107. },
  108. isEvidence: '', // 是否必填营业执照
  109. add_form: {
  110. tempSave: '',
  111. latitude: '',
  112. longitude: '',
  113. password: '',
  114. area: '',
  115. mobile: '',
  116. enableStatus: true, // 启用状态
  117. name: '',
  118. code: '',
  119. type: '',
  120. provinceCode: '',
  121. cityCode: '',
  122. districtCode: '',
  123. address: '',
  124. managerMobile: '',
  125. shopId: '', // 商铺的id
  126. departmentId: '', // 部门的id
  127. salesManId: '',
  128. salesManCode: '',
  129. salesManName: '',
  130. birthday: '',
  131. remark: '',
  132. reservoirId: '',
  133. extend: {
  134. license: ''
  135. },
  136. contact: {
  137. area: '',
  138. name: '',
  139. mobile: '',
  140. provinceCode: '',
  141. cityCode: '',
  142. districtCode: '',
  143. address: ''
  144. }
  145. },
  146. customer_id: ''
  147. };
  148. },
  149. watch: {
  150. reservoirData(val) {
  151. if (val) {
  152. this.add_form.reservoirId = val.id;
  153. this.reservoir_name = val.reservoirName;
  154. }
  155. },
  156. shopData(val) {
  157. if (val) {
  158. this.add_form.shopId = val.id;
  159. this.shop_name = val.name;
  160. }
  161. },
  162. customerTypeData(val) {
  163. if (val) {
  164. this.add_form.type = val.id;
  165. this.type_name = val.name;
  166. this.isEvidence = val.isEvidence;
  167. }
  168. },
  169. staffData(val) {
  170. if (val) {
  171. this.add_form.salesManId = val.id;
  172. this.add_form.salesManCode = val.staffCode;
  173. this.add_form.salesManName = val.staffName;
  174. }
  175. }
  176. },
  177. onLoad(options) {
  178. if (options.id) {
  179. this.customer_id = options.id;
  180. uni.setNavigationBarTitle({
  181. title: '修改客户信息'
  182. });
  183. this.getCustomerInfo();
  184. }
  185. },
  186. methods: {
  187. getCustomerInfo() {
  188. this.$u.api.getCustomerInfo(this.customer_id).then(({ data }) => {
  189. this.department_name = data.departmentName;
  190. this.shop_name = data.shopName;
  191. this.type_name = data.customerType;
  192. this.reservoir_name = data.reservoirName;
  193. this.region_name = data.area.provinceName + data.area.cityName + data.area.districtName;
  194. this.birthday = data.birthday ? this.$u.timeFormat(data.birthday, 'yyyy-mm-dd') : '';
  195. this.add_form = {
  196. ...data,
  197. enableStatus: data.enableStatus === 5,
  198. contact: data.contact[0],
  199. extend: data.extend || {
  200. license: ''
  201. }
  202. };
  203. });
  204. },
  205. submit() {
  206. this.$refs.uForm.validate(valid => {
  207. if (valid) {
  208. if (!this.add_form.type) {
  209. this.$u.toast('请选择客户类型');
  210. return;
  211. }
  212. if (!this.$u.test.mobile(this.add_form.mobile)) {
  213. this.$u.toast('登录账号格式有误');
  214. return;
  215. }
  216. if (this.isEvidence === 5 && !this.add_form.extend.license) {
  217. this.$u.toast(`客户类型为【${this.type_name}】的客户必须【上传营业执照】`);
  218. return;
  219. }
  220. if (!this.customer_id) {
  221. this.$u.api
  222. .addCustomer({
  223. ...this.add_form,
  224. enableStatus: this.add_form.enableStatus ? 5 : 4
  225. })
  226. .then(res => {
  227. this.$u.toast('新增成功');
  228. setTimeout(res => {
  229. uni.navigateBack();
  230. }, 1500);
  231. });
  232. } else {
  233. this.$u.api
  234. .editCustomer(this.customer_id, {
  235. ...this.add_form,
  236. enableStatus: this.add_form.enableStatus ? 5 : 4
  237. })
  238. .then(res => {
  239. this.$u.toast('修改成功');
  240. setTimeout(res => {
  241. uni.navigateBack();
  242. }, 1500);
  243. });
  244. }
  245. }
  246. });
  247. },
  248. regionConfirm(val) {
  249. this.add_form.provinceCode = val[0].value;
  250. this.add_form.cityCode = val[1].value;
  251. this.add_form.districtCode = val[2].value;
  252. // 联系方式
  253. this.add_form.contact.provinceCode = val[0].value;
  254. this.add_form.contact.cityCode = val[1].value;
  255. this.add_form.contact.districtCode = val[2].value;
  256. let name = '';
  257. val.forEach(item => {
  258. name += item.label;
  259. });
  260. this.region_name = name;
  261. },
  262. regionCancel(val) {
  263. this.region_show = false;
  264. },
  265. departmentConfirm(val) {
  266. this.add_form.departmentId = val[val.length - 1].value;
  267. this.department_name = val[val.length - 1].label;
  268. this.add_form.salesManId = '';
  269. this.add_form.salesManCode = '';
  270. this.add_form.salesManName = '';
  271. },
  272. departmentCancel(val) {
  273. this.show_department = false;
  274. },
  275. openSel(key) {
  276. this[key] = true;
  277. },
  278. // 图片上传成功
  279. uploadSuccess(imgUrl) {
  280. this.add_form.extend.license = imgUrl;
  281. },
  282. //移除图片
  283. imgRemove(arr) {
  284. this.add_form.extend.license = '';
  285. },
  286. birthdayConfirm(val) {
  287. this.add_form.birthday = val.timestamp;
  288. this.birthday = val.year + '-' + val.month + '-' + val.day;
  289. }
  290. },
  291. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  292. onReady() {
  293. this.$refs.uForm.setRules(this.rules);
  294. }
  295. };
  296. </script>
  297. <style></style>