registerTow.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <!-- 注册2 -->
  2. <template>
  3. <view class="register">
  4. <view class="register_li" v-for="(item,index) in qpSupplierCredentialsDtos">
  5. <view class="register_li_t"><text v-if="item.required==1" style="color: #f00;margin-right: 10rpx;">*</text>{{item.naturalName}}</view>
  6. <view class="register_li_b">
  7. <img src="@/pages_supplier/images/Version3.0/icon_zc_scbg.png">
  8. <img v-if="item.naturalName" :src="baseUrl+item.naturalUrl">
  9. <img src="@/pages_supplier/images/Version3.0/icon_zc_sc.png" @click="selectImage(item)">
  10. </view>
  11. <view class="register_li_b2">
  12. <view><text v-if="item.required==1" style="color: #f00;margin-right: 10rpx;">*</text>有效期</view>
  13. <picker mode="date" @change="startChange(item,$event)">
  14. <input class="picker-text" disabled type="text" v-model="item.startTime" placeholder="开始时间">
  15. </picker>
  16. <view>-</view>
  17. <picker mode="date" @change="endChange(item,$event)">
  18. <input class="picker-text2" disabled type="text" v-model="item.endTime" placeholder="结束时间">
  19. </picker>
  20. </view>
  21. <view class="register_li_b3">{{item.remark}}</view>
  22. </view>
  23. <view class="sub_btn" @click="submitForm()">提交</view>
  24. </view>
  25. </template>
  26. <script>
  27. import {supplierRegister,certificateList,supplierAmend} from '@/api/apiDemo/index.js'
  28. import { config } from '@/api/request/config.js'
  29. export default {
  30. data() {
  31. return {
  32. baseUrl:config.base_url,
  33. qpSupplierDto:null,
  34. qpSupplierCredentialsDtos:[],
  35. license:null,
  36. }
  37. },
  38. onLoad(option) {
  39. let form=JSON.parse(decodeURIComponent(option.form));
  40. if(JSON.parse(decodeURIComponent(option.license))){
  41. this.license=JSON.parse(decodeURIComponent(option.license));
  42. }
  43. this.qpSupplierDto=form;
  44. this.getList()
  45. },
  46. onShow(){
  47. },
  48. methods: {
  49. // 图片上传
  50. selectImage(item) {
  51. let self = this;
  52. wx.chooseImage({
  53. count: 1,
  54. sizeType: ["original", "compressed"],
  55. sourceType: ["album", "camera"],
  56. success: function(res) {
  57. let tempFilePaths = res.tempFilePaths[0];
  58. self.uploadImg(item,tempFilePaths);
  59. }
  60. });
  61. },
  62. async uploadImg(item,tempFilePaths){
  63. var self = this;
  64. uni.showLoading({
  65. title: '上传中',
  66. mask: true
  67. });
  68. uni.uploadFile({
  69. url: config.base_url+'/base/file/upload', //仅为示例,非真实的接口地址
  70. header:{'Authorization':uni.getStorageSync('token')},
  71. filePath: tempFilePaths,
  72. name: 'file',
  73. formData: {
  74. 'user': 'test'
  75. },
  76. success: (uploadFileRes) => {
  77. let res = JSON.parse(uploadFileRes.data);
  78. if(res.code == 200){
  79. item.naturalUrl=res.data.url;
  80. }else{
  81. uni.showToast({
  82. title: res.msg,
  83. icon:"none",
  84. mask:true,
  85. duration: 2000
  86. });
  87. }
  88. },
  89. fail: err => {},
  90. complete: () => {
  91. uni.hideLoading()
  92. }
  93. });
  94. },
  95. //删除图片
  96. delImg(index){
  97. this.newData.imgList.splice(index,1);
  98. },
  99. //开始时间选中事件
  100. startChange(item,e){
  101. if(new Date(e.target.value).getTime()>=new Date(item.endTime).getTime()){
  102. uni.showToast({
  103. title: '结束时间不能小于开始时间',
  104. icon:"none",
  105. mask:true,
  106. duration: 2000
  107. });
  108. }else{
  109. item.startTime=e.target.value
  110. }
  111. },
  112. //结束时间选中事件
  113. endChange(item,e){
  114. if(new Date(item.startTime).getTime()>=new Date(e.target.value).getTime()){
  115. uni.showToast({
  116. title: '结束时间不能小于开始时间',
  117. icon:"none",
  118. mask:true,
  119. duration: 2000
  120. });
  121. }else{
  122. item.endTime=e.target.value
  123. }
  124. },
  125. //获取列表数据
  126. async getList(){
  127. let _this = this;
  128. const {data} = await certificateList({type:1})
  129. if(data.code==200){
  130. //重新渲染后台返回数据
  131. data.data.forEach(function(item){
  132. _this.qpSupplierCredentialsDtos.push({'required':item.required,'naturalName':item.name,'naturalUrl':'','startTime':'','endTime':'','remark':item.remark,'certificateId':item.id})
  133. })
  134. //循环对比把详情的值渲染到资料模板上
  135. if(_this.license){
  136. _this.qpSupplierCredentialsDtos.forEach(function(item){
  137. _this.license.forEach(function(item2){
  138. if(item.certificateId==item2.certificateId){
  139. item.naturalUrl=item2.naturalUrl
  140. item.startTime=item2.startTime
  141. item.endTime=item2.endTime
  142. }
  143. })
  144. })
  145. }
  146. }
  147. },
  148. //注册提交
  149. async submitForm(){
  150. let _this = this;
  151. let isPass=true;
  152. //提交的时候过滤空数据
  153. let arr=[];
  154. for(let i=0;i<_this.qpSupplierCredentialsDtos.length;i++){
  155. if(_this.qpSupplierCredentialsDtos[i].required==1){
  156. if(!_this.qpSupplierCredentialsDtos[i].naturalUrl){
  157. isPass=false;
  158. uni.showToast({
  159. title: '未上传'+_this.qpSupplierCredentialsDtos[i].naturalName+',请上传'+_this.qpSupplierCredentialsDtos[i].naturalName,
  160. icon:"none",
  161. mask:true,
  162. duration: 2000
  163. });
  164. return
  165. }
  166. if(!_this.qpSupplierCredentialsDtos[i].startTime || !_this.qpSupplierCredentialsDtos[i].endTime){
  167. isPass=false;
  168. uni.showToast({
  169. title: '请选择'+_this.qpSupplierCredentialsDtos[i].naturalName+'有效期',
  170. icon:"none",
  171. mask:true,
  172. duration: 2000
  173. });
  174. return
  175. }
  176. arr.push(_this.qpSupplierCredentialsDtos[i])
  177. }else{
  178. arr.push(_this.qpSupplierCredentialsDtos[i])
  179. }
  180. }
  181. if(isPass){
  182. _this.qpSupplierDto.qpSupplierCredentialsDtos=arr;
  183. //修改
  184. if(_this.qpSupplierDto.id){
  185. const {data} = await supplierAmend(_this.qpSupplierDto);
  186. if(data.code == 200){
  187. uni.showToast({
  188. title: '提交成功',
  189. icon:"none",
  190. mask:true,
  191. duration: 2000
  192. });
  193. setTimeout(function(){
  194. uni.redirectTo({
  195. url: '/pages/login',
  196. });
  197. },2000);
  198. }
  199. }else{//注册
  200. const {data} = await supplierRegister(_this.qpSupplierDto);
  201. if(data.code == 200){
  202. uni.showToast({
  203. title: '提交成功',
  204. icon:"none",
  205. mask:true,
  206. duration: 2000
  207. });
  208. setTimeout(function(){
  209. uni.redirectTo({
  210. url: '/pages_supplier/register/registerSuccess?form='+encodeURIComponent(JSON.stringify(_this.qpSupplierDto)),//注册
  211. });
  212. },2000);
  213. }
  214. }
  215. }
  216. },
  217. }
  218. }
  219. </script>
  220. <style lang="stylus" scoped>
  221. .register{
  222. height:auto;
  223. width:100%;
  224. display flex
  225. flex-direction column;
  226. padding-bottom: 220rpx;
  227. .register_li{
  228. background #fff;
  229. border-radius:20rpx;
  230. margin:20rpx 20rpx 0;
  231. padding:0 20rpx;
  232. box-sizing: border-box;
  233. .register_li_t{
  234. font-size: 28rpx;
  235. font-family: PingFang SC;
  236. font-weight: 500;
  237. color: #333333;
  238. line-height: 28rpx;
  239. margin: 36rpx 0;
  240. }
  241. .register_li_b{
  242. width: 450rpx;
  243. height: 270rpx;
  244. margin-left: 106rpx;
  245. position: relative;
  246. >img:nth-child(1){
  247. width: 450rpx;
  248. height: 270rpx;
  249. position: absolute;
  250. left: 0;
  251. top: 0;
  252. }
  253. >img:nth-child(2){
  254. width: 450rpx;
  255. height: 270rpx;
  256. position: absolute;
  257. left: 0;
  258. top: 0;
  259. }
  260. >img:nth-child(3){
  261. width: 100rpx;
  262. height: 100rpx;
  263. position: absolute;
  264. left: 187rpx;
  265. top: 86rpx;
  266. }
  267. }
  268. .register_li_b2{
  269. border-bottom: 1px solid #f5f5f5;
  270. height: 100rpx;
  271. display: flex;
  272. justify-content: flex-start;
  273. align-items: center;
  274. >view:nth-child(1){
  275. font-size: 28rpx;
  276. font-family: PingFang SC;
  277. font-weight: 500;
  278. color: #333333;
  279. line-height: 100rpx;
  280. margin-right: 150rpx;
  281. }
  282. .picker-text{
  283. font-size: 24rpx;
  284. font-family: PingFang SC;
  285. font-weight: 500;
  286. color: #CCCCCC;
  287. line-height: 100rpx;
  288. width: 188rpx;
  289. }
  290. >view:nth-child(2){
  291. font-size: 24rpx;
  292. font-family: PingFang SC;
  293. font-weight: 500;
  294. color: #CCCCCC;
  295. line-height: 100rpx;
  296. }
  297. .picker-text2{
  298. font-size: 24rpx;
  299. font-family: PingFang SC;
  300. font-weight: 500;
  301. color: #CCCCCC;
  302. line-height: 100rpx;
  303. width: 188rpx;
  304. text-align: right;
  305. }
  306. }
  307. .register_li_b3{
  308. font-size: 24rpx;
  309. font-family: PingFang SC;
  310. font-weight: 500;
  311. color: #999999;
  312. line-height: 36rpx;
  313. margin: 34rpx 0;
  314. }
  315. }
  316. /* 按钮 */
  317. .sub_btn{
  318. width: 650rpx;
  319. height: 100rpx;
  320. background: #0183FA;
  321. border-radius: 20rpx;
  322. font-size: 28rpx;
  323. font-family: PingFang SC;
  324. font-weight: 500;
  325. color: #FFFFFF;
  326. line-height: 100rpx;
  327. text-align: center;
  328. margin-left: 50rpx;
  329. position: fixed;
  330. bottom:30rpx;
  331. z-index: 1000;
  332. }
  333. }
  334. /deep/.input-value-border{
  335. display :none !important;
  336. }
  337. </style>