create.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-01-12 11:57:48
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-03-22 11:26:04
  6. * @Description: file content
  7. * @FilePath: \oms\pages\distributor\create.vue
  8. -->
  9. <template>
  10. <view class="home">
  11. <view class="nav">
  12. <view :style="{ paddingTop }">
  13. <view class="title" :style="[{ height }, { lineHeight: height }]">
  14. <view class="back" @click="goBack()">
  15. <u-icon name="arrow-left" color="#ffffff" size="22"></u-icon>
  16. </view>
  17. <text>新建经销商</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="main">
  22. <u-form :model="addForm" :rules="rules" ref="addForm" label-width="0">
  23. <u-form-item prop="distName" customStyle="padding:40rpx 0 34rpx" borderBottom>
  24. <view class="form-label flex_l">
  25. <view class="label-tag"></view>
  26. 名称
  27. </view>
  28. <u-input border="none" v-model="addForm.distName" placeholder="请输入名称"></u-input>
  29. </u-form-item>
  30. <u-form-item prop="provinceDesc" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showProvince = true">
  31. <view class="form-label flex_l">
  32. <view class="label-tag"></view>
  33. 选择省份
  34. </view>
  35. <u-input
  36. :readonly="true"
  37. placeholder="请选择省份"
  38. v-model="addForm.provinceDesc"
  39. border="none"
  40. suffixIcon="arrow-down"
  41. suffixIconStyle="color:#CDCDCD"
  42. clearable
  43. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  44. </u-form-item>
  45. <u-form-item prop="registerDistrict" customStyle="padding:40rpx 0 34rpx" borderBottom>
  46. <view class="form-label flex_l">
  47. <view class="label-tag"></view>
  48. 注册地
  49. </view>
  50. <u-input border="none" v-model="addForm.registerDistrict" placeholder="请输入备注"></u-input>
  51. </u-form-item>
  52. </u-form>
  53. <view class="center">
  54. <view class="handle-btn" @click="handleAdd" :class="!flag ? 'disabledBtn' : ''">保存</view>
  55. </view>
  56. </view>
  57. <!-- 选择省 -->
  58. <u-picker
  59. :show="showProvince"
  60. :columns="provinceColumns"
  61. keyName="distName"
  62. @cancel="showProvince = false"
  63. @confirm="pickProvince"></u-picker>
  64. <!-- 选择销售 -->
  65. <u-notify ref="uNotify"></u-notify>
  66. <u-toast ref="uToast"></u-toast>
  67. </view>
  68. </template>
  69. <script>
  70. import { mapGetters } from 'vuex'
  71. import to from 'await-to-js'
  72. import distrApi from '../../api/base/distr'
  73. import SelectUser from 'components/SelectUser'
  74. export default {
  75. name: 'omsIndex',
  76. components: { SelectUser },
  77. data() {
  78. return {
  79. flag: true,
  80. height: '',
  81. paddingTop: '',
  82. showProvince: false,
  83. provinceColumns: [],
  84. addForm: {
  85. distName: '',
  86. provinceId: null,
  87. provinceDesc: '',
  88. registerDistrict: '',
  89. distType: '10',
  90. },
  91. rules: {
  92. distName: [{ required: true, trigger: 'blur', message: '请输入名称' }],
  93. registerDistrict: [{ required: true, trigger: 'blur', message: '请输入注册地' }],
  94. provinceDesc: [{ required: true, trigger: 'blur', message: '请选择省份' }],
  95. },
  96. }
  97. },
  98. computed: {
  99. ...mapGetters(['userId', 'nickName']),
  100. },
  101. created() {
  102. const navData = uni.getMenuButtonBoundingClientRect()
  103. this.height = navData.height + 'px'
  104. this.paddingTop = navData.top + 'px'
  105. },
  106. mounted() {
  107. this.getOptions()
  108. },
  109. methods: {
  110. getOptions() {
  111. Promise.all([distrApi.getProvinceList()])
  112. .then(([province]) => {
  113. this.provinceColumns = [province.data.list]
  114. })
  115. .catch((err) => console.log(err))
  116. },
  117. // 省份选择
  118. pickProvince(e) {
  119. this.addForm.provinceId = e.value[0].id
  120. this.addForm.provinceDesc = e.value[0].distName
  121. this.showProvince = false
  122. },
  123. handleAdd() {
  124. if (!this.flag) return
  125. this.$refs.addForm
  126. .validate()
  127. .then(async () => {
  128. let params = this.addForm
  129. params.belongSale = this.nickName
  130. params.belongSaleId = this.userId
  131. this.flag = false
  132. const [err, res] = await to(distrApi.doAdd(params))
  133. this.flag = true
  134. if (err) return
  135. if (res && res.code == 200) {
  136. this.$refs.uToast.show({
  137. type: 'success',
  138. message: '创建成功',
  139. complete: () => {
  140. uni.navigateBack({
  141. //关闭当前页面,返回上一页面或多级页面。
  142. delta: 1,
  143. })
  144. },
  145. })
  146. }
  147. })
  148. .catch((err) => {
  149. this.$refs.uNotify.show({
  150. top: this.height + this.paddingTop + 10,
  151. type: 'warning',
  152. message: err[0].message,
  153. duration: 1000 * 3,
  154. })
  155. })
  156. },
  157. goBack() {
  158. uni.navigateBack({
  159. //关闭当前页面,返回上一页面或多级页面。
  160. delta: 1,
  161. })
  162. },
  163. },
  164. }
  165. </script>
  166. <style>
  167. page {
  168. background: #f2f3f5;
  169. }
  170. </style>
  171. <style lang="scss" scoped>
  172. .home {
  173. padding-top: 188rpx;
  174. .nav {
  175. position: absolute;
  176. left: 0;
  177. top: 0;
  178. width: 100%;
  179. height: 284rpx;
  180. background: #3e7ef8;
  181. .title {
  182. position: relative;
  183. text-align: center;
  184. font-size: 32rpx;
  185. font-weight: bold;
  186. color: #ffffff;
  187. .back {
  188. position: absolute;
  189. top: 0;
  190. bottom: 0;
  191. margin: auto;
  192. left: 70rpx;
  193. display: flex;
  194. }
  195. }
  196. }
  197. .main {
  198. position: absolute;
  199. width: 100%;
  200. height: calc(100vh - 188rpx);
  201. background: #ffffff;
  202. box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
  203. border-radius: 31rpx 31rpx 0 0;
  204. padding: 0 32rpx;
  205. overflow: auto;
  206. padding-bottom: 64rpx;
  207. .form-label {
  208. font-size: 32rpx;
  209. font-weight: bold;
  210. color: #323232;
  211. padding-bottom: 18rpx;
  212. .label-tag {
  213. width: 15rpx;
  214. height: 15rpx;
  215. background: #ff4d4f;
  216. border-radius: 50%;
  217. margin-right: 10rpx;
  218. }
  219. }
  220. .upload-file-box {
  221. padding: 20rpx 0;
  222. position: relative;
  223. .upload-btn {
  224. position: absolute;
  225. right: 0;
  226. top: 26rpx;
  227. }
  228. }
  229. }
  230. .handle-btn {
  231. width: 569rpx;
  232. height: 92rpx;
  233. background: #3e7ef8;
  234. border-radius: 31rpx;
  235. margin: 116rpx auto 0;
  236. font-size: 32rpx;
  237. color: #ffffff;
  238. text-align: center;
  239. line-height: 92rpx;
  240. }
  241. }
  242. </style>