InsertzzSupplierEx.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view>
  3. <uni-forms ref="form" labelPosition="left" labelAlign="left" @submit="submitForm">
  4. <view class="uni-form-item uni-column">
  5. <view class="title"><text class="uni-form-item__title">标题</text></view>
  6. <view class="uni-input-wrapper">
  7. <input class="uni-input" focus placeholder="请填写标题" v-model="title" />
  8. </view>
  9. </view>
  10. <view class="uni-form-item uni-column">
  11. <view class="title"><text class="uni-form-item__title">所属项目</text></view>
  12. <view class="uni-input-wrapper" style="justify-content: left;">
  13. <picker mode="selector" :value="index" :range="array" range-key="projectName" @change="bindPickerChange" v-model="projectCode"
  14. style="width: 100%;">
  15. <view class="uni-input">{{array.length>0?array[index].projectName:''}}</view>
  16. </picker>
  17. </view>
  18. </view>
  19. <view class="uni-form-item uni-column">
  20. <view class="title"><text class="uni-form-item__title">原因</text></view>
  21. <view class="uni-textarea">
  22. <textarea focus placeholder="请输入原因" v-model="reason" auto-height="true" />
  23. </view>
  24. </view>
  25. <view class="uni-form-item uni-column">
  26. <view class="title" style="background-color: #efefef;"><text class="uni-form-item__title">上传文件</text></view>
  27. <view class="content">
  28. <g-upfile ref='gUpfile' :mode="imgList" @chooseFile='chooseFile' @imgDelete='imgDelete' :control='control'
  29. :columnNum="columnNum" :maxCount="maxCount" @limitFileSizeList='limitFileSizeList' @limitFileTypeList='limitFileTypeList' :maxFileSize="20000"></g-upfile>
  30. </view>
  31. </view>
  32. <view style="margin-bottom: 120px;">
  33. </view>
  34. <view class="uni-btn-v uni-column">
  35. <button type="primary" form-type="submit" style="border-radius: 15px;" >提交</button>
  36. </view>
  37. </uni-forms>
  38. </view>
  39. </template>
  40. <script>
  41. import permision from "@/common/permission.js";
  42. import {InsertzzSupplierEx,GetProjectBySupplierCode} from "@/common/api/requisitionApi.js";
  43. import {Decimal} from 'decimal.js'; //decimal计算
  44. export default {
  45. data() {
  46. return {
  47. needFormCach:false, //是否需要表单缓存
  48. title:'',
  49. projectCode:'',
  50. requisitionType:0,
  51. reason:'',
  52. supplierCode:this.$store.state.user.supplierCode, //用户编号
  53. imageList: [],
  54. countIndex: 5,
  55. count: [1, 2, 3, 4, 5],
  56. array: [],
  57. index: 0,
  58. date: this.$util.getDate({
  59. format: true
  60. }),
  61. startDate:this.$util.getDate('start'),
  62. endDate:this.$util.getDate('end'),
  63. control: true,
  64. columnNum: 3,
  65. imgList: [],
  66. urlList:[],
  67. maxCount:5
  68. }
  69. },
  70. onLoad(){
  71. console.info('onLoad');
  72. console.info(uni.getStorageSync('storage_state'));
  73. //console.info(this);
  74. this.$util.persistLogin(this);
  75. //console.info(this.$store.state.user);
  76. //const page = getCurrentPages();
  77. //console.info(page);
  78. },
  79. onUnload() {
  80. this.imageList = [],
  81. this.countIndex = 5;
  82. },
  83. created: function() {
  84. console.info('created');
  85. this.GetDropDown();
  86. },
  87. updated:function(){
  88. },
  89. methods: {
  90. input(form, name, value) {
  91. this.$refs[form].setValue(name, value)
  92. },
  93. /**
  94. * 手动提交
  95. * @param {Object} form
  96. */
  97. submitForm(e) {
  98. console.info('submitForm');
  99. let _this=this;
  100. if(this.title==='')
  101. {
  102. uni.showToast({
  103. icon:"none",
  104. title:"请填写申请标题",
  105. duration:3000
  106. });
  107. return;
  108. }
  109. if(this.title.length>200)
  110. {
  111. uni.showToast({
  112. icon:"none",
  113. title:"申请标题不能多于200字",
  114. duration:3000
  115. });
  116. return;
  117. }
  118. if(this.projectCode=="")
  119. {
  120. uni.showToast({
  121. icon:"none",
  122. title:"请选择项目",
  123. duration:3000
  124. });
  125. return;
  126. }
  127. if(this.reason===""){
  128. uni.showToast({
  129. icon:"none",
  130. title:"原因不能为空",
  131. duration:3000
  132. });
  133. return;
  134. }
  135. if(this.reason.length>500){
  136. uni.showToast({
  137. icon:"none",
  138. title:"原因不能超过500字",
  139. duration:3000
  140. });
  141. return;
  142. }
  143. if(this.$util.isEmpty(this.supplierCode)){
  144. uni.showToast({
  145. icon:"none",
  146. title:"登录人信息丢失,请重新登录再操作",
  147. duration:4000
  148. });
  149. return;
  150. }
  151. let requisitionType=this.$util.getQuery("type")-0;
  152. var dto={title:this.title,projectCode:this.projectCode,supplierCode:this.supplierCode,reason:this.reason,checkPerson:''};
  153. console.info('dto',dto);
  154. //return;
  155. //var data={dto:dto};
  156. //var strList=JSON.stringify(list);
  157. //var strData=JSON.stringify(data);
  158. InsertzzSupplierEx(dto).then((res)=>{
  159. console.info("插入结果",res);
  160. if(res){
  161. //上传图片
  162. _this.uploadFileToServe(res) ;
  163. uni.navigateTo({
  164. url:'/pages/template/SupplierList/SupplierList'
  165. })
  166. }
  167. else{
  168. uni.showToast({
  169. title:'添加失败,重新操作',
  170. icon:'none',
  171. duration:3000
  172. })
  173. }
  174. });
  175. },
  176. bindPickerChange: function(e) {
  177. //console.log('picker发送选择改变,携带值为:' + e.detail.value);
  178. //console.info(e.detail);
  179. this.index = e.detail.value;
  180. this.projectCode=this.array[this.index].projectCode;
  181. console.info('bindPickerChange',this.projectCode);
  182. },
  183. bindDateChange: function(e) {
  184. this.date = e.detail.value;
  185. this.requisitionDate=this.date;
  186. console.info(this.date);
  187. },
  188. countChange: function(e) {
  189. this.countIndex = e.detail.value;
  190. },
  191. GetDropDown:function(){
  192. let that=this;
  193. GetProjectBySupplierCode(this.supplierCode).then((res)=>{
  194. console.info('GetProjectBySupplierCode',res);
  195. res.forEach(function(item,index,array){
  196. that.$set(that.array,index,item);
  197. });
  198. that.projectCode=that.array[0].projectCode;
  199. console.info('array',that.array);
  200. });
  201. },
  202. openWindow:function(){
  203. },
  204. /*
  205. 上传后返回的值:
  206. list:上传后图片数组
  207. v:返回当前上传图片的临时路径
  208. */
  209. chooseFile(list, v) {
  210. console.log("上传图片_list:", list)
  211. console.log("上传图片_v:", v);
  212. this.urlList=list;
  213. console.info("urlList",this.urlList);
  214. },
  215. /*
  216. 删除图片:
  217. list:删除返回删除后剩余的图片数组
  218. eq:返回删除的数组
  219. */
  220. imgDelete(list, eq) {
  221. console.log("删除图片_list:", list);
  222. console.log("删除图片_eq:", eq);
  223. this.urlList=list;
  224. console.info("urlList",this.urlList);
  225. },
  226. /*限制文件大小列表*/
  227. limitFileSizeList(list){
  228. console.info('limitFileSizeList:',list);
  229. if(list){
  230. if(list.length>0){
  231. uni.showModal({
  232. title:'警告',
  233. content: list.join()+' 文件大小超过2000KB',
  234. showCancel:false
  235. });
  236. }
  237. }
  238. },
  239. /*限制文件类型列表*/
  240. limitFileTypeList(list,allowFileType){
  241. console.info('limitFileTypeList:',list);
  242. console.info('limitFileTypeList:',allowFileType);
  243. if(list){
  244. if(list.length>0){
  245. uni.showModal({
  246. title:'警告',
  247. content: list.join()+' 文件类型必须是'+allowFileType.join(),
  248. showCancel:false
  249. });
  250. }
  251. }
  252. },
  253. /*
  254. 执行上传服务:
  255. urlList:要上传的图片:数组类型
  256. */
  257. uploadFileToServe(masterCode) {
  258. let _this=this;
  259. var urlList=_this.urlList;
  260. if (!urlList || urlList.length <= 0) {
  261. return;
  262. };
  263. //console.info(urlList);
  264. //return;
  265. for (let i = 0; i < urlList.length; i++) {
  266. console.info('x-token',_this.$store.state.token.tokenStr);
  267. uni.uploadFile({
  268. url: '/api/Common/UploadImage',
  269. filePath: urlList[i],
  270. name: 'file',
  271. formData: {
  272. createPerson:_this.$store.state.user.supplierCode,
  273. masterCode:masterCode,
  274. attachMentType:'zzSupplierExAttach'
  275. },
  276. headers: {
  277. 'Content-Type': 'multipart/form-data; boundary = ' + new Date().getTime(),
  278. 'X-Token':_this.$store.state.token.tokenStr
  279. //这里要把content-type设置为multipard/form-data,同时还要设置boundary
  280. },
  281. success: (uploadFileRes) => {
  282. console.log("图片上传:",uploadFileRes.data);
  283. }
  284. });
  285. }
  286. }
  287. }
  288. }
  289. </script>
  290. <style scoped>
  291. /* 头条小程序组件内不能引入字体 */
  292. /* #ifdef MP-TOUTIAO */
  293. @font-face {
  294. font-family: uniicons;
  295. font-weight: normal;
  296. font-style: normal;
  297. src: url("~@/static/uni.ttf") format("truetype");
  298. }
  299. /* #endif */
  300. page {
  301. display: flex;
  302. flex-direction: column;
  303. box-sizing: border-box;
  304. background-color: #efeff4;
  305. min-height: 100%;
  306. height: auto;
  307. }
  308. view {
  309. font-size: 14px;
  310. line-height: inherit;
  311. }
  312. .uni-form-item__title {
  313. font-size: 16px;
  314. line-height: 24px;
  315. }
  316. .uni-input-wrapper {
  317. /* #ifndef APP-NVUE */
  318. display: flex;
  319. /* #endif */
  320. padding: 8px 13px;
  321. flex-direction: row;
  322. flex-wrap: nowrap;
  323. background-color: #FFFFFF;
  324. }
  325. .title{
  326. background-color: #efefef;
  327. }
  328. .uni-input {
  329. height: 28px;
  330. line-height: 28px;
  331. font-size: 15px;
  332. padding: 0px;
  333. flex: 1;
  334. background-color: #FFFFFF;
  335. }
  336. .uni-icon {
  337. font-family: uniicons;
  338. font-size: 24px;
  339. font-weight: normal;
  340. font-style: normal;
  341. width: 24px;
  342. height: 24px;
  343. line-height: 24px;
  344. color: #999999;
  345. }
  346. .uni-eye-active {
  347. color: #007AFF;
  348. }
  349. .uni-btn-v{
  350. position: fixed;
  351. bottom: 0;
  352. width:100%;
  353. }
  354. .header-slot-box {
  355. font-size:15px;
  356. margin: 5px 5px;
  357. width:20%;
  358. justify-content: center;
  359. }
  360. .body-slot-box {
  361. font-size:15px;
  362. margin: 5px 5px;
  363. width:40%;
  364. justify-content: center;
  365. }
  366. .footer-slot-box {
  367. font-size:15px;
  368. margin: 5px 5px;
  369. width:40%;
  370. justify-content: center;
  371. }
  372. .uni-textarea textarea{
  373. font-size:15px;
  374. }
  375. .content {
  376. padding: 40rpx;
  377. background-color: #fff;
  378. }
  379. /* 上传控件 */
  380. .uploadControl {
  381. border: 1rpx solid #eee;
  382. border-radius: 10rpx;
  383. width: 130rpx;
  384. display: block;
  385. height: 130rpx;
  386. text-align: center;
  387. line-height: 130rpx;
  388. font-size: 30rpx;
  389. color: #888;
  390. background-color: #eeeeee;
  391. }
  392. </style>