#### **axml代码**
```
<view class="flex_c pd_l15 pd_r15 pd_t10 pd_b10 fs13">
<view class="flexitem t_gy6">申请信息</view>
</view>
<form class="carform mg_b10" onSubmit="formSubmit" onReset="formReset">
<view class="list">
<view class="item flex_c">
<view class="label">申请人:</view>
<view class="flexitem">
<input class="ta_r" disabled placeholder="申请人" value="{{user.name}}"></input>
</view>
</view>
<view class="item lower flex_c">
<view class="label">供应商:</view>
<view class="flexitem row-title">
<picker onChange="bindObjPickerChange" value="{{arrIndex}}" range="{{supplierList}}" range-key="name">
<view class="row">
<view class="row-extra">{{supplierList[arrIndex].name}}</view>
</view>
</picker>
</view>
</view>
<view class="item lower flex_c">
<view class="label">下单日期:</view>
<view class="flexitem" onTap="onStartTime">
<view class="icon date ta_r">{{startTime}}</view>
</view>
</view>
<view class="item lower flex_c">
<view class="label">采购日期:</view>
<view class="flexitem" onTap="onEndTime">
<view class="icon date ta_r">{{endTime}}</view>
</view>
</view>
<view class="item">
<view class="lower flex_c">
<view class="label">照片:</view>
</view>
<view class="flexitem flex_c">
<am-input-item type="text" placeholder="点击上传采购照片" onFocus="onUploadFileMultiple"></am-input-item>
<image a:for="{{feeImagesList}}" a:key="key" mode="scaleToFill" src="{{baseUrl + item}}"></image>
</view>
</view>
<view class="item">
<view class="lower flex_c">
<view class="label">备注:</view>
</view>
<view class="flex_c flexitem">
<textarea placeholder="请输入备注" name="remark" class="fs15"></textarea>
</view>
</view>
</view>
<approveflow approvalList="{{approvalList}}" copyList="{{copyList}}"></approveflow>
<!-- <view a:for="{{approvalList}}">审批人:{{item.title}}-{{item.person_text?item.person_text:item.department_text}}</view>
<view a:for="{{copyList}}">抄送人:{{item.person_text}}</view> -->
<view class="fixbtn">
<button loading="{{submitLoading}}" disabled="{{submitLoading}}" formType="submit">提交申请</button>
</view>
</form>
```
*****
#### **js请求代码**
```
import stockApi from '/api/impl/stockApi';
import userApi from '/api/impl/userApi';
import commonApi from '/api/impl/commonApi';
import Validate from '/util/common/validate.js'
let app = getApp();
Page({
data: {
code: '',
user: [],
departmentName: '',
usecarColumn: [],
usecarChildColumn: [],
usecarChildTypeId: '',
usecarChildTypeText: '',
startTime: '',
endTime: '',
nowDate: '',
approvalList: [],
copyList: [],
eventCode: 'use_car',
passengers: '',
passengersText: '',
submitLoading: false,
baseUrl: app.globalData.baseUrl,
initialMileageImage: '',
feeImagesList: [],
supplierList:[
{
id: 0,
name: '请选择',
},
],
arrIndex: 0,
supplierId:'',
},
onLoad() {
this.getUserDepartment();
this.getUseCarType();
this.getFlowSet();
let myDate = new Date();
this.setData({
nowDate: myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + myDate.getDate() + ' ' + myDate.getHours() + ':' + myDate.getMinutes(),
user: app.globalData.userInfo
});
//表单验证
this.initValidate();
this.getSupplierList();
},
/**
* 验证函数
*/
initValidate() {
const rules = {
start_time: {
required: true
},
end_time: {
required: true
},
remark: {
required: true
},
}
const messages = {
start_time: {
required: '下单日期不能为空'
},
end_time: {
required: '采购日期不能为空'
},
remark: {
required: '备注不能为空'
}
}
this.validate = new Validate(rules, messages)
},
//获取申请人信息
getUserDepartment(){
let _this = this
userApi.getUserDepartment().then(function(res){
let data = res.data
_this.setData({
departmentName: data.name
})
})
},
//审批人
getUseCarType(){
let _this = this
commonApi.getUseCarType().then(function(res){
let data = res.data
_this.setData({
usecarColumn: data
})
})
},
//抄送
getFlowSet(){
let _this = this
commonApi.getFlowSet(_this.data.eventCode).then(function(res){
let data = res.data
_this.setData({
approvalList: data.approval,
copyList: data.copy
})
})
},
//表单提交
formSubmit: function(e) {
let _this = this;
let params = e.detail.value;
params.code = _this.data.eventCode;
params.start_time = _this.data.startTime;
params.end_time = _this.data.endTime;
params.supplier_id = _this.data.supplierId;
params.bill_image = _this.data.feeImagesList.join(',');
//校验表单
if (!_this.validate.checkForm(params)) {
const error = _this.validate.errorList[0]
dd.alert({content: error.msg});
return false
}
_this.setData({
submitLoading: true
});
stockApi.stockin(params).then(function(res){
_this.setData({
submitLoading: false
})
dd.showToast({content: res.msg});
dd.navigateBack();
}).catch(function(err){
_this.setData({
submitLoading: false
})
dd.alert({content: err.msg});
});
},
formReset: function() {
console.log('form发生了reset事件')
},
// 下单日期:
onStartTime() {
let _this = this;
dd.datePicker({
format: 'yyyy-MM-dd HH:mm',
currentDate: _this.data.nowDate,
startDate: _this.data.nowDate,
// endDate: '2012-01-10 11:11',
success: (res) => {
_this.setData({
startTime: res.date
});
},
});
},
// 采购日期:
onEndTime() {
let _this = this;
dd.datePicker({
format: 'yyyy-MM-dd HH:mm',
currentDate: _this.data.nowDate,
startDate: _this.data.nowDate,
// endDate: '2012-01-10 11:11',
success: (res) => {
_this.setData({
endTime: res.date
});
},
});
},
// 多图上传
onUploadFileMultiple() {
let _this = this;
dd.chooseImage({
count: 10,
success: (res) => {
dd.compressImage({
filePaths:res.filePaths,
compressLevel:2,
success:(res2)=>{
let filePaths = res2.filePaths
filePaths.forEach(item => {
commonApi.uploadFile(item).then(res3 => {
let feeImagesList = _this.data.feeImagesList;
feeImagesList.push(res3.data.url);
_this.setData({
feeImagesList: feeImagesList
})
}).catch(err3 => {
console.log(err3)
})
});
}
});
},
});
},
// 预览图片
previewImage: function (e) {
let imageurl = this.data.baseUrl + e.currentTarget.dataset.imageurl;
dd.previewImage({
current: 0,
urls: [
imageurl
],
});
},
//供应商切换
bindObjPickerChange(e) {
let _this = this;
let supplierList = _this.data.supplierList;
let supplierId = supplierList[e.detail.value] ? supplierList[e.detail.value].id : 0;
console.log(supplierId)
_this.setData({
arrIndex: e.detail.value,
supplierId: supplierId,
});
},
//获取供应商列表
getSupplierList: function(){
let _this = this
stockApi.getSupplierList().then(function(res){
let data = res.data
_this.setData({
supplierList: data,
supplierId: 0,
})
})
},
//不关闭跳转指定页面
goUsecarlist() {
dd.navigateTo({
url: '/page/home/apply/usecarlist/usecarlist'
})
},
goUsecarrider() {
dd.navigateTo({
url: '/page/home/apply/usecarrider/usecarrider?passengers=' + this.data.passengers + '&passengersText=' + this.data.passengersText
})
}
});
```