diyfields.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view v-if="registerfield.length > 0">
  3. <form @submit="bindSave">
  4. <view class="tui-form">
  5. <view class="tui-view-input">
  6. <block v-for="(item, index) in registerfield" :key="index">
  7. <block v-if="item.inputtype == 'text'">
  8. <tui-list-cell :hover="false" padding="0">
  9. <view class="tui-line-cell">
  10. <view class="tui-title">{{ item.viewmingcheng }}</view>
  11. <input v-model="item.fieldsvalue" placeholder-class="tui-phcolor" class="tui-input"
  12. name="name" :placeholder="'请输入' + item.viewmingcheng" type="text" />
  13. </view>
  14. </tui-list-cell>
  15. </block>
  16. <block v-if="item.inputtype == 'textarea'">
  17. <tui-list-cell :hover="false" :lineLeft="false">
  18. <view class="tui-cell-input">
  19. <textarea class="weui-textarea" v-model="item.fieldsvalue"
  20. :placeholder="'请输入' + item.viewmingcheng" style="height: 3.3em" />
  21. </view>
  22. </tui-list-cell>
  23. </block>
  24. <block v-if="item.inputtype == 'pic'">
  25. <tui-list-cell :hover="true" :lineLeft="false" :arrow="true">
  26. <view @click="chooseImg(index)" class="tui-list-cell">
  27. <view>{{ item.viewmingcheng }}</view>
  28. <image :src="item.fieldsvalue || '/static/images/default_img.png'"
  29. class="tui-avatar">
  30. </image>
  31. </view>
  32. </tui-list-cell>
  33. </block>
  34. <block v-if="item.inputtype == 'pics'">
  35. <tui-list-cell :hover="false" :lineLeft="false">
  36. <view class="tui-img__title">{{ item.viewmingcheng }}</view>
  37. <view>
  38. <tui-upload :value="item.fieldsvalue" :limit="5" :params="index"
  39. @complete="uploadresult" @remove="remove">
  40. </tui-upload>
  41. </view>
  42. </tui-list-cell>
  43. </block>
  44. <block v-if="item.inputtype == 'lbs'">
  45. <tui-list-cell @tap="onChangePosition(index)" :arrow="true" padding="0">
  46. <view class="tui-line-cell">
  47. <view class="tui-title"><text
  48. class="tui-title-city-text">{{ item.viewmingcheng }}</text>
  49. </view>
  50. <input placeholder-class="tui-phcolor" class="tui-input tui-pr__30" disabled
  51. :placeholder="'请选择' + item.viewmingcheng" maxlength="50" type="text"
  52. v-model="item.fieldsvalue.region_name" />
  53. </view>
  54. </tui-list-cell>
  55. </block>
  56. <block v-if="item.inputtype == 'checkbox'">
  57. <tui-list-cell :hover="false" :lineLeft="false">
  58. <view class="uni-list">
  59. <button class="ptypebut" @click="selcate" :data-index="index"
  60. :data-val="checkitem.val"
  61. :class="item.fieldsvalue.includes(checkitem.val.toString()) ? 'selcss' : ''"
  62. type="default" v-for="checkitem in item.selectvaluearray"
  63. :key="checkitem.val">{{ checkitem.key
  64. }}</button>
  65. </view>
  66. </tui-list-cell>
  67. </block>
  68. <block v-if="item.inputtype === 'select'">
  69. <tui-list-cell :padding="0" :hover="true" :lineLeft="false" :arrow="true">
  70. <view class="tui-list-cell" style="padding: 0rpx;">
  71. <picker style="width: 100%;padding: 40rpx 30rpx 40rpx 30rpx;"
  72. @change="bindSelectChange" range-key="key"
  73. :data-selectval="item.selectvaluearray" :data-index="index" :data-sid="item.id"
  74. :range="item.selectvaluearray">
  75. <view v-if="item.fieldsvalue_name" class="weui-select">
  76. {{ item.fieldsvalue_name }}
  77. </view>
  78. <view v-else style="color: #888" class="weui-select">请选择{{ item.viewmingcheng }}
  79. </view>
  80. </picker>
  81. </view>
  82. </tui-list-cell>
  83. </block>
  84. </block>
  85. </view>
  86. <view class="tui-btn-box">
  87. <button form-type="submit" class="btn86"
  88. :style="'background:'+ pagestyleconfig.appstylecolor">{{submittxt}}</button>
  89. </view>
  90. </view>
  91. </form>
  92. </view>
  93. </template>
  94. <script>
  95. const util = require("@/utils/util.js")
  96. export default {
  97. name: 'diyfields',
  98. props: {
  99. ptype: {
  100. type: String,
  101. default: ''
  102. },
  103. orderid: {
  104. type: String,
  105. default: ''
  106. },
  107. update: {
  108. type: String,
  109. default: ''
  110. },
  111. submittxt: {
  112. type: String,
  113. default: '提交'
  114. },
  115. posturl: {
  116. type: String,
  117. default: 'registerfield.update'
  118. },
  119. gourl: {
  120. type: String,
  121. default: '/pages/login/success'
  122. },
  123. gotype: {
  124. type: String,
  125. default: 'reLaunch'
  126. }
  127. },
  128. data() {
  129. return {
  130. registerfield: {},
  131. pagestyleconfig: [],
  132. latitude: '',
  133. longitude: ''
  134. };
  135. },
  136. mounted() {
  137. let _this = this;
  138. _this.$request.get('registerfield.list', {
  139. update: _this.update,
  140. ptype: _this.ptype,
  141. orderid: _this.orderid,
  142. samkey: (new Date()).valueOf()
  143. }).then(res => {
  144. console.log(res);
  145. if (res.errno == 0) {
  146. if (res.is_submit == 1) {
  147. uni.reLaunch({
  148. url: "/pages/login/success?ptype=" + _this.ptype
  149. });
  150. } else {
  151. _this.registerfield = res.data;
  152. console.log(_this.registerfield);
  153. }
  154. }
  155. });
  156. _this.$request.post('config', {
  157. mo: 'pagestyle'
  158. }).then(res => {
  159. if (res.errno == 0) {
  160. _this.pagestyleconfig = res.data
  161. }
  162. });
  163. },
  164. watch: {},
  165. methods: {
  166. bindSave: function(e) {
  167. var _this = this;
  168. _this.$request.post(_this.posturl, {
  169. update: _this.update,
  170. orderid: _this.orderid,
  171. registerfield: JSON.stringify(_this.registerfield)
  172. }).then(res => {
  173. if (res.errno != 0) {
  174. uni.showToast({
  175. title: res.msg,
  176. icon: 'none'
  177. });
  178. return;
  179. } else {
  180. //console.log(res.errno);
  181. uni.showModal({
  182. title: '提示',
  183. content: res.msg,
  184. showCancel: false,
  185. //是否显示取消按钮
  186. success: function(res) {
  187. if (res.cancel) { //点击取消,默认隐藏弹框
  188. } else {
  189. if (_this.gourl != 'no') {
  190. if (_this.gotype == 'reLaunch') {
  191. uni.reLaunch({
  192. url: _this.gourl + "?ptype=" + _this.ptype
  193. });
  194. } else {
  195. _this.sam.navigateTo(_this.gourl + "?ptype=" + _this
  196. .ptype);
  197. //console.log(_this.gourl);
  198. }
  199. }
  200. }
  201. }
  202. });
  203. }
  204. });
  205. },
  206. selcate: function(e) {
  207. var item = e.currentTarget.dataset.val.toString();
  208. var index = e.currentTarget.dataset.index;
  209. if (this.registerfield[index].fieldsvalue.includes(item)) {
  210. this.delcateids(index, item);
  211. } else {
  212. this.registerfield[index].fieldsvalue.push(item);
  213. }
  214. },
  215. bindSelectChange: function(e) {
  216. if (e.detail.value) {
  217. this.registerfield[e.currentTarget.dataset.index].fieldsvalue = this.registerfield[e.currentTarget
  218. .dataset.index].selectvaluearray[e.detail.value].val;
  219. this.registerfield[e.currentTarget.dataset.index].fieldsvalue_name = this.registerfield[e
  220. .currentTarget
  221. .dataset.index].selectvaluearray[e.detail.value].key;
  222. }
  223. },
  224. delcateids: function(index, val) {
  225. var sel = this.registerfield[index].fieldsvalue.findIndex(item => {
  226. if (item == val) {
  227. return true;
  228. }
  229. })
  230. // console.log(index)
  231. this.registerfield[index].fieldsvalue.splice(sel, 1)
  232. },
  233. chooseImg: function(key) {
  234. var _this = this;
  235. uni.chooseImage({
  236. count: 1,
  237. // 默认9
  238. sizeType: ['original', 'compressed'],
  239. // 可以指定是原图还是压缩图,默认二者都有
  240. sourceType: ['album', 'camera'],
  241. // 可以指定来源是相册还是相机,默认二者都有
  242. success: function(res) {
  243. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  244. var tempFilePaths = res.tempFilePaths;
  245. _this.Imgupload(key, tempFilePaths[0]);
  246. }
  247. });
  248. },
  249. Imgupload: function(key, path) {
  250. var _this = this;
  251. _this.$request.uploadFile(path).then(res => {
  252. _this.registerfield[key].fieldsvalue = res.url;
  253. });
  254. },
  255. onChangePosition: function(key) {
  256. const _this = this;
  257. console.log('sdfasdf');
  258. uni.chooseLocation({
  259. success(res) {
  260. _this.$request.post('geocoder.address2area', {
  261. address: res.address,
  262. latitude: res.latitude,
  263. longitude: res.longitude
  264. }).then(apires => {
  265. console.log(res);
  266. _this.registerfield[key].fieldsvalue = {
  267. region_name: res.name,
  268. address: res.address,
  269. province_name: apires.data.province_name,
  270. city_name: apires.data.city_name,
  271. district_name: apires.data.district_name || '',
  272. latitude: res.latitude,
  273. longitude: res.longitude,
  274. };
  275. });
  276. }
  277. });
  278. },
  279. uploadresult: function(e) {
  280. console.log(e)
  281. this.registerfield[e.params].fieldsvalue = e.imgArr;
  282. },
  283. remove: function(e) {
  284. //移除图片
  285. //console.log(e)
  286. let index = e.index
  287. }
  288. }
  289. }
  290. </script>
  291. <style lang="scss" scoped>
  292. .tui-list-cell {
  293. width: 100%;
  294. color: $uni-text-color;
  295. display: flex;
  296. align-items: center;
  297. justify-content: space-between;
  298. padding: 24rpx 60rpx 24rpx 30rpx;
  299. box-sizing: border-box;
  300. font-size: 30rpx;
  301. }
  302. .tui-line-cell {
  303. width: 100%;
  304. padding: 24rpx 30rpx;
  305. box-sizing: border-box;
  306. display: flex;
  307. align-items: center;
  308. }
  309. .tui-title {
  310. color: #888888;
  311. width: 180rpx;
  312. font-size: 28rpx;
  313. flex-shrink: 0;
  314. }
  315. .tui-title-city-text {
  316. width: 180rpx;
  317. height: 40rpx;
  318. display: block;
  319. line-height: 46rpx;
  320. }
  321. .tui-input {
  322. width: 500rpx;
  323. }
  324. .tui-avatar {
  325. width: 130rpx;
  326. height: 130rpx;
  327. display: block;
  328. }
  329. .tui-img__title {
  330. padding-bottom: 24rpx;
  331. }
  332. .uni-list {
  333. width: 100%;
  334. padding-top: 15rpx;
  335. padding-bottom: 20rpx;
  336. padding-left: 20rpx;
  337. padding-right: 20rpx;
  338. box-sizing: border-box;
  339. display: flex;
  340. align-items: center;
  341. flex-wrap: wrap;
  342. }
  343. .ptypebut {
  344. width: 40%;
  345. display: flex;
  346. align-items: center;
  347. justify-content: center;
  348. flex-direction: column;
  349. padding-top: 5rpx;
  350. padding-bottom: 5rpx;
  351. margin-bottom: 10rpx;
  352. }
  353. .selcss {
  354. color: #fff;
  355. background: #007aff !important;
  356. }
  357. .checkboxbox {
  358. padding: 20rpx;
  359. }
  360. .container {
  361. backgroundColor: #fff;
  362. padding-bottom: 80rpx;
  363. .tui-page-title {
  364. width: 100%;
  365. font-size: 48rpx;
  366. font-weight: bold;
  367. color: $uni-text-color;
  368. line-height: 42rpx;
  369. padding: 110rpx 40rpx 40rpx 40rpx;
  370. box-sizing: border-box;
  371. }
  372. .tui-form {
  373. .tui-view-input {
  374. width: 100%;
  375. box-sizing: border-box;
  376. padding: 0 0rpx;
  377. .tui-cell-input {
  378. width: 100%;
  379. display: flex;
  380. align-items: center;
  381. padding-top: 48rpx;
  382. padding-bottom: $uni-spacing-col-base;
  383. input {
  384. flex: 1;
  385. padding-left: $uni-spacing-row-base;
  386. }
  387. .tui-icon-close {
  388. margin-left: auto;
  389. }
  390. .tui-btn-send {
  391. width: 156rpx;
  392. text-align: right;
  393. flex-shrink: 0;
  394. font-size: $uni-font-size-base;
  395. color: $uni-color-primary;
  396. }
  397. .tui-gray {
  398. color: $uni-text-color-placeholder;
  399. }
  400. .tui-textarea {
  401. width: 100%;
  402. height: 300rpx;
  403. font-size: 28rpx;
  404. padding: 20rpx 30rpx;
  405. box-sizing: border-box;
  406. background-color: #fff;
  407. }
  408. }
  409. }
  410. .tui-cell-text {
  411. width: 100%;
  412. padding: 40rpx $uni-spacing-row-lg;
  413. box-sizing: border-box;
  414. font-size: $uni-font-size-sm;
  415. color: $uni-text-color-grey;
  416. display: flex;
  417. align-items: center;
  418. .tui-color-primary {
  419. color: $uni-color-primary;
  420. padding-left: $uni-spacing-row-sm;
  421. }
  422. }
  423. }
  424. }
  425. .tui-btn-box {
  426. width: 100%;
  427. padding: 0 $uni-spacing-row-lg;
  428. box-sizing: border-box;
  429. margin-top: 20rpx;
  430. }
  431. .btn72 {
  432. width: 100%;
  433. height: 72rpx;
  434. line-height: 72rpx;
  435. border-radius: 98rpx;
  436. color: #fff;
  437. }
  438. .btn86 {
  439. width: 100%;
  440. height: 86rpx;
  441. line-height: 86rpx;
  442. border-radius: 98rpx;
  443. color: #fff;
  444. }
  445. </style>